Skip to content

Commit

Permalink
Save the key backup key to secret storage
Browse files Browse the repository at this point in the history
When setting up secret storage, if we have a key backup key in cache
(like we do for the cross signing secrets).
  • Loading branch information
dbkr committed Nov 22, 2024
1 parent 336797e commit 332f9ca
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/rust-crypto/rust-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,20 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
await this.secretStorage.store("m.cross_signing.self_signing", crossSigningPrivateKeys.self_signing_key);
}

// likewise with the key backup key: if we have one, store it in secret storage (if it's not already there)
// also don't bother storing it if we're about to set up a new backup
if (!setupNewKeyBackup) {
const keyBackupKey = await this.getSessionBackupPrivateKey();

const keyBackupKeyInStorage = await secretStorageCanAccessSecrets(this.secretStorage, [
"m.megolm_backup.v1",
]);

if (keyBackupKey && !keyBackupKeyInStorage) {
await this.secretStorage.store("m.megolm_backup.v1", encodeBase64(keyBackupKey));
}
}

if (setupNewKeyBackup) {
await this.resetKeyBackup();
}
Expand Down

0 comments on commit 332f9ca

Please sign in to comment.