1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Fix rust migration when ssss secret not encrypted (#4168)

This commit is contained in:
Valere
2024-04-26 14:59:17 +02:00
committed by GitHub
parent 1da5e8f56a
commit 65d858f9a3
2 changed files with 63 additions and 11 deletions

View File

@@ -27,6 +27,7 @@ import { CrossSigningKeyInfo, Curve25519AuthData } from "../crypto-api";
import { RustCrypto } from "./rust-crypto";
import { KeyBackupInfo } from "../crypto-api/keybackup";
import { sleep } from "../utils";
import { encodeBase64 } from "../base64";
/**
* Determine if any data needs migrating from the legacy store, and do so.
@@ -400,19 +401,20 @@ async function getAndDecryptCachedSecretKey(
legacyPickleKey: Uint8Array,
name: string,
): Promise<string | undefined> {
let encodedKey: IEncryptedPayload | null = null;
await legacyStore.doTxn("readonly", "account", (txn) => {
legacyStore.getSecretStorePrivateKey(
txn,
(k) => {
encodedKey = k as IEncryptedPayload | null;
},
name as keyof SecretStorePrivateKeys,
);
const key = await new Promise<any>((resolve) => {
legacyStore.doTxn("readonly", [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => {
legacyStore.getSecretStorePrivateKey(txn, resolve, name as keyof SecretStorePrivateKeys);
});
});
return encodedKey === null ? undefined : await decryptAES(encodedKey, legacyPickleKey, name);
if (key && key.ciphertext && key.iv && key.mac) {
return await decryptAES(key as IEncryptedPayload, legacyPickleKey, name);
} else if (key instanceof Uint8Array) {
// This is a legacy backward compatibility case where the key was stored in clear.
return encodeBase64(key);
} else {
return undefined;
}
}
/**