From 1e92169305984b1282bfa7260b22896a40991879 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Tue, 11 Feb 2025 15:59:16 +0100 Subject: [PATCH] Clean up unused code in `CreateSecretStorageDialog` (#29205) * CreateSecretStorageDialog: remove unused state `accountPasswordCorrect` This was never set to anything other than `null`, and never read. * CreateSecretStorageDialog: remove unused prop `accountPassword` This was never set, so we may as well remove it. * CreateSecretStorageDialog: remove unused state `accountPassword` This is now no longer set to anything other than `""`. * CreateSecretStorageDialog: remove unused state `canUploadKeysWithPasswordOnly` This is no longer read, so let's remove the code that populates it. * CreateSecretStorageDialog: remove unused prop `hasCancel` This is never set, so may as well remove * Update src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx --- .../security/CreateSecretStorageDialog.tsx | 123 +++++------------- 1 file changed, 29 insertions(+), 94 deletions(-) diff --git a/src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx b/src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx index 5d40967bb4e..14ad5d30394 100644 --- a/src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx +++ b/src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx @@ -10,13 +10,7 @@ Please see LICENSE files in the repository root for full details. import React, { createRef } from "react"; import FileSaver from "file-saver"; import { logger } from "matrix-js-sdk/src/logger"; -import { - type AuthDict, - type CrossSigningKeys, - MatrixError, - type UIAFlow, - type UIAResponse, -} from "matrix-js-sdk/src/matrix"; +import { type AuthDict, type UIAResponse } from "matrix-js-sdk/src/matrix"; import { type GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api"; import classNames from "classnames"; import CheckmarkIcon from "@vector-im/compound-design-tokens/assets/web/icons/check"; @@ -61,8 +55,6 @@ enum Phase { const PASSWORD_MIN_SCORE = 4; // So secure, many characters, much complex, wow, etc, etc. interface IProps { - hasCancel?: boolean; - accountPassword?: string; forceReset?: boolean; resetCrossSigning?: boolean; onFinished(ok?: boolean): void; @@ -77,11 +69,6 @@ interface IState { downloaded: boolean; setPassphrase: boolean; - // does the server offer a UI auth flow with just m.login.password - // for /keys/device_signing/upload? - canUploadKeysWithPasswordOnly: boolean | null; - accountPassword: string; - accountPasswordCorrect: boolean | null; canSkip: boolean; passPhraseKeySelected: string; error?: boolean; @@ -96,7 +83,6 @@ interface IState { */ export default class CreateSecretStorageDialog extends React.PureComponent { public static defaultProps: Partial = { - hasCancel: true, forceReset: false, resetCrossSigning: false, }; @@ -117,16 +103,6 @@ export default class CreateSecretStorageDialog extends React.PureComponent { - try { - await MatrixClientPeg.safeGet().uploadDeviceSigningKeys(undefined, {} as CrossSigningKeys); - // We should never get here: the server should always require - // UI auth to upload device signing keys. If we do, we upload - // no keys which would be a no-op. - logger.log("uploadDeviceSigningKeys unexpectedly succeeded without UI auth!"); - } catch (error) { - if (!(error instanceof MatrixError) || !error.data || !error.data.flows) { - logger.log("uploadDeviceSigningKeys advertised no flows!"); - return; - } - const canUploadKeysWithPasswordOnly = error.data.flows.some((f: UIAFlow) => { - return f.stages.length === 1 && f.stages[0] === "m.login.password"; - }); - this.setState({ - canUploadKeysWithPasswordOnly, - }); - } - } - private onKeyPassphraseChange = (e: React.ChangeEvent): void => { this.setState({ passPhraseKeySelected: e.target.value, @@ -234,44 +180,33 @@ export default class CreateSecretStorageDialog extends React.PureComponent Promise>, ): Promise => { - if (this.state.canUploadKeysWithPasswordOnly && this.state.accountPassword) { - await makeRequest({ - type: "m.login.password", - identifier: { - type: "m.id.user", - user: MatrixClientPeg.safeGet().getSafeUserId(), - }, - password: this.state.accountPassword, - }); - } else { - const dialogAesthetics = { - [SSOAuthEntry.PHASE_PREAUTH]: { - title: _t("auth|uia|sso_title"), - body: _t("auth|uia|sso_preauth_body"), - continueText: _t("auth|sso"), - continueKind: "primary", - }, - [SSOAuthEntry.PHASE_POSTAUTH]: { - title: _t("encryption|confirm_encryption_setup_title"), - body: _t("encryption|confirm_encryption_setup_body"), - continueText: _t("action|confirm"), - continueKind: "primary", - }, - }; - - const { finished } = Modal.createDialog(InteractiveAuthDialog, { - title: _t("encryption|bootstrap_title"), - matrixClient: MatrixClientPeg.safeGet(), - makeRequest, - aestheticsForStagePhases: { - [SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics, - [SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics, - }, - }); - const [confirmed] = await finished; - if (!confirmed) { - throw new Error("Cross-signing key upload auth canceled"); - } + const dialogAesthetics = { + [SSOAuthEntry.PHASE_PREAUTH]: { + title: _t("auth|uia|sso_title"), + body: _t("auth|uia|sso_preauth_body"), + continueText: _t("auth|sso"), + continueKind: "primary", + }, + [SSOAuthEntry.PHASE_POSTAUTH]: { + title: _t("encryption|confirm_encryption_setup_title"), + body: _t("encryption|confirm_encryption_setup_body"), + continueText: _t("action|confirm"), + continueKind: "primary", + }, + }; + + const { finished } = Modal.createDialog(InteractiveAuthDialog, { + title: _t("encryption|bootstrap_title"), + matrixClient: MatrixClientPeg.safeGet(), + makeRequest, + aestheticsForStagePhases: { + [SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics, + [SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics, + }, + }); + const [confirmed] = await finished; + if (!confirmed) { + throw new Error("Cross-signing key upload auth canceled"); } }; @@ -811,7 +746,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent
{content}