diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-15 18:24:50 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | e52be3a6b82025b6795b73d448381953821d18bb (patch) | |
tree | c7dfaf9e2ed9020d5c6a595f803f501c4f20de54 /include/odhtdb/DatabaseStorage.hpp | |
parent | 0f95a9de53f23db735b7f1d1ecdb7acdd59bba0d (diff) |
Add methods to store/retrieve encrypted user (using argon2 for hash)
Diffstat (limited to 'include/odhtdb/DatabaseStorage.hpp')
-rw-r--r-- | include/odhtdb/DatabaseStorage.hpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/include/odhtdb/DatabaseStorage.hpp b/include/odhtdb/DatabaseStorage.hpp index 886412c..613f2e8 100644 --- a/include/odhtdb/DatabaseStorage.hpp +++ b/include/odhtdb/DatabaseStorage.hpp @@ -10,6 +10,8 @@ #include "OwnedMemory.hpp" #include "DatabaseOperation.hpp" #include "DatabaseOrder.hpp" +#include "sql/SqlQuery.hpp" +#include "sql/SqlExec.hpp" #include <vector> #include <stdexcept> #include <boost/filesystem/path.hpp> @@ -50,12 +52,6 @@ namespace odhtdb DatabaseStorageCorrupt(const std::string &errMsg) : DatabaseStorageException(errMsg) {} }; - class DatabaseStorageNoSuchLocalStorageUser : public DatabaseStorageException - { - public: - DatabaseStorageNoSuchLocalStorageUser(const std::string &errMsg) : DatabaseStorageException(errMsg) {} - }; - class DatabaseStorageWrongPassword : public DatabaseStorageException { public: @@ -70,6 +66,12 @@ namespace odhtdb using FetchNodeUserActionGapsCallbackFunc = std::function<void(const DataView userPublicKey, u64 start, u64 range)>; using FetchNodeUserLatestActionCounterCallbackFunc = std::function<void(const DataView userPublicKey, u64 latestActionCounter)>; + struct NodeUserKeyPair + { + const Hash nodeHash; + const Signature::KeyPair keyPair; + }; + class DatabaseStorage { public: @@ -109,13 +111,14 @@ namespace odhtdb // Throws DatabaseStorageNotFound if user doesn't exist in node u64 getUserActionCounter(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const; - // Username and key pair has to be unique, returns true on success - //bool storeLocalUser(const std::string &username, const Signature::KeyPair &keyPair, const std::string &password); + // Username has to be either unique or if it's the same as existing one, then password has to match. + // Node has to be unique for the user. + // Throws DatabaseStorageWrongPassword or SqlExecException on failure (if username is not unique in node). + void storeUserPasswordEncrypted(const Hash &nodeHash, const std::string &username, const std::string &password, const Signature::KeyPair &keyPair); - // Returns public key and private key of encrypted local user. - // Throws DatabaseStorageNoSuchLocalStorageUser if user does not exist in local storage. - // Throws DatabaseStorageWrongPassword if password for the stored local user is wrong. - //Signature::KeyPair decryptLocalEncryptedUser(const std::string &username, const std::string &password); + // Returns nodes, public key and private key of encrypted user. + // Throws DatabaseStorageWrongPassword if password for the stored user is wrong. + std::vector<NodeUserKeyPair> getStoredUserNodeDataDecrypted(const std::string &username, const std::string &password); // Returns true and node decryption key if node exists and we have the decryption key, // otherwise return false and OwnedMemory with data set to nullptr |