1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-28 18:43:26 +00:00

Allow epheremal pin to survive process reload on desktop and add epheremal pin store for rust

This commit is contained in:
Bernd Schoolmann
2024-12-01 23:54:11 +01:00
parent f79141c421
commit d8da1a95d5
11 changed files with 159 additions and 20 deletions

View File

@@ -1,9 +1,9 @@
import { firstValueFrom, map, timeout } from "rxjs";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { BiometricStateService } from "@bitwarden/key-management";
import { PinServiceAbstraction } from "../../../../auth/src/common/abstractions";
import { VaultTimeoutSettingsService } from "../../abstractions/vault-timeout/vault-timeout-settings.service";
import { AccountService } from "../../auth/abstractions/account.service";
import { AuthService } from "../../auth/abstractions/auth.service";
@@ -16,15 +16,16 @@ export class DefaultProcessReloadService implements ProcessReloadServiceAbstract
private reloadInterval: any = null;
constructor(
private pinService: PinServiceAbstraction,
private messagingService: MessagingService,
private reloadCallback: () => Promise<void> = null,
private vaultTimeoutSettingsService: VaultTimeoutSettingsService,
private biometricStateService: BiometricStateService,
private accountService: AccountService,
private logService: LogService,
) {}
async startProcessReload(authService: AuthService): Promise<void> {
this.logService.info("[ProcessReloadService] Starting process reload");
const accounts = await firstValueFrom(this.accountService.accounts$);
if (accounts != null) {
const keys = Object.keys(accounts);
@@ -33,6 +34,9 @@ export class DefaultProcessReloadService implements ProcessReloadServiceAbstract
let status = await firstValueFrom(authService.authStatusFor$(userId as UserId));
status = await authService.getAuthStatus(userId);
if (status === AuthenticationStatus.Unlocked) {
this.logService.info(
`[ProcessReloadService] User ${userId} is unlocked, skipping process reload`,
);
return;
}
}
@@ -41,18 +45,10 @@ export class DefaultProcessReloadService implements ProcessReloadServiceAbstract
// A reloadInterval has already been set and is executing
if (this.reloadInterval != null) {
this.logService.info(`[ProcessReloadService] Process reload already in progress`);
return;
}
// If there is an active user, check if they have a pinKeyEncryptedUserKeyEphemeral. If so, prevent process reload upon lock.
const userId = (await firstValueFrom(this.accountService.activeAccount$))?.id;
if (userId != null) {
const ephemeralPin = await this.pinService.getPinKeyEncryptedUserKeyEphemeral(userId);
if (ephemeralPin != null) {
return;
}
}
this.cancelProcessReload();
await this.executeProcessReload();
}
@@ -86,6 +82,7 @@ export class DefaultProcessReloadService implements ProcessReloadServiceAbstract
}
}
this.logService.info("[ProcessReloadService] Sending message to os reload implementation");
this.messagingService.send("reloadProcess");
if (this.reloadCallback != null) {
await this.reloadCallback();
@@ -93,6 +90,7 @@ export class DefaultProcessReloadService implements ProcessReloadServiceAbstract
return;
}
if (this.reloadInterval == null) {
this.logService.info("[ProcessReloadService] Setting reload interval");
this.reloadInterval = setInterval(async () => await this.executeProcessReload(), 1000);
}
}