1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-02 04:48:57 +02:00

Ps/pm-8197/clean-up-desktop-biometric-ipc (#9275)

* Do not process reload on account switch

* Validate specified key against specified user

* Grab userId immediately for user key retrieval
This commit is contained in:
Matt Gibson 2024-05-20 16:19:58 -04:00 committed by GitHub
parent ac47cca944
commit f2d24e036b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -411,7 +411,8 @@ export class AppComponent implements OnInit, OnDestroy {
this.masterPasswordService.forceSetPasswordReason$(message.userId),
)) != ForceSetPasswordReason.None;
if (locked) {
this.messagingService.send("locked", { userId: message.userId });
this.modalService.closeAll();
await this.router.navigate(["lock"]);
} else if (forcedPasswordReset) {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises

View File

@ -174,7 +174,7 @@ export class CryptoService implements CryptoServiceAbstraction {
userId ??= await firstValueFrom(this.stateProvider.activeUserId$);
masterKey ??= await firstValueFrom(this.masterPasswordService.masterKey$(userId));
return await this.validateUserKey(masterKey as unknown as UserKey);
return await this.validateUserKey(masterKey as unknown as UserKey, userId);
}
// TODO: legacy support for user key is no longer needed since we require users to migrate on login
@ -193,9 +193,10 @@ export class CryptoService implements CryptoServiceAbstraction {
}
async getUserKeyFromStorage(keySuffix: KeySuffixOptions, userId?: UserId): Promise<UserKey> {
userId ??= await firstValueFrom(this.stateProvider.activeUserId$);
const userKey = await this.getKeyFromStorage(keySuffix, userId);
if (userKey) {
if (!(await this.validateUserKey(userKey))) {
if (!(await this.validateUserKey(userKey, userId))) {
this.logService.warning("Invalid key, throwing away stored keys");
await this.clearAllStoredUserKeys(userId);
}
@ -663,13 +664,15 @@ export class CryptoService implements CryptoServiceAbstraction {
}
// ---HELPERS---
protected async validateUserKey(key: UserKey): Promise<boolean> {
protected async validateUserKey(key: UserKey, userId: UserId): Promise<boolean> {
if (!key) {
return false;
}
try {
const encPrivateKey = await firstValueFrom(this.activeUserEncryptedPrivateKeyState.state$);
const encPrivateKey = await firstValueFrom(
this.stateProvider.getUserState$(USER_ENCRYPTED_PRIVATE_KEY, userId),
);
if (encPrivateKey == null) {
return false;
}