First sucessfull comunication
authorMicke Nordin <mickewiki@gmail.com>
Sun, 10 Jan 2010 10:51:12 +0000 (11:51 +0100)
committerMicke Nordin <mickewiki@gmail.com>
Sun, 10 Jan 2010 10:51:12 +0000 (11:51 +0100)
COPYRIGHT
client.sh [new file with mode: 0755]
mnencd.cpp
mnencd.hpp [new file with mode: 0644]
protocol_v_0.txt [new file with mode: 0644]

index 73a87ca..442b48b 100644 (file)
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -1,2 +1,2 @@
 mencd.cpp i realeased under a three clause BSD license and all other
-files is released under GPL v.3.
+files is released under GPL v.3 or later.
diff --git a/client.sh b/client.sh
new file mode 100755 (executable)
index 0000000..6a8c2ed
--- /dev/null
+++ b/client.sh
@@ -0,0 +1,4 @@
+#/bin/bash
+
+echo "$1" > /home/micke/.fifo/fife
+cat /home/micke/.fifo/fife
index b419432..68be9a5 100644 (file)
@@ -40,63 +40,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <iostream>
 #include "mnenc.hpp"
 #include "password.hpp"
-
-std::string remove_char(std::string str, char c) {
-       std::string::size_type k = 0;
-       while((k=str.find(c,k))!=str.npos) {
-               str.erase(k, 1);
-       }
-       return str;
-}
-
-std::string remove_chars(std::string str) {
-       std::string chars = " \t\n\b\a-?+\\{[]}'*'";
-       for(int i = 0; i < (signed) chars.size(); i++) {
-               str = remove_char(str, chars[i]);
-       }
-       
-       return str;     
-}
-
-std::string make_filename(std::string user, std::string app) {
-       return remove_chars(app + user);
-}
-std::string get_password(std::string masterpasswd, std::string user, std::string app) {
-       mnenc menc = mnenc();
-       menc.genkey(masterpasswd);
-       std::string key = menc.get_key();
-       password pw = password("", "", key);
-       pw.from_file(make_filename(user, app));
-       return menc.decrypt(key, pw.get_enc());
-}
-
-void put_password(std::string masterpasswd, std::string passwd, std::string user, std::string app) {
-       mnenc menc = mnenc();
-       menc.genkey(masterpasswd);
-       std::string key = menc.get_key();
-       password pw = password(menc.encrypt(key, passwd ), "", key);
-       pw.to_file(make_filename(user, app));
-}
-
-std::string do_something(std::string str) {
-       //Nothing here yet
-       return "Blahonga";
-}
-
-std::string m_read() {
-       std::string str;
-       std::ifstream is("fife");
-       getline(is, str);
-       is.close();
-       return str;
-}
-
-void m_send(std::string message) {
-       std::ofstream os("fife");
-       os << message;
-       os.close();
-}
-
+#include "mnencd.hpp"
 
 int main(int argc, char** argv) {
        /* Our process ID and Session ID */
@@ -142,7 +86,9 @@ int main(int argc, char** argv) {
 
        /* The Big Loop */
        while (1) {
-               m_send(do_something(m_read()));
+               std::string request = m_read();
+               std::string reply = do_something(request);
+               m_send(reply);
                sleep(1); /* wait 1 second*/
        }
        unlink("fife");
diff --git a/mnencd.hpp b/mnencd.hpp
new file mode 100644 (file)
index 0000000..379f7f9
--- /dev/null
@@ -0,0 +1,83 @@
+//      mnencd.hpp
+//      
+//      Copyright 2010 Micke Nordin <mickewiki@gmail.com>
+//      
+//      This program is free software; you can redistribute it and/or modify
+//      it under the terms of the GNU General Public License as published by
+//      the Free Software Foundation; either version 3 of the License, or
+//      (at your option) any later version.
+//      
+//      This program is distributed in the hope that it will be useful,
+//      but WITHOUT ANY WARRANTY; without even the implied warranty of
+//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//      GNU General Public License for more details.
+//      
+//      You should have received a copy of the GNU General Public License
+//      along with this program; if not, write to the Free Software
+//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+//      MA 02110-1301, USA.
+#ifndef _mnencd_h_included_
+#define _mnencd_h_included_
+#include <string>
+#include <iostream>
+#include <fstream>
+
+std::string remove_char(std::string str, char c) {
+       std::string::size_type k = 0;
+       while((k=str.find(c,k))!=str.npos) {
+               str.erase(k, 1);
+       }
+       return str;
+}
+
+std::string remove_chars(std::string str) {
+       std::string chars = " \t\n\b\a-?+\\{[]}'*'";
+       for(int i = 0; i < (signed) chars.size(); i++) {
+               str = remove_char(str, chars[i]);
+       }
+       
+       return str;     
+}
+
+std::string make_filename(std::string user, std::string app) {
+       return remove_chars(app + user);
+}
+std::string get_password(std::string masterpasswd, std::string user, std::string app) {
+       mnenc menc = mnenc();
+       menc.genkey(masterpasswd);
+       std::string key = menc.get_key();
+       password pw = password("", "", key);
+       pw.from_file(make_filename(user, app));
+       return menc.decrypt(key, pw.get_enc());
+}
+
+void put_password(std::string masterpasswd, std::string passwd, std::string user, std::string app) {
+       mnenc menc = mnenc();
+       menc.genkey(masterpasswd);
+       std::string key = menc.get_key();
+       password pw = password(menc.encrypt(key, passwd ), "", key);
+       pw.to_file(make_filename(user, app));
+}
+
+std::string do_something(std::string str) {
+       if(str[0] == '0')       {
+               return "201_Created\n";
+       } else {
+               return "400_Bad_Request " + str + '\n';
+       }
+}
+
+std::string m_read() {
+       std::string str;
+       std::ifstream is("fife");
+       getline(is, str);
+       is.close();
+       return str;
+}
+
+void m_send(std::string message) {
+       std::ofstream os("fife");
+       os << message;
+       os.close();
+}
+#endif
diff --git a/protocol_v_0.txt b/protocol_v_0.txt
new file mode 100644 (file)
index 0000000..4057a6d
--- /dev/null
@@ -0,0 +1,37 @@
+Protocol:
+=Unlock keyring daemon=
+0_Unlock|<masterkey>
+
+==Reply==
+201_Created
+400_Bad_Request 
+500_Internal_Server_Error
+503_Service_Unavailable
+
+=Encrypt password=
+10_Encrypt|<appname>|<username>|<password>
+
+==Reply==
+201_Created
+400_Bad_Request 
+500_Internal_Server_Error
+503_Service_Unavailable
+
+=Decrypt password=
+20_Decrypt|<appname>|<username>
+
+==Reply==
+200_OK |<password>
+400_Bad_Request 
+500_Internal_Server_Error
+503_Service_Unavailable
+
+=Check if password exists=
+30_Check|<appname>|<username>
+
+==Reply==
+201_Created
+400_Bad_Request 
+404_Not_Found
+500_Internal_Server_Error
+503_Service_Unavailable