diff --git a/spec/integ/crypto/megolm-backup.spec.ts b/spec/integ/crypto/megolm-backup.spec.ts index e0a2c790df..8978750949 100644 --- a/spec/integ/crypto/megolm-backup.spec.ts +++ b/spec/integ/crypto/megolm-backup.spec.ts @@ -945,7 +945,29 @@ describe("megolm-keys backup", () => { expect(await aliceCrypto.getActiveSessionBackupVersion()).toEqual(testData.SIGNED_BACKUP_DATA.version); }); - it("does not enable a backup signed by an untrusted device", async () => { + it("enables a backup not signed by a trusted device, when we have the decryption key", async () => { + aliceClient = await initTestClient(); + const aliceCrypto = aliceClient.getCrypto()!; + + // download the device list, to match the trusted-device case + await aliceClient.startClient(); + await waitForDeviceList(); + + fetchMock.get("path:/_matrix/client/v3/room_keys/version", testData.SIGNED_BACKUP_DATA); + + // Alice does *not* trust the device that signed the backup, but *does* have the decryption key. + await aliceCrypto.storeSessionBackupPrivateKey( + Buffer.from(testData.BACKUP_DECRYPTION_KEY_BASE64, "base64"), + testData.SIGNED_BACKUP_DATA.version!, + ); + + const result = await aliceCrypto.checkKeyBackupAndEnable(); + expect(result).toBeTruthy(); + expect(result!.trustInfo).toEqual({ trusted: false, matchesDecryptionKey: true }); + expect(await aliceCrypto.getActiveSessionBackupVersion()).toEqual(testData.SIGNED_BACKUP_DATA.version); + }); + + it("does not enable a backup signed by an untrusted device when we do not have the decryption key", async () => { aliceClient = await initTestClient(); const aliceCrypto = aliceClient.getCrypto()!; diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index 426a9c3ce5..4fcc9532b3 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -1292,7 +1292,7 @@ describe("verification", () => { const requestId = await requestPromises.get("m.megolm_backup.v1"); - const infoCopy = Object.assign({}, matchingBackupInfo); + const infoCopy = Object.assign({}, nonMatchingBackupInfo); delete infoCopy.auth_data.signatures; await sendBackupGossipAndExpectVersion(requestId!, BACKUP_DECRYPTION_KEY_BASE64, infoCopy); diff --git a/src/rust-crypto/backup.ts b/src/rust-crypto/backup.ts index 342055163a..33364c1440 100644 --- a/src/rust-crypto/backup.ts +++ b/src/rust-crypto/backup.ts @@ -137,6 +137,7 @@ export class RustBackupManager extends TypedEventEmitter { if (!force && this.checkedForBackup) { @@ -164,9 +165,10 @@ export class RustBackupManager extends TypedEventEmitter