Skip to content

Commit a592e28

Browse files
committed
Element-R: emit VerificationRequestReceived on incoming request
1 parent ff53557 commit a592e28

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

spec/integ/crypto/verification.spec.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,11 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
984984
// Add verification request from Bob to Alice in the DM between them
985985
returnRoomMessageFromSync(TEST_ROOM_ID, createVerificationRequestEvent());
986986

987-
// Wait for the sync response to be processed
988-
await syncPromise(aliceClient);
987+
// Wait for the request to be received
988+
const request1 = await emitPromise(aliceClient, CryptoEvent.VerificationRequestReceived);
989+
expect(request1.roomId).toBe(TEST_ROOM_ID);
990+
expect(request1.isSelfVerification).toBe(false);
991+
expect(request1.otherUserId).toBe("@bob:xyz");
989992

990993
const request = aliceClient.getCrypto()!.findVerificationRequestDMInProgress(TEST_ROOM_ID, "@bob:xyz");
991994
// Expect to find the verification request received during the sync
@@ -1021,14 +1024,19 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
10211024
await awaitDecryption(matrixEvent);
10221025
expect(matrixEvent.getContent().msgtype).toEqual("m.bad.encrypted");
10231026

1027+
const requestEventPromise = emitPromise(aliceClient, CryptoEvent.VerificationRequestReceived);
1028+
10241029
// Send Bob the room keys
10251030
returnToDeviceMessageFromSync(toDeviceEvent);
10261031

10271032
// advance the clock, because the devicelist likes to sleep for 5ms during key downloads
10281033
await jest.advanceTimersByTimeAsync(10);
10291034

1030-
// Wait for the message to be decrypted
1031-
await awaitDecryption(matrixEvent, { waitOnDecryptionFailure: true });
1035+
// Wait for the request to be decrypted
1036+
const request1 = await requestEventPromise;
1037+
expect(request1.roomId).toBe(TEST_ROOM_ID);
1038+
expect(request1.isSelfVerification).toBe(false);
1039+
expect(request1.otherUserId).toBe("@bob:xyz");
10321040

10331041
const request = aliceClient.getCrypto()!.findVerificationRequestDMInProgress(TEST_ROOM_ID, "@bob:xyz");
10341042
// Expect to find the verification request received during the sync

src/rust-crypto/rust-crypto.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { keyFromPassphrase } from "../crypto/key_passphrase";
6262
import { encodeRecoveryKey } from "../crypto/recoverykey";
6363
import { crypto } from "../crypto/crypto";
6464
import { isVerificationEvent, RustVerificationRequest, verificationMethodIdentifierToMethod } from "./verification";
65-
import { EventType } from "../@types/event";
65+
import { EventType, MsgType } from "../@types/event";
6666
import { CryptoEvent } from "../crypto";
6767
import { TypedEventEmitter } from "../models/typed-event-emitter";
6868
import { RustBackupCryptoEventMap, RustBackupCryptoEvents, RustBackupDecryptor, RustBackupManager } from "./backup";
@@ -1407,6 +1407,31 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
14071407
new RustSdkCryptoJs.RoomId(roomId),
14081408
);
14091409

1410+
if (
1411+
event.getType() === EventType.RoomMessage &&
1412+
event.getContent().msgtype === MsgType.KeyVerificationRequest
1413+
) {
1414+
const request: RustSdkCryptoJs.VerificationRequest | undefined = this.olmMachine.getVerificationRequest(
1415+
new RustSdkCryptoJs.UserId(event.getSender()!),
1416+
event.getId()!,
1417+
);
1418+
1419+
if (!request) {
1420+
logger.warn(
1421+
`Unable to find rust-side VerificationRequest for just-received verification request ${event.getId()}`,
1422+
);
1423+
} else {
1424+
this.emit(
1425+
CryptoEvent.VerificationRequestReceived,
1426+
new RustVerificationRequest(
1427+
request,
1428+
this.outgoingRequestProcessor,
1429+
this._supportedVerificationMethods,
1430+
),
1431+
);
1432+
}
1433+
}
1434+
14101435
// that may have caused us to queue up outgoing requests, so make sure we send them.
14111436
this.outgoingRequestLoop();
14121437
}

0 commit comments

Comments
 (0)