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" @@ -554,38 +553,10 @@ } 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 + // This migration was turned into no-op due to + // concerns outlined in the following issue: + // https://linear.app/comm/issue/ENG-7638/investigate-android-crash-on-sqlite-migration-38 return true; -#endif } bool create_synced_metadata_table(sqlite3 *db) { 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