You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
ElementR: report invalid keys rather than failing to restore from backup (#4006)
* rust-crypto: allow reporting failures when restoring keys * add test and catch more invalid keys * remove checks for room_id and session_id as they are guaranteed to be set * remove obsolete comment
This commit is contained in:
@ -46,7 +46,7 @@ import {
|
|||||||
} from "../../../src";
|
} from "../../../src";
|
||||||
import { mkEvent } from "../../test-utils/test-utils";
|
import { mkEvent } from "../../test-utils/test-utils";
|
||||||
import { CryptoBackend } from "../../../src/common-crypto/CryptoBackend";
|
import { CryptoBackend } from "../../../src/common-crypto/CryptoBackend";
|
||||||
import { IEventDecryptionResult } from "../../../src/@types/crypto";
|
import { IEventDecryptionResult, IMegolmSessionData } from "../../../src/@types/crypto";
|
||||||
import { OutgoingRequestProcessor } from "../../../src/rust-crypto/OutgoingRequestProcessor";
|
import { OutgoingRequestProcessor } from "../../../src/rust-crypto/OutgoingRequestProcessor";
|
||||||
import {
|
import {
|
||||||
AccountDataClient,
|
AccountDataClient,
|
||||||
@ -1260,6 +1260,34 @@ describe("RustCrypto", () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("ignores invalid keys when restoring from backup", async () => {
|
||||||
|
const rustCrypto = await makeTestRustCrypto();
|
||||||
|
const olmMachine: OlmMachine = rustCrypto["olmMachine"];
|
||||||
|
|
||||||
|
await olmMachine.enableBackupV1(
|
||||||
|
(testData.SIGNED_BACKUP_DATA.auth_data as Curve25519AuthData).public_key,
|
||||||
|
testData.SIGNED_BACKUP_DATA.version!,
|
||||||
|
);
|
||||||
|
|
||||||
|
const backup = Array.from(testData.MEGOLM_SESSION_DATA_ARRAY);
|
||||||
|
// in addition to correct keys, we restore an invalid key
|
||||||
|
backup.push({ room_id: "!roomid", session_id: "sessionid" } as IMegolmSessionData);
|
||||||
|
const progressCallback = jest.fn();
|
||||||
|
await rustCrypto.importBackedUpRoomKeys(backup, { progressCallback });
|
||||||
|
expect(progressCallback).toHaveBeenCalledWith({
|
||||||
|
total: 3,
|
||||||
|
successes: 0,
|
||||||
|
stage: "load_keys",
|
||||||
|
failures: 1,
|
||||||
|
});
|
||||||
|
expect(progressCallback).toHaveBeenCalledWith({
|
||||||
|
total: 3,
|
||||||
|
successes: 1,
|
||||||
|
stage: "load_keys",
|
||||||
|
failures: 1,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -212,15 +212,18 @@ export class RustBackupManager extends TypedEventEmitter<RustBackupCryptoEvents,
|
|||||||
}
|
}
|
||||||
keysByRoom.get(roomId)!.set(key.session_id, key);
|
keysByRoom.get(roomId)!.set(key.session_id, key);
|
||||||
}
|
}
|
||||||
await this.olmMachine.importBackedUpRoomKeys(keysByRoom, (progress: BigInt, total: BigInt): void => {
|
await this.olmMachine.importBackedUpRoomKeys(
|
||||||
const importOpt: ImportRoomKeyProgressData = {
|
keysByRoom,
|
||||||
total: Number(total),
|
(progress: BigInt, total: BigInt, failures: BigInt): void => {
|
||||||
successes: Number(progress),
|
const importOpt: ImportRoomKeyProgressData = {
|
||||||
stage: "load_keys",
|
total: Number(total),
|
||||||
failures: 0,
|
successes: Number(progress),
|
||||||
};
|
stage: "load_keys",
|
||||||
opts?.progressCallback?.(importOpt);
|
failures: Number(failures),
|
||||||
});
|
};
|
||||||
|
opts?.progressCallback?.(importOpt);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private keyBackupCheckInProgress: Promise<KeyBackupCheck | null> | null = null;
|
private keyBackupCheckInProgress: Promise<KeyBackupCheck | null> | null = null;
|
||||||
|
Reference in New Issue
Block a user