Skip to content

Commit

Permalink
CreateSecretStorageDialog: remove unused state `canUploadKeysWithPass…
Browse files Browse the repository at this point in the history
…wordOnly`

This is no longer read, so let's remove the code that populates it.
  • Loading branch information
richvdh committed Feb 5, 2025
1 parent 436989f commit bc604df
Showing 1 changed file with 1 addition and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -76,9 +70,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;
canSkip: boolean;
passPhraseKeySelected: string;
error?: boolean;
Expand Down Expand Up @@ -128,18 +119,13 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
// does the server offer a UI auth flow with just m.login.password
// for /keys/device_signing/upload?
canSkip: !isSecureBackupRequired(cli),
canUploadKeysWithPasswordOnly: null,
passPhraseKeySelected,
};
}

public componentDidMount(): void {
const keyFromCustomisations = ModuleRunner.instance.extensions.cryptoSetup.createSecretStorageKey();
if (keyFromCustomisations) this.initExtension(keyFromCustomisations);

if (this.state.canUploadKeysWithPasswordOnly === null) {
this.queryKeyUploadAuth();
}
}

private initExtension(keyFromCustomisations: Uint8Array): void {
Expand All @@ -150,27 +136,6 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
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 => {
this.setState({
passPhraseKeySelected: e.target.value,
Expand Down

0 comments on commit bc604df

Please sign in to comment.