aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-14 03:07:43 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commit4241bcd4e14095e4340a0300e205f6fdc503f1d8 (patch)
tree609041efdeac4cd8836c3b0a8569ffdf956c4d5d /include
parentb995e79eaf3ac940547beb902c1e1da5c08308ec (diff)
Remove user/group classes, user public key/group id directly to database instead
Diffstat (limited to 'include')
-rw-r--r--include/odhtdb/Database.hpp21
-rw-r--r--include/odhtdb/DatabaseStorage.hpp61
-rw-r--r--include/odhtdb/Group.hpp29
-rw-r--r--include/odhtdb/LocalUser.hpp35
-rw-r--r--include/odhtdb/LocalUserEncrypted.hpp50
-rw-r--r--include/odhtdb/OwnedMemory.hpp3
-rw-r--r--include/odhtdb/RemoteUser.hpp24
-rw-r--r--include/odhtdb/User.hpp39
8 files changed, 17 insertions, 245 deletions
diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp
index 1e4d470..332a784 100644
--- a/include/odhtdb/Database.hpp
+++ b/include/odhtdb/Database.hpp
@@ -20,11 +20,7 @@
#include <functional>
namespace odhtdb
-{
- class User;
- class LocalUser;
- class Group;
-
+{
class CommitCreateException : public std::runtime_error
{
public:
@@ -115,14 +111,15 @@ namespace odhtdb
class DatabaseCreateResponse
{
public:
- DatabaseCreateResponse(LocalUser *nodeAdminUser, std::shared_ptr<OwnedMemory> key, std::shared_ptr<Hash> hash);
+ DatabaseCreateResponse(std::shared_ptr<Signature::KeyPair> nodeAdminKeyPair, std::shared_ptr<OwnedMemory> nodeAdminGroupId, std::shared_ptr<OwnedMemory> key, std::shared_ptr<Hash> hash);
- const LocalUser* getNodeAdminUser() const;
- // Size of encryption key is odhtdb::KEY_BYTE_SIZE (found in Encryption.hpp)
+ const std::shared_ptr<Signature::KeyPair> getNodeAdminKeyPair() const;
+ const std::shared_ptr<OwnedMemory> getNodeAdminGroupId() const;
const std::shared_ptr<OwnedMemory> getNodeEncryptionKey() const;
const std::shared_ptr<Hash> getRequestHash() const;
private:
- LocalUser *nodeAdminUser;
+ std::shared_ptr<Signature::KeyPair> nodeAdminKeyPair;
+ std::shared_ptr<OwnedMemory> nodeAdminGroupId;
std::shared_ptr<OwnedMemory> key;
std::shared_ptr<Hash> hash;
};
@@ -171,12 +168,10 @@ namespace odhtdb
// Throws DatabaseCreateException on failure.
std::unique_ptr<DatabaseCreateResponse> create();
- // Throws DatabaseCreateException on failure.
- std::unique_ptr<DatabaseCreateResponse> create(const Signature::KeyPair &creatorKeyPair);
// Throws PermissionDeniedException if user @userToPerformActionWith is not allowed to add data to node
- void addData(const DatabaseNode &nodeInfo, const LocalUser *userToPerformActionWith, DataView dataToAdd);
+ void addData(const DatabaseNode &nodeInfo, const Signature::KeyPair &userToPerformActionWith, DataView dataToAdd);
// Throws PermissionDeniedException if user @userToPerformActionWith is not allowed to add user @userToAdd to group @groupToAddUserTo
- void addUser(const DatabaseNode &nodeInfo, const LocalUser *userToPerformActionWith, const Signature::PublicKey &userToAddPublicKey, Group *groupToAddUserTo);
+ void addUser(const DatabaseNode &nodeInfo, const Signature::KeyPair &userToPerformActionWith, const Signature::PublicKey &userToAddPublicKey, const DataView &groupToAddUserTo);
ntp::NtpTimestamp getSyncedTimestampUtc() const;
private:
diff --git a/include/odhtdb/DatabaseStorage.hpp b/include/odhtdb/DatabaseStorage.hpp
index 3c4d9bc..0d94c91 100644
--- a/include/odhtdb/DatabaseStorage.hpp
+++ b/include/odhtdb/DatabaseStorage.hpp
@@ -6,8 +6,7 @@
#include "Signature.hpp"
#include "Encryption.hpp"
#include "Group.hpp"
-#include "LocalUser.hpp"
-#include "LocalUserEncrypted.hpp"
+#include "Permission.hpp"
#include "OwnedMemory.hpp"
#include "DatabaseOperation.hpp"
#include <vector>
@@ -24,48 +23,6 @@ namespace odhtdb
{
class Database;
- struct DatabaseStorageObjectDecrypted
- {
- DatabaseOperation operation;
- OwnedMemory data;
- };
-
- struct DatabaseStorageObject
- {
- Hash requestHash;
- DataView data;
- u64 createdTimestamp; // In microseconds
- Signature::PublicKey creatorPublicKey;
- DatabaseStorageObjectDecrypted decryptedObject;
-
- DatabaseStorageObject(const Hash &_requestHash, DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey);
- };
-
- struct DatabaseStorageObjectList
- {
- Signature::PublicKey creatorPublicKey;
- DataView data;
- u64 createdTimestamp; // In microseconds
- std::vector<Group*> groups;
- std::vector<DatabaseStorageObject*> objects;
-
- DatabaseStorageObjectList(const Signature::PublicKey &_creatorPublicKey) :
- creatorPublicKey(_creatorPublicKey)
- {
-
- }
- };
-
- struct DatabaseStorageQuarantineObject
- {
- DataView data;
- u64 createdTimestamp; // In microseconds
- u64 storedTimestamp; // In microseconds
- Signature::PublicKey creatorPublicKey;
-
- DatabaseStorageQuarantineObject(DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey);
- };
-
class DatabaseStorageException : public std::runtime_error
{
public:
@@ -103,18 +60,9 @@ namespace odhtdb
DatabaseStorageWrongPassword(const std::string &errMsg) : DatabaseStorageException(errMsg) {}
};
- using DatabaseStorageMap = MapHash<DatabaseStorageObjectList*>;
- using DatabaseStorageQuarantineMap = Signature::MapPublicKey<std::vector<DatabaseStorageQuarantineObject*>>;
-
const int PASSWORD_SALT_LEN = 16;
const int HASHED_PASSWORD_LEN = 32;
- struct NodeLocalUser
- {
- Hash nodeHash;
- LocalUser *localUser;
- };
-
using FetchNodeRawCallbackFunc = std::function<void(const DataView)>;
using FetchNodeAddDataRawCallbackFunc = std::function<void(const DataView)>;
@@ -131,14 +79,14 @@ namespace odhtdb
bool doesDataExist(const Hash &requestHash) const;
// Throws DatabaseStorageAlreadyExists if data with hash already exists
- void createStorage(const Hash &hash, Group *creatorGroup, u64 timestamp, const void *data, usize size);
+ void createStorage(const Hash &hash, const Signature::PublicKey &adminPublicKey, const DataView &adminGroupId, u64 timestamp, const void *data, usize size);
// Throws DatabaseStorageNotFound if data with @nodeHash hash has not been created yet.
// Throws DatabaseStorageAlreadyExists if same data has been added before (hash of @data, in @dataHash)
void appendStorage(const Hash &nodeHash, const Hash &dataHash, DatabaseOperation operation, const Signature::PublicKey &creatorPublicKey, u64 timestamp, const void *data, usize size, const DataView &additionalDataView);
// Throws DatabaseStorageAlreadyExists if group already exists in node
- void addGroup(const Hash &nodeHash, Group *group);
+ void addGroup(const Hash &nodeHash, const DataView &groupId, const Permission &permissions);
void addUserToGroup(const Hash &nodeHash, const Signature::PublicKey &userPublicKey, const DataView &groupId);
@@ -148,6 +96,9 @@ namespace odhtdb
void fetchNodeRaw(const Hash &nodeHash, FetchNodeRawCallbackFunc callbackFunc);
void fetchNodeAddDataRaw(const Hash &nodeHash, FetchNodeAddDataRawCallbackFunc callbackFunc);
+ bool isUserAllowedToAddDataInNode(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const;
+ bool isUserAllowedToAddUserToGroupInNode(const Hash &nodeHash, const Signature::PublicKey &userPublicKey, const DataView &groupToAddUserTo) 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);
diff --git a/include/odhtdb/Group.hpp b/include/odhtdb/Group.hpp
index f8de78e..37058fd 100644
--- a/include/odhtdb/Group.hpp
+++ b/include/odhtdb/Group.hpp
@@ -1,35 +1,6 @@
#pragma once
-#include "types.hpp"
-#include "DataView.hpp"
-#include "Permission.hpp"
-#include "utils.hpp"
-#include <vector>
-#include <stdexcept>
-
namespace odhtdb
{
- class User;
-
const int GROUP_ID_LENGTH = 16;
-
- class Group
- {
- DISABLE_COPY(Group)
- friend class User;
- public:
- Group(uint8_t id[GROUP_ID_LENGTH], const Permission &permission);
- ~Group();
-
- DataView getId() const;
- const Permission& getPermission() const;
- const std::vector<const User*>& getUsers() const;
- private:
- void addUser(const User *user);
- bool removeUser(const User *user);
- private:
- uint8_t id[GROUP_ID_LENGTH];
- Permission permission;
- std::vector<const User*> users;
- };
}
diff --git a/include/odhtdb/LocalUser.hpp b/include/odhtdb/LocalUser.hpp
deleted file mode 100644
index b60b516..0000000
--- a/include/odhtdb/LocalUser.hpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#pragma once
-
-#include "User.hpp"
-#include "types.hpp"
-
-namespace odhtdb
-{
- class LocalUser : public User
- {
- public:
- static LocalUser* create(const Signature::KeyPair &keyPair, Group *group)
- {
- return new LocalUser(keyPair, group);
- }
-
- const Signature::PublicKey& getPublicKey() const override
- {
- return keyPair.getPublicKey();
- }
-
- const Signature::PrivateKey& getPrivateKey() const
- {
- return keyPair.getPrivateKey();
- }
-
- const Signature::KeyPair& getKeyPair() const
- {
- return keyPair;
- }
- private:
- LocalUser(const Signature::KeyPair &_keyPair, Group *group);
- private:
- Signature::KeyPair keyPair;
- };
-}
diff --git a/include/odhtdb/LocalUserEncrypted.hpp b/include/odhtdb/LocalUserEncrypted.hpp
deleted file mode 100644
index 7919cb3..0000000
--- a/include/odhtdb/LocalUserEncrypted.hpp
+++ /dev/null
@@ -1,50 +0,0 @@
-#pragma once
-
-#include "types.hpp"
-#include "Encryption.hpp"
-#include "Signature.hpp"
-
-namespace odhtdb
-{
- struct EncryptedPrivateKey
- {
- u8 nonce[ENCRYPTION_NONCE_BYTE_SIZE];
- u8 encryptedPrivateKey[ENCRYPTION_CHECKSUM_BYTE_SIZE + PRIVATE_KEY_NUM_BYTES];
-
- EncryptedPrivateKey();
- EncryptedPrivateKey(const EncryptedPrivateKey &other);
-
- // Throws DecryptionException if password (or salt) is wrong
- Signature::PrivateKey decrypt(const DataView &plainPassword, const DataView &salt) const;
- };
-
- // Local user with encrypted private key
- class LocalUserEncrypted
- {
- public:
- static LocalUserEncrypted* create(const Signature::PublicKey &publicKey, const EncryptedPrivateKey &encryptedPrivateKey)
- {
- return new LocalUserEncrypted(publicKey, encryptedPrivateKey);
- }
-
- const Signature::PublicKey& getPublicKey() const
- {
- return publicKey;
- }
-
- const EncryptedPrivateKey& getPrivateKey() const
- {
- return encryptedPrivateKey;
- }
- private:
- LocalUserEncrypted(const Signature::PublicKey &_publicKey, const EncryptedPrivateKey &_encryptedPrivateKey) :
- publicKey(_publicKey),
- encryptedPrivateKey(_encryptedPrivateKey)
- {
-
- }
- private:
- Signature::PublicKey publicKey;
- EncryptedPrivateKey encryptedPrivateKey;
- };
-}
diff --git a/include/odhtdb/OwnedMemory.hpp b/include/odhtdb/OwnedMemory.hpp
index 5dcdf25..67afe06 100644
--- a/include/odhtdb/OwnedMemory.hpp
+++ b/include/odhtdb/OwnedMemory.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "types.hpp"
+#include "DataView.hpp"
namespace odhtdb
{
@@ -16,6 +17,8 @@ namespace odhtdb
OwnedMemory(OwnedMemory&) = delete;
OwnedMemory& operator = (OwnedMemory&) = delete;
+ const DataView getView() const { return DataView(data, size); }
+
void *data;
usize size;
};
diff --git a/include/odhtdb/RemoteUser.hpp b/include/odhtdb/RemoteUser.hpp
deleted file mode 100644
index 2658132..0000000
--- a/include/odhtdb/RemoteUser.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-
-#include "User.hpp"
-
-namespace odhtdb
-{
- class RemoteUser : public User
- {
- public:
- static RemoteUser* create(const Signature::PublicKey &publicKey, Group *group)
- {
- return new RemoteUser(publicKey, group);
- }
-
- const Signature::PublicKey& getPublicKey() const override
- {
- return publicKey;
- }
- private:
- RemoteUser(const Signature::PublicKey &_publicKey, Group *group) : User(User::Type::REMOTE, group), publicKey(_publicKey) {}
- private:
- Signature::PublicKey publicKey;
- };
-}
diff --git a/include/odhtdb/User.hpp b/include/odhtdb/User.hpp
deleted file mode 100644
index 15e6492..0000000
--- a/include/odhtdb/User.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-
-#include "Signature.hpp"
-#include "types.hpp"
-#include "Permission.hpp"
-#include <stdexcept>
-#include <vector>
-
-namespace odhtdb
-{
- class Group;
- class DatabaseStorage;
-
- class User
- {
- friend class DatabaseStorage;
- public:
- enum class Type : u8
- {
- LOCAL,
- REMOTE
- };
-
- virtual ~User();
-
- virtual void addToGroup(Group *group);
-
- Type getType() const { return type; }
- virtual const std::vector<Group*>& getGroups() const { return groups; }
- virtual const Signature::PublicKey& getPublicKey() const = 0;
-
- virtual bool isAllowedToPerformAction(PermissionType action) const;
- protected:
- User(Type type, Group *group);
- protected:
- Type type;
- std::vector<Group*> groups;
- };
-}