mirror of
https://github.com/bitwarden/browser.git
synced 2025-02-26 03:01:53 +01:00
Minor cleanup
This commit is contained in:
parent
a77cca82c8
commit
41134aee98
@ -1,9 +1,11 @@
|
|||||||
import { CryptoService, VaultTimeoutService } from 'jslib/abstractions';
|
import { CryptoService, LogService, VaultTimeoutService } from 'jslib/abstractions';
|
||||||
import { StorageService } from 'jslib/abstractions/storage.service';
|
import { StorageService } from 'jslib/abstractions/storage.service';
|
||||||
import { ConstantsService } from 'jslib/services';
|
import { ConstantsService } from 'jslib/services';
|
||||||
import { BrowserApi } from '../browser/browserApi';
|
import { BrowserApi } from '../browser/browserApi';
|
||||||
import RuntimeBackground from './runtime.background';
|
import RuntimeBackground from './runtime.background';
|
||||||
|
|
||||||
|
const MessageValidTimeout = 10 * 1000;
|
||||||
|
|
||||||
export class NativeMessagingBackground {
|
export class NativeMessagingBackground {
|
||||||
private connected = false;
|
private connected = false;
|
||||||
private port: browser.runtime.Port | chrome.runtime.Port;
|
private port: browser.runtime.Port | chrome.runtime.Port;
|
||||||
@ -19,7 +21,7 @@ export class NativeMessagingBackground {
|
|||||||
this.connected = true;
|
this.connected = true;
|
||||||
|
|
||||||
this.port.onMessage.addListener((msg) => this.onMessage(msg));
|
this.port.onMessage.addListener((msg) => this.onMessage(msg));
|
||||||
|
|
||||||
this.port.onDisconnect.addListener(() => {
|
this.port.onDisconnect.addListener(() => {
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
});
|
});
|
||||||
@ -46,12 +48,13 @@ export class NativeMessagingBackground {
|
|||||||
private async onMessage(rawMessage: any) {
|
private async onMessage(rawMessage: any) {
|
||||||
const message = JSON.parse(await this.cryptoService.decryptToUtf8(rawMessage));
|
const message = JSON.parse(await this.cryptoService.decryptToUtf8(rawMessage));
|
||||||
|
|
||||||
if (Math.abs(message.timestamp - Date.now()) > 10*1000) {
|
if (Math.abs(message.timestamp - Date.now()) > MessageValidTimeout) {
|
||||||
console.error("MESSAGE IS TO OLD");
|
// tslint:disable-next-line
|
||||||
|
console.error('NativeMessage is to old, ignoring.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(message.command) {
|
switch (message.command) {
|
||||||
case 'biometricUnlock': {
|
case 'biometricUnlock': {
|
||||||
await this.storageService.remove(ConstantsService.biometricAwaitingAcceptance);
|
await this.storageService.remove(ConstantsService.biometricAwaitingAcceptance);
|
||||||
|
|
||||||
@ -60,7 +63,7 @@ export class NativeMessagingBackground {
|
|||||||
if (message.response === 'unlocked') {
|
if (message.response === 'unlocked') {
|
||||||
await this.storageService.save(ConstantsService.biometricUnlockKey, true);
|
await this.storageService.save(ConstantsService.biometricUnlockKey, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.cryptoService.toggleKey();
|
await this.cryptoService.toggleKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +72,9 @@ export class NativeMessagingBackground {
|
|||||||
this.vaultTimeoutService.biometricLocked = false;
|
this.vaultTimeoutService.biometricLocked = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
// tslint:disable-next-line
|
||||||
|
console.error('NativeMessage, got unknown command.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.resolver) {
|
if (this.resolver) {
|
||||||
|
Loading…
Reference in New Issue
Block a user