You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
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
This commit is contained in:
@@ -854,7 +854,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
|
||||
|
||||
/**
|
||||
* If we have a backup key for the current, trusted backup in cache,
|
||||
* and we have secret storage active, save it to secret storage.
|
||||
* save it to secret storage.
|
||||
*/
|
||||
private async saveBackupKeyToStorage(): Promise<void> {
|
||||
const keyBackupInfo = await this.backupManager.getServerBackupInfo();
|
||||
@@ -863,12 +863,6 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
|
||||
return;
|
||||
}
|
||||
|
||||
const activeBackupVersion = await this.backupManager.getActiveBackupVersion();
|
||||
if (!activeBackupVersion || activeBackupVersion !== keyBackupInfo.version) {
|
||||
logger.info("Not saving backup key to secret storage: backup keys do not match active backup version");
|
||||
return;
|
||||
}
|
||||
|
||||
const backupKeys: RustSdkCryptoJs.BackupKeys = await this.olmMachine.getBackupKeys();
|
||||
if (!backupKeys.decryptionKey) {
|
||||
logger.info("Not saving backup key to secret storage: no backup key");
|
||||
@@ -880,15 +874,10 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
|
||||
return;
|
||||
}
|
||||
|
||||
const backupKeyFromStorage = await this.secretStorage.get("m.megolm_backup.v1");
|
||||
const backupKeyBase64 = backupKeys.decryptionKey.toBase64();
|
||||
|
||||
// The backup version that the key corresponds to isn't saved in 4S so if it's different, we must assume
|
||||
// it's stale and overwrite.
|
||||
if (backupKeyFromStorage !== backupKeyBase64) {
|
||||
await this.secretStorage.store("m.megolm_backup.v1", backupKeyBase64);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the secretStorage key to the secret storage
|
||||
|
||||
Reference in New Issue
Block a user