From 11727833a2050a31beb4fce8f4da9dc9c4927114 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 9 Apr 2020 17:54:45 +0200 Subject: [PATCH] mark request as cancelled immediately after verifier is cancelled in case send errors prevent us from receiving remote echo --- src/crypto/verification/Base.js | 1 + .../verification/request/VerificationRequest.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/crypto/verification/Base.js b/src/crypto/verification/Base.js index 332840860..c3a8e0ec6 100644 --- a/src/crypto/verification/Base.js +++ b/src/crypto/verification/Base.js @@ -287,6 +287,7 @@ export class VerificationBase extends EventEmitter { this._endTimer(); // always kill the activity timer if (!this._done) { this.cancelled = true; + this.request.onVerifierCancelled(); if (this.userId && this.deviceId) { // send a cancellation to the other user (if it wasn't // cancelled by the other user) diff --git a/src/crypto/verification/request/VerificationRequest.js b/src/crypto/verification/request/VerificationRequest.js index afb0d51a4..47fa44657 100644 --- a/src/crypto/verification/request/VerificationRequest.js +++ b/src/crypto/verification/request/VerificationRequest.js @@ -73,6 +73,7 @@ export class VerificationRequest extends EventEmitter { this._accepting = false; this._declining = false; this._verifierHasFinished = false; + this._cancelled = false; this._chosenMethod = null; // we keep a copy of the QR Code data (including other user master key) around // for QR reciprocate verification, to protect against @@ -525,7 +526,7 @@ export class VerificationRequest extends EventEmitter { } const cancelEvent = this._getEventByEither(CANCEL_TYPE); - if (cancelEvent && phase() !== PHASE_DONE) { + if ((this._cancelled || cancelEvent) && phase() !== PHASE_DONE) { transitions.push({phase: PHASE_CANCELLED, event: cancelEvent}); return transitions; } @@ -858,6 +859,15 @@ export class VerificationRequest extends EventEmitter { return true; } + onVerifierCancelled() { + this._cancelled = true; + // move to cancelled phase + const newTransitions = this._applyPhaseTransitions(); + if (newTransitions.length) { + this._setPhase(newTransitions[newTransitions.length - 1].phase); + } + } + onVerifierFinished() { this.channel.send("m.key.verification.done", {}); this._verifierHasFinished = true;