diff --git a/skeema/gradido_login/user_backups.sql b/skeema/gradido_login/user_backups.sql index 29fd3037a..9fe9d810e 100644 --- a/skeema/gradido_login/user_backups.sql +++ b/skeema/gradido_login/user_backups.sql @@ -2,5 +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, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; diff --git a/src/cpp/controller/UserBackups.cpp b/src/cpp/controller/UserBackups.cpp index 9eb744ac6..9d683f758 100644 --- a/src/cpp/controller/UserBackups.cpp +++ b/src/cpp/controller/UserBackups.cpp @@ -15,10 +15,10 @@ namespace controller { // --------------- static members ----------------------------- - Poco::AutoPtr UserBackups::create(int user_id, const std::string& passphrase) + Poco::AutoPtr 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(new UserBackups(db)); } @@ -59,6 +59,11 @@ namespace controller { return mKeyPair; } + KeyPairEd25519* UserBackups::createGradidoKeyPair() + { + + } + std::string UserBackups::getPassphrase(ServerConfig::Mnemonic_Types type) { if ((int)type < 0 || (int)type >= ServerConfig::Mnemonic_Types::MNEMONIC_MAX) { diff --git a/src/cpp/controller/UserBackups.h b/src/cpp/controller/UserBackups.h index d54e9f7d5..c1cb08047 100644 --- a/src/cpp/controller/UserBackups.h +++ b/src/cpp/controller/UserBackups.h @@ -3,6 +3,7 @@ #include "../model/table/UserBackups.h" #include "../Crypto/KeyPair.h" +#include "../Crypto/KeyPairEd25519.h" #include "Poco/SharedPtr.h" @@ -15,7 +16,7 @@ namespace controller { ~UserBackups(); - static Poco::AutoPtr create(int user_id, const std::string& passphrase); + static Poco::AutoPtr create(int user_id, const std::string& passphrase, ServerConfig::Mnemonic_Types type); static std::vector> load(int user_id); @@ -23,8 +24,13 @@ namespace controller { inline Poco::AutoPtr getModel() { return _getModel(); } + //! depracted //! \return create keyPair from passphrase if not exist, else return existing pointer Poco::SharedPtr 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 static std::string formatPassphrase(std::string passphrase, int targetLinesCount = 5); diff --git a/src/cpp/model/table/UserBackups.cpp b/src/cpp/model/table/UserBackups.cpp index 1adbfbc51..047593b89 100644 --- a/src/cpp/model/table/UserBackups.cpp +++ b/src/cpp/model/table/UserBackups.cpp @@ -6,20 +6,20 @@ namespace model { namespace table { UserBackups::UserBackups() - : mUserId(0) + : mUserId(0), mMnemonicType(0) { } - UserBackups::UserBackups(int user_id, const std::string& passphrase) - : mUserId(user_id), mPassphrase(passphrase) + UserBackups::UserBackups(int user_id, const std::string& passphrase, ServerConfig::Mnemonic_Types type) + : mUserId(user_id), mPassphrase(passphrase), mMnemonicType(type) { } 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(); insert << "INSERT INTO " << getTableName() - << " (user_id, passphrase) VALUES(?,?)" - , use(mUserId), bind(mPassphrase); + << " (user_id, passphrase, mnemonic_type) VALUES(?,?,?)" + , use(mUserId), bind(mPassphrase), use(mMnemonicType); unlock(); return insert; } @@ -46,9 +46,9 @@ namespace model { { 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 << " = ?" - , into(mID), into(mUserId), into(mPassphrase); + , into(mID), into(mUserId), into(mPassphrase), into(mMnemonicType); return select; @@ -69,7 +69,7 @@ namespace model { { 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 << " = ?"; @@ -83,7 +83,7 @@ namespace model { 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] << " = ? "; if (conditionType == MYSQL_CONDITION_AND) { for (int i = 1; i < fieldNames.size(); i++) { @@ -99,7 +99,7 @@ namespace model { addError(new ParamError("UserBackups::_loadFromDB", "condition type not implemented", conditionType)); } //<< " where " << fieldName << " = ?" - select, into(mID), into(mUserId), into(mPassphrase); + select, into(mID), into(mUserId), into(mPassphrase), into(mMnemonicType); return select; @@ -111,6 +111,7 @@ namespace model { std::stringstream ss; ss << "user_id: " << mUserId << std::endl; ss << "passphrase: " << mPassphrase << std::endl; + ss << "mnemonic type: " << mMnemonicType << std::endl; return ss.str(); } } diff --git a/src/cpp/model/table/UserBackups.h b/src/cpp/model/table/UserBackups.h index df1cc0fa0..cad5f4910 100644 --- a/src/cpp/model/table/UserBackups.h +++ b/src/cpp/model/table/UserBackups.h @@ -7,12 +7,12 @@ namespace model { namespace table { - typedef Poco::Tuple UserBackupsTuple; + typedef Poco::Tuple UserBackupsTuple; class UserBackups : public ModelBase { 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(); ~UserBackups(); @@ -23,6 +23,7 @@ namespace model { inline int getUserId() const { return mUserId; } inline const std::string& getPassphrase() const { return mPassphrase; } + inline int getMnemonicType() const { return mMnemonicType; } inline void setUserId(int user_Id) { mUserId = user_Id; } @@ -35,6 +36,7 @@ namespace model { int mUserId; std::string mPassphrase; + int mMnemonicType; };