mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add mnemonic type field to user_backups to allow using multiple mnemonic word lists with some same words
This commit is contained in:
parent
5934f7c69e
commit
b2dc53c899
@ -2,5 +2,6 @@ CREATE TABLE `user_backups` (
|
|||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`user_id` int(11) NOT NULL,
|
`user_id` int(11) NOT NULL,
|
||||||
`passphrase` text COLLATE utf8_bin NOT NULL,
|
`passphrase` text COLLATE utf8_bin NOT NULL,
|
||||||
|
`mnemonic_type` int(11) NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||||
|
|||||||
@ -15,10 +15,10 @@ namespace controller {
|
|||||||
|
|
||||||
// --------------- static members -----------------------------
|
// --------------- static members -----------------------------
|
||||||
|
|
||||||
Poco::AutoPtr<UserBackups> UserBackups::create(int user_id, const std::string& passphrase)
|
Poco::AutoPtr<UserBackups> UserBackups::create(int user_id, const std::string& passphrase, ServerConfig::Mnemonic_Types type)
|
||||||
{
|
{
|
||||||
|
|
||||||
auto db = new model::table::UserBackups(user_id, passphrase);
|
auto db = new model::table::UserBackups(user_id, passphrase, type);
|
||||||
return Poco::AutoPtr<UserBackups>(new UserBackups(db));
|
return Poco::AutoPtr<UserBackups>(new UserBackups(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +59,11 @@ namespace controller {
|
|||||||
return mKeyPair;
|
return mKeyPair;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeyPairEd25519* UserBackups::createGradidoKeyPair()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
std::string UserBackups::getPassphrase(ServerConfig::Mnemonic_Types type)
|
std::string UserBackups::getPassphrase(ServerConfig::Mnemonic_Types type)
|
||||||
{
|
{
|
||||||
if ((int)type < 0 || (int)type >= ServerConfig::Mnemonic_Types::MNEMONIC_MAX) {
|
if ((int)type < 0 || (int)type >= ServerConfig::Mnemonic_Types::MNEMONIC_MAX) {
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "../model/table/UserBackups.h"
|
#include "../model/table/UserBackups.h"
|
||||||
#include "../Crypto/KeyPair.h"
|
#include "../Crypto/KeyPair.h"
|
||||||
|
#include "../Crypto/KeyPairEd25519.h"
|
||||||
|
|
||||||
#include "Poco/SharedPtr.h"
|
#include "Poco/SharedPtr.h"
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ namespace controller {
|
|||||||
|
|
||||||
~UserBackups();
|
~UserBackups();
|
||||||
|
|
||||||
static Poco::AutoPtr<UserBackups> create(int user_id, const std::string& passphrase);
|
static Poco::AutoPtr<UserBackups> create(int user_id, const std::string& passphrase, ServerConfig::Mnemonic_Types type);
|
||||||
|
|
||||||
static std::vector<Poco::AutoPtr<UserBackups>> load(int user_id);
|
static std::vector<Poco::AutoPtr<UserBackups>> load(int user_id);
|
||||||
|
|
||||||
@ -23,8 +24,13 @@ namespace controller {
|
|||||||
|
|
||||||
inline Poco::AutoPtr<model::table::UserBackups> getModel() { return _getModel<model::table::UserBackups>(); }
|
inline Poco::AutoPtr<model::table::UserBackups> getModel() { return _getModel<model::table::UserBackups>(); }
|
||||||
|
|
||||||
|
//! depracted
|
||||||
//! \return create keyPair from passphrase if not exist, else return existing pointer
|
//! \return create keyPair from passphrase if not exist, else return existing pointer
|
||||||
Poco::SharedPtr<KeyPair> getKeyPair();
|
Poco::SharedPtr<KeyPair> getKeyPair();
|
||||||
|
|
||||||
|
//! \return newly created key pair from passphrase or nullptr if not possible, caller becomes owner of pointer
|
||||||
|
KeyPairEd25519* createGradidoKeyPair();
|
||||||
|
|
||||||
//! \brief adding newlines to make block format
|
//! \brief adding newlines to make block format
|
||||||
static std::string formatPassphrase(std::string passphrase, int targetLinesCount = 5);
|
static std::string formatPassphrase(std::string passphrase, int targetLinesCount = 5);
|
||||||
|
|
||||||
|
|||||||
@ -6,20 +6,20 @@ namespace model {
|
|||||||
namespace table {
|
namespace table {
|
||||||
|
|
||||||
UserBackups::UserBackups()
|
UserBackups::UserBackups()
|
||||||
: mUserId(0)
|
: mUserId(0), mMnemonicType(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UserBackups::UserBackups(int user_id, const std::string& passphrase)
|
UserBackups::UserBackups(int user_id, const std::string& passphrase, ServerConfig::Mnemonic_Types type)
|
||||||
: mUserId(user_id), mPassphrase(passphrase)
|
: mUserId(user_id), mPassphrase(passphrase), mMnemonicType(type)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UserBackups::UserBackups(const UserBackupsTuple& tuple)
|
UserBackups::UserBackups(const UserBackupsTuple& tuple)
|
||||||
: ModelBase(tuple.get<0>()), mUserId(tuple.get<1>()), mPassphrase(tuple.get<2>())
|
: ModelBase(tuple.get<0>()), mUserId(tuple.get<1>()), mPassphrase(tuple.get<2>()), mMnemonicType(tuple.get<3>())
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -35,8 +35,8 @@ namespace model {
|
|||||||
|
|
||||||
lock();
|
lock();
|
||||||
insert << "INSERT INTO " << getTableName()
|
insert << "INSERT INTO " << getTableName()
|
||||||
<< " (user_id, passphrase) VALUES(?,?)"
|
<< " (user_id, passphrase, mnemonic_type) VALUES(?,?,?)"
|
||||||
, use(mUserId), bind(mPassphrase);
|
, use(mUserId), bind(mPassphrase), use(mMnemonicType);
|
||||||
unlock();
|
unlock();
|
||||||
return insert;
|
return insert;
|
||||||
}
|
}
|
||||||
@ -46,9 +46,9 @@ namespace model {
|
|||||||
{
|
{
|
||||||
Poco::Data::Statement select(session);
|
Poco::Data::Statement select(session);
|
||||||
|
|
||||||
select << "SELECT id, user_id, passphrase FROM " << getTableName()
|
select << "SELECT id, user_id, passphrase, mnemonic_type FROM " << getTableName()
|
||||||
<< " where " << fieldName << " = ?"
|
<< " where " << fieldName << " = ?"
|
||||||
, into(mID), into(mUserId), into(mPassphrase);
|
, into(mID), into(mUserId), into(mPassphrase), into(mMnemonicType);
|
||||||
|
|
||||||
|
|
||||||
return select;
|
return select;
|
||||||
@ -69,7 +69,7 @@ namespace model {
|
|||||||
{
|
{
|
||||||
Poco::Data::Statement select(session);
|
Poco::Data::Statement select(session);
|
||||||
|
|
||||||
select << "SELECT id, user_id, passphrase FROM " << getTableName()
|
select << "SELECT id, user_id, passphrase, mnemonic_type FROM " << getTableName()
|
||||||
<< " where " << fieldName << " = ?";
|
<< " where " << fieldName << " = ?";
|
||||||
|
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ namespace model {
|
|||||||
throw Poco::NullValueException("UserRoles::_loadFromDB fieldNames empty or contain only one field");
|
throw Poco::NullValueException("UserRoles::_loadFromDB fieldNames empty or contain only one field");
|
||||||
}
|
}
|
||||||
|
|
||||||
select << "SELECT id, user_id, passphrase FROM " << getTableName()
|
select << "SELECT id, user_id, passphrase, mnemonic_type FROM " << getTableName()
|
||||||
<< " where " << fieldNames[0] << " = ? ";
|
<< " where " << fieldNames[0] << " = ? ";
|
||||||
if (conditionType == MYSQL_CONDITION_AND) {
|
if (conditionType == MYSQL_CONDITION_AND) {
|
||||||
for (int i = 1; i < fieldNames.size(); i++) {
|
for (int i = 1; i < fieldNames.size(); i++) {
|
||||||
@ -99,7 +99,7 @@ namespace model {
|
|||||||
addError(new ParamError("UserBackups::_loadFromDB", "condition type not implemented", conditionType));
|
addError(new ParamError("UserBackups::_loadFromDB", "condition type not implemented", conditionType));
|
||||||
}
|
}
|
||||||
//<< " where " << fieldName << " = ?"
|
//<< " where " << fieldName << " = ?"
|
||||||
select, into(mID), into(mUserId), into(mPassphrase);
|
select, into(mID), into(mUserId), into(mPassphrase), into(mMnemonicType);
|
||||||
|
|
||||||
|
|
||||||
return select;
|
return select;
|
||||||
@ -111,6 +111,7 @@ namespace model {
|
|||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "user_id: " << mUserId << std::endl;
|
ss << "user_id: " << mUserId << std::endl;
|
||||||
ss << "passphrase: " << mPassphrase << std::endl;
|
ss << "passphrase: " << mPassphrase << std::endl;
|
||||||
|
ss << "mnemonic type: " << mMnemonicType << std::endl;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,12 +7,12 @@
|
|||||||
namespace model {
|
namespace model {
|
||||||
namespace table {
|
namespace table {
|
||||||
|
|
||||||
typedef Poco::Tuple<int, int, std::string> UserBackupsTuple;
|
typedef Poco::Tuple<int, int, std::string, int> UserBackupsTuple;
|
||||||
|
|
||||||
class UserBackups : public ModelBase
|
class UserBackups : public ModelBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UserBackups(int user_id, const std::string& passphrase);
|
UserBackups(int user_id, const std::string& passphrase, ServerConfig::Mnemonic_Types type);
|
||||||
UserBackups(const UserBackupsTuple& tuple);
|
UserBackups(const UserBackupsTuple& tuple);
|
||||||
UserBackups();
|
UserBackups();
|
||||||
~UserBackups();
|
~UserBackups();
|
||||||
@ -23,6 +23,7 @@ namespace model {
|
|||||||
|
|
||||||
inline int getUserId() const { return mUserId; }
|
inline int getUserId() const { return mUserId; }
|
||||||
inline const std::string& getPassphrase() const { return mPassphrase; }
|
inline const std::string& getPassphrase() const { return mPassphrase; }
|
||||||
|
inline int getMnemonicType() const { return mMnemonicType; }
|
||||||
|
|
||||||
inline void setUserId(int user_Id) { mUserId = user_Id; }
|
inline void setUserId(int user_Id) { mUserId = user_Id; }
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ namespace model {
|
|||||||
|
|
||||||
int mUserId;
|
int mUserId;
|
||||||
std::string mPassphrase;
|
std::string mPassphrase;
|
||||||
|
int mMnemonicType;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user