From 40e39bd08e6aebe47daceb6c6bbce02a9bd87525 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 17 Jun 2024 19:20:57 +0100 Subject: [PATCH] Remove now-unreachable `tryToUnlockSecretStorageWithDehydrationKey` --- src/SecurityManager.ts | 57 +----------------------------------------- 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/src/SecurityManager.ts b/src/SecurityManager.ts index c2254d3dfe0a..873aec08e29d 100644 --- a/src/SecurityManager.ts +++ b/src/SecurityManager.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Crypto, ICryptoCallbacks, MatrixClient, encodeBase64, SecretStorage } from "matrix-js-sdk/src/matrix"; +import { Crypto, ICryptoCallbacks, encodeBase64, SecretStorage } from "matrix-js-sdk/src/matrix"; import { deriveKey } from "matrix-js-sdk/src/crypto/key_passphrase"; import { decodeRecoveryKey } from "matrix-js-sdk/src/crypto/recoverykey"; import { logger } from "matrix-js-sdk/src/logger"; @@ -40,8 +40,6 @@ let secretStorageKeys: Record = {}; let secretStorageKeyInfo: Record = {}; let secretStorageBeingAccessed = false; -let nonInteractive = false; - let dehydrationCache: { key?: Uint8Array; keyInfo?: SecretStorage.SecretStorageKeyDescription; @@ -138,10 +136,6 @@ async function getSecretStorageKey({ return [keyId, keyFromCustomisations]; } - if (nonInteractive) { - throw new Error("Could not unlock non-interactively"); - } - const inputToKey = makeInputToKey(keyInfo); const { finished } = Modal.createDialog( AccessSecretStorageDialog, @@ -430,52 +424,3 @@ async function doAccessSecretStorage(func: () => Promise, forceReset: bool throw e; } } - -// FIXME: this function name is a bit of a mouthful -export async function tryToUnlockSecretStorageWithDehydrationKey(client: MatrixClient): Promise { - const key = dehydrationCache.key; - let restoringBackup = false; - if (key && (await client.isSecretStorageReady())) { - logger.log("Trying to set up cross-signing using dehydration key"); - secretStorageBeingAccessed = true; - nonInteractive = true; - try { - await client.checkOwnCrossSigningTrust(); - - // we also need to set a new dehydrated device to replace the - // device we rehydrated - let dehydrationKeyInfo = {}; - if (dehydrationCache.keyInfo && dehydrationCache.keyInfo.passphrase) { - dehydrationKeyInfo = { passphrase: dehydrationCache.keyInfo.passphrase }; - } - await client.setDehydrationKey(key, dehydrationKeyInfo, "Backup device"); - - // and restore from backup - const backupInfo = await client.getKeyBackupVersion(); - if (backupInfo) { - restoringBackup = true; - // don't await, because this can take a long time - client.restoreKeyBackupWithSecretStorage(backupInfo).finally(() => { - secretStorageBeingAccessed = false; - nonInteractive = false; - if (!isCachingAllowed()) { - secretStorageKeys = {}; - secretStorageKeyInfo = {}; - } - }); - } - } finally { - dehydrationCache = {}; - // the secret storage cache is needed for restoring from backup, so - // don't clear it yet if we're restoring from backup - if (!restoringBackup) { - secretStorageBeingAccessed = false; - nonInteractive = false; - if (!isCachingAllowed()) { - secretStorageKeys = {}; - secretStorageKeyInfo = {}; - } - } - } - } -}