diff --git a/src/cpp/Crypto/KeyPair.cpp b/src/cpp/Crypto/KeyPair.cpp index 3f56d3d6a..9bccc3fd8 100644 --- a/src/cpp/Crypto/KeyPair.cpp +++ b/src/cpp/Crypto/KeyPair.cpp @@ -14,7 +14,11 @@ using namespace Poco::Data::Keywords; KeyPair::KeyPair() : mPrivateKey(nullptr), mSodiumSecret(nullptr) { - + // TODO: set memory to zero for + // unsigned char mPublicKey[ed25519_pubkey_SIZE]; + // unsigned char mSodiumPublic[crypto_sign_PUBLICKEYBYTES]; + memset(mPublicKey, 0, ed25519_pubkey_SIZE); + memset(mSodiumPublic, 0, crypto_sign_PUBLICKEYBYTES); } KeyPair::~KeyPair() @@ -91,6 +95,14 @@ bool KeyPair::generateFromPassphrase(const char* passphrase, Mnemonic* word_sour } mSodiumSecret = new ObfusArray(crypto_sign_SECRETKEYBYTES, sodium_secret); + // print hex for all keys for debugging + printf("//********** Keys *************//\n"); + printf("Public: \t%s\n", getHex(mPublicKey, ed25519_pubkey_SIZE).data()); + printf("Private: \t%s\n", getHex(*mPrivateKey, mPrivateKey->size()).data()); + printf("Sodium Public: \t%s\n", getHex(mSodiumPublic, crypto_sign_PUBLICKEYBYTES).data()); + printf("Sodium Private: \t%s\n", getHex(*mSodiumSecret, mSodiumSecret->size()).data()); + printf("//********* Keys End ************//\n"); + // using return true; } @@ -107,6 +119,18 @@ std::string KeyPair::getPubkeyHex() return pubHex; } +std::string KeyPair::getHex(const unsigned char* data, size_t size) +{ + size_t hexSize = size * 2 + 1; + char* hexString = (char*)malloc(hexSize); + memset(hexString, 0, hexSize); + sodium_bin2hex(hexString, hexSize, data, size); + std::string hex = hexString; + free(hexString); + + return hex; +} + bool KeyPair::savePrivKey(int userId) { auto cm = ConnectionManager::getInstance(); diff --git a/src/cpp/Crypto/KeyPair.h b/src/cpp/Crypto/KeyPair.h index e300f4a38..3c259a17e 100644 --- a/src/cpp/Crypto/KeyPair.h +++ b/src/cpp/Crypto/KeyPair.h @@ -19,13 +19,15 @@ public: bool generateFromPassphrase(const char* passphrase, Mnemonic* word_source); std::string getPubkeyHex(); bool savePrivKey(int userId); - + static std::string getHex(const unsigned char* data, size_t size); inline const unsigned char* getPublicKey() const { return mSodiumPublic; } protected: const ObfusArray* getPrivateKey() const { return mSodiumSecret; } + + private: ObfusArray* mPrivateKey; ObfusArray* mSodiumSecret; diff --git a/src/cpp/HTTPInterface/CheckEmailPage.cpp b/src/cpp/HTTPInterface/CheckEmailPage.cpp index 4f7a50437..dd9b062dc 100644 --- a/src/cpp/HTTPInterface/CheckEmailPage.cpp +++ b/src/cpp/HTTPInterface/CheckEmailPage.cpp @@ -45,6 +45,13 @@ void CheckEmailPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: responseStream << "\n"; responseStream << "\n"; responseStream << "\n"; responseStream << "\n"; responseStream << "
\n"; - responseStream << "