Skip to content

Commit

Permalink
Ps/pm-8197/clean-up-desktop-biometric-ipc (#9275)
Browse files Browse the repository at this point in the history
* Do not process reload on account switch

* Validate specified key against specified user

* Grab userId immediately for user key retrieval

(cherry picked from commit f2d24e0)
  • Loading branch information
MGibson1 committed May 20, 2024
1 parent ca5128d commit a22d83f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion apps/desktop/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,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
Expand Down
11 changes: 6 additions & 5 deletions libs/common/src/platform/services/crypto.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,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
Expand All @@ -184,9 +184,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);
}
Expand Down Expand Up @@ -721,14 +722,14 @@ 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 [userId, encPrivateKey] = await firstValueFrom(
this.activeUserEncryptedPrivateKeyState.combinedState$,
const encPrivateKey = await firstValueFrom(
this.stateProvider.getUserState$(USER_ENCRYPTED_PRIVATE_KEY, userId),
);
if (encPrivateKey == null) {
return false;
Expand Down

0 comments on commit a22d83f

Please sign in to comment.