diff --git a/native/cpp/CommonCpp/CryptoTools/Tools.h b/native/cpp/CommonCpp/CryptoTools/Tools.h --- a/native/cpp/CommonCpp/CryptoTools/Tools.h +++ b/native/cpp/CommonCpp/CryptoTools/Tools.h @@ -4,7 +4,9 @@ #include #include +#ifndef EMSCRIPTEN #include "olm/olm.h" +#endif // base64-encoded #define KEYSIZE 43 diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h @@ -11,14 +11,18 @@ #include "entities/Report.h" #include "entities/Thread.h" +#ifndef EMSCRIPTEN #include - #include +#endif + #include namespace comm { +#ifndef EMSCRIPTEN namespace jsi = facebook::jsi; +#endif /** * if any initialization/cleaning up steps are required for specific diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h @@ -11,19 +11,21 @@ class SQLiteQueryExecutor : public DatabaseQueryExecutor { static void migrate(); - static void assign_encryption_key(); static auto &getStorage(); static std::once_flag initialized; static int sqlcipherEncryptionKeySize; static std::string secureStoreEncryptionKeyID; +#ifndef EMSCRIPTEN + static void assign_encryption_key(); +#endif + public: static std::string sqliteFilePath; static std::string encryptionKey; SQLiteQueryExecutor(); - static void initialize(std::string &databasePath); std::unique_ptr getThread(std::string threadID) const override; std::string getDraft(std::string key) const override; void updateDraft(std::string key, std::string text) const override; @@ -78,7 +80,11 @@ void setMetadata(std::string entry_name, std::string data) const override; void clearMetadata(std::string entry_name) const override; std::string getMetadata(std::string entry_name) const override; + +#ifndef EMSCRIPTEN static void clearSensitiveData(); + static void initialize(std::string &databasePath); +#endif }; } // namespace comm diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp @@ -1,5 +1,4 @@ #include "SQLiteQueryExecutor.h" -#include "CommSecureStore.h" #include "Logger.h" #include "sqlite_orm.h" @@ -8,6 +7,10 @@ #include #include +#ifndef EMSCRIPTEN +#include "CommSecureStore.h" +#endif + #define ACCOUNT_ID 1 namespace comm { @@ -850,15 +853,6 @@ sqlite3_close(db); } -void SQLiteQueryExecutor::assign_encryption_key() { - CommSecureStore commSecureStore{}; - std::string encryptionKey = comm::crypto::Tools::generateRandomHexString( - SQLiteQueryExecutor::sqlcipherEncryptionKeySize); - commSecureStore.set( - SQLiteQueryExecutor::secureStoreEncryptionKeyID, encryptionKey); - SQLiteQueryExecutor::encryptionKey = encryptionKey; -} - auto &SQLiteQueryExecutor::getStorage() { static auto storage = make_storage( SQLiteQueryExecutor::sqliteFilePath, @@ -941,21 +935,6 @@ return storage; } -void SQLiteQueryExecutor::initialize(std::string &databasePath) { - std::call_once(SQLiteQueryExecutor::initialized, [&databasePath]() { - SQLiteQueryExecutor::sqliteFilePath = databasePath; - CommSecureStore commSecureStore{}; - folly::Optional maybeEncryptionKey = - commSecureStore.get(SQLiteQueryExecutor::secureStoreEncryptionKeyID); - - if (file_exists(databasePath) && maybeEncryptionKey) { - SQLiteQueryExecutor::encryptionKey = maybeEncryptionKey.value(); - return; - } - SQLiteQueryExecutor::assign_encryption_key(); - }); -} - SQLiteQueryExecutor::SQLiteQueryExecutor() { SQLiteQueryExecutor::migrate(); } @@ -1286,6 +1265,7 @@ return (entry == nullptr) ? "" : entry->data; } +#ifndef EMSCRIPTEN void SQLiteQueryExecutor::clearSensitiveData() { if (file_exists(SQLiteQueryExecutor::sqliteFilePath) && std::remove(SQLiteQueryExecutor::sqliteFilePath.c_str())) { @@ -1298,4 +1278,29 @@ SQLiteQueryExecutor::migrate(); } +void SQLiteQueryExecutor::initialize(std::string &databasePath) { + std::call_once(SQLiteQueryExecutor::initialized, [&databasePath]() { + SQLiteQueryExecutor::sqliteFilePath = databasePath; + CommSecureStore commSecureStore{}; + folly::Optional maybeEncryptionKey = + commSecureStore.get(SQLiteQueryExecutor::secureStoreEncryptionKeyID); + + if (file_exists(databasePath) && maybeEncryptionKey) { + SQLiteQueryExecutor::encryptionKey = maybeEncryptionKey.value(); + return; + } + SQLiteQueryExecutor::assign_encryption_key(); + }); +} + +void SQLiteQueryExecutor::assign_encryption_key() { + CommSecureStore commSecureStore{}; + std::string encryptionKey = comm::crypto::Tools::generateRandomHexString( + SQLiteQueryExecutor::sqlcipherEncryptionKeySize); + commSecureStore.set( + SQLiteQueryExecutor::secureStoreEncryptionKeyID, encryptionKey); + SQLiteQueryExecutor::encryptionKey = encryptionKey; +} +#endif + } // namespace comm diff --git a/web/database/_generated/comm_query_executor.wasm b/web/database/_generated/comm_query_executor.wasm index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@