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 @@ -14,7 +14,6 @@ #ifndef EMSCRIPTEN #include "../CryptoTools/CryptoModule.h" -#include "../Notifications/BackgroundDataStorage/NotificationsCryptoModule.h" #include "CommSecureStore.h" #include "PlatformSpecificTools.h" #include "StaffUtils.h" @@ -553,41 +552,6 @@ return create_table(db, query, "integrity_store"); } -bool migrate_notifs_crypto_account(sqlite3 *db) { -#ifndef EMSCRIPTEN - std::string legacyCryptoAccountDataKey = "cryptoAccountDataKey"; - folly::Optional secretKey = - CommSecureStore::get(legacyCryptoAccountDataKey); - - if (!secretKey.hasValue()) { - return false; - } - - std::unique_ptr legacyNotifsAccount = - NotificationsCryptoModule::migrateLegacyNotificationsCryptoModule(); - - if (!legacyNotifsAccount) { - return true; - } - - std::string insert_notifs_account_query = - "REPLACE INTO olm_persist_account (id, account_data) " - "VALUES (?, ?);"; - - crypto::Persist legacyNotifsPersist = - legacyNotifsAccount->storeAsB64(secretKey.value()); - std::string notifsAccountData = std::string( - legacyNotifsPersist.account.begin(), legacyNotifsPersist.account.end()); - - replaceEntity( - db, insert_notifs_account_query, {NOTIFS_ACCOUNT_ID, notifsAccountData}); - - return true; -#else - return true; -#endif -} - bool create_synced_metadata_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS synced_metadata (" @@ -1001,7 +965,7 @@ {35, {create_communities_table, true}}, {36, {create_messages_to_device_table, true}}, {37, {create_integrity_table, true}}, - {38, {migrate_notifs_crypto_account, true}}, + {38, {[](sqlite3 *) { return true; }, false}}, {39, {create_synced_metadata_table, true}}, {40, {create_keyservers_synced, true}}, {41, {create_aux_user_table, true}}}}; diff --git a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h --- a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h +++ b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h @@ -39,8 +39,6 @@ const static std::string initialEncryptedMessageContent; const static int olmEncryptedTypeMessage; - static std::unique_ptr - migrateLegacyNotificationsCryptoModule(); static void clearSensitiveData(); static void persistNotificationsSession( const std::string &keyserverID, diff --git a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp --- a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp +++ b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp @@ -183,42 +183,6 @@ return {std::move(session), picklingKey}; } -std::unique_ptr -NotificationsCryptoModule::migrateLegacyNotificationsCryptoModule() { - const std::string notificationsCryptoAccountPath = - PlatformSpecificTools::getNotificationsCryptoAccountPath(); - std::ifstream notificationCryptoAccountCheck(notificationsCryptoAccountPath); - - if (!notificationCryptoAccountCheck.good()) { - notificationCryptoAccountCheck.close(); - return nullptr; - } - notificationCryptoAccountCheck.close(); - - std::string legacySecureStoreNotifsAccountKey = - "notificationsCryptoAccountDataKey"; - folly::Optional legacyPicklingKey = - CommSecureStore::get(legacySecureStoreNotifsAccountKey); - if (!legacyPicklingKey.hasValue()) { - throw std::runtime_error( - "Attempt to migrate legacy notifications account but pickling key " - "missing."); - } - - std::unique_ptr legacyCryptoModule = - NotificationsCryptoModule::deserializeCryptoModule( - notificationsCryptoAccountPath, legacyPicklingKey.value()); - - std::string legacyNotificationsSessionID = "keyserverHostedNotificationsID"; - std::shared_ptr legacyNotificationsSession = - legacyCryptoModule->getSessionByDeviceId(legacyNotificationsSessionID); - - NotificationsCryptoModule::persistNotificationsSession( - ashoatKeyserverIDUsedOnlyForMigrationFromLegacyNotifStorage, - legacyNotificationsSession); - return legacyCryptoModule; -} - void NotificationsCryptoModule::clearSensitiveData() { std::string notificationsCryptoAccountPath = PlatformSpecificTools::getNotificationsCryptoAccountPath(); @@ -332,8 +296,17 @@ } void NotificationsCryptoModule::LegacyStatefulDecryptResult::flushState() { + std::shared_ptr legacyNotificationsSession = + this->cryptoModule->getSessionByDeviceId(keyserverHostedNotificationsID); NotificationsCryptoModule::serializeAndFlushCryptoModule( std::move(this->cryptoModule), this->path, this->picklingKey); + try { + NotificationsCryptoModule::persistNotificationsSession( + ashoatKeyserverIDUsedOnlyForMigrationFromLegacyNotifStorage, + legacyNotificationsSession); + } catch (const CommMMKV::InitFromNSEForbiddenError &e) { + return; + } } std::unique_ptr diff --git a/web/shared-worker/_generated/comm_query_executor.wasm b/web/shared-worker/_generated/comm_query_executor.wasm index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@