From e1e9f690c9c4088715c4a9fa495bd237f0ba16af Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Thu, 5 Dec 2019 12:53:59 -0500 Subject: [PATCH] ignore m.key.verification.done messages when we don't expect any more messages --- src/crypto/verification/Base.js | 12 ++++++++---- src/crypto/verification/SAS.js | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/crypto/verification/Base.js b/src/crypto/verification/Base.js index 0026facaa..4c0ddf8bb 100644 --- a/src/crypto/verification/Base.js +++ b/src/crypto/verification/Base.js @@ -173,10 +173,14 @@ export default class VerificationBase extends EventEmitter { if (this._done) { return; } else if (e.getType() === this._expectedEvent) { - this._expectedEvent = undefined; - this._rejectEvent = undefined; - this._resetTimer(); - this._resolveEvent(e); + // if we receive an expected m.key.verification.done, then just + // ignore it, since we don't need to do anything about it + if (this._expectedEvent !== "m.key.verification.done") { + this._expectedEvent = undefined; + this._rejectEvent = undefined; + this._resetTimer(); + this._resolveEvent(e); + } } else if (e.getType() === "m.key.verification.cancel") { const reject = this._reject; this._reject = undefined; diff --git a/src/crypto/verification/SAS.js b/src/crypto/verification/SAS.js index 97dc8ffc6..fc0f50c7c 100644 --- a/src/crypto/verification/SAS.js +++ b/src/crypto/verification/SAS.js @@ -270,7 +270,14 @@ export default class SAS extends Base { [e] = await Promise.all([ - this._waitForEvent("m.key.verification.mac"), + this._waitForEvent("m.key.verification.mac") + .then((e) => { + // we don't expect any more messages from the other + // party, and they may send a m.key.verification.done + // when they're done on their end + this._expectedEvent = "m.key.verification.done"; + return e; + }), verifySAS, ]); content = e.getContent(); @@ -347,7 +354,14 @@ export default class SAS extends Base { [e] = await Promise.all([ - this._waitForEvent("m.key.verification.mac"), + this._waitForEvent("m.key.verification.mac") + .then((e) => { + // we don't expect any more messages from the other + // party, and they may send a m.key.verification.done + // when they're done on their end + this._expectedEvent = "m.key.verification.done"; + return e; + }), verifySAS, ]); content = e.getContent();