diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/odhtdb/Database.hpp | 20 | ||||
-rw-r--r-- | include/odhtdb/DatabaseNode.hpp | 6 | ||||
-rw-r--r-- | include/odhtdb/DatabaseStorage.hpp | 16 | ||||
-rw-r--r-- | include/odhtdb/FileUtils.hpp | 2 | ||||
-rw-r--r-- | include/odhtdb/OwnedMemory.hpp | 28 | ||||
-rw-r--r-- | include/odhtdb/PasswordHash.hpp | 2 |
6 files changed, 51 insertions, 23 deletions
diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp index 04c3b62..a2914ac 100644 --- a/include/odhtdb/Database.hpp +++ b/include/odhtdb/Database.hpp @@ -113,16 +113,16 @@ namespace odhtdb class DatabaseCreateResponse { public: - DatabaseCreateResponse(std::shared_ptr<Signature::KeyPair> nodeAdminKeyPair, std::shared_ptr<OwnedMemory> nodeAdminGroupId, std::shared_ptr<OwnedMemory> key, std::shared_ptr<Hash> hash); + DatabaseCreateResponse(std::shared_ptr<Signature::KeyPair> nodeAdminKeyPair, std::shared_ptr<OwnedByteArray> nodeAdminGroupId, std::shared_ptr<OwnedByteArray> key, std::shared_ptr<Hash> hash); 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<OwnedByteArray> getNodeAdminGroupId() const; + const std::shared_ptr<OwnedByteArray> getNodeEncryptionKey() const; const std::shared_ptr<Hash> getRequestHash() const; private: std::shared_ptr<Signature::KeyPair> nodeAdminKeyPair; - std::shared_ptr<OwnedMemory> nodeAdminGroupId; - std::shared_ptr<OwnedMemory> key; + std::shared_ptr<OwnedByteArray> nodeAdminGroupId; + std::shared_ptr<OwnedByteArray> key; std::shared_ptr<Hash> hash; }; @@ -194,7 +194,7 @@ namespace odhtdb // Throws DatabaseStorageWrongPassword if password for the stored user is wrong. MapHash<StoredNodeInfo> getStoredNodeUserInfoDecrypted(const std::string &username, const std::string &password) const; - std::vector<OwnedMemory> getUserGroups(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const; + std::vector<OwnedByteArray> getUserGroups(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const; void receiveCustomMessage(const dht::InfoHash &requestKey, ReceiveCustomMessageCallbackFunc callbackFunc); @@ -203,10 +203,10 @@ namespace odhtdb static dht::InfoHash getInfoHash(const void *data, usize size); private: - void deserializeCreateRequest(const std::shared_ptr<dht::Value> &value, const Hash &hash, const std::shared_ptr<OwnedMemory> encryptionKey); - void deserializeAddRequest(const std::shared_ptr<dht::Value> &value, const Hash &requestDataHash, const std::shared_ptr<Hash> &nodeHash, const std::shared_ptr<OwnedMemory> encryptionKey); - bool listenCreateData(std::shared_ptr<dht::Value> value, const Hash &hash, const std::shared_ptr<OwnedMemory> encryptionKey); - bool listenAddData(std::shared_ptr<dht::Value> value, const Hash &requestDataHash, const std::shared_ptr<Hash> nodeHash, const std::shared_ptr<OwnedMemory> encryptionKey); + void deserializeCreateRequest(const std::shared_ptr<dht::Value> &value, const Hash &hash, const std::shared_ptr<OwnedByteArray> encryptionKey); + void deserializeAddRequest(const std::shared_ptr<dht::Value> &value, const Hash &requestDataHash, const std::shared_ptr<Hash> &nodeHash, const std::shared_ptr<OwnedByteArray> encryptionKey); + bool listenCreateData(std::shared_ptr<dht::Value> value, const Hash &hash, const std::shared_ptr<OwnedByteArray> encryptionKey); + bool listenAddData(std::shared_ptr<dht::Value> value, const Hash &requestDataHash, const std::shared_ptr<Hash> nodeHash, const std::shared_ptr<OwnedByteArray> encryptionKey); private: dht::DhtRunner node; DatabaseStorage databaseStorage; diff --git a/include/odhtdb/DatabaseNode.hpp b/include/odhtdb/DatabaseNode.hpp index 620cd40..c707af9 100644 --- a/include/odhtdb/DatabaseNode.hpp +++ b/include/odhtdb/DatabaseNode.hpp @@ -11,14 +11,14 @@ namespace odhtdb public: DatabaseNode() {} - DatabaseNode(const std::shared_ptr<OwnedMemory> &_encryptionKey, const std::shared_ptr<Hash> &_nodeHash) : + DatabaseNode(const std::shared_ptr<OwnedByteArray> &_encryptionKey, const std::shared_ptr<Hash> &_nodeHash) : encryptionKey(_encryptionKey), nodeHash(_nodeHash) { } - const std::shared_ptr<OwnedMemory> getNodeEncryptionKey() const + const std::shared_ptr<OwnedByteArray> getNodeEncryptionKey() const { return encryptionKey; } @@ -28,7 +28,7 @@ namespace odhtdb return nodeHash; } private: - std::shared_ptr<OwnedMemory> encryptionKey; + std::shared_ptr<OwnedByteArray> encryptionKey; std::shared_ptr<Hash> nodeHash; }; } diff --git a/include/odhtdb/DatabaseStorage.hpp b/include/odhtdb/DatabaseStorage.hpp index a618420..9f93994 100644 --- a/include/odhtdb/DatabaseStorage.hpp +++ b/include/odhtdb/DatabaseStorage.hpp @@ -75,7 +75,7 @@ namespace odhtdb struct StoredNodeInfo { - std::shared_ptr<OwnedMemory> nodeEncryptionKey; + std::shared_ptr<OwnedByteArray> nodeEncryptionKey; std::shared_ptr<Signature::KeyPair> userKeyPair; }; @@ -135,14 +135,14 @@ namespace odhtdb MapHash<StoredNodeInfo> getStoredNodeUserInfoDecrypted(const std::string &username, const std::string &password) const; // 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 - std::pair<bool, std::shared_ptr<OwnedMemory>> getNodeDecryptionKey(const Hash &nodeHash); + // otherwise return false and OwnedByteArray with data set to nullptr + std::pair<bool, std::shared_ptr<OwnedByteArray>> getNodeDecryptionKey(const Hash &nodeHash); void setNodeDecryptionKey(const Hash &nodeHash, const DataView &decryptionKey); const std::vector<dht::NodeExport>& getRemoteNodes() const; void setRemoteNodes(const std::vector<dht::NodeExport> &remoteNodes); - std::vector<OwnedMemory> getUserGroups(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const; + std::vector<OwnedByteArray> getUserGroups(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const; const dht::crypto::Identity& getIdentity() const; @@ -155,10 +155,10 @@ namespace odhtdb void bindCheckError(int sqliteBindResult); void loadMetadataFromFile(); void loadRemoteNodesFromFile(); - bool decryptNodeData(const Hash &nodeHash, const std::shared_ptr<OwnedMemory> decryptionKey); - bool decryptNodeData(const Hash &nodeHash, const std::shared_ptr<OwnedMemory> decryptionKey, const Signature::PublicKey *creatorPublicKey, const DataView &adminGroupId, u64 timestamp); - bool decryptNodeAddData(i64 rowId, const Hash &nodeHash, const Hash &dataHash, u64 timestamp, const Signature::PublicKey *creatorPublicKey, const DataView &encryptedData, const std::shared_ptr<OwnedMemory> decryptionKey); - bool decryptNodeAddUser(i64 rowId, const Hash &nodeHash, const Hash &dataHash, u64 timestamp, const Signature::PublicKey *creatorPublicKey, const Signature::PublicKey *userToAddPublicKey, const DataView &groupToAddUserTo, const std::shared_ptr<OwnedMemory> decryptionKey); + bool decryptNodeData(const Hash &nodeHash, const std::shared_ptr<OwnedByteArray> decryptionKey); + bool decryptNodeData(const Hash &nodeHash, const std::shared_ptr<OwnedByteArray> decryptionKey, const Signature::PublicKey *creatorPublicKey, const DataView &adminGroupId, u64 timestamp); + bool decryptNodeAddData(i64 rowId, const Hash &nodeHash, const Hash &dataHash, u64 timestamp, const Signature::PublicKey *creatorPublicKey, const DataView &encryptedData, const std::shared_ptr<OwnedByteArray> decryptionKey); + bool decryptNodeAddUser(i64 rowId, const Hash &nodeHash, const Hash &dataHash, u64 timestamp, const Signature::PublicKey *creatorPublicKey, const Signature::PublicKey *userToAddPublicKey, const DataView &groupToAddUserTo, const std::shared_ptr<OwnedByteArray> decryptionKey); i64 getNodeRowId(const Hash &nodeHash); i64 getNodeAddDataRowId(const Hash &requestHash); diff --git a/include/odhtdb/FileUtils.hpp b/include/odhtdb/FileUtils.hpp index 88721ed..155f53a 100644 --- a/include/odhtdb/FileUtils.hpp +++ b/include/odhtdb/FileUtils.hpp @@ -14,7 +14,7 @@ namespace odhtdb }; // Throws FileException on error - OwnedMemory fileGetContent(const boost::filesystem::path &filepath); + OwnedByteArray fileGetContent(const boost::filesystem::path &filepath); // Creates file if it doesn't exist. // Throws FileException on error diff --git a/include/odhtdb/OwnedMemory.hpp b/include/odhtdb/OwnedMemory.hpp index 67afe06..4c6df1c 100644 --- a/include/odhtdb/OwnedMemory.hpp +++ b/include/odhtdb/OwnedMemory.hpp @@ -22,4 +22,32 @@ namespace odhtdb void *data; usize size; }; + + class OwnedByteArray + { + public: + OwnedByteArray() : data(nullptr), size(0) {} + OwnedByteArray(u8 *_data, usize _size) : data(_data), size(_size) {} + OwnedByteArray(OwnedByteArray &&other) + { + data = other.data; + size = other.size; + + other.data = nullptr; + other.size = 0; + } + ~OwnedByteArray() + { + delete[] data; + } + + // Do not allow copy of this struct, forcing move when returning a OwnedByteArray in a function + OwnedByteArray(OwnedByteArray&) = delete; + OwnedByteArray& operator = (OwnedByteArray&) = delete; + + const DataView getView() const { return DataView(data, size); } + + u8 *data; + usize size; + }; } diff --git a/include/odhtdb/PasswordHash.hpp b/include/odhtdb/PasswordHash.hpp index bc02c53..6d23358 100644 --- a/include/odhtdb/PasswordHash.hpp +++ b/include/odhtdb/PasswordHash.hpp @@ -7,5 +7,5 @@ namespace odhtdb { const int HASH_PASSWORD_LENGTH = 32; - OwnedMemory hashPassword(const DataView &plainPassword, const DataView &salt); + OwnedByteArray hashPassword(const DataView &plainPassword, const DataView &salt); } |