|
| 1 | +/* |
| 2 | + * Copyright 2025 New Vector Ltd. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial |
| 5 | + * Please see LICENSE files in the repository root for full details. |
| 6 | + */ |
| 7 | + |
| 8 | +import React, { JSX } from "react"; |
| 9 | +import { InlineSpinner } from "@vector-im/compound-web"; |
| 10 | + |
| 11 | +import { useMatrixClientContext } from "../../../../contexts/MatrixClientContext"; |
| 12 | +import BaseTool from "./BaseTool"; |
| 13 | +import { useAsyncMemo } from "../../../../hooks/useAsyncMemo"; |
| 14 | +import { _t } from "../../../../languageHandler"; |
| 15 | + |
| 16 | +interface KeyBackupProps { |
| 17 | + onBack(): void; |
| 18 | +} |
| 19 | + |
| 20 | +export function Crypto({ onBack }: KeyBackupProps): JSX.Element { |
| 21 | + return ( |
| 22 | + <BaseTool onBack={onBack} className="mx_Crypto"> |
| 23 | + <KeyStorage /> |
| 24 | + </BaseTool> |
| 25 | + ); |
| 26 | +} |
| 27 | + |
| 28 | +function KeyStorage(): JSX.Element { |
| 29 | + const matrixClient = useMatrixClientContext(); |
| 30 | + const keyStorageData = useAsyncMemo(async () => { |
| 31 | + const crypto = matrixClient.getCrypto(); |
| 32 | + if (!crypto) return null; |
| 33 | + |
| 34 | + const backupInfo = await crypto.getKeyBackupInfo(); |
| 35 | + const backupKeyStored = Boolean(await matrixClient.isKeyBackupKeyStored()); |
| 36 | + const backupKeyFromCache = await crypto.getSessionBackupPrivateKey(); |
| 37 | + const backupKeyCached = Boolean(backupKeyFromCache); |
| 38 | + const backupKeyWellFormed = backupKeyFromCache instanceof Uint8Array; |
| 39 | + const activeBackupVersion = await crypto.getActiveSessionBackupVersion(); |
| 40 | + const secretStorageKeyInAccount = await matrixClient.secretStorage.hasKey(); |
| 41 | + const secretStorageReady = await crypto.isSecretStorageReady(); |
| 42 | + |
| 43 | + return { |
| 44 | + backupInfo, |
| 45 | + backupKeyStored, |
| 46 | + backupKeyCached, |
| 47 | + backupKeyWellFormed, |
| 48 | + activeBackupVersion, |
| 49 | + secretStorageKeyInAccount, |
| 50 | + secretStorageReady, |
| 51 | + }; |
| 52 | + }, [matrixClient]); |
| 53 | + |
| 54 | + if (keyStorageData === undefined) return <InlineSpinner aria-label={_t("common|loading")} />; |
| 55 | + if (keyStorageData === null) return <span>{_t("devtools|crypto|crypto_not_available")}</span>; |
| 56 | + |
| 57 | + const { |
| 58 | + backupInfo, |
| 59 | + backupKeyStored, |
| 60 | + backupKeyCached, |
| 61 | + backupKeyWellFormed, |
| 62 | + activeBackupVersion, |
| 63 | + secretStorageKeyInAccount, |
| 64 | + secretStorageReady, |
| 65 | + } = keyStorageData; |
| 66 | + |
| 67 | + return ( |
| 68 | + <table className="mx_KeyStorage"> |
| 69 | + <thead>{_t("devtools|crypto|key_storage")}</thead> |
| 70 | + <tbody> |
| 71 | + <tr> |
| 72 | + <th scope="row">{_t("devtools|crypto|key_backup_latest_version")}</th> |
| 73 | + <td> |
| 74 | + {backupInfo |
| 75 | + ? `${backupInfo.version} (${_t("settings|security|key_backup_algorithm")}) ${backupInfo.algorithm}` |
| 76 | + : _t("devtools|crypto|key_backup_inactive_warning")} |
| 77 | + </td> |
| 78 | + </tr> |
| 79 | + <tr> |
| 80 | + <th scope="row">{_t("devtools|crypto|backup_key_stored_status")}</th> |
| 81 | + <td> |
| 82 | + {backupKeyStored |
| 83 | + ? _t("devtools|crypto|backup_key_stored") |
| 84 | + : _t("devtools|crypto|backup_key_not_stored")} |
| 85 | + </td> |
| 86 | + </tr> |
| 87 | + <tr> |
| 88 | + <th scope="row">{_t("devtools|crypto|key_backup_active_version")}</th> |
| 89 | + <td> |
| 90 | + {activeBackupVersion === null |
| 91 | + ? _t("devtools|crypto|key_backup_active_version_none") |
| 92 | + : activeBackupVersion} |
| 93 | + </td> |
| 94 | + </tr> |
| 95 | + <tr> |
| 96 | + <th scope="row">{_t("devtools|crypto|backup_key_cached_status")}</th> |
| 97 | + <td> |
| 98 | + {`${ |
| 99 | + backupKeyCached |
| 100 | + ? _t("devtools|crypto|backup_key_cached") |
| 101 | + : _t("devtools|crypto|backup_key_not_cached") |
| 102 | + }, |
| 103 | + ${ |
| 104 | + backupKeyWellFormed |
| 105 | + ? _t("devtools|crypto|backup_key_well_formed") |
| 106 | + : _t("devtools|crypto|backup_key_unexpected_type") |
| 107 | + }`} |
| 108 | + </td> |
| 109 | + </tr> |
| 110 | + <tr> |
| 111 | + <th scope="row">{_t("devtools|crypto|4s_public_key_status")}</th> |
| 112 | + <td> |
| 113 | + {secretStorageKeyInAccount |
| 114 | + ? _t("devtools|crypto|4s_public_key_in_account_data") |
| 115 | + : _t("devtools|crypto|4s_public_key_not_in_account_data")} |
| 116 | + </td> |
| 117 | + </tr> |
| 118 | + <tr> |
| 119 | + <th scope="row">{_t("devtools|crypto|secret_storage_status")}</th> |
| 120 | + <td> |
| 121 | + {secretStorageReady |
| 122 | + ? _t("devtools|crypto|secret_storage_ready") |
| 123 | + : _t("devtools|crypto|secret_storage_not_ready")} |
| 124 | + </td> |
| 125 | + </tr> |
| 126 | + </tbody> |
| 127 | + </table> |
| 128 | + ); |
| 129 | +} |
0 commit comments