1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

ElementR: Process all verification events, not just requests (#3650)

* Process all verification event

* Add test for `isVerificationEvent`

* Review changes

* Remove null comparison and add doc to remote echo

* review changes
This commit is contained in:
Florian Duros
2023-08-09 16:14:58 +02:00
committed by GitHub
parent 3f7af189e4
commit 3a5d66057e
3 changed files with 71 additions and 11 deletions

View File

@@ -55,8 +55,8 @@ import { secretStorageContainsCrossSigningKeys } from "./secret-storage";
import { keyFromPassphrase } from "../crypto/key_passphrase";
import { encodeRecoveryKey } from "../crypto/recoverykey";
import { crypto } from "../crypto/crypto";
import { RustVerificationRequest, verificationMethodIdentifierToMethod } from "./verification";
import { EventType, MsgType } from "../@types/event";
import { isVerificationEvent, RustVerificationRequest, verificationMethodIdentifierToMethod } from "./verification";
import { EventType } from "../@types/event";
import { CryptoEvent } from "../crypto";
import { TypedEventEmitter } from "../models/typed-event-emitter";
import { RustBackupCryptoEventMap, RustBackupCryptoEvents, RustBackupManager } from "./backup";
@@ -1054,15 +1054,13 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
* @param event - live event
*/
public async onLiveEventFromSync(event: MatrixEvent): Promise<void> {
// Ignore state event
if (event.isState()) return;
// Ignore state event or remote echo
// transaction_id is provided in case of remote echo {@link https://spec.matrix.org/v1.7/client-server-api/#local-echo}
if (event.isState() || !!event.getUnsigned().transaction_id) return;
const processEvent = async (evt: MatrixEvent): Promise<void> => {
// Process only key validation request
if (
evt.getType() === EventType.RoomMessage &&
evt.getContent().msgtype === MsgType.KeyVerificationRequest
) {
// Process only verification event
if (isVerificationEvent(event)) {
await this.onKeyVerificationRequest(evt);
}
};
@@ -1072,6 +1070,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
// 5 mins
const TIMEOUT_DELAY = 5 * 60 * 1000;
// After 5mins, we are not expecting the event to be decrypted
const timeoutId = setTimeout(() => event.off(MatrixEventEvent.Decrypted, onDecrypted), TIMEOUT_DELAY);
const onDecrypted = (decryptedEvent: MatrixEvent, error?: Error): void => {
@@ -1081,7 +1080,6 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
event.off(MatrixEventEvent.Decrypted, onDecrypted);
processEvent(decryptedEvent);
};
// After 5mins, we are not expecting the event to be decrypted
event.on(MatrixEventEvent.Decrypted, onDecrypted);
} else {