mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
try to recover priv key from user backup in SigningTransaction if private key is missing
This commit is contained in:
parent
15d7cf5e61
commit
1b3cd9701c
@ -295,7 +295,7 @@ namespace controller {
|
||||
//! \return -1 no matching entry found
|
||||
//! \return -2 if user id is not set or invalid
|
||||
//! \return 0 matching entry found
|
||||
int User::tryLoadPassphraseUserBackup()
|
||||
int User::tryLoadPassphraseUserBackup(KeyPairEd25519** createdKeyPair = nullptr)
|
||||
{
|
||||
auto user_model = getModel();
|
||||
if (user_model->getID() <= 0) return -2;
|
||||
@ -308,7 +308,11 @@ namespace controller {
|
||||
continue;
|
||||
}
|
||||
auto key_pair = std::unique_ptr<KeyPairEd25519>(user_backup->createGradidoKeyPair());
|
||||
|
||||
if (key_pair->isTheSame(user_model->getPublicKey())) {
|
||||
if (createdKeyPair) {
|
||||
*createdKeyPair = key_pair.get();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ namespace controller {
|
||||
//! \return -1 no matching entry found
|
||||
//! \return -2 user id invalid or net set
|
||||
//! \return 0 matching entry found
|
||||
int tryLoadPassphraseUserBackup();
|
||||
int tryLoadPassphraseUserBackup(KeyPairEd25519** createdKeyPair = nullptr);
|
||||
|
||||
inline size_t load(const std::string& email) { return getModel()->loadFromDB("email", email); }
|
||||
//! \brief try to load user from db via user_id
|
||||
|
||||
@ -71,10 +71,20 @@ int SigningTransaction::run() {
|
||||
//auto privKey = mUser->getPrivKey();
|
||||
//if (!mUser->hasPrivKey()) {
|
||||
auto gradido_key_pair = mNewUser->getGradidoKeyPair();
|
||||
|
||||
if(!gradido_key_pair || !gradido_key_pair->hasPrivateKey()) {
|
||||
addError(new Error("SigningTransaction", "user cannot decrypt private key"));
|
||||
sendErrorsAsEmail();
|
||||
return -2;
|
||||
KeyPairEd25519** key_pair_ptr = nullptr;
|
||||
if (!mNewUser->tryLoadPassphraseUserBackup(key_pair_ptr)) {
|
||||
if(mNewUser->setGradidoKeyPair(*key_pair_ptr))
|
||||
{
|
||||
mNewUser->getModel()->updatePrivkey();
|
||||
}
|
||||
}
|
||||
else {
|
||||
addError(new Error("SigningTransaction", "user cannot decrypt private key"));
|
||||
sendErrorsAsEmail();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
// get body bytes
|
||||
model::messages::gradido::Transaction transaction;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user