Skip to content

Commit a22d83f

Browse files
committed
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 (cherry picked from commit f2d24e0)
1 parent ca5128d commit a22d83f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

apps/desktop/src/app/app.component.ts

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

libs/common/src/platform/services/crypto.service.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class CryptoService implements CryptoServiceAbstraction {
165165
userId ??= await firstValueFrom(this.stateProvider.activeUserId$);
166166
masterKey ??= await firstValueFrom(this.masterPasswordService.masterKey$(userId));
167167

168-
return await this.validateUserKey(masterKey as unknown as UserKey);
168+
return await this.validateUserKey(masterKey as unknown as UserKey, userId);
169169
}
170170

171171
// TODO: legacy support for user key is no longer needed since we require users to migrate on login
@@ -184,9 +184,10 @@ export class CryptoService implements CryptoServiceAbstraction {
184184
}
185185

186186
async getUserKeyFromStorage(keySuffix: KeySuffixOptions, userId?: UserId): Promise<UserKey> {
187+
userId ??= await firstValueFrom(this.stateProvider.activeUserId$);
187188
const userKey = await this.getKeyFromStorage(keySuffix, userId);
188189
if (userKey) {
189-
if (!(await this.validateUserKey(userKey))) {
190+
if (!(await this.validateUserKey(userKey, userId))) {
190191
this.logService.warning("Invalid key, throwing away stored keys");
191192
await this.clearAllStoredUserKeys(userId);
192193
}
@@ -721,14 +722,14 @@ export class CryptoService implements CryptoServiceAbstraction {
721722
}
722723

723724
// ---HELPERS---
724-
protected async validateUserKey(key: UserKey): Promise<boolean> {
725+
protected async validateUserKey(key: UserKey, userId: UserId): Promise<boolean> {
725726
if (!key) {
726727
return false;
727728
}
728729

729730
try {
730-
const [userId, encPrivateKey] = await firstValueFrom(
731-
this.activeUserEncryptedPrivateKeyState.combinedState$,
731+
const encPrivateKey = await firstValueFrom(
732+
this.stateProvider.getUserState$(USER_ENCRYPTED_PRIVATE_KEY, userId),
732733
);
733734
if (encPrivateKey == null) {
734735
return false;

0 commit comments

Comments
 (0)