From 8bd5d6aeb3db540aa8e1a58196ed2669871f0a1e Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Thu, 9 Jan 2025 15:35:44 +0100 Subject: [PATCH] Use `matrixClient.secretStorage.getDefaultKeyId` instead of `matrixClient.getCrypto().checkKeyBackupAndEnable` to know if we need to set up a recovery key --- .../settings/encryption/ChangeRecoveryKey.tsx | 10 +++++----- .../settings/encryption/RecoveryPanel.tsx | 19 +++++++++++-------- .../tabs/user/EncryptionUserSettingsTab.tsx | 2 +- test/test-utils/test-utils.ts | 1 + .../encryption/ChangeRecoveryKey-test.tsx | 8 ++++++-- .../encryption/RecoveryPanel-test.tsx | 13 +++++-------- .../__snapshots__/RecoveryPanel-test.tsx.snap | 4 ++-- .../user/EncryptionUserSettingsTab-test.tsx | 7 +++---- 8 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/components/views/settings/encryption/ChangeRecoveryKey.tsx b/src/components/views/settings/encryption/ChangeRecoveryKey.tsx index cb8e05c176c..630f7ac8a9d 100644 --- a/src/components/views/settings/encryption/ChangeRecoveryKey.tsx +++ b/src/components/views/settings/encryption/ChangeRecoveryKey.tsx @@ -41,7 +41,7 @@ interface ChangeRecoveryKeyProps { * If true, the component will display the flow to change the recovery key. * If false,the component will display the flow to set up a new recovery key. */ - userHasKeyBackup: boolean; + userHasRecoveryKey: boolean; /** * Called when the recovery key is successfully changed. */ @@ -56,7 +56,7 @@ interface ChangeRecoveryKeyProps { * A component to set up or change the recovery key. */ export function ChangeRecoveryKey({ - userHasKeyBackup, + userHasRecoveryKey, onFinish, onCancelClick, }: ChangeRecoveryKeyProps): JSX.Element | null { @@ -64,7 +64,7 @@ export function ChangeRecoveryKey({ // If the user is setting up recovery for the first time, we first show them a panel explaining what // "recovery" is about. Otherwise, we jump straight to showing the user the new key. - const [state, setState] = useState(userHasKeyBackup ? "save_key_change_flow" : "inform_user"); + const [state, setState] = useState(userHasRecoveryKey ? "save_key_change_flow" : "inform_user"); // We create a new recovery key, the recovery key will be displayed to the user const recoveryKey = useAsyncMemo(() => matrixClient.getCrypto()!.createRecoveryKeyFromPassphrase(), []); @@ -110,7 +110,7 @@ export function ChangeRecoveryKey({ // when we will try to access the secret storage during the bootstrap await withSecretStorageKeyCache(() => crypto.bootstrapSecretStorage({ - setupNewKeyBackup: !userHasKeyBackup, + setupNewKeyBackup: !userHasRecoveryKey, setupNewSecretStorage: true, createSecretStorageKey: async () => recoveryKey, }), @@ -126,7 +126,7 @@ export function ChangeRecoveryKey({ const pages = [ _t("settings|encryption|title"), - userHasKeyBackup + userHasRecoveryKey ? _t("settings|encryption|recovery|change_recovery_key") : _t("settings|encryption|recovery|set_up_recovery"), ]; diff --git a/src/components/views/settings/encryption/RecoveryPanel.tsx b/src/components/views/settings/encryption/RecoveryPanel.tsx index 3fae27d1c34..0a14ec9465a 100644 --- a/src/components/views/settings/encryption/RecoveryPanel.tsx +++ b/src/components/views/settings/encryption/RecoveryPanel.tsx @@ -18,13 +18,13 @@ import { SettingsSubheader } from "../SettingsSubheader"; /** * The possible states of the recovery panel. - * - `loading`: We are checking the backup, the recovery and the secrets. - * - `missing_backup`: The user has no backup. + * - `loading`: We are checking the recovery key and the secrets. + * - `missing_recovery_key`: The user has no recovery key. * - `secrets_not_cached`: The user has a backup but the secrets are not cached. * This shouldn't happen but we have seen cases where the secrets gossiping failed or shared partial secrets when verified with another device. * - `good`: The user has a backup and the secrets are cached. */ -type State = "loading" | "missing_backup" | "secrets_not_cached" | "good"; +type State = "loading" | "missing_recovery_key" | "secrets_not_cached" | "good"; interface RecoveryPanelProps { /** @@ -38,7 +38,7 @@ interface RecoveryPanelProps { */ export function RecoveryPanel({ onChangeRecoveryKeyClick }: RecoveryPanelProps): JSX.Element { const [state, setState] = useState("loading"); - const isMissingBackup = state === "missing_backup"; + const isMissingRecoveryKey = state === "missing_recovery_key"; const matrixClient = useMatrixClientContext(); @@ -46,8 +46,8 @@ export function RecoveryPanel({ onChangeRecoveryKeyClick }: RecoveryPanelProps): const crypto = matrixClient.getCrypto()!; // Check if the user has a backup - const hasBackup = Boolean(await crypto.checkKeyBackupAndEnable()); - if (!hasBackup) return setState("missing_backup"); + const hasRecoveryKey = Boolean(await matrixClient.secretStorage.getDefaultKeyId()); + if (!hasRecoveryKey) return setState("missing_recovery_key"); // Check if the secrets are cached const cachedSecrets = (await crypto.getCrossSigningStatus()).privateKeysCachedLocally; @@ -66,7 +66,7 @@ export function RecoveryPanel({ onChangeRecoveryKeyClick }: RecoveryPanelProps): case "loading": content = ; break; - case "missing_backup": + case "missing_recovery_key": content = (