From: Micke Nordin Date: Tue, 19 Jan 2010 20:24:21 +0000 (+0100) Subject: Starting to move stuff in to a lib X-Git-Url: http://git.maemo.org/git/?p=mnenc;a=commitdiff_plain;h=0c123c0a3e5c6b5a1716e63f56cb0e9ffce8bded Starting to move stuff in to a lib --- diff --git a/artwork/demon.svg b/artwork/demon.svg new file mode 100644 index 0000000..9a251f1 --- /dev/null +++ b/artwork/demon.svg @@ -0,0 +1,304 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/artwork/key24.png b/artwork/key24.png new file mode 100644 index 0000000..a62c05b Binary files /dev/null and b/artwork/key24.png differ diff --git a/artwork/key48.png b/artwork/key48.png new file mode 100644 index 0000000..472fd2f Binary files /dev/null and b/artwork/key48.png differ diff --git a/artwork/key64.png b/artwork/key64.png new file mode 100644 index 0000000..23974ce Binary files /dev/null and b/artwork/key64.png differ diff --git a/artwork/key_logo.png b/artwork/key_logo.png new file mode 100644 index 0000000..242a7a2 Binary files /dev/null and b/artwork/key_logo.png differ diff --git a/libmnenc/Makefile b/libmnenc/Makefile new file mode 100755 index 0000000..de68ef1 --- /dev/null +++ b/libmnenc/Makefile @@ -0,0 +1,46 @@ +CXX=g++ +all: libmnenc.so libmnenc.la + +libmnenc.so: mnenc.cpp + $(CXX) -fPIC -g -c -Wall mnenc.cpp + $(CXX) -shared -Wl,-soname,libmnenc.so.1 -o libmnenc.so.0.0.0 mnenc.o -lc + +libmnenc.la: mnenc.cpp + libtool --mode=compile g++ -Wall -c mnenc.cpp + libtool --mode=link g++ -Wall -o libmnenc.la mnenc.lo + ar -cvq libmnenc.a mnenc.o + +install-static: + cp libmnenc.a /usr/lib/ + cp libmnenc.la /usr/lib/ + cp mnenc.hpp /usr/include/ + +install-dynamic: + cp libmnenc.so.0.0.0 /usr/lib/ + ln -s /usr/lib/libmnenc.so.0.0.0 /usr/lib/libmnenc.so.0 + ln -s /usr/lib/libmnenc.so.0.0.0 /usr/lib/libmnenc.so.1 + ln -s /usr/lib/libmnenc.so.0.0.0 /usr/lib/libmnenc.so + +install: install-dynamic install-static + +.PHONY: uninstall-dynamic +uninstall-dynamic: + rm /usr/lib/libmnenc.so.0.0.0 /usr/lib/libmnenc.so.0 /usr/lib/libmnenc.so.1 /usr/lib/libmnenc.so + +.PHONY: uninstall-static +uninstall-static: + rm /usr/lib/libmnenc.la /usr/lib/libmnenc.a + +.PHONY: uninstall +uninstall: uninstall-dynamic uninstall-static + +.PHONY: clean-dynamic +clean-dynamic: + rm -rf libmnenc.so.0.0.0 mnenc.o .libs + +.PHONY: clean-static +clean-static: + rm -rf libmnenc.la libmnenc.a mnenc.o mnenc.lo .libs + +.PHONY: clean +clean: clean-static clean-dynamic diff --git a/libmnenc/mnenc.cpp b/libmnenc/mnenc.cpp new file mode 100644 index 0000000..0e162da --- /dev/null +++ b/libmnenc/mnenc.cpp @@ -0,0 +1,159 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "mnenc.hpp" + +using namespace std; + +mnenc::mnenc() { //Constructor + make_folder(); + get_imei(); //see get_imei below + imei += imei; //imei now have 30 digits + imei += imei; //imei now have 60 digits + imei += imei; //imei now have 120 digits + imei += imei; //imei now have 240 digits, should now be longer than any password +} + +void mnenc::encrypt(string str) { //Run xor against imei + for(int i=0; i < (signed) str.size(); i++) { + str[i] = str[i] ^ imei[i]; + } + enc = str; +} + +void mnenc::decrypt(string str) { //Same as above only the other way around + for(int i = 0; i < (signed) enc.size(); i++) { + str[i] = imei[i] ^ str[i]; + } + dec = str; +} + +bool mnenc::to_file(string filename) { //Save to file + bool worked = false; + ofstream keyfile; + keyfile.open(filename.c_str()); + if(keyfile.is_open()) { + keyfile << enc; + keyfile.close(); + worked = true; + } + return worked; +} + +bool mnenc::from_file(string filename) { //Read password file + bool worked = false; + ifstream keyfile(filename.c_str()); + string encryptedpw = ""; + string line = ""; + if (keyfile.is_open()) { + while (! keyfile.eof() ) { + getline (keyfile,line); + encryptedpw += line; + } + keyfile.close(); + worked = true; + } + enc = encryptedpw; + decrypt(enc); // Automatically decrypt password on read + return worked; +} + +string mnenc::genkey() { + string key = ""; + srand(time(NULL)); + for(int i = 0; i < 15; i++) { + key += (rand() % 10); //generate a random number between 0 and 9 + } + string username = getenv("USER"); //Get username + string filename = "/home/" + username + "/.mnenc/.keyfile"; //This is where the key goes + ofstream os; + os.open(filename.c_str()); + if(os.is_open()) { + os << key; + os.close(); + } + return key; +} +void mnenc::get_imei() { + /* TODO + * Implement this in c++ since it is realy realy ugly to shell out like this... + */ + + string username = getenv("USER"); //Get username + string filename = "/home/" + username + "/.mnenc/.keyfile"; //This is where the key goes if we generate it + string cmd = "dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.SIM /com/nokia/phone/SIM/security Phone.Sim.Security.get_imei | grep string | sed -e 's/^.*\\\"\\([0-9]\\)/\\1/' -e 's/\\\"//'"; //Command used when shelling out to get imei + if(system(cmd.c_str()) == 0) { //if we can get imei from dbus + FILE *fp; //a file pointer + char buffer[1024]; //Some tmp storage + fp = popen(cmd.c_str(), "r"); //Open a pipe whith the command + while ( fgets(buffer, 1024, fp) != NULL ) //Read the result + imei.append(buffer); //Add the result to our attribute + pclose(fp); //Close the pipe + } else { //If we could not get imei + ifstream keyfile(filename.c_str()); //open the keyfile + string k = ""; + string line = ""; + if (keyfile.is_open()) { //if it worked + while (! keyfile.eof() ) { //Get the key from there + getline (keyfile,line); + k += line; + } + keyfile.close(); //Close the file + imei = k; //And save result + } else { //If that didnt work + imei = genkey(); //generate a new key and save that to teh keyfile + } + + } +} + +bool mnenc::user_from_file(string filename) { //Read userfile (Added by hexagon 2010-01-17) + bool worked = false; + ifstream userfile(filename.c_str()); + string buf = ""; + string line = ""; + if (userfile.is_open()) { + while (! userfile.eof() ) { + getline (userfile,line); + buf += line; + } + userfile.close(); + worked = true; + } + user = buf; + return worked; +} + +bool mnenc::user_to_file(string filename) { //Save username to file (Added by hexagon 2010-01-17) + bool worked = false; + ofstream userfile; + userfile.open(filename.c_str()); + if(userfile.is_open()) { + userfile << user; + userfile.close(); + worked = true; + } + return worked; +} + +void mnenc::set_user(string usr) { // Sets username (Added by hexagon 2010-01-17) + user = usr.c_str(); +} + +string mnenc::get_user() { // Gets username (Added by hexagon 2010-01-17) + return user; +} + +void mnenc::make_folder() { + string username = getenv("USER"); //Get username + string foldername = "/home/" + username + "/.mnenc"; //This is where the key goes + int ret = chdir(foldername.c_str()); + if(ret != 0) { + mkdir(foldername.c_str(), 0755); + } +} diff --git a/libmnenc/mnenc.hpp b/libmnenc/mnenc.hpp new file mode 100644 index 0000000..5bea13a --- /dev/null +++ b/libmnenc/mnenc.hpp @@ -0,0 +1,62 @@ +/* -------------------------------------------------------------------------------------------- +Copyright 2010 Micke Nordin . All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list + of conditions and the following disclaimer in the documentation and/or other materials + provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY Micke Nordin ``AS IS'' AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Micke Nordin OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those of the +authors and should not be interpreted as representing official policies, either expressed +or implied, of Micke Nordin. +------------------------------------------------------------------------------------------- */ + + +#ifndef _mnenc_h_ +#define _mnenc_h_ +#include + +using namespace std; + +class mnenc { + private: + string dec; //Decrypted password + string enc; //Encrypted password + string user; //Username + string imei; //Imei + void get_imei(); //Gets the imei of the phone + void set_enc(string str) {enc = str;}; //set encrypted password + void set_dec(string str) {dec = str;}; //set decrypted password + string genkey(); //generate a key to be used instead of imei + void make_folder(); //Create /home/user/.qtify if it doesnt exist + + public: + mnenc(); + void encrypt(string str); //encrypt password + void decrypt(string str); //decrypt password + string get_dec() {return dec;}; //get decrypted password + string get_enc() {return enc;}; //Get encrypted password + bool to_file(string filename); //Save to file + bool from_file(string filename); //get from file + /* Added by hexagon */ + bool user_to_file(string filename); //Save to file + bool user_from_file(string filename); //get from file + void set_user(string user); + string get_user(); +}; +#endif diff --git a/libmnenc/mnenc_test.cpp b/libmnenc/mnenc_test.cpp new file mode 100644 index 0000000..5b46b8f --- /dev/null +++ b/libmnenc/mnenc_test.cpp @@ -0,0 +1,19 @@ +#include +#include + +using namespace std; + +int main(int argc, char** argv) +{ + mnenc micke; //Declare a encryptor/decryptor + micke.encrypt("Blahonga"); //Encrypt the password Blahonga + micke.decrypt(micke.get_enc()); //Decrypt the password + cout << micke.get_enc() << endl; //Display encrypted password + cout << micke.get_dec() << endl; //Display decrypted password + micke.to_file("deletethistestfile.txt"); //Save to file + micke.from_file("deletethistestfile.txt"); //Read from file + cout << micke.get_enc() << endl; //Display encrypted password + cout << micke.get_dec() << endl; //Display decrypted password + + return 0; +} diff --git a/mnencd.hpp b/mnencd.hpp index 4eb4bb2..ba7e6a8 100644 --- a/mnencd.hpp +++ b/mnencd.hpp @@ -71,8 +71,22 @@ void put_password(std::string masterpasswd, std::string passwd, std::string user password pw = password(menc.encrypt(key, passwd ), "", key); pw.to_file(make_filename(user, app)); } +std::string do_something(std::string str) { //Handle requests for secure pipe + pid_t proc = fork(); + std::string reply = ""; + if( proc == 0 ) { // child + reply = open_connection( str ); + } else if( p > 0 ) { // parent + // Store p somewhere + } else { // fork failed + } + + return reply; +} +std::string open_connection(std::string str) { -std::string do_something(std::string str) { //Handle requests +} +std::string do_something_else(std::string str) { //Handle requests std::vector request; //Incomming message stored here request = explode(str, "|"); //explode request with function from php.hpp