Skip to content

Commit 3219aef

Browse files
authored
Avoid key prompts when resetting crypto (#4586)
* Avoid key prompts when resetting crypto Attempting to get the backup key out of secret storage can cause the user to be prompted for their key, which is not helpful if this is being done as part of a reset. This check was redundant anyway and we can just overwrite the key with the same value. Also fix docs and remove check for active backup. * Fix doc
1 parent aba4e69 commit 3219aef

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

src/rust-crypto/rust-crypto.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
854854

855855
/**
856856
* If we have a backup key for the current, trusted backup in cache,
857-
* and we have secret storage active, save it to secret storage.
857+
* save it to secret storage.
858858
*/
859859
private async saveBackupKeyToStorage(): Promise<void> {
860860
const keyBackupInfo = await this.backupManager.getServerBackupInfo();
@@ -863,12 +863,6 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
863863
return;
864864
}
865865

866-
const activeBackupVersion = await this.backupManager.getActiveBackupVersion();
867-
if (!activeBackupVersion || activeBackupVersion !== keyBackupInfo.version) {
868-
logger.info("Not saving backup key to secret storage: backup keys do not match active backup version");
869-
return;
870-
}
871-
872866
const backupKeys: RustSdkCryptoJs.BackupKeys = await this.olmMachine.getBackupKeys();
873867
if (!backupKeys.decryptionKey) {
874868
logger.info("Not saving backup key to secret storage: no backup key");
@@ -880,14 +874,9 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
880874
return;
881875
}
882876

883-
const backupKeyFromStorage = await this.secretStorage.get("m.megolm_backup.v1");
884877
const backupKeyBase64 = backupKeys.decryptionKey.toBase64();
885878

886-
// The backup version that the key corresponds to isn't saved in 4S so if it's different, we must assume
887-
// it's stale and overwrite.
888-
if (backupKeyFromStorage !== backupKeyBase64) {
889-
await this.secretStorage.store("m.megolm_backup.v1", backupKeyBase64);
890-
}
879+
await this.secretStorage.store("m.megolm_backup.v1", backupKeyBase64);
891880
}
892881

893882
/**

0 commit comments

Comments
 (0)