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
This commit is contained in:
Richard van der Hoff
2025-02-11 15:22:01 +00:00
committed by GitHub
parent 161323b595
commit f7b010a0b3
@@ -10,13 +10,7 @@ Please see LICENSE files in the repository root for full details.
import React, { createRef } from "react"; import React, { createRef } from "react";
import FileSaver from "file-saver"; import FileSaver from "file-saver";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { import { type AuthDict, type UIAResponse } from "matrix-js-sdk/src/matrix";
type AuthDict,
type CrossSigningKeys,
MatrixError,
type UIAFlow,
type UIAResponse,
} from "matrix-js-sdk/src/matrix";
import { type GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api"; import { type GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api";
import classNames from "classnames"; import classNames from "classnames";
import CheckmarkIcon from "@vector-im/compound-design-tokens/assets/web/icons/check"; 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. const PASSWORD_MIN_SCORE = 4; // So secure, many characters, much complex, wow, etc, etc.
interface IProps { interface IProps {
hasCancel?: boolean;
accountPassword?: string;
forceReset?: boolean; forceReset?: boolean;
resetCrossSigning?: boolean; resetCrossSigning?: boolean;
onFinished(ok?: boolean): void; onFinished(ok?: boolean): void;
@@ -77,11 +69,6 @@ interface IState {
downloaded: boolean; downloaded: boolean;
setPassphrase: 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; canSkip: boolean;
passPhraseKeySelected: string; passPhraseKeySelected: string;
error?: boolean; error?: boolean;
@@ -96,7 +83,6 @@ interface IState {
*/ */
export default class CreateSecretStorageDialog extends React.PureComponent<IProps, IState> { export default class CreateSecretStorageDialog extends React.PureComponent<IProps, IState> {
public static defaultProps: Partial<IProps> = { public static defaultProps: Partial<IProps> = {
hasCancel: true,
forceReset: false, forceReset: false,
resetCrossSigning: false, resetCrossSigning: false,
}; };
@@ -117,16 +103,6 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
passPhraseKeySelected = SecureBackupSetupMethod.Passphrase; passPhraseKeySelected = SecureBackupSetupMethod.Passphrase;
} }
const accountPassword = props.accountPassword || "";
let canUploadKeysWithPasswordOnly: boolean | null = null;
if (accountPassword) {
// If we have an account password in memory, let's simplify and
// assume it means password auth is also supported for device
// signing key upload as well. This avoids hitting the server to
// test auth flows, which may be slow under high load.
canUploadKeysWithPasswordOnly = true;
}
const keyFromCustomisations = ModuleRunner.instance.extensions.cryptoSetup.createSecretStorageKey(); const keyFromCustomisations = ModuleRunner.instance.extensions.cryptoSetup.createSecretStorageKey();
const phase = keyFromCustomisations ? Phase.Loading : Phase.ChooseKeyPassphrase; const phase = keyFromCustomisations ? Phase.Loading : Phase.ChooseKeyPassphrase;
@@ -138,23 +114,14 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
copied: false, copied: false,
downloaded: false, downloaded: false,
setPassphrase: false, setPassphrase: false,
// does the server offer a UI auth flow with just m.login.password
// for /keys/device_signing/upload?
accountPasswordCorrect: null,
canSkip: !isSecureBackupRequired(cli), canSkip: !isSecureBackupRequired(cli),
canUploadKeysWithPasswordOnly,
passPhraseKeySelected, passPhraseKeySelected,
accountPassword,
}; };
} }
public componentDidMount(): void { public componentDidMount(): void {
const keyFromCustomisations = ModuleRunner.instance.extensions.cryptoSetup.createSecretStorageKey(); const keyFromCustomisations = ModuleRunner.instance.extensions.cryptoSetup.createSecretStorageKey();
if (keyFromCustomisations) this.initExtension(keyFromCustomisations); if (keyFromCustomisations) this.initExtension(keyFromCustomisations);
if (this.state.canUploadKeysWithPasswordOnly === null) {
this.queryKeyUploadAuth();
}
} }
private initExtension(keyFromCustomisations: Uint8Array): void { private initExtension(keyFromCustomisations: Uint8Array): void {
@@ -165,27 +132,6 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
this.bootstrapSecretStorage(); this.bootstrapSecretStorage();
} }
private async queryKeyUploadAuth(): Promise<void> {
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<HTMLInputElement>): void => { private onKeyPassphraseChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
this.setState({ this.setState({
passPhraseKeySelected: e.target.value, passPhraseKeySelected: e.target.value,
@@ -234,44 +180,33 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
private doBootstrapUIAuth = async ( private doBootstrapUIAuth = async (
makeRequest: (authData: AuthDict) => Promise<UIAResponse<void>>, makeRequest: (authData: AuthDict) => Promise<UIAResponse<void>>,
): Promise<void> => { ): Promise<void> => {
if (this.state.canUploadKeysWithPasswordOnly && this.state.accountPassword) { const dialogAesthetics = {
await makeRequest({ [SSOAuthEntry.PHASE_PREAUTH]: {
type: "m.login.password", title: _t("auth|uia|sso_title"),
identifier: { body: _t("auth|uia|sso_preauth_body"),
type: "m.id.user", continueText: _t("auth|sso"),
user: MatrixClientPeg.safeGet().getSafeUserId(), continueKind: "primary",
}, },
password: this.state.accountPassword, [SSOAuthEntry.PHASE_POSTAUTH]: {
}); title: _t("encryption|confirm_encryption_setup_title"),
} else { body: _t("encryption|confirm_encryption_setup_body"),
const dialogAesthetics = { continueText: _t("action|confirm"),
[SSOAuthEntry.PHASE_PREAUTH]: { continueKind: "primary",
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, { const { finished } = Modal.createDialog(InteractiveAuthDialog, {
title: _t("encryption|bootstrap_title"), title: _t("encryption|bootstrap_title"),
matrixClient: MatrixClientPeg.safeGet(), matrixClient: MatrixClientPeg.safeGet(),
makeRequest, makeRequest,
aestheticsForStagePhases: { aestheticsForStagePhases: {
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics, [SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics, [SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
}, },
}); });
const [confirmed] = await finished; const [confirmed] = await finished;
if (!confirmed) { if (!confirmed) {
throw new Error("Cross-signing key upload auth canceled"); throw new Error("Cross-signing key upload auth canceled");
}
} }
}; };
@@ -811,7 +746,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
top={this.topComponent} top={this.topComponent}
title={this.titleForPhase(this.state.phase)} title={this.titleForPhase(this.state.phase)}
titleClass={titleClass} titleClass={titleClass}
hasCancel={this.props.hasCancel && [Phase.Passphrase].includes(this.state.phase)} hasCancel={false}
fixedWidth={false} fixedWidth={false}
> >
<div>{content}</div> <div>{content}</div>