Reset key storage if restoring from Recovery encounters the wrong decryption key (#32668)
* Set up the MatrixClient before each RecoveryPanelOutOfSync test Without this, we can't override MatrixClient methods until we've called `renderComponent`, which is awkward. * Actually test that we load the decryption key in RecoveryPanelOutOfSync It turns out the existing test didn't actually go down the expected code path and call loadSessionBackupPrivateKeyFromSecretStorage. * Reset key storage if restoring from Recovery encounters the wrong decryption key Fixes https://github.com/element-hq/element-web/issues/31793 Depends on https://github.com/matrix-org/matrix-js-sdk/pull/5202 When we try to load the key storage decryption key from Recovery, but we find that it does not match the public key of the current key storage backup, create a new key storage backup.
This commit is contained in:
@@ -9,6 +9,7 @@ import React, { type JSX } from "react";
|
||||
import { Button } from "@vector-im/compound-web";
|
||||
import KeyIcon from "@vector-im/compound-design-tokens/assets/web/icons/key";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { DecryptionKeyDoesNotMatchError } from "matrix-js-sdk/src/crypto-api";
|
||||
|
||||
import { SettingsSection } from "../shared/SettingsSection";
|
||||
import { _t } from "../../../../languageHandler";
|
||||
@@ -92,7 +93,18 @@ export function RecoveryPanelOutOfSync({
|
||||
if (needsBackupReset) {
|
||||
await resetKeyBackupAndWait(crypto);
|
||||
} else if (await matrixClient.isKeyBackupKeyStored()) {
|
||||
await crypto.loadSessionBackupPrivateKeyFromSecretStorage();
|
||||
try {
|
||||
await crypto.loadSessionBackupPrivateKeyFromSecretStorage();
|
||||
} catch (error: any) {
|
||||
if (error instanceof DecryptionKeyDoesNotMatchError) {
|
||||
logger.error(
|
||||
"RecoveryPanelOutOfSync: decryption key does not match the public backup. Replacing.",
|
||||
);
|
||||
await resetKeyBackupAndWait(crypto);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user