1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-28 10:33:31 +00:00

Ensure corrupt private key still works for initialization

This commit is contained in:
Bernd Schoolmann
2025-11-26 11:57:45 +01:00
parent bb3080bbfe
commit 317d74d96e

View File

@@ -2,6 +2,7 @@ import * as bigInt from "big-integer";
import {
NEVER,
Observable,
catchError,
combineLatest,
concatMap,
distinctUntilChanged,
@@ -588,8 +589,17 @@ export class DefaultKeyService implements KeyServiceAbstraction {
}
// Can successfully derive public key
await SdkLoadService.Ready;
const publicKey = PureCrypto.rsa_extract_public_key(encPrivateKey, key.toEncoded());
let publicKey: Uint8Array;
try {
await SdkLoadService.Ready;
publicKey = PureCrypto.rsa_extract_public_key(encPrivateKey, key.toEncoded());
} catch (e) {
this.logService.error(
"[KeyService] Failed to extract public key: " + e,
"encrypted private key size: " + encPrivateKey.length,
);
return false;
}
if (publicKey == null) {
// failed to decrypt
@@ -768,6 +778,10 @@ export class DefaultKeyService implements KeyServiceAbstraction {
) as UserPublicKey,
};
}),
catchError((e: unknown) => {
this.logService.error("[KeyService] Failed to extract public key: " + e);
return of(null);
}),
);
}