Skip to content

Commit 32f51e8

Browse files
authored
History sharing: do /keys/query before checking for key bundle (#4992)
* History sharing: do `/keys/query` before checking for key bundle The next release of matrix-sdk-crypto-wasm will check that the device that sent us the key bundle data was correctly cross-signed by its owner, which means we need to have the owner's cross-signing keys before we check if we have the bundle. This replicates a change made in the Rust SDK, at https://github.com/matrix-org/matrix-rust-sdk/pull/5510/files#diff-9f89fa75c4eb3743ae674be1bb90f75169bd815a259917799c71b8a546449d51R133-R140. * fix unit test * Comment
1 parent 82aa04d commit 32f51e8

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

spec/unit/rust-crypto/rust-crypto.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,6 +2353,7 @@ describe("RustCrypto", () => {
23532353

23542354
beforeEach(async () => {
23552355
mockOlmMachine = {
2356+
queryKeysForUsers: jest.fn().mockReturnValue({}),
23562357
getReceivedRoomKeyBundleData: jest.fn(),
23572358
receiveRoomKeyBundle: jest.fn(),
23582359
} as unknown as Mocked<OlmMachine>;
@@ -2377,6 +2378,7 @@ describe("RustCrypto", () => {
23772378
it("does nothing if there is no key bundle", async () => {
23782379
mockOlmMachine.getReceivedRoomKeyBundleData.mockResolvedValue(undefined);
23792380
await rustCrypto.maybeAcceptKeyBundle("!room_id", "@bob:example.org");
2381+
expect(mockOlmMachine.queryKeysForUsers).toHaveBeenCalledTimes(1);
23802382
expect(mockOlmMachine.getReceivedRoomKeyBundleData).toHaveBeenCalledTimes(1);
23812383
expect(mockOlmMachine.getReceivedRoomKeyBundleData.mock.calls[0][0].toString()).toEqual("!room_id");
23822384
expect(mockOlmMachine.getReceivedRoomKeyBundleData.mock.calls[0][1].toString()).toEqual("@bob:example.org");

src/rust-crypto/rust-crypto.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,22 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
326326
* Implementation of {@link CryptoBackend.maybeAcceptKeyBundle}.
327327
*/
328328
public async maybeAcceptKeyBundle(roomId: string, inviter: string): Promise<void> {
329-
// TODO: retry this if it gets interrupted or it fails.
329+
// TODO: retry this if it gets interrupted or it fails. (https://github.com/matrix-org/matrix-rust-sdk/issues/5112)
330330
// TODO: do this in the background.
331-
// TODO: handle the bundle message arriving after the invite.
331+
// TODO: handle the bundle message arriving after the invite (https://github.com/element-hq/element-web/issues/30740)
332332

333333
const logger = new LogSpan(this.logger, `maybeAcceptKeyBundle(${roomId}, ${inviter})`);
334334

335+
// Make sure we have an up-to-date idea of the inviter's cross-signing keys, so that we can check if the
336+
// device that sent us the bundle data was correctly cross-signed.
337+
//
338+
// TODO: it would be nice to skip this step if we have an up-to-date copy of the inviter's cross-signing keys,
339+
// but we don't have an easy way to check that. Possibly the rust side could trigger a key request and then
340+
// block until it happens.
341+
logger.info(`Checking inviter cross-signing keys`);
342+
const request = this.olmMachine.queryKeysForUsers([new RustSdkCryptoJs.UserId(inviter)]);
343+
await this.outgoingRequestProcessor.makeOutgoingRequest(request);
344+
335345
const bundleData = await this.olmMachine.getReceivedRoomKeyBundleData(
336346
new RustSdkCryptoJs.RoomId(roomId),
337347
new RustSdkCryptoJs.UserId(inviter),

0 commit comments

Comments
 (0)