From c3aabafc12633d372a8364b2f94bd9b25343ef06 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Fri, 9 Dec 2022 14:14:06 +0000 Subject: [PATCH] Simplify checks for cross-signing setup (#9721) When the user logs in, we need to know if we should prompt them to verify from an existing device, which means figuring out if the user has set up cross-signing keys. Currently we do this by explicitly downloading the user's keys and then trying to fetch the cross-signing key. This is trickier to implement with the rust-sdk, so instead let's use the newly-added `userHasCrossSigningKeys` in the js-sdk. --- src/components/structures/MatrixChat.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 9327a45ea2..84efcea68a 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -371,10 +371,14 @@ export default class MatrixChat extends React.PureComponent { } const promisesList: Promise[] = [this.firstSyncPromise.promise]; + let crossSigningIsSetUp = false; if (cryptoEnabled) { - // wait for the client to finish downloading cross-signing keys for us so we - // know whether or not we have keys set up on this account - promisesList.push(cli.downloadKeys([cli.getUserId()])); + // check if the user has previously published public cross-signing keys, + // as a proxy to figure out if it's worth prompting the user to verify + // from another device. + promisesList.push((async () => { + crossSigningIsSetUp = await cli.userHasCrossSigningKeys(); + })()); } // Now update the state to say we're waiting for the first sync to complete rather @@ -388,14 +392,16 @@ export default class MatrixChat extends React.PureComponent { return; } - const crossSigningIsSetUp = cli.getStoredCrossSigningForUser(cli.getUserId()); if (crossSigningIsSetUp) { + // if the user has previously set up cross-signing, verify this device so we can fetch the + // private keys. if (SecurityCustomisations.SHOW_ENCRYPTION_SETUP_UI === false) { this.onLoggedIn(); } else { this.setStateForNewView({ view: Views.COMPLETE_SECURITY }); } } else if (await cli.doesServerSupportUnstableFeature("org.matrix.e2e_cross_signing")) { + // if cross-signing is not yet set up, do so now if possible. this.setStateForNewView({ view: Views.E2E_SETUP }); } else { this.onLoggedIn();