From a36affb3ee1b4c592b77c5c732c52890acc56bc0 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 11 Sep 2024 17:22:34 +1000 Subject: [PATCH] chore: build bins test --- .github/workflows/build-binaries.yml | 2 +- ts/session/apis/snode_api/SNodeAPI.ts | 5 ++ ts/util/accountManager.ts | 70 ++++++++++++++++----------- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml index 66fa53ba4..e32f858c5 100644 --- a/.github/workflows/build-binaries.yml +++ b/.github/workflows/build-binaries.yml @@ -76,7 +76,7 @@ jobs: working-directory: ./release/ - name: Upload Production Artifacts - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v4 with: name: ${{ runner.os }}-${{ runner.arch }}-production path: release diff --git a/ts/session/apis/snode_api/SNodeAPI.ts b/ts/session/apis/snode_api/SNodeAPI.ts index 37a508cbf..0af2ca039 100644 --- a/ts/session/apis/snode_api/SNodeAPI.ts +++ b/ts/session/apis/snode_api/SNodeAPI.ts @@ -29,6 +29,11 @@ const forceNetworkDeletion = async (): Promise | null> => { try { const maliciousSnodes = await pRetry( async () => { + if (!window.isOnline) { + window?.log?.warn('forceNetworkDeletion: we are offline.'); + return null; + } + const userSwarm = await getSwarmFor(userX25519PublicKey); const snodeToMakeRequestTo: Snode | undefined = sample(userSwarm); diff --git a/ts/util/accountManager.ts b/ts/util/accountManager.ts index 32850bbd0..950206d4e 100644 --- a/ts/util/accountManager.ts +++ b/ts/util/accountManager.ts @@ -21,6 +21,7 @@ import { updateConfirmModal, updateDeleteAccountModal } from '../state/ducks/mod import { actions as userActions } from '../state/ducks/user'; import { Registration } from './registration'; import { Storage, saveRecoveryPhrase, setLocalPubKey, setSignInByLinking } from './storage'; +import { PromiseUtils } from '../session/utils'; import { SnodeAPI } from '../session/apis/snode_api/SNodeAPI'; /** @@ -271,10 +272,14 @@ export async function sendConfigMessageAndDeleteEverything() { try { // DELETE LOCAL DATA ONLY, NOTHING ON NETWORK window?.log?.info('DeleteAccount => Sending a last SyncConfiguration'); + if (window.isOnline) { + // be sure to wait for the message being effectively sent. Otherwise we won't be able to encrypt it for our devices ! + await forceSyncConfigurationNowIfNeeded(true); + window?.log?.info('Last configuration message sent!'); + } else { + window?.log?.warn('sendConfigMessageAndDeleteEverything: we are offline, just deleting'); + } - // be sure to wait for the message being effectively sent. Otherwise we won't be able to encrypt it for our devices ! - await forceSyncConfigurationNowIfNeeded(true); - window?.log?.info('Last configuration message sent!'); await deleteDbLocally(); } catch (error) { // if an error happened, it's not related to the delete everything on network logic as this is handled above. @@ -294,38 +299,47 @@ export async function sendConfigMessageAndDeleteEverything() { } } +async function deleteEverythingOnNetwork() { + const allRoomInfos = await getAllValidOpenGroupV2ConversationRoomInfos(); + const allRoomInfosArray = Array.from(allRoomInfos?.values() || []); + // clear all sogs inboxes (includes message requests) + + if (allRoomInfosArray.length) { + // clear each inbox per sogs + + const clearInboxPromises = allRoomInfosArray.map(async roomInfo => { + const success = await clearInbox(roomInfo); + if (!success) { + throw Error(`Failed to clear inbox for ${roomInfo.conversationId}`); + } + return true; + }); + + const results = await Promise.allSettled(clearInboxPromises); + results.forEach((result, index) => { + if (result.status === 'rejected') { + window.log.error(result.reason); + } else { + window.log.info('Inbox cleared for room', allRoomInfosArray[index]); + } + }); + } + + return SnodeAPI.forceNetworkDeletion(); +} + export async function deleteEverythingAndNetworkData() { try { // DELETE EVERYTHING ON NETWORK, AND THEN STUFF LOCALLY STORED // a bit of duplicate code below, but it's easier to follow every case like that (helped with returns) - - // clear all sogs inboxes (includes message requests) - const allRoomInfos = await getAllValidOpenGroupV2ConversationRoomInfos(); - const allRoomInfosArray = Array.from(allRoomInfos?.values() || []); - - if (allRoomInfosArray.length) { - // clear each inbox per sogs - - const clearInboxPromises = allRoomInfosArray.map(async roomInfo => { - const success = await clearInbox(roomInfo); - if (!success) { - throw Error(`Failed to clear inbox for ${roomInfo.conversationId}`); - } - return true; - }); - - const results = await Promise.allSettled(clearInboxPromises); - results.forEach((result, index) => { - if (result.status === 'rejected') { - window.log.error(result.reason); - } else { - window.log.info('Inbox cleared for room', allRoomInfosArray[index]); - } - }); + let potentiallyMaliciousSnodes: Array | null = null; + try { + potentiallyMaliciousSnodes = await PromiseUtils.timeout(deleteEverythingOnNetwork(), 15000); + } catch (e) { + potentiallyMaliciousSnodes = null; // mark as generic fail } // send deletion message to the network - const potentiallyMaliciousSnodes = await SnodeAPI.forceNetworkDeletion(); if (potentiallyMaliciousSnodes === null || potentiallyMaliciousSnodes.length) { window?.log?.warn('DeleteAccount => forceNetworkDeletion failed');