Skip to content

Commit 2d67a35

Browse files
authored
Merge pull request #1776 from matrix-org/dbkr/rescue_lost_megolm_key
Attempt to fix megolm key not being in SSSS
2 parents ab5b69b + 05a20ab commit 2d67a35

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/crypto/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,20 @@ export class Crypto extends EventEmitter {
967967
fixedBackupKey || sessionBackupKey,
968968
));
969969
await builder.addSessionBackupPrivateKeyToCache(decodedBackupKey);
970+
} else if (this.backupManager.getKeyBackupEnabled()) {
971+
// key backup is enabled but we don't have a session backup key in SSSS: see if we have one in
972+
// the cache or the user can provide one, and if so, write it to SSSS
973+
const backupKey = await this.getSessionBackupPrivateKey() || await getKeyBackupPassphrase();
974+
if (!backupKey) {
975+
// This will require user intervention to recover from since we don't have the key
976+
// backup key anywhere. The user should probably just set up a new key backup and
977+
// the key for the new backup will be stored. If we hit this scenario in the wild
978+
// with any frequency, we should do more than just log an error.
979+
logger.error("Key backup is enabled but couldn't get key backup key!");
980+
return;
981+
}
982+
logger.info("Got session backup key from cache/user that wasn't in SSSS: saving to SSSS");
983+
await secretStorage.store("m.megolm_backup.v1", olmlib.encodeBase64(backupKey));
970984
}
971985

972986
const operation = builder.buildOperation();

0 commit comments

Comments
 (0)