Skip to content

Commit 43830d0

Browse files
committed
enable backup if the key we received a correct key
1 parent e99267d commit 43830d0

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/rust-crypto/backup.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ export class RustBackupManager extends TypedEventEmitter<RustBackupCryptoEvents,
199199
`handleBackupSecretReceived: A valid backup decryption key has been received and stored in cache.`,
200200
);
201201
await this.saveBackupDecryptionKey(backupDecryptionKey, latestBackupInfo.version);
202+
// Check if the backup should be enabled (e.g. if it's properly
203+
// signed), and enable it if it should
204+
if (this.keyBackupCheckInProgress) {
205+
await this.keyBackupCheckInProgress;
206+
}
207+
this.keyBackupCheckInProgress = this.doCheckKeyBackup(latestBackupInfo).finally(() => {
208+
this.keyBackupCheckInProgress = null;
209+
});
210+
await this.keyBackupCheckInProgress;
202211
return true;
203212
} catch (e) {
204213
this.logger.warn("handleBackupSecretReceived: Invalid backup decryption key", e);
@@ -281,12 +290,17 @@ export class RustBackupManager extends TypedEventEmitter<RustBackupCryptoEvents,
281290

282291
private keyBackupCheckInProgress: Promise<KeyBackupCheck | null> | null = null;
283292

284-
/** Helper for `checkKeyBackup` */
285-
private async doCheckKeyBackup(): Promise<KeyBackupCheck | null> {
293+
/** Helper to check the key backup status, and enable/disable it as appropriate
294+
*
295+
* A KeyBackupInfo can be passed if it was fetched recently, to avoid trying to
296+
* re-fetch it from the server.
297+
*/
298+
private async doCheckKeyBackup(backupInfo?: KeyBackupInfo | null | undefined): Promise<KeyBackupCheck | null> {
286299
this.logger.debug("Checking key backup status...");
287-
let backupInfo: KeyBackupInfo | null | undefined;
288300
try {
289-
backupInfo = await this.requestKeyBackupVersion();
301+
if (!backupInfo) {
302+
backupInfo = await this.requestKeyBackupVersion();
303+
}
290304
} catch (e) {
291305
this.logger.warn("Error checking for active key backup", e);
292306
this.serverBackupInfo = undefined;

0 commit comments

Comments
 (0)