aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-27 09:21:27 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commit2ecdfb3b47882411659a0efe451b0910c85a32f5 (patch)
tree1c2c5c91c9e2264580b707d5616b786f85b5ce85 /include
parent04cfe9c03baa5691ebfad6e039e4f0acd74fd8e1 (diff)
Change local storage to fit dchat better
Diffstat (limited to 'include')
-rw-r--r--include/odhtdb/Database.hpp2
-rw-r--r--include/odhtdb/DatabaseStorage.hpp47
-rw-r--r--include/odhtdb/Group.hpp1
-rw-r--r--include/odhtdb/LocalUser.hpp5
-rw-r--r--include/odhtdb/User.hpp2
5 files changed, 48 insertions, 9 deletions
diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp
index 3e4a393..9aff90e 100644
--- a/include/odhtdb/Database.hpp
+++ b/include/odhtdb/Database.hpp
@@ -140,6 +140,8 @@ namespace odhtdb
void seed(const DatabaseNode &nodeToSeed);
// Throws DatabaseCreateException on failure.
std::unique_ptr<DatabaseCreateResponse> create(const std::string &ownerName, const std::string &nodeName);
+ // Throws DatabaseCreateException on failure.
+ std::unique_ptr<DatabaseCreateResponse> create(const std::string &ownerName, const Signature::KeyPair &keyPair, const std::string &nodeName);
// Throws DatabaseAddException on failure
void addData(const DatabaseNode &nodeInfo, LocalUser *userToPerformActionWith, DataView dataToAdd);
// Throws PermissionDeniedException if user @userToPerformActionWith is not allowed to add user @userToAdd to group @groupToAddUserTo
diff --git a/include/odhtdb/DatabaseStorage.hpp b/include/odhtdb/DatabaseStorage.hpp
index f3c3087..34e523e 100644
--- a/include/odhtdb/DatabaseStorage.hpp
+++ b/include/odhtdb/DatabaseStorage.hpp
@@ -43,22 +43,41 @@ namespace odhtdb
DatabaseStorageQuarantineObject(DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey);
};
- class DatabaseStorageAlreadyExists : public std::runtime_error
+ class DatabaseStorageException : public std::runtime_error
{
public:
- DatabaseStorageAlreadyExists(const std::string &errMsg) : std::runtime_error(errMsg) {}
+ DatabaseStorageException(const std::string &errMsg) : std::runtime_error(errMsg) {}
+ virtual ~DatabaseStorageException() {}
};
- class DatabaseStorageNotFound : public std::runtime_error
+ class DatabaseStorageAlreadyExists : public DatabaseStorageException
{
public:
- DatabaseStorageNotFound(const std::string &errMsg) : std::runtime_error(errMsg) {}
+ DatabaseStorageAlreadyExists(const std::string &errMsg) : DatabaseStorageException(errMsg) {}
};
- class DatabaseStorageCorrupt : public std::runtime_error
+ class DatabaseStorageNotFound : public DatabaseStorageException
{
public:
- DatabaseStorageCorrupt(const std::string &errMsg) : std::runtime_error(errMsg) {}
+ DatabaseStorageNotFound(const std::string &errMsg) : DatabaseStorageException(errMsg) {}
+ };
+
+ class DatabaseStorageCorrupt : public DatabaseStorageException
+ {
+ public:
+ DatabaseStorageCorrupt(const std::string &errMsg) : DatabaseStorageException(errMsg) {}
+ };
+
+ class DatabaseStorageNoSuchLocalStorageUser : public DatabaseStorageException
+ {
+ public:
+ DatabaseStorageNoSuchLocalStorageUser(const std::string &errMsg) : DatabaseStorageException(errMsg) {}
+ };
+
+ class DatabaseStorageWrongPassword : public DatabaseStorageException
+ {
+ public:
+ DatabaseStorageWrongPassword(const std::string &errMsg) : DatabaseStorageException(errMsg) {}
};
using DatabaseStorageMap = MapHash<DatabaseStorageObjectList*>;
@@ -67,6 +86,8 @@ namespace odhtdb
const int PASSWORD_SALT_LEN = 16;
const int HASHED_PASSWORD_LEN = 32;
+ using NodeLocalUser = std::pair<Hash, LocalUser*>;
+
class DatabaseStorage
{
public:
@@ -98,8 +119,18 @@ namespace odhtdb
// Returns nullptr if a user with public key @publicKey doesn't exist in node @nodeHash or if no node with id @nodeHash exists
User* getUserByPublicKey(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const;
- // Username, public key and private key has to be unique
- bool storeLocalUser(const std::string &username, const Signature::PublicKey &publicKey, const Signature::PrivateKey &privateKey, const std::string &password);
+ // 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);
+
+ // 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);
+
+ // Get stored local user by public & private key in all nodes they exist.
+ // Creates a new user object and replaces user object in the nodes.
+ // Safe to call multiple times.
+ std::vector<NodeLocalUser> getLocalNodeUsers(const Signature::KeyPair &keyPair);
const dht::crypto::Identity& getIdentity() const;
diff --git a/include/odhtdb/Group.hpp b/include/odhtdb/Group.hpp
index 890b2fc..cd28923 100644
--- a/include/odhtdb/Group.hpp
+++ b/include/odhtdb/Group.hpp
@@ -36,6 +36,7 @@ namespace odhtdb
const std::vector<const User*>& getUsers() const;
private:
void addUser(const User *user);
+ bool removeUser(const User *user);
private:
std::string name;
uint8_t id[GROUP_ID_LENGTH];
diff --git a/include/odhtdb/LocalUser.hpp b/include/odhtdb/LocalUser.hpp
index b9bdde6..c87ba45 100644
--- a/include/odhtdb/LocalUser.hpp
+++ b/include/odhtdb/LocalUser.hpp
@@ -22,6 +22,11 @@ namespace odhtdb
{
return keyPair.getPrivateKey();
}
+
+ const Signature::KeyPair& getKeyPair() const
+ {
+ return keyPair;
+ }
private:
LocalUser(const Signature::KeyPair &_keyPair, const std::string &name, Group *group);
private:
diff --git a/include/odhtdb/User.hpp b/include/odhtdb/User.hpp
index 3236d4c..beb8974 100644
--- a/include/odhtdb/User.hpp
+++ b/include/odhtdb/User.hpp
@@ -29,7 +29,7 @@ namespace odhtdb
REMOTE
};
- virtual ~User(){}
+ virtual ~User();
virtual void addToGroup(Group *group);