1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 18:23:31 +00:00

Ensure biometric unlock works even if popup is not in focus

This commit is contained in:
Hinton
2020-10-12 18:01:34 +02:00
parent 5eb0ce1e09
commit 894d245361
6 changed files with 80 additions and 42 deletions

View File

@@ -1,4 +1,8 @@
import { CryptoService, VaultTimeoutService } from 'jslib/abstractions';
import { StorageService } from 'jslib/abstractions/storage.service';
import { ConstantsService } from 'jslib/services';
import { BrowserApi } from '../browser/browserApi';
import RuntimeBackground from './runtime.background';
export class NativeMessagingBackground {
private connected = false;
@@ -6,18 +10,16 @@ export class NativeMessagingBackground {
private resolver: any = null;
constructor(private storageService: StorageService, private cryptoService: CryptoService,
private vaultTimeoutService: VaultTimeoutService, private runtimeBackground: RuntimeBackground) {}
connect() {
this.port = BrowserApi.connectNative('com.8bit.bitwarden');
this.connected = true;
this.port.onMessage.addListener((msg: any) => {
if (this.resolver) {
this.resolver(msg);
} else {
// tslint:disable-next-line
console.error('NO RESOLVER');
}
});
this.port.onMessage.addListener((msg) => this.onMessage(msg));
this.port.onDisconnect.addListener(() => {
this.connected = false;
});
@@ -37,4 +39,30 @@ export class NativeMessagingBackground {
this.resolver = resolve;
});
}
private async onMessage(msg: any) {
switch(msg.command) {
case 'biometricUnlock': {
await this.storageService.remove(ConstantsService.biometricAwaitingAcceptance);
const enabled = await this.storageService.get(ConstantsService.biometricUnlockKey);
if (enabled === null || enabled === false) {
if (msg.response === 'unlocked') {
await this.storageService.save(ConstantsService.biometricUnlockKey, true);
}
await this.cryptoService.toggleKey();
}
if (this.vaultTimeoutService.biometricLocked) {
this.runtimeBackground.processMessage({command: 'unlocked'}, null, null);
this.vaultTimeoutService.biometricLocked = false;
}
}
}
if (this.resolver) {
this.resolver(msg);
}
}
}