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 -1 no matching entry found
|
||||||
//! \return -2 if user id is not set or invalid
|
//! \return -2 if user id is not set or invalid
|
||||||
//! \return 0 matching entry found
|
//! \return 0 matching entry found
|
||||||
int User::tryLoadPassphraseUserBackup()
|
int User::tryLoadPassphraseUserBackup(KeyPairEd25519** createdKeyPair = nullptr)
|
||||||
{
|
{
|
||||||
auto user_model = getModel();
|
auto user_model = getModel();
|
||||||
if (user_model->getID() <= 0) return -2;
|
if (user_model->getID() <= 0) return -2;
|
||||||
@ -308,7 +308,11 @@ namespace controller {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto key_pair = std::unique_ptr<KeyPairEd25519>(user_backup->createGradidoKeyPair());
|
auto key_pair = std::unique_ptr<KeyPairEd25519>(user_backup->createGradidoKeyPair());
|
||||||
|
|
||||||
if (key_pair->isTheSame(user_model->getPublicKey())) {
|
if (key_pair->isTheSame(user_model->getPublicKey())) {
|
||||||
|
if (createdKeyPair) {
|
||||||
|
*createdKeyPair = key_pair.get();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,7 @@ namespace controller {
|
|||||||
//! \return -1 no matching entry found
|
//! \return -1 no matching entry found
|
||||||
//! \return -2 user id invalid or net set
|
//! \return -2 user id invalid or net set
|
||||||
//! \return 0 matching entry found
|
//! \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); }
|
inline size_t load(const std::string& email) { return getModel()->loadFromDB("email", email); }
|
||||||
//! \brief try to load user from db via user_id
|
//! \brief try to load user from db via user_id
|
||||||
|
|||||||
@ -71,11 +71,21 @@ int SigningTransaction::run() {
|
|||||||
//auto privKey = mUser->getPrivKey();
|
//auto privKey = mUser->getPrivKey();
|
||||||
//if (!mUser->hasPrivKey()) {
|
//if (!mUser->hasPrivKey()) {
|
||||||
auto gradido_key_pair = mNewUser->getGradidoKeyPair();
|
auto gradido_key_pair = mNewUser->getGradidoKeyPair();
|
||||||
|
|
||||||
if(!gradido_key_pair || !gradido_key_pair->hasPrivateKey()) {
|
if(!gradido_key_pair || !gradido_key_pair->hasPrivateKey()) {
|
||||||
|
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"));
|
addError(new Error("SigningTransaction", "user cannot decrypt private key"));
|
||||||
sendErrorsAsEmail();
|
sendErrorsAsEmail();
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// get body bytes
|
// get body bytes
|
||||||
model::messages::gradido::Transaction transaction;
|
model::messages::gradido::Transaction transaction;
|
||||||
auto bodyBytes = transaction.mutable_bodybytes();
|
auto bodyBytes = transaction.mutable_bodybytes();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user