From 45f7cc5d27b338dae1d36c211cc5720c82f3de35 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 20 Mar 2015 10:57:03 +0400 Subject: Change file architecture --- CryptClass/AESCrypt.cpp | 126 ----------------------- CryptClass/AESCrypt.hpp | 101 ------------------ CryptClass/AbstractSKA.hpp | 57 ----------- CryptClass/HASHCrypt.cpp | 116 --------------------- CryptClass/HASHCrypt.hpp | 135 ------------------------ IOFileClass/FileManIOFile.cpp | 147 --------------------------- IOFileClass/FileManIOFile.hpp | 133 ------------------------ ParserClass/AbstractIDManager.cpp | 39 ------- ParserClass/AbstractIDManager.hpp | 59 ----------- ParserClass/FileManContainer/Website.cpp | 67 ------------ ParserClass/FileManContainer/Website.hpp | 83 --------------- ParserClass/FileManParser.cpp | 132 ------------------------ ParserClass/FileManParser.hpp | 114 --------------------- main.cpp | 80 --------------- src/CryptClass/AESCrypt.cpp | 126 +++++++++++++++++++++++ src/CryptClass/AESCrypt.hpp | 101 ++++++++++++++++++ src/CryptClass/AbstractSKA.hpp | 57 +++++++++++ src/CryptClass/HASHCrypt.cpp | 116 +++++++++++++++++++++ src/CryptClass/HASHCrypt.hpp | 135 ++++++++++++++++++++++++ src/IOFileClass/FileManIOFile.cpp | 147 +++++++++++++++++++++++++++ src/IOFileClass/FileManIOFile.hpp | 133 ++++++++++++++++++++++++ src/ParserClass/AbstractIDManager.cpp | 39 +++++++ src/ParserClass/AbstractIDManager.hpp | 59 +++++++++++ src/ParserClass/FileManContainer/Website.cpp | 67 ++++++++++++ src/ParserClass/FileManContainer/Website.hpp | 83 +++++++++++++++ src/ParserClass/FileManParser.cpp | 132 ++++++++++++++++++++++++ src/ParserClass/FileManParser.hpp | 114 +++++++++++++++++++++ src/main.cpp | 80 +++++++++++++++ 28 files changed, 1389 insertions(+), 1389 deletions(-) delete mode 100644 CryptClass/AESCrypt.cpp delete mode 100644 CryptClass/AESCrypt.hpp delete mode 100644 CryptClass/AbstractSKA.hpp delete mode 100644 CryptClass/HASHCrypt.cpp delete mode 100644 CryptClass/HASHCrypt.hpp delete mode 100644 IOFileClass/FileManIOFile.cpp delete mode 100644 IOFileClass/FileManIOFile.hpp delete mode 100644 ParserClass/AbstractIDManager.cpp delete mode 100644 ParserClass/AbstractIDManager.hpp delete mode 100644 ParserClass/FileManContainer/Website.cpp delete mode 100644 ParserClass/FileManContainer/Website.hpp delete mode 100644 ParserClass/FileManParser.cpp delete mode 100644 ParserClass/FileManParser.hpp delete mode 100644 main.cpp create mode 100644 src/CryptClass/AESCrypt.cpp create mode 100644 src/CryptClass/AESCrypt.hpp create mode 100644 src/CryptClass/AbstractSKA.hpp create mode 100644 src/CryptClass/HASHCrypt.cpp create mode 100644 src/CryptClass/HASHCrypt.hpp create mode 100644 src/IOFileClass/FileManIOFile.cpp create mode 100644 src/IOFileClass/FileManIOFile.hpp create mode 100644 src/ParserClass/AbstractIDManager.cpp create mode 100644 src/ParserClass/AbstractIDManager.hpp create mode 100644 src/ParserClass/FileManContainer/Website.cpp create mode 100644 src/ParserClass/FileManContainer/Website.hpp create mode 100644 src/ParserClass/FileManParser.cpp create mode 100644 src/ParserClass/FileManParser.hpp create mode 100644 src/main.cpp diff --git a/CryptClass/AESCrypt.cpp b/CryptClass/AESCrypt.cpp deleted file mode 100644 index d3ea949..0000000 --- a/CryptClass/AESCrypt.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/** - * @file AESCrypt.cpp - * @brief AESCrypt class definitions - * @author manzerbredes - * @date 8 Mars 2015 - * - * Contain all definitions of AESCrypt class. - * - */ - - -//----- class ----- -#include "AESCrypt.hpp" - - - -//Constructor -AESCrypt::AESCrypt(){ - this->hash=HASHCrypt(); //Init hash attribute -} - -//Destructor -AESCrypt::~AESCrypt(){ - -} - - - -//Encrypt string with string key -std::string AESCrypt::encrypt(std::string key, std::string data){ - - //Generate SHA-256 - byte digest[32]; - hash.getSHA_256(key, digest, (int)sizeof(digest)); - - return encryptRoutine(data, digest, sizeof(digest)); - -} - - - -//Encrypt string with byte* key -std::string AESCrypt::encrypt(byte* key, std::string data){ - return encryptRoutine(data, key, 32); -} - - - -//The encryptRoutine -std::string AESCrypt::encryptRoutine(std::string data, byte* digest, int size){ - //Contain data encrypted - std::string cipher; - - - //Use try, catch to be ensure no problems happening - try{ - //Create encoder to encrypt data - CryptoPP::ECB_Mode::Encryption encoder; - encoder.SetKey( digest, size ); - - //Encrypt data with StreamTransformationFilter with NO PADDING - CryptoPP::StringSource ss1(data, true, - new CryptoPP::StreamTransformationFilter( encoder, - new CryptoPP::StringSink( cipher ), - CryptoPP::StreamTransformationFilter::ZEROS_PADDING - - ) - ); - } - catch( CryptoPP::Exception& e ) - { - std::cerr << e.what() << std::endl; - exit(EXIT_FAILURE); - } - - //return encrypted data - return cipher; - - -} - - - -//Decrypt string -std::string AESCrypt::decrypt(std::string key, std::string data){ - - //Get SHA-256 - byte digest[32]; - hash.getSHA_256(key, digest, (int)sizeof(digest)); - - - //Contain data decrypted - std::string cipher; - - //Use try, catch to be ensure no problems happening - try { - - //Create decoder to encrypt data - CryptoPP::ECB_Mode< CryptoPP::AES >::Decryption decoder; - decoder.SetKey( digest, sizeof(digest) ); - - //Decrypt data with StreamTransformationFilter with NO PADDING - CryptoPP::StringSource ss3( data, true, - new CryptoPP::StreamTransformationFilter( decoder, - new CryptoPP::StringSink( cipher ), - CryptoPP::StreamTransformationFilter::NO_PADDING - ) - ); - } - catch( CryptoPP::Exception& e ) - { - std::cerr << e.what() << std::endl; - exit(1); - } - - //Remove ZEROS padding - int i=0; - for(i=0;i - -//----- crypto++ ----- -#include -#include -#include - - -/** - * @class AESCrypt AESCrypt.hpp "/CryptClass/AESCrypt.hpp" - * @brief Class for Advanced Encryption Standard (AES) algorithm - * @author manzerbredes - * - * This class provide AES encrypt and decrypt. - * Key used is 32 bytes key (256 bits). - * - * \bug Find another solution for managing padding. - */ -class AESCrypt : public AbstractSKA { - - - public: - //Constructor - AESCrypt(); - - //Destructor - ~AESCrypt(); - - - /** - * @brief Run encryptRoutine. - * - * @param key : key used to encrypt data - * @param data : contain data to encrypt. - * - * @return string : correspond to crypted data - * - * Run encryptRoutine with byte* key or string key. - * Allow you to choose between string key or byte key. - * - */ - std::string encrypt(std::string key, std::string data); - std::string encrypt(byte* key, std::string data); - - - /** - * @brief Decrypt data from AES algorithm. - * - * @param key : key used to encrypt data - * @param data : contain data to decrypt from AES encrypt. - * - * @return string : correspond to decrypted data - * - * Decrypt data, and return them into a string. - * - */ - std::string decrypt(std::string key, std::string data); - - - - private: - - /** - * @brief Encrypt data with AES algorithm. - * - * @param key : key used to encrypt data - * @param data : contain data to encrypt. - * - * @return string : correspond to crypted data - * - * Encrypt data, and return them into a string. - * Padding are blank space. - * - */ - std::string encryptRoutine(std::string data, byte* digest, int size); - - - //Attributes: - - HASHCrypt hash; ///< hash instance to generate SHA-256 hash code. - - -}; - -#endif diff --git a/CryptClass/AbstractSKA.hpp b/CryptClass/AbstractSKA.hpp deleted file mode 100644 index 7622ab4..0000000 --- a/CryptClass/AbstractSKA.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @file AbstractSKA.hpp - * @brief Class for Symmetric-Key Algorithm (SKA) - * @author manzerbredes - * @date 8 Mars 2015 - * - * Specify which method the algorithm must be implement. - * - */ - -#ifndef __AbstractSKA__ -#define __AbstractSKA__ - - -//----- std ----- -#include - - - -/** - * @class AbstractSKA AbstractSKA.hpp "/CryptClass/AbstractSKA.hpp" - * @brief Class for Symmetric-Key Algorithm (SKA) - * @author manzerbredes - * - * This class should not be instantiate directly. - * - */ -class AbstractSKA { - - public: - /** - * @brief Encrypt data. - * - * @param key : key used to encrypt data - * @param data : contain data to encrypt. - * - * This method must be overwritten. - * **Warning** data will be modified. - * - */ - virtual std::string encrypt(std::string key, std::string data) = 0; - - - /** - * @brief Decrypt data. - * - * @param key : key used to decrypt data - * @param data : contain data to decrypt. - * - * This method must be overwritten. - * **Warning** data will be modified. - * - */ - virtual std::string decrypt(std::string key, std::string data) = 0; -}; - -#endif diff --git a/CryptClass/HASHCrypt.cpp b/CryptClass/HASHCrypt.cpp deleted file mode 100644 index eed9cb5..0000000 --- a/CryptClass/HASHCrypt.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/** - * @file HASHCrypt.cpp - * @brief HASHCrypt class definitions - * @author manzerbredes - * @date 8 Mars 2015 - * - * Contain all definitions of HASHCrypt class. - * - */ - - -//----- class ----- -#include "HASHCrypt.hpp" - - - -//Constructor -HASHCrypt::HASHCrypt(){ -} - -//Destructor -HASHCrypt::~HASHCrypt(){ -} - - - -//Contruct MD5 over 128 bits and put it into digest -void HASHCrypt::getMD5_128(std::string chain, byte* digest, int size){ - - //Digest size controller - this->checkDigestSize(CryptoPP::Weak1::MD5::DIGESTSIZE,size); - - //Create the MD5 on digest parameter - CryptoPP::Weak1::MD5 hash; - hash.CalculateDigest( digest, (byte*) chain.c_str(), chain.length() ); - -} - - - -//Contruct SHA-256 and put it into digest -void HASHCrypt::getSHA_256(std::string chain, byte* digest, int size){ - - //Digest size controller - this->checkDigestSize(CryptoPP::SHA256::DIGESTSIZE,size); - - //Create the SHA-256 on digest parameter - CryptoPP::SHA256 hash; - hash.CalculateDigest( digest, (byte*) chain.c_str(), chain.length() ); - - -} - - - -//Compare 2 digest (same size) -bool HASHCrypt::compareDigest(byte* digest1, byte* digest2, int size){ - - //Try is more safe - try - { - //Compare the two digest - for(int i=0; igetInvalidDigestSizeError(sizeRequired, size); - } - - } - catch(std::string erreur){ - std::cerr << erreur < -#include -#include - -//----- crypto++ ----- -#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 -#include //For MD5 -#include //For Hex convertion -#include //For SHA - - -/** - * @class HASHCrypt HASHCrypt.hpp "/CryptClass/HASHCrypt.hpp" - * @brief Hashing class - * @author manzerbredes - * - * Class who handle hashing functions on a byte* parameter. - * HASHCrypt try to detect errors and throw exceptions. - * HASHCrypt use crypto++ library. - */ -class HASHCrypt{ - - public: - /** - * @brief Contructor - */ - HASHCrypt(); - - /** - * @brief Destructor - */ - ~HASHCrypt(); - - - /** - * @brief Create an MD5 over 128 bits on a digest array of bytes. - * - * @param chain : Chain to hash - * @param digest : An array of bytes (8 bits) - * @param size : Length of digest - * - * **Warning** digest will be modified. - * Digest must be an array of byte with 16 entries - * Invalid size can cause "Segmentation Fault" - */ - void getMD5_128(std::string chain, byte* digest, int size); - - - /** - * @brief Create an SHA over 256 bits on a digest array of bytes. - * - * @param chain : Chain to hash - * @param digest : An array of bytes (8 bits) - * @param size : Length of digest - * - * **Warning** digest will be modified. - * Digest must be an array of byte with 32 entries - * Invalid size can cause "Segmentation Fault" - */ - void getSHA_256(std::string chain, byte* digest, int size); //Return SHA_256 - - - /** - * @brief Convert digest to a string of HEX characters - * - * @param digest : an array of bytes (8 bits) - * @param size : length of digest - * - * @return return a string of hex digest equivalent - * - * Digest must be an array of byte. - */ - std::string digestToString(byte* digest, int size); //Return a string - - - /** - * @brief Compare 2 digest - * - * @param digest1 : An array of bytes (8 bits) - * @param digest2 : An array of bytes (8 bits) - * @param size : Length of the array digest1 or digest2 - * - * @return return a boolean (true if digest1 equals to digest2 and false else) - * - * **Warning** if sizeof(digest1) != sizeof(digest 2) : segmentation fault ! - * Compare the two digest. - * - */ - bool compareDigest(byte* digest1, byte* digest2, int size); - - - private: - - /** - * @brief Check the digest size - * - * @param sizeRequired : Digest size expected - * @param size : Given digest size - * - * Throw an exception, and stop the program if - * sizeRequired != size - * Use getInvalidDigestSizeError method. - */ - void checkDigestSize(int sizeRequired, int size); - - - /** - * @brief Make "invalid digest size" error message. - * - * @param sizeRequired : Digest size expected - * @param size : Given digest size - * - * @return a string correspond to the error message - * - * Construct an error message with sizeRequired and size. - */ - std::string getInvalidDigestSizeError(int sizeRequired, int size); - -}; - -#endif diff --git a/IOFileClass/FileManIOFile.cpp b/IOFileClass/FileManIOFile.cpp deleted file mode 100644 index ea49201..0000000 --- a/IOFileClass/FileManIOFile.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/** - * @file FileManIOFile.cpp - * @brief FileManIOFile class definitions - * @author manzerbredes - * @date 9 Mars 2015 - * - * Contain all definitions of FileManIOFile class. - * - */ - - -#include "FileManIOFile.hpp" - -//Constructor with filename -FileManIOFile::FileManIOFile(std::string filename){ - this->filename=filename; - this->readable=false; - this->data=""; - this->key; -} - -//Destructor -FileManIOFile::~FileManIOFile(){ -} - - - -//Read the filename with a key -void FileManIOFile::read(std::string key){ - - //create file object - std::ifstream file; - - //Clear data - this->data.clear(); - - //Open file - file.open (this->filename, std::ios::in | std::ios::binary); - - //Get MD5 of decrypted data - byte fileMD5[16]; - file.read((char*) fileMD5, sizeof(fileMD5)); - - //Read all data - char car; - file.read(&car, sizeof(car)); - - while(file){ - this->data+=car, - file.read(&car, sizeof(car)); - - } - - //Decrypt data - this->data=this->aes.decrypt(key, this->data); - - //Get current MD5 of decrypted data - byte currentMD5[16]; - this->hash.getMD5_128(this->data, currentMD5, sizeof(currentMD5)); - - //Compare the 2 MD5 to find if file is fully decrypted - if(this->hash.compareDigest(fileMD5, currentMD5, sizeof(currentMD5))){ - //Set readable - this->readable=true; - //Save the key - this->hash.getSHA_256(key, this->key, 32); - } - else{ - this->readable=false; - } - - //Close file - file.close(); - - -} - - - -//Write file with key -void FileManIOFile::write(std::string key,std::string data){ - - std::string dataEncrypted; - - dataEncrypted=this->aes.encrypt(key, data); - - this->writeRoutine(data, dataEncrypted); - - -} - -//Write file without key -void FileManIOFile::write(std::string data){ - if(not(this->readable)){ - std::cout << "Can't write data without key (read it before) !" << std::endl; - std::exit(EXIT_FAILURE); - } - - std::string dataEncrypted; - - dataEncrypted=this->aes.encrypt(this->key, data); - this->writeRoutine(data, dataEncrypted); - - -} - - - -//Get readable attribute -bool FileManIOFile::isReadable(){ - return this->readable; -} - - - -//Write file -void FileManIOFile::writeRoutine(std::string data, std::string dataEncrypted){ - - //Save MD5 of decrypted data - byte digest[16]; - this->hash.getMD5_128(data, digest, sizeof(digest)); - - //Create file instance - std::ofstream file; - - //Open it - file.open(this->filename, std::ios::out | std::ios::binary); - - //Write MD5 on 16 first bytes - file.write((char *) digest,sizeof(digest)); - - //Write data - file.write(dataEncrypted.c_str(), dataEncrypted.size()); - - //Close file - file.close(); - - //Save data to attribute - this->data=data; -} - - - -//Get data -std::string FileManIOFile::getData(){ - return this->data; -} diff --git a/IOFileClass/FileManIOFile.hpp b/IOFileClass/FileManIOFile.hpp deleted file mode 100644 index 221cf13..0000000 --- a/IOFileClass/FileManIOFile.hpp +++ /dev/null @@ -1,133 +0,0 @@ -/** - * @file FileManIOFile.hpp - * @brief FileManIOFile class definitions - * @author manzerbredes - * @date 9 Mars 2015 - * - * Contain all definitions of FileManIOFile class. - * - */ - - -#ifndef __FileManIOFile__ -#define __FileManIOFile__ - - -//----- std ----- -#include -#include -#include - - -//----- class ----- -#include "HASHCrypt.hpp" -#include "AESCrypt.hpp" - - - - -/** - * @class FileManIOFile FileManIOFile.hpp "/CryptClass/FileManIOFile.hpp" - * @brief Class for quick open and close encrypted files. - * @author manzerbredes - * - * -----File organisation----- - * - * 16 first bytes : md5 of decrypted data - * Rest of the file : data encrypted (ASE for now) - * - * \bug Need check if file exist and can be opened - */ -class FileManIOFile { - - public: - - //Constructor - FileManIOFile(std::string filename); - - //Destructor - ~FileManIOFile(); - - - /** - * @brief Read encrypted file. - * - * @param key : key to encrypt data - * - * Read data from "filename" attribute. - * If file fully decrypted, readable var switch to true, - * and key saved in key attribute (before been crypted with SHA-256 algorithm). - * - */ - void read(std::string key); - - - /** - * @brief Write data in encrypted file. - * - * @param key : key to encrypt data - * @param data : data to write - * - * Write the file with or without key. - * To write data without key, you need to read it before (to save the key - * in attribute key). - * - */ - void write(std::string key, std::string data); - void write(std::string data); - - - /** - * @brief True if file fully decrypted. - * - * @return readable attribute - * - * Return "readable" attribute. - * - */ - bool isReadable(); - - - /** - * @brief Get data attribute. - * - * @return data attribute. - * - * **Warning** if data not fully decrypted (readable!=true), - * data will be unreadable (unparsable). - * - */ - std::string getData(); - - - private: - - /** - * @brief Write data in encrypted file. - * - * @param data : data to write (for MD5) - * @param dataEncrypted : data to write - * - * Write encryptedData to filename - * - */ - void writeRoutine(std::string data, std::string dataEncrypted); - - - //Attributes: - - AESCrypt aes; ///< AES instance - - HASHCrypt hash; ///< HASH instance - - std::string filename; ///< Filename attribute - - std::string data; ///< Data attribute - - bool readable; ///< Readable attribute - - byte key[32]; ///< Key in SHA-256 - -}; - -#endif diff --git a/ParserClass/AbstractIDManager.cpp b/ParserClass/AbstractIDManager.cpp deleted file mode 100644 index e1c5e13..0000000 --- a/ParserClass/AbstractIDManager.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @file AbstractIDManager.cpp - * @brief AbstractIDManager class definitions - * @author manzerbredes - * @date 11 Mars 2015 - * - * Contain all implémentations of AbstractIDManager class. - * - */ - -#include "AbstractIDManager.hpp" - -AbstractIDManager::AbstractIDManager(){ - this->id=this->generateId(); -} - -AbstractIDManager::AbstractIDManager(std::string id){ - this->id=id; -} -AbstractIDManager::~AbstractIDManager(){ - this->id=id; -} - - - -void AbstractIDManager::setId(std::string id){ - this->id = id; -} - -std::string AbstractIDManager::generateId(){ - boost::uuids::uuid uuid = boost::uuids::random_generator()(); - std::stringstream ss; - ss << uuid; - return ss.str(); -} - -std::string AbstractIDManager::getId() const{ - return this->id; -} diff --git a/ParserClass/AbstractIDManager.hpp b/ParserClass/AbstractIDManager.hpp deleted file mode 100644 index 67d5f6f..0000000 --- a/ParserClass/AbstractIDManager.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/** - * @file AbstractIDManager.hpp - * @brief AbstractIDManager class definitions - * @author manzerbredes - * @date 11 Mars 2015 - * - * Contain all definitions of AbstractIDManager class. - * If you want to manage id in class (like container), use - * this class as superclass. - * - */ - -//----- std ----- -#include -#include - - -//----- boost ----- -#include // uuid class -#include // generators -#include // streaming operators etc. - - - - -/** - * @class AbstractIDManager AbstractIDManager.hpp "/CryptClass/AbstractIDManager.hpp" - * @brief Managing ID - * @author manzerbredes - * - * This class should not be instantiate directly. - * - */ - class AbstractIDManager{ - - - public: - //Constructor - AbstractIDManager(); - - //Constructor, init with id - AbstractIDManager(std::string); - - //Destructor - ~AbstractIDManager(); - - - //Getters and setters - std::string getId() const; - void setId(std::string id); - - - private: - //Generate and random id - std::string generateId(); - - std::string id; ///< String id attribute - - }; diff --git a/ParserClass/FileManContainer/Website.cpp b/ParserClass/FileManContainer/Website.cpp deleted file mode 100644 index f65a66d..0000000 --- a/ParserClass/FileManContainer/Website.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/** - * @file Website.cpp - * @brief Website class definitions - * @author manzerbredes - * @date 11 Mars 2015 - * - * Contain all implementations of Website class. - * - */ - - -#include "Website.hpp" - - -//Constructor -Website::Website(){ - -} - - - -//----- Getters ----- -std::string Website::getTitle(){ - return this->title; -} -std::string Website::getUrl(){ - return this->url; -} -std::string Website::getUsername(){ - return this->username; -} -std::string Website::getPassword(){ - return this->password; -} -std::string Website::getDescription(){ - return this->description; -} - - - -//----- Setters ----- -void Website::setTitle(std::string title){ - this->title = title; -} -void Website::setUrl(std::string url){ - this->url = url; -} -void Website::setUsername(std::string username){ - this->username = username; -} -void Website::setPassword(std::string password){ - this->password = password; -} -void Website::setDescription(std::string description){ - this->description = description; -} - - - -//Equality comparator -bool Website::operator==(const Website& website) const{ - if((this->getId()).compare(website.getId())==0){ - return true; - } - return false; -} - diff --git a/ParserClass/FileManContainer/Website.hpp b/ParserClass/FileManContainer/Website.hpp deleted file mode 100644 index cb293d4..0000000 --- a/ParserClass/FileManContainer/Website.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/** - * @file Website.hpp - * @brief Website class definitions - * @author manzerbredes - * @date 11 Mars 2015 - * - * Contain all definitions of Website class. - * - */ - -#ifndef __WEBSITE__ -#define __WEBSITE__ - -#include - - -/** - * @class FileManIOFile FileManIOFile.hpp "/CryptClass/FileManIOFile.hpp" - * @brief Class for quick open and close encrypted file. - * @author manzerbredes - * - * -----File organisation----- - * - * 16 first bytes : md5 of decrypted file - * rest of the file : data encrypted (ASE for now) - * - */ - -#include -#include "AbstractIDManager.hpp" - -/** - * @class Website Website.hpp "/ParserClass/FileManContainer/Website.hpp" - * @brief Class for quick open and close encrypted file. - * @author manzerbredes - * - * Container for website data. - * - */ -class Website : public AbstractIDManager { - - - public: - - Website(); - - /** - * @brief Containner getters. - */ - - std::string getTitle(); - std::string getUrl(); - std::string getUsername(); - std::string getPassword(); - std::string getDescription(); - - - /** - * @brief Containner setters. - */ - void setTitle(std::string title); - void setUrl(std::string url); - void setUsername(std::string username); - void setPassword(std::string password); - void setDescription(std::string description); - - - /** - * @brief Equality comparator - */ - bool operator==(const Website& website) const; - - private: - - std::string title; ///< Title of the website - std::string url; ///< Url of the website - std::string username; ///< username of the account - std::string password; ///< password of the account - std::string description; ///< Description of the website -}; - - -#endif diff --git a/ParserClass/FileManParser.cpp b/ParserClass/FileManParser.cpp deleted file mode 100644 index 57a485a..0000000 --- a/ParserClass/FileManParser.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/** - * @file FileManParser.cpp - * @brief FileManParser class definitions - * @author manzerbredes - * @date 11 Mars 2015 - * - * Contain all implementations of FileManParser class. - * - */ - - -#include "FileManParser.hpp" - - -FileManParser::FileManParser(std::string data){ - - //String to stringstream - (this->dataStream) << data; - - //Create parser - //parser.parse_stream(dataStream); - (this->parser).parse_file("Doxygen/doc.xml"); - - //Retrieve document - this->document=(this->parser).get_document(); - - //Init root Node - this->rootNode=(this->document)->get_root_node(); - - //Init container: - this->initWebsites(); - - - -} - - -std::string FileManParser::getDocument(){ - std::string data=(this->document)->write_to_string(); - return data; -} - - -std::vector* FileManParser::getWebsites(){ - return this->websites; -} - - - - -//----------------Container part------------------------ -void FileManParser::initWebsites(){ - this->websites=new std::vector; - - std::vector websitesNodeSet=this->rootNode->find("//websites"); - this->websitesNode=websitesNodeSet.at(0); - - std::vector websiteNodeSet=this->websitesNode->find("*"); - - for(int i=0;iget_attribute_value("id")); - - std::vector websiteChildren=current->find("*"); - - for(int j=0;j contentNodes=currentChild->get_children(); - xmlpp::CdataNode* cdataNode=(xmlpp::CdataNode*)contentNodes.front(); - std::string cdataContent=cdataNode->get_content(); - - - if(currentChild->get_name().compare("title")==0){ - newWebsite.setTitle(cdataContent); - } - else if(currentChild->get_name().compare("url")==0){ - newWebsite.setUrl(cdataContent); - } - else if(currentChild->get_name().compare("username")==0){ - newWebsite.setUsername(cdataContent); - } - else if(currentChild->get_name().compare("password")==0){ - newWebsite.setPassword(cdataContent); - } - else if(currentChild->get_name().compare("description")==0){ - newWebsite.setDescription(cdataContent); - } - } - this->websites->push_back(newWebsite); - } -} - - - - - - - - - -void FileManParser::updateParser(){ - this->rootNode->remove_child(this->websitesNode); - - xmlpp::Element* websitesNode=this->rootNode->add_child("websites"); - this->websitesNode=(xmlpp::Node*)websitesNode; - - for(int i=0;iwebsites->size();i++){ - xmlpp::Element* current=this->websitesNode->add_child("website"); - Website currentWebsite=this->websites->at(i); - - current->set_attribute("id", currentWebsite.getId()); - xmlpp::Element* title=current->add_child("title"); - title->add_child_cdata(currentWebsite.getTitle()); - - xmlpp::Element* url=current->add_child("url"); - url->add_child_cdata(currentWebsite.getUrl()); - - xmlpp::Element* username=current->add_child("username"); - username->add_child_cdata(currentWebsite.getUsername()); - - xmlpp::Element* password=current->add_child("password"); - password->add_child_cdata(currentWebsite.getPassword()); - - xmlpp::Element* description=current->add_child("description"); - description->add_child_cdata(currentWebsite.getDescription()); - - } -} diff --git a/ParserClass/FileManParser.hpp b/ParserClass/FileManParser.hpp deleted file mode 100644 index f0d01e5..0000000 --- a/ParserClass/FileManParser.hpp +++ /dev/null @@ -1,114 +0,0 @@ -/** - * @file FileManParser.hpp - * @brief FileManParser class definitions - * @author manzerbredes - * @date 11 Mars 2015 - * - * Contain all definitions of FileManParser class. - * - */ - - - -#ifndef __FileManParser__ -#define __FileManParser__ - - - -//----- std ----- -#include -#include -#include -#include - -//----- class ----- -#include "Website.hpp" - -//----- libxml++ ----- -#include -#include - - - -/** - * @class FileManParser FileManParser.hpp "/ParserClass/FileManContainer/FileManParser.hpp" - * @brief Class for parser un xml file in a string. - * @author manzerbredes - * - * Parse string using libxml++ library. - * - */ -class FileManParser{ - - - public: - - //Constructor - FileManParser(std::string data); - - - /** - * @brief Get document in string - * - * @return a string that contain the document - * - * Return current document. - * To have an up-to-date document, please run updateParser() before. - * - */ - std::string getDocument(); - - - /** - * @brief Write data in encrypted file. - * - * @return vector pointer that point to the vector of website in document - * - * You can modified this vector, and for apply change run updateParser() - * - */ - std::vector* getWebsites(); - - - - /** - * @brief Update the parser - * - * Apply all modifications you have made on the vector object (example std::vector* websites). - * - */ - void updateParser(); - - - private: - - - /** - * @brief Instanciate websites vector - * - * Read the document and create all Website object and put them into - * the websites vector attribute. - * - */ - void initWebsites(); - - - //Parser attributes - std::stringstream dataStream; ///< Contain the document you want to parse - xmlpp::DomParser parser; ///< Contain the parser - - - - //Document attributes - xmlpp::Document* document; ///< Contain the document (generate by the parser and dataStream) - xmlpp::Node* rootNode; ///< Contain the root node of the document - - - //Website attributes - xmlpp::Node* websitesNode; ///< Contain the websites node of the document - std::vector *websites; ///< Contain all website of the document (you can modify it and run updateParser to apply all modifications). - -}; - - -#endif diff --git a/main.cpp b/main.cpp deleted file mode 100644 index b2f344f..0000000 --- a/main.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @file main.cpp - * @brief Entry point - * @author manzerbredes - * @version Prototype - * @date 8 Mars 2015 - * - * Entry point of the application. - * - */ - - - - -//----- std ----- - -#include -#include -#include - - -//----- class ----- -#include "FileManIOFile.hpp" -#include "FileManParser.hpp" -#include "Website.hpp" - - -#include - - -/** - * @fn int main(int argc, char *argv[]) - * @author manzerbredes - * @brief main function - * @param argc contain *argv[] length - * @param *argv[] contain the arguments list - * @return Return code, an int. - */ -int main(int argc, char *argv[]){ - - - - /* Initialisation de GTK+ */ - gtk_init(&argc, &argv); - - - GtkWidget* MainWindow=NULL; - - MainWindow=gtk_window_new(GTK_WINDOW_TOPLEVEL); - - g_signal_connect(G_OBJECT(MainWindow), "delete-event", G_CALLBACK(gtk_main_quit), NULL); - - - GtkWidget* bouton; - - bouton=gtk_button_new_with_label("Hello Bro :"); - gtk_container_add(GTK_CONTAINER(MainWindow), bouton); - - g_signal_connect(G_OBJECT(bouton), "leave", G_CALLBACK(gtk_main_quit), NULL); - - gtk_window_set_title(GTK_WINDOW(MainWindow), "forgetIt"); - gtk_window_set_default_size(GTK_WINDOW(MainWindow), 500,500); - - gtk_window_set_position(GTK_WINDOW(MainWindow), GTK_WIN_POS_CENTER); - - - - gtk_widget_show_all(MainWindow); - - - gtk_main(); - - - - return EXIT_SUCCESS; - -} - - - diff --git a/src/CryptClass/AESCrypt.cpp b/src/CryptClass/AESCrypt.cpp new file mode 100644 index 0000000..d3ea949 --- /dev/null +++ b/src/CryptClass/AESCrypt.cpp @@ -0,0 +1,126 @@ +/** + * @file AESCrypt.cpp + * @brief AESCrypt class definitions + * @author manzerbredes + * @date 8 Mars 2015 + * + * Contain all definitions of AESCrypt class. + * + */ + + +//----- class ----- +#include "AESCrypt.hpp" + + + +//Constructor +AESCrypt::AESCrypt(){ + this->hash=HASHCrypt(); //Init hash attribute +} + +//Destructor +AESCrypt::~AESCrypt(){ + +} + + + +//Encrypt string with string key +std::string AESCrypt::encrypt(std::string key, std::string data){ + + //Generate SHA-256 + byte digest[32]; + hash.getSHA_256(key, digest, (int)sizeof(digest)); + + return encryptRoutine(data, digest, sizeof(digest)); + +} + + + +//Encrypt string with byte* key +std::string AESCrypt::encrypt(byte* key, std::string data){ + return encryptRoutine(data, key, 32); +} + + + +//The encryptRoutine +std::string AESCrypt::encryptRoutine(std::string data, byte* digest, int size){ + //Contain data encrypted + std::string cipher; + + + //Use try, catch to be ensure no problems happening + try{ + //Create encoder to encrypt data + CryptoPP::ECB_Mode::Encryption encoder; + encoder.SetKey( digest, size ); + + //Encrypt data with StreamTransformationFilter with NO PADDING + CryptoPP::StringSource ss1(data, true, + new CryptoPP::StreamTransformationFilter( encoder, + new CryptoPP::StringSink( cipher ), + CryptoPP::StreamTransformationFilter::ZEROS_PADDING + + ) + ); + } + catch( CryptoPP::Exception& e ) + { + std::cerr << e.what() << std::endl; + exit(EXIT_FAILURE); + } + + //return encrypted data + return cipher; + + +} + + + +//Decrypt string +std::string AESCrypt::decrypt(std::string key, std::string data){ + + //Get SHA-256 + byte digest[32]; + hash.getSHA_256(key, digest, (int)sizeof(digest)); + + + //Contain data decrypted + std::string cipher; + + //Use try, catch to be ensure no problems happening + try { + + //Create decoder to encrypt data + CryptoPP::ECB_Mode< CryptoPP::AES >::Decryption decoder; + decoder.SetKey( digest, sizeof(digest) ); + + //Decrypt data with StreamTransformationFilter with NO PADDING + CryptoPP::StringSource ss3( data, true, + new CryptoPP::StreamTransformationFilter( decoder, + new CryptoPP::StringSink( cipher ), + CryptoPP::StreamTransformationFilter::NO_PADDING + ) + ); + } + catch( CryptoPP::Exception& e ) + { + std::cerr << e.what() << std::endl; + exit(1); + } + + //Remove ZEROS padding + int i=0; + for(i=0;i + +//----- crypto++ ----- +#include +#include +#include + + +/** + * @class AESCrypt AESCrypt.hpp "/CryptClass/AESCrypt.hpp" + * @brief Class for Advanced Encryption Standard (AES) algorithm + * @author manzerbredes + * + * This class provide AES encrypt and decrypt. + * Key used is 32 bytes key (256 bits). + * + * \bug Find another solution for managing padding. + */ +class AESCrypt : public AbstractSKA { + + + public: + //Constructor + AESCrypt(); + + //Destructor + ~AESCrypt(); + + + /** + * @brief Run encryptRoutine. + * + * @param key : key used to encrypt data + * @param data : contain data to encrypt. + * + * @return string : correspond to crypted data + * + * Run encryptRoutine with byte* key or string key. + * Allow you to choose between string key or byte key. + * + */ + std::string encrypt(std::string key, std::string data); + std::string encrypt(byte* key, std::string data); + + + /** + * @brief Decrypt data from AES algorithm. + * + * @param key : key used to encrypt data + * @param data : contain data to decrypt from AES encrypt. + * + * @return string : correspond to decrypted data + * + * Decrypt data, and return them into a string. + * + */ + std::string decrypt(std::string key, std::string data); + + + + private: + + /** + * @brief Encrypt data with AES algorithm. + * + * @param key : key used to encrypt data + * @param data : contain data to encrypt. + * + * @return string : correspond to crypted data + * + * Encrypt data, and return them into a string. + * Padding are blank space. + * + */ + std::string encryptRoutine(std::string data, byte* digest, int size); + + + //Attributes: + + HASHCrypt hash; ///< hash instance to generate SHA-256 hash code. + + +}; + +#endif diff --git a/src/CryptClass/AbstractSKA.hpp b/src/CryptClass/AbstractSKA.hpp new file mode 100644 index 0000000..7622ab4 --- /dev/null +++ b/src/CryptClass/AbstractSKA.hpp @@ -0,0 +1,57 @@ +/** + * @file AbstractSKA.hpp + * @brief Class for Symmetric-Key Algorithm (SKA) + * @author manzerbredes + * @date 8 Mars 2015 + * + * Specify which method the algorithm must be implement. + * + */ + +#ifndef __AbstractSKA__ +#define __AbstractSKA__ + + +//----- std ----- +#include + + + +/** + * @class AbstractSKA AbstractSKA.hpp "/CryptClass/AbstractSKA.hpp" + * @brief Class for Symmetric-Key Algorithm (SKA) + * @author manzerbredes + * + * This class should not be instantiate directly. + * + */ +class AbstractSKA { + + public: + /** + * @brief Encrypt data. + * + * @param key : key used to encrypt data + * @param data : contain data to encrypt. + * + * This method must be overwritten. + * **Warning** data will be modified. + * + */ + virtual std::string encrypt(std::string key, std::string data) = 0; + + + /** + * @brief Decrypt data. + * + * @param key : key used to decrypt data + * @param data : contain data to decrypt. + * + * This method must be overwritten. + * **Warning** data will be modified. + * + */ + virtual std::string decrypt(std::string key, std::string data) = 0; +}; + +#endif diff --git a/src/CryptClass/HASHCrypt.cpp b/src/CryptClass/HASHCrypt.cpp new file mode 100644 index 0000000..eed9cb5 --- /dev/null +++ b/src/CryptClass/HASHCrypt.cpp @@ -0,0 +1,116 @@ +/** + * @file HASHCrypt.cpp + * @brief HASHCrypt class definitions + * @author manzerbredes + * @date 8 Mars 2015 + * + * Contain all definitions of HASHCrypt class. + * + */ + + +//----- class ----- +#include "HASHCrypt.hpp" + + + +//Constructor +HASHCrypt::HASHCrypt(){ +} + +//Destructor +HASHCrypt::~HASHCrypt(){ +} + + + +//Contruct MD5 over 128 bits and put it into digest +void HASHCrypt::getMD5_128(std::string chain, byte* digest, int size){ + + //Digest size controller + this->checkDigestSize(CryptoPP::Weak1::MD5::DIGESTSIZE,size); + + //Create the MD5 on digest parameter + CryptoPP::Weak1::MD5 hash; + hash.CalculateDigest( digest, (byte*) chain.c_str(), chain.length() ); + +} + + + +//Contruct SHA-256 and put it into digest +void HASHCrypt::getSHA_256(std::string chain, byte* digest, int size){ + + //Digest size controller + this->checkDigestSize(CryptoPP::SHA256::DIGESTSIZE,size); + + //Create the SHA-256 on digest parameter + CryptoPP::SHA256 hash; + hash.CalculateDigest( digest, (byte*) chain.c_str(), chain.length() ); + + +} + + + +//Compare 2 digest (same size) +bool HASHCrypt::compareDigest(byte* digest1, byte* digest2, int size){ + + //Try is more safe + try + { + //Compare the two digest + for(int i=0; igetInvalidDigestSizeError(sizeRequired, size); + } + + } + catch(std::string erreur){ + std::cerr << erreur < +#include +#include + +//----- crypto++ ----- +#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 +#include //For MD5 +#include //For Hex convertion +#include //For SHA + + +/** + * @class HASHCrypt HASHCrypt.hpp "/CryptClass/HASHCrypt.hpp" + * @brief Hashing class + * @author manzerbredes + * + * Class who handle hashing functions on a byte* parameter. + * HASHCrypt try to detect errors and throw exceptions. + * HASHCrypt use crypto++ library. + */ +class HASHCrypt{ + + public: + /** + * @brief Contructor + */ + HASHCrypt(); + + /** + * @brief Destructor + */ + ~HASHCrypt(); + + + /** + * @brief Create an MD5 over 128 bits on a digest array of bytes. + * + * @param chain : Chain to hash + * @param digest : An array of bytes (8 bits) + * @param size : Length of digest + * + * **Warning** digest will be modified. + * Digest must be an array of byte with 16 entries + * Invalid size can cause "Segmentation Fault" + */ + void getMD5_128(std::string chain, byte* digest, int size); + + + /** + * @brief Create an SHA over 256 bits on a digest array of bytes. + * + * @param chain : Chain to hash + * @param digest : An array of bytes (8 bits) + * @param size : Length of digest + * + * **Warning** digest will be modified. + * Digest must be an array of byte with 32 entries + * Invalid size can cause "Segmentation Fault" + */ + void getSHA_256(std::string chain, byte* digest, int size); //Return SHA_256 + + + /** + * @brief Convert digest to a string of HEX characters + * + * @param digest : an array of bytes (8 bits) + * @param size : length of digest + * + * @return return a string of hex digest equivalent + * + * Digest must be an array of byte. + */ + std::string digestToString(byte* digest, int size); //Return a string + + + /** + * @brief Compare 2 digest + * + * @param digest1 : An array of bytes (8 bits) + * @param digest2 : An array of bytes (8 bits) + * @param size : Length of the array digest1 or digest2 + * + * @return return a boolean (true if digest1 equals to digest2 and false else) + * + * **Warning** if sizeof(digest1) != sizeof(digest 2) : segmentation fault ! + * Compare the two digest. + * + */ + bool compareDigest(byte* digest1, byte* digest2, int size); + + + private: + + /** + * @brief Check the digest size + * + * @param sizeRequired : Digest size expected + * @param size : Given digest size + * + * Throw an exception, and stop the program if + * sizeRequired != size + * Use getInvalidDigestSizeError method. + */ + void checkDigestSize(int sizeRequired, int size); + + + /** + * @brief Make "invalid digest size" error message. + * + * @param sizeRequired : Digest size expected + * @param size : Given digest size + * + * @return a string correspond to the error message + * + * Construct an error message with sizeRequired and size. + */ + std::string getInvalidDigestSizeError(int sizeRequired, int size); + +}; + +#endif diff --git a/src/IOFileClass/FileManIOFile.cpp b/src/IOFileClass/FileManIOFile.cpp new file mode 100644 index 0000000..ea49201 --- /dev/null +++ b/src/IOFileClass/FileManIOFile.cpp @@ -0,0 +1,147 @@ +/** + * @file FileManIOFile.cpp + * @brief FileManIOFile class definitions + * @author manzerbredes + * @date 9 Mars 2015 + * + * Contain all definitions of FileManIOFile class. + * + */ + + +#include "FileManIOFile.hpp" + +//Constructor with filename +FileManIOFile::FileManIOFile(std::string filename){ + this->filename=filename; + this->readable=false; + this->data=""; + this->key; +} + +//Destructor +FileManIOFile::~FileManIOFile(){ +} + + + +//Read the filename with a key +void FileManIOFile::read(std::string key){ + + //create file object + std::ifstream file; + + //Clear data + this->data.clear(); + + //Open file + file.open (this->filename, std::ios::in | std::ios::binary); + + //Get MD5 of decrypted data + byte fileMD5[16]; + file.read((char*) fileMD5, sizeof(fileMD5)); + + //Read all data + char car; + file.read(&car, sizeof(car)); + + while(file){ + this->data+=car, + file.read(&car, sizeof(car)); + + } + + //Decrypt data + this->data=this->aes.decrypt(key, this->data); + + //Get current MD5 of decrypted data + byte currentMD5[16]; + this->hash.getMD5_128(this->data, currentMD5, sizeof(currentMD5)); + + //Compare the 2 MD5 to find if file is fully decrypted + if(this->hash.compareDigest(fileMD5, currentMD5, sizeof(currentMD5))){ + //Set readable + this->readable=true; + //Save the key + this->hash.getSHA_256(key, this->key, 32); + } + else{ + this->readable=false; + } + + //Close file + file.close(); + + +} + + + +//Write file with key +void FileManIOFile::write(std::string key,std::string data){ + + std::string dataEncrypted; + + dataEncrypted=this->aes.encrypt(key, data); + + this->writeRoutine(data, dataEncrypted); + + +} + +//Write file without key +void FileManIOFile::write(std::string data){ + if(not(this->readable)){ + std::cout << "Can't write data without key (read it before) !" << std::endl; + std::exit(EXIT_FAILURE); + } + + std::string dataEncrypted; + + dataEncrypted=this->aes.encrypt(this->key, data); + this->writeRoutine(data, dataEncrypted); + + +} + + + +//Get readable attribute +bool FileManIOFile::isReadable(){ + return this->readable; +} + + + +//Write file +void FileManIOFile::writeRoutine(std::string data, std::string dataEncrypted){ + + //Save MD5 of decrypted data + byte digest[16]; + this->hash.getMD5_128(data, digest, sizeof(digest)); + + //Create file instance + std::ofstream file; + + //Open it + file.open(this->filename, std::ios::out | std::ios::binary); + + //Write MD5 on 16 first bytes + file.write((char *) digest,sizeof(digest)); + + //Write data + file.write(dataEncrypted.c_str(), dataEncrypted.size()); + + //Close file + file.close(); + + //Save data to attribute + this->data=data; +} + + + +//Get data +std::string FileManIOFile::getData(){ + return this->data; +} diff --git a/src/IOFileClass/FileManIOFile.hpp b/src/IOFileClass/FileManIOFile.hpp new file mode 100644 index 0000000..221cf13 --- /dev/null +++ b/src/IOFileClass/FileManIOFile.hpp @@ -0,0 +1,133 @@ +/** + * @file FileManIOFile.hpp + * @brief FileManIOFile class definitions + * @author manzerbredes + * @date 9 Mars 2015 + * + * Contain all definitions of FileManIOFile class. + * + */ + + +#ifndef __FileManIOFile__ +#define __FileManIOFile__ + + +//----- std ----- +#include +#include +#include + + +//----- class ----- +#include "HASHCrypt.hpp" +#include "AESCrypt.hpp" + + + + +/** + * @class FileManIOFile FileManIOFile.hpp "/CryptClass/FileManIOFile.hpp" + * @brief Class for quick open and close encrypted files. + * @author manzerbredes + * + * -----File organisation----- + * + * 16 first bytes : md5 of decrypted data + * Rest of the file : data encrypted (ASE for now) + * + * \bug Need check if file exist and can be opened + */ +class FileManIOFile { + + public: + + //Constructor + FileManIOFile(std::string filename); + + //Destructor + ~FileManIOFile(); + + + /** + * @brief Read encrypted file. + * + * @param key : key to encrypt data + * + * Read data from "filename" attribute. + * If file fully decrypted, readable var switch to true, + * and key saved in key attribute (before been crypted with SHA-256 algorithm). + * + */ + void read(std::string key); + + + /** + * @brief Write data in encrypted file. + * + * @param key : key to encrypt data + * @param data : data to write + * + * Write the file with or without key. + * To write data without key, you need to read it before (to save the key + * in attribute key). + * + */ + void write(std::string key, std::string data); + void write(std::string data); + + + /** + * @brief True if file fully decrypted. + * + * @return readable attribute + * + * Return "readable" attribute. + * + */ + bool isReadable(); + + + /** + * @brief Get data attribute. + * + * @return data attribute. + * + * **Warning** if data not fully decrypted (readable!=true), + * data will be unreadable (unparsable). + * + */ + std::string getData(); + + + private: + + /** + * @brief Write data in encrypted file. + * + * @param data : data to write (for MD5) + * @param dataEncrypted : data to write + * + * Write encryptedData to filename + * + */ + void writeRoutine(std::string data, std::string dataEncrypted); + + + //Attributes: + + AESCrypt aes; ///< AES instance + + HASHCrypt hash; ///< HASH instance + + std::string filename; ///< Filename attribute + + std::string data; ///< Data attribute + + bool readable; ///< Readable attribute + + byte key[32]; ///< Key in SHA-256 + +}; + +#endif diff --git a/src/ParserClass/AbstractIDManager.cpp b/src/ParserClass/AbstractIDManager.cpp new file mode 100644 index 0000000..e1c5e13 --- /dev/null +++ b/src/ParserClass/AbstractIDManager.cpp @@ -0,0 +1,39 @@ +/** + * @file AbstractIDManager.cpp + * @brief AbstractIDManager class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all implémentations of AbstractIDManager class. + * + */ + +#include "AbstractIDManager.hpp" + +AbstractIDManager::AbstractIDManager(){ + this->id=this->generateId(); +} + +AbstractIDManager::AbstractIDManager(std::string id){ + this->id=id; +} +AbstractIDManager::~AbstractIDManager(){ + this->id=id; +} + + + +void AbstractIDManager::setId(std::string id){ + this->id = id; +} + +std::string AbstractIDManager::generateId(){ + boost::uuids::uuid uuid = boost::uuids::random_generator()(); + std::stringstream ss; + ss << uuid; + return ss.str(); +} + +std::string AbstractIDManager::getId() const{ + return this->id; +} diff --git a/src/ParserClass/AbstractIDManager.hpp b/src/ParserClass/AbstractIDManager.hpp new file mode 100644 index 0000000..67d5f6f --- /dev/null +++ b/src/ParserClass/AbstractIDManager.hpp @@ -0,0 +1,59 @@ +/** + * @file AbstractIDManager.hpp + * @brief AbstractIDManager class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of AbstractIDManager class. + * If you want to manage id in class (like container), use + * this class as superclass. + * + */ + +//----- std ----- +#include +#include + + +//----- boost ----- +#include // uuid class +#include // generators +#include // streaming operators etc. + + + + +/** + * @class AbstractIDManager AbstractIDManager.hpp "/CryptClass/AbstractIDManager.hpp" + * @brief Managing ID + * @author manzerbredes + * + * This class should not be instantiate directly. + * + */ + class AbstractIDManager{ + + + public: + //Constructor + AbstractIDManager(); + + //Constructor, init with id + AbstractIDManager(std::string); + + //Destructor + ~AbstractIDManager(); + + + //Getters and setters + std::string getId() const; + void setId(std::string id); + + + private: + //Generate and random id + std::string generateId(); + + std::string id; ///< String id attribute + + }; diff --git a/src/ParserClass/FileManContainer/Website.cpp b/src/ParserClass/FileManContainer/Website.cpp new file mode 100644 index 0000000..f65a66d --- /dev/null +++ b/src/ParserClass/FileManContainer/Website.cpp @@ -0,0 +1,67 @@ +/** + * @file Website.cpp + * @brief Website class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all implementations of Website class. + * + */ + + +#include "Website.hpp" + + +//Constructor +Website::Website(){ + +} + + + +//----- Getters ----- +std::string Website::getTitle(){ + return this->title; +} +std::string Website::getUrl(){ + return this->url; +} +std::string Website::getUsername(){ + return this->username; +} +std::string Website::getPassword(){ + return this->password; +} +std::string Website::getDescription(){ + return this->description; +} + + + +//----- Setters ----- +void Website::setTitle(std::string title){ + this->title = title; +} +void Website::setUrl(std::string url){ + this->url = url; +} +void Website::setUsername(std::string username){ + this->username = username; +} +void Website::setPassword(std::string password){ + this->password = password; +} +void Website::setDescription(std::string description){ + this->description = description; +} + + + +//Equality comparator +bool Website::operator==(const Website& website) const{ + if((this->getId()).compare(website.getId())==0){ + return true; + } + return false; +} + diff --git a/src/ParserClass/FileManContainer/Website.hpp b/src/ParserClass/FileManContainer/Website.hpp new file mode 100644 index 0000000..cb293d4 --- /dev/null +++ b/src/ParserClass/FileManContainer/Website.hpp @@ -0,0 +1,83 @@ +/** + * @file Website.hpp + * @brief Website class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of Website class. + * + */ + +#ifndef __WEBSITE__ +#define __WEBSITE__ + +#include + + +/** + * @class FileManIOFile FileManIOFile.hpp "/CryptClass/FileManIOFile.hpp" + * @brief Class for quick open and close encrypted file. + * @author manzerbredes + * + * -----File organisation----- + * + * 16 first bytes : md5 of decrypted file + * rest of the file : data encrypted (ASE for now) + * + */ + +#include +#include "AbstractIDManager.hpp" + +/** + * @class Website Website.hpp "/ParserClass/FileManContainer/Website.hpp" + * @brief Class for quick open and close encrypted file. + * @author manzerbredes + * + * Container for website data. + * + */ +class Website : public AbstractIDManager { + + + public: + + Website(); + + /** + * @brief Containner getters. + */ + + std::string getTitle(); + std::string getUrl(); + std::string getUsername(); + std::string getPassword(); + std::string getDescription(); + + + /** + * @brief Containner setters. + */ + void setTitle(std::string title); + void setUrl(std::string url); + void setUsername(std::string username); + void setPassword(std::string password); + void setDescription(std::string description); + + + /** + * @brief Equality comparator + */ + bool operator==(const Website& website) const; + + private: + + std::string title; ///< Title of the website + std::string url; ///< Url of the website + std::string username; ///< username of the account + std::string password; ///< password of the account + std::string description; ///< Description of the website +}; + + +#endif diff --git a/src/ParserClass/FileManParser.cpp b/src/ParserClass/FileManParser.cpp new file mode 100644 index 0000000..57a485a --- /dev/null +++ b/src/ParserClass/FileManParser.cpp @@ -0,0 +1,132 @@ +/** + * @file FileManParser.cpp + * @brief FileManParser class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all implementations of FileManParser class. + * + */ + + +#include "FileManParser.hpp" + + +FileManParser::FileManParser(std::string data){ + + //String to stringstream + (this->dataStream) << data; + + //Create parser + //parser.parse_stream(dataStream); + (this->parser).parse_file("Doxygen/doc.xml"); + + //Retrieve document + this->document=(this->parser).get_document(); + + //Init root Node + this->rootNode=(this->document)->get_root_node(); + + //Init container: + this->initWebsites(); + + + +} + + +std::string FileManParser::getDocument(){ + std::string data=(this->document)->write_to_string(); + return data; +} + + +std::vector* FileManParser::getWebsites(){ + return this->websites; +} + + + + +//----------------Container part------------------------ +void FileManParser::initWebsites(){ + this->websites=new std::vector; + + std::vector websitesNodeSet=this->rootNode->find("//websites"); + this->websitesNode=websitesNodeSet.at(0); + + std::vector websiteNodeSet=this->websitesNode->find("*"); + + for(int i=0;iget_attribute_value("id")); + + std::vector websiteChildren=current->find("*"); + + for(int j=0;j contentNodes=currentChild->get_children(); + xmlpp::CdataNode* cdataNode=(xmlpp::CdataNode*)contentNodes.front(); + std::string cdataContent=cdataNode->get_content(); + + + if(currentChild->get_name().compare("title")==0){ + newWebsite.setTitle(cdataContent); + } + else if(currentChild->get_name().compare("url")==0){ + newWebsite.setUrl(cdataContent); + } + else if(currentChild->get_name().compare("username")==0){ + newWebsite.setUsername(cdataContent); + } + else if(currentChild->get_name().compare("password")==0){ + newWebsite.setPassword(cdataContent); + } + else if(currentChild->get_name().compare("description")==0){ + newWebsite.setDescription(cdataContent); + } + } + this->websites->push_back(newWebsite); + } +} + + + + + + + + + +void FileManParser::updateParser(){ + this->rootNode->remove_child(this->websitesNode); + + xmlpp::Element* websitesNode=this->rootNode->add_child("websites"); + this->websitesNode=(xmlpp::Node*)websitesNode; + + for(int i=0;iwebsites->size();i++){ + xmlpp::Element* current=this->websitesNode->add_child("website"); + Website currentWebsite=this->websites->at(i); + + current->set_attribute("id", currentWebsite.getId()); + xmlpp::Element* title=current->add_child("title"); + title->add_child_cdata(currentWebsite.getTitle()); + + xmlpp::Element* url=current->add_child("url"); + url->add_child_cdata(currentWebsite.getUrl()); + + xmlpp::Element* username=current->add_child("username"); + username->add_child_cdata(currentWebsite.getUsername()); + + xmlpp::Element* password=current->add_child("password"); + password->add_child_cdata(currentWebsite.getPassword()); + + xmlpp::Element* description=current->add_child("description"); + description->add_child_cdata(currentWebsite.getDescription()); + + } +} diff --git a/src/ParserClass/FileManParser.hpp b/src/ParserClass/FileManParser.hpp new file mode 100644 index 0000000..f0d01e5 --- /dev/null +++ b/src/ParserClass/FileManParser.hpp @@ -0,0 +1,114 @@ +/** + * @file FileManParser.hpp + * @brief FileManParser class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of FileManParser class. + * + */ + + + +#ifndef __FileManParser__ +#define __FileManParser__ + + + +//----- std ----- +#include +#include +#include +#include + +//----- class ----- +#include "Website.hpp" + +//----- libxml++ ----- +#include +#include + + + +/** + * @class FileManParser FileManParser.hpp "/ParserClass/FileManContainer/FileManParser.hpp" + * @brief Class for parser un xml file in a string. + * @author manzerbredes + * + * Parse string using libxml++ library. + * + */ +class FileManParser{ + + + public: + + //Constructor + FileManParser(std::string data); + + + /** + * @brief Get document in string + * + * @return a string that contain the document + * + * Return current document. + * To have an up-to-date document, please run updateParser() before. + * + */ + std::string getDocument(); + + + /** + * @brief Write data in encrypted file. + * + * @return vector pointer that point to the vector of website in document + * + * You can modified this vector, and for apply change run updateParser() + * + */ + std::vector* getWebsites(); + + + + /** + * @brief Update the parser + * + * Apply all modifications you have made on the vector object (example std::vector* websites). + * + */ + void updateParser(); + + + private: + + + /** + * @brief Instanciate websites vector + * + * Read the document and create all Website object and put them into + * the websites vector attribute. + * + */ + void initWebsites(); + + + //Parser attributes + std::stringstream dataStream; ///< Contain the document you want to parse + xmlpp::DomParser parser; ///< Contain the parser + + + + //Document attributes + xmlpp::Document* document; ///< Contain the document (generate by the parser and dataStream) + xmlpp::Node* rootNode; ///< Contain the root node of the document + + + //Website attributes + xmlpp::Node* websitesNode; ///< Contain the websites node of the document + std::vector *websites; ///< Contain all website of the document (you can modify it and run updateParser to apply all modifications). + +}; + + +#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..b2f344f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,80 @@ +/** + * @file main.cpp + * @brief Entry point + * @author manzerbredes + * @version Prototype + * @date 8 Mars 2015 + * + * Entry point of the application. + * + */ + + + + +//----- std ----- + +#include +#include +#include + + +//----- class ----- +#include "FileManIOFile.hpp" +#include "FileManParser.hpp" +#include "Website.hpp" + + +#include + + +/** + * @fn int main(int argc, char *argv[]) + * @author manzerbredes + * @brief main function + * @param argc contain *argv[] length + * @param *argv[] contain the arguments list + * @return Return code, an int. + */ +int main(int argc, char *argv[]){ + + + + /* Initialisation de GTK+ */ + gtk_init(&argc, &argv); + + + GtkWidget* MainWindow=NULL; + + MainWindow=gtk_window_new(GTK_WINDOW_TOPLEVEL); + + g_signal_connect(G_OBJECT(MainWindow), "delete-event", G_CALLBACK(gtk_main_quit), NULL); + + + GtkWidget* bouton; + + bouton=gtk_button_new_with_label("Hello Bro :"); + gtk_container_add(GTK_CONTAINER(MainWindow), bouton); + + g_signal_connect(G_OBJECT(bouton), "leave", G_CALLBACK(gtk_main_quit), NULL); + + gtk_window_set_title(GTK_WINDOW(MainWindow), "forgetIt"); + gtk_window_set_default_size(GTK_WINDOW(MainWindow), 500,500); + + gtk_window_set_position(GTK_WINDOW(MainWindow), GTK_WIN_POS_CENTER); + + + + gtk_widget_show_all(MainWindow); + + + gtk_main(); + + + + return EXIT_SUCCESS; + +} + + + -- cgit v1.2.3