From a291f6c2c5b293a164cd2bb2785cee760a0a8903 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 30 Apr 2020 22:08:00 +0100 Subject: [PATCH 1/3] Wait for user to be verified in e2e setup Wait for our user to become verified and cross-signing to be ready before declaring that we're finsihed, otherwise we could end up prompting the user to verify again if we just wait for the verification itself to complete. Fixes part of https://github.com/vector-im/riot-web/issues/13464 --- src/stores/SetupEncryptionStore.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/stores/SetupEncryptionStore.js b/src/stores/SetupEncryptionStore.js index cbbbefb129..031c28ddb1 100644 --- a/src/stores/SetupEncryptionStore.js +++ b/src/stores/SetupEncryptionStore.js @@ -17,6 +17,7 @@ limitations under the License. import EventEmitter from 'events'; import { MatrixClientPeg } from '../MatrixClientPeg'; import { accessSecretStorage, AccessCancelledError } from '../CrossSigningManager'; +import { PHASE_DONE as VERIF_PHASE_DONE } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest"; export const PHASE_INTRO = 0; export const PHASE_BUSY = 1; @@ -39,6 +40,7 @@ export class SetupEncryptionStore extends EventEmitter { this.verificationRequest = null; this.backupInfo = null; MatrixClientPeg.get().on("crypto.verification.request", this.onVerificationRequest); + MatrixClientPeg.get().on('userTrustStatusChanged', this._onUserTrustStatusChanged); } stop() { @@ -51,6 +53,7 @@ export class SetupEncryptionStore extends EventEmitter { } if (MatrixClientPeg.get()) { MatrixClientPeg.get().removeListener("crypto.verification.request", this.onVerificationRequest); + MatrixClientPeg.get().removeListener('userTrustStatusChanged', this._onUserTrustStatusChanged); } } @@ -102,6 +105,15 @@ export class SetupEncryptionStore extends EventEmitter { } } + _onUserTrustStatusChanged = async (userId) => { + if (userId !== MatrixClientPeg.get().getUserId()) return; + const crossSigningReady = await MatrixClientPeg.get().isCrossSigningReady(); + if (crossSigningReady) { + this.phase = PHASE_DONE; + this.emit("update"); + } + } + onVerificationRequest = async (request) => { if (request.otherUserId !== MatrixClientPeg.get().getUserId()) return; @@ -119,6 +131,14 @@ export class SetupEncryptionStore extends EventEmitter { this.verificationRequest.off("change", this.onVerificationRequestChange); this.verificationRequest = null; this.emit("update"); + } else if (this.verificationRequest.phase === VERIF_PHASE_DONE) { + this.verificationRequest.off("change", this.onVerificationRequestChange); + this.verificationRequest = null; + // At this point, the verification has finished, we just need to wait for + // cross signing to be ready to use, so wait for the user trust status to + // change. + this.phase = PHASE_BUSY; + this.emit("update"); } } From 4377e4161f5aa8ed98b9f2ebfbe9192d77797767 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 30 Apr 2020 22:21:48 +0100 Subject: [PATCH 2/3] Clear more state in DeviceListener Especially the devices at start, otherwise they'll just be wrong if you log in after logging out. --- src/DeviceListener.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DeviceListener.js b/src/DeviceListener.js index d948911d7c..d2ba8219db 100644 --- a/src/DeviceListener.js +++ b/src/DeviceListener.js @@ -78,6 +78,8 @@ export default class DeviceListener { this._dismissedThisDeviceToast = false; this._keyBackupInfo = null; this._keyBackupFetchedAt = null; + this._ourDeviceIdsAtStart = null; + this._displayingToastsForDeviceIds = new Set(); } /** From a04564d1e37c2f1b265154ff6c678ef0e25781fc Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 1 May 2020 10:58:00 +0100 Subject: [PATCH 3/3] Guard against race when waiting for cross-signing to be ready Check to see if cross-signing is already set up after a verification is done to make sure it doesn't race and we end up waiting forever. --- src/stores/SetupEncryptionStore.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/stores/SetupEncryptionStore.js b/src/stores/SetupEncryptionStore.js index 031c28ddb1..ae1f998b02 100644 --- a/src/stores/SetupEncryptionStore.js +++ b/src/stores/SetupEncryptionStore.js @@ -126,7 +126,7 @@ export class SetupEncryptionStore extends EventEmitter { this.emit("update"); } - onVerificationRequestChange = () => { + onVerificationRequestChange = async () => { if (this.verificationRequest.cancelled) { this.verificationRequest.off("change", this.onVerificationRequestChange); this.verificationRequest = null; @@ -136,8 +136,9 @@ export class SetupEncryptionStore extends EventEmitter { this.verificationRequest = null; // At this point, the verification has finished, we just need to wait for // cross signing to be ready to use, so wait for the user trust status to - // change. - this.phase = PHASE_BUSY; + // change (or change to DONE if it's already ready). + const crossSigningReady = await MatrixClientPeg.get().isCrossSigningReady(); + this.phase = crossSigningReady ? PHASE_DONE : PHASE_BUSY; this.emit("update"); } }