mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add function to detect correct mnemonic type if incorrect type in db (for example after db update)
This commit is contained in:
parent
cb5ab57158
commit
045971e919
@ -2,6 +2,6 @@ CREATE TABLE `user_backups` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int(11) NOT NULL,
|
||||
`passphrase` text COLLATE utf8_bin NOT NULL,
|
||||
`mnemonic_type` int(11) NULL,
|
||||
`mnemonic_type` int(11) DEFAULT '-1'
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include "UserBackups.h"
|
||||
#include "../../controller/User.h"
|
||||
|
||||
using namespace Poco::Data::Keywords;
|
||||
|
||||
@ -8,20 +9,20 @@ namespace model {
|
||||
UserBackups::UserBackups()
|
||||
: mUserId(0), mMnemonicType(0)
|
||||
{
|
||||
|
||||
detectMnemonic();
|
||||
}
|
||||
|
||||
UserBackups::UserBackups(int user_id, const std::string& passphrase, ServerConfig::Mnemonic_Types type)
|
||||
: mUserId(user_id), mPassphrase(passphrase), mMnemonicType(type)
|
||||
{
|
||||
|
||||
detectMnemonic();
|
||||
}
|
||||
|
||||
|
||||
UserBackups::UserBackups(const UserBackupsTuple& tuple)
|
||||
: ModelBase(tuple.get<0>()), mUserId(tuple.get<1>()), mPassphrase(tuple.get<2>()), mMnemonicType(tuple.get<3>())
|
||||
{
|
||||
|
||||
detectMnemonic();
|
||||
}
|
||||
|
||||
UserBackups::~UserBackups()
|
||||
@ -114,5 +115,30 @@ namespace model {
|
||||
ss << "mnemonic type: " << mMnemonicType << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void UserBackups::detectMnemonic()
|
||||
{
|
||||
if (mMnemonicType == -1) {
|
||||
const static char* function_name = "UserBackups::detectMnemonic";
|
||||
auto user = controller::User::create();
|
||||
if (1 == user->load(mUserId)) {
|
||||
auto user_model = user->getModel();
|
||||
KeyPairEd25519 user_key(user_model->getPublicKey);
|
||||
auto mnemonic = Passphrase::detectMnemonic(mPassphrase, &user_key);
|
||||
|
||||
for (int i = 0; i < ServerConfig::MNEMONIC_MAX; i++) {
|
||||
if (&ServerConfig::g_Mnemonic_WordLists[i] == mnemonic) {
|
||||
mMnemonicType = i;
|
||||
updateIntoDB("mnemonic_type", mMnemonicType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
addError(new ParamError(function_name, "error loading user for user_backup", mUserId));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -27,7 +27,17 @@ namespace model {
|
||||
|
||||
inline void setUserId(int user_Id) { mUserId = user_Id; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//! \brief call from constructor if mMnemonicType -1
|
||||
//!
|
||||
//! for repairing db entries after db update
|
||||
//! load user from users, find by user_id
|
||||
//! create key pair from passphrase with all mnemonics and find key pair witch matching public key
|
||||
//! attention! for invalid mnemonic it will be run every time
|
||||
void detectMnemonic();
|
||||
|
||||
Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName);
|
||||
Poco::Data::Statement _loadIdFromDB(Poco::Data::Session session);
|
||||
Poco::Data::Statement _loadMultipleFromDB(Poco::Data::Session session, const std::string& fieldName);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user