adding self-healing function for User::sign, working only while passphrase is saved not encrypted

This commit is contained in:
Dario 2020-03-16 11:50:03 +01:00
parent c9d1a0f268
commit 0366c782f1
3 changed files with 18 additions and 1 deletions

View File

@ -1111,9 +1111,22 @@ MemoryBin* User::sign(const unsigned char* message, size_t messageSize)
}
}
if (correctPassphraseFound) {
// save corrected key into db
auto encyrptedPrivKey = encrypt(privKey);
auto newUser = controller::User::create();
if (1 == newUser->load(mDBId)) {
auto userModel = newUser->getModel();
userModel->setPrivateKey(encyrptedPrivKey);
userModel->updatePrivkey();
mm->releaseMemory(encyrptedPrivKey);
}
// sign with received key
auto const_privKey = keys.getPrivateKey();
auto signBinBuffer = mm->getFreeMemory(crypto_sign_BYTES);
unsigned long long actualSignLength = 0;
if (crypto_sign_detached(*signBinBuffer, &actualSignLength, message, messageSize, *const_privKey)) {

View File

@ -140,6 +140,7 @@ namespace model {
return select;
}
/*
std::string mEmail;
std::string mFirstName;

View File

@ -41,6 +41,9 @@ namespace model {
const char* getTableName() const { return "users"; }
std::string toString();
std::string toHTMLString();
// specific db operation
inline size_t updatePrivkey() { lock(); auto result = updateIntoDB("privkey", mPrivateKey); unlock(); return result; }
// default getter unlocked