initial commit
authorMicke Nordin <micke@hal.mickenordin.se>
Sat, 9 Jan 2010 23:25:20 +0000 (00:25 +0100)
committerMicke Nordin <micke@hal.mickenordin.se>
Sat, 9 Jan 2010 23:25:20 +0000 (00:25 +0100)
Makefile [new file with mode: 0755]
main.cpp [new file with mode: 0644]
mnenc.cpp [new file with mode: 0644]
mnenc.hpp [new file with mode: 0644]
mnencd.cpp [new file with mode: 0644]
mnencd.o [new file with mode: 0644]
password.cpp [new file with mode: 0644]
password.hpp [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100755 (executable)
index 0000000..3fdbbe9
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+encryptor : main.o password.o mnenc.o
+       g++ -o mnenc -g -Wall main.o password.o mnenc.o
+
+main.o: main.cpp password.hpp mnenc.hpp
+       g++ -c -g -Wall main.cpp
+
+password.o: password.cpp password.hpp
+       g++ -c -g -Wall password.cpp
+       
+encryptor.o: mnenc.cpp mnenc.hpp
+       g++ -c -g -Wall mnenc.cpp
+       
+clean:
+       rm *.o mnenc
diff --git a/main.cpp b/main.cpp
new file mode 100644 (file)
index 0000000..6ec947d
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,45 @@
+//      main.cpp
+//      
+//      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.
+
+
+
+#include "mnenc.hpp"
+#include "password.hpp"
+
+int main(int argc, char** argv)
+{
+       mnenc menc = mnenc();
+       if(argc == 1) {
+               menc.genkey("MittMaster lösenord0092992££$$€");
+               std::cout << "Genererar key från hårdkodad lösenord\n";
+       } else {
+               menc.genkey(argv[1]);
+               std::cout << "Genererar key från medskickat lösenord\n";
+
+       }
+       std::string dec ="HarTestarJag LITE0123456789]][[[++++099";
+       std::string key = menc.get_key();
+       std::string enc = menc.encrypt(key, dec);
+       password pw = password(enc, dec, key);
+       pw.to_string();
+       pw.to_file("Passwdtest.txt");
+       pw.from_file("Passwdtest.txt"),
+       pw.to_string();
+       return 0;
+}
diff --git a/mnenc.cpp b/mnenc.cpp
new file mode 100644 (file)
index 0000000..92d6dc2
--- /dev/null
+++ b/mnenc.cpp
@@ -0,0 +1,65 @@
+//      mnenc.cpp\r
+//      \r
+//      Copyright 2010 Micke Nordin <mickewiki@gmail.com>\r
+//      \r
+//      This program is free software; you can redistribute it and/or modify\r
+//      it under the terms of the GNU General Public License as published by\r
+//      the Free Software Foundation; either version 3 of the License, or\r
+//      (at your option) any later version.\r
+//      \r
+//      This program is distributed in the hope that it will be useful,\r
+//      but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+//      GNU General Public License for more details.\r
+//      \r
+//      You should have received a copy of the GNU General Public License\r
+//      along with this program; if not, write to the Free Software\r
+//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\r
+//      MA 02110-1301, USA.\r
+\r
+\r
+\r
+#include <iostream>\r
+#include <string>\r
+#include <fstream>\r
+#include <cstdlib>\r
+#include <ctime>\r
+#include "mnenc.hpp"\r
+\r
+mnenc::mnenc() {\r
+       key = "";\r
+}\r
+\r
+void mnenc::genkey(std::string str) {\r
+       key = str + str + str + str + str + str + str + str + str;\r
+}\r
+\r
+std::string mnenc::encrypt(std::string key, std::string str) {\r
+       for(int i=0; i < (signed) str.size(); i++)      {\r
+               str[i]=str[i]^key[i];\r
+       }\r
+       return str;\r
+}\r
\r
+std::string mnenc::decrypt(std::string key, std::string passwd) {\r
+       for(int i=0; i < (signed) passwd.size(); i++)   {\r
+               passwd[i] = key[i] ^ passwd[i];\r
+       }\r
+       return passwd;\r
+}\r
+std::string mnenc::get_key() {\r
+       if(key != "") {\r
+               return key;\r
+       } else {\r
+               std::cerr << "Error: No key generated.";\r
+               return key;\r
+       }\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
diff --git a/mnenc.hpp b/mnenc.hpp
new file mode 100644 (file)
index 0000000..28ecd83
--- /dev/null
+++ b/mnenc.hpp
@@ -0,0 +1,42 @@
+//      mnenc.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 _mnenc_h_included_
+#define _mnenc_h_included_
+#include <iostream>
+#include <string>
+#include <fstream>
+#include <cstdlib>
+#include <ctime>
+
+
+class mnenc{
+       private: 
+               std::string key;
+               
+       public:
+               mnenc();
+               void genkey(std::string str);
+               std::string encrypt(std::string key, std::string str);
+               std::string decrypt(std::string key, std::string passwd);
+               std::string get_key();
+};
+
+#endif
diff --git a/mnencd.cpp b/mnencd.cpp
new file mode 100644 (file)
index 0000000..52cdace
--- /dev/null
@@ -0,0 +1,142 @@
+//      mdaemon.cpp
+//      
+//      Copyright 2010 Micke Nordin <micke@hal>
+//      
+//      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 2 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.
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <fcntl.h>
+#include <cstdio>
+#include <cstdlib>
+#include <string>
+#include <cerrno>
+#include <fstream>
+#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();
+}
+
+
+int main(int argc, char** argv) {
+       /* Our process ID and Session ID */
+       pid_t pid, sid;
+       
+       /* Fork off the parent process */
+       pid = fork();
+       if (pid < 0) {
+               exit(EXIT_FAILURE);
+       }
+       /* If we got a good PID, then
+          we can exit the parent process. */
+       if (pid > 0) {
+               exit(EXIT_SUCCESS);
+       }
+
+       /* Change the file mode mask */
+       umask(0);
+               
+       /* Open any logs here */        
+               
+       /* Create a new SID for the child process */
+       sid = setsid();
+       if (sid < 0) {
+               /* Log the failure */
+               exit(EXIT_FAILURE);
+       }
+       
+
+       
+       /* Change the current working directory */
+       if ((chdir("/home/micke/.fifo")) < 0) {
+               /* Log the failure */
+               exit(EXIT_FAILURE);
+       }
+       
+       /* Close out the standard file descriptors */
+       close(STDIN_FILENO);
+       close(STDOUT_FILENO);
+       close(STDERR_FILENO);
+       
+       /* Daemon-specific initialization goes here */
+       
+       mkfifo("./fife", 0777);
+
+       /* The Big Loop */
+       while (1) {
+               m_send(do_something(m_read()));
+               sleep(1); /* wait 1 second*/
+       }
+       unlink("fife");
+       exit(EXIT_SUCCESS);
+}
diff --git a/mnencd.o b/mnencd.o
new file mode 100644 (file)
index 0000000..f284cde
Binary files /dev/null and b/mnencd.o differ
diff --git a/password.cpp b/password.cpp
new file mode 100644 (file)
index 0000000..5ec2cd6
--- /dev/null
@@ -0,0 +1,60 @@
+//      password.cpp
+//      
+//      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.
+
+#include "password.hpp"
+#include <iostream>
+#include <fstream>
+password::password(std::string enc, std::string dec, std::string k) {
+       encryptedpw = enc;
+       decryptedpw = dec;
+       key = k;
+}
+void password::to_string() {
+       std::cout << "Encrypted: " << encryptedpw << std::endl;
+       std::cout << "Decrypted: " << decryptedpw << std::endl;
+}
+
+bool password::to_file(std::string filename) {
+       bool worked = false;
+       std::ofstream keyfile;
+       if(keyfile.open(filename.c_str())) {
+               keyfile << encryptedpw;
+               keyfile.close();
+               worked = true;
+       }
+       return worked;
+}
+
+bool password::from_file(std::string filename) {
+       bool worked = false;
+       std::ifstream keyfile(filename.c_str());
+       std::string k = "";
+       std::string line = "";
+       if (keyfile.is_open()) {
+               while (! keyfile.eof() ) {
+                       getline (keyfile,line);
+                       k += line;
+               }
+               keyfile.close();
+               worked = true;
+       }
+       key = k;
+       return worked;
+}
+
diff --git a/password.hpp b/password.hpp
new file mode 100644 (file)
index 0000000..51ba65c
--- /dev/null
@@ -0,0 +1,39 @@
+//      password.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 _password_h_included_
+#define _password_h_included_
+#include <string>
+
+class password {
+       private:
+               std::string encryptedpw;
+               std::string decryptedpw;
+               std::string key;
+       public:
+               password(std::string enc, std::string dec, std::string k);
+               void to_string();               
+               std::string get_enc() {return encryptedpw;}
+               std::string get_dec() {return decryptedpw;}
+               std::string get_key() {return key;}
+               bool to_file(std::string filename);             
+               bool from_file(std::string filename);
+};
+#endif