aboutsummaryrefslogtreecommitdiff
path: root/src/DatabaseStorage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/DatabaseStorage.cpp')
-rw-r--r--src/DatabaseStorage.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp
index ccf5d26..b4c9a9e 100644
--- a/src/DatabaseStorage.cpp
+++ b/src/DatabaseStorage.cpp
@@ -23,7 +23,7 @@ namespace odhtdb
};
const u64 QUARANTINE_STORAGE_TIME_MICROSECONDS = 60 * 1.0e6;
- const u16 STORAGE_VERSION = 3;
+ const u16 STORAGE_VERSION = 4;
static void sqlite_exec_checked(sqlite3 *db, const char *sql)
{
@@ -111,7 +111,7 @@ namespace odhtdb
"CREATE TABLE IF NOT EXISTS NodeDecryptionKey(node BLOB UNIQUE NOT NULL, decryptionKey BLOB NOT NULL);"
"CREATE TABLE IF NOT EXISTS NodeUserGroupAssoc(node BLOB NOT NULL, userPublicKey BLOB NOT NULL, groupId BLOB NOT NULL, FOREIGN KEY(node, userPublicKey) REFERENCES NodeUser(node, publicKey), FOREIGN KEY(groupId) REFERENCES NodeGroup(groupId));"
- "CREATE TABLE IF NOT EXISTS NodeRaw(node INTEGER NOT NULL, data BLOB NOT NULL, FOREIGN KEY(node) REFERENCES Node(id));"
+ "CREATE TABLE IF NOT EXISTS NodeRaw(node BLOB NOT NULL, data BLOB NOT NULL, FOREIGN KEY(node) REFERENCES Node(nodeHash));"
"CREATE TABLE IF NOT EXISTS NodeAddDataRaw(nodeId INTEGER NOT NULL, nodeAddDataId INTEGER NOT NULL, data BLOB NOT NULL, FOREIGN KEY(nodeId) REFERENCES Node(id), FOREIGN KEY(nodeAddDataId) REFERENCES NodeAddData(id));"
"CREATE TABLE IF NOT EXISTS NodeUserActionGap(id INTEGER PRIMARY KEY, nodeUserId INTEGER NOT NULL, start INTEGER NOT NULL, range INTEGER NOT NULL, FOREIGN KEY(nodeUserId) REFERENCES NodeUser(id));"
@@ -471,7 +471,7 @@ namespace odhtdb
sqlite3_clear_bindings(insertNodeRawStmt);
int rc;
- rc = sqlite3_bind_int64(insertNodeRawStmt, 1, getNodeRowId(hash));
+ rc = sqlite3_bind_blob(insertNodeRawStmt, 1, hash.getData(), hash.getSize(), SQLITE_STATIC);
bindCheckError(rc);
rc = sqlite3_bind_blob(insertNodeRawStmt, 2, data, size, SQLITE_STATIC);
@@ -1230,13 +1230,23 @@ namespace odhtdb
u8 nonce[ENCRYPTION_NONCE_BYTE_SIZE];
deserializer.extract(nonce, ENCRYPTION_NONCE_BYTE_SIZE);
DataView dataToDecrypt((void*)deserializer.getBuffer(), deserializer.getSize());
- Decryption decryptedBody(dataToDecrypt, DataView(nonce, ENCRYPTION_NONCE_BYTE_SIZE), DataView(decryptionKey->data, ENCRYPTION_KEY_BYTE_SIZE));
- setNodeAddDataDecryptedData(rowId, decryptedBody.getDecryptedText());
-
- Log::debug("Got add object, timestamp: %zu, data: %.*s", timestamp, decryptedBody.getDecryptedText().size, decryptedBody.getDecryptedText().data);
- const DatabaseAddNodeRequest addNodeRequest(&nodeHash, &dataHash, timestamp, creatorPublicKey, decryptedBody.getDecryptedText());
- if(database->onAddNodeCallbackFunc)
- database->onAddNodeCallbackFunc(addNodeRequest);
+ try
+ {
+ Decryption decryptedBody(dataToDecrypt, DataView(nonce, ENCRYPTION_NONCE_BYTE_SIZE), DataView(decryptionKey->data, ENCRYPTION_KEY_BYTE_SIZE));
+ setNodeAddDataDecryptedData(rowId, decryptedBody.getDecryptedText());
+
+ Log::debug("Got add object, timestamp: %zu, data: %.*s", timestamp, decryptedBody.getDecryptedText().size, decryptedBody.getDecryptedText().data);
+ const DatabaseAddNodeRequest addNodeRequest(&nodeHash, &dataHash, timestamp, creatorPublicKey, decryptedBody.getDecryptedText());
+ if(database->onAddNodeCallbackFunc)
+ database->onAddNodeCallbackFunc(addNodeRequest);
+ }
+ catch(DecryptionException &e)
+ {
+ Log::error("Failed to decrypt data. Nonce: (data: %s, size: %u), dataToDecrypt: (data: %s, size: %u)",
+ bin2hex((const char*)nonce, ENCRYPTION_NONCE_BYTE_SIZE).c_str(), ENCRYPTION_NONCE_BYTE_SIZE,
+ bin2hex((const char*)dataToDecrypt.data, dataToDecrypt.size).c_str(), dataToDecrypt.size);
+ throw e;
+ }
return true;
}