Minor cleanup

This commit is contained in:
Hinton 2020-10-16 11:09:49 +02:00
parent a77cca82c8
commit 41134aee98
1 changed files with 12 additions and 6 deletions

View File

@ -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 { ConstantsService } from 'jslib/services';
import { BrowserApi } from '../browser/browserApi';
import RuntimeBackground from './runtime.background';
const MessageValidTimeout = 10 * 1000;
export class NativeMessagingBackground {
private connected = false;
private port: browser.runtime.Port | chrome.runtime.Port;
@ -46,12 +48,13 @@ export class NativeMessagingBackground {
private async onMessage(rawMessage: any) {
const message = JSON.parse(await this.cryptoService.decryptToUtf8(rawMessage));
if (Math.abs(message.timestamp - Date.now()) > 10*1000) {
console.error("MESSAGE IS TO OLD");
if (Math.abs(message.timestamp - Date.now()) > MessageValidTimeout) {
// tslint:disable-next-line
console.error('NativeMessage is to old, ignoring.');
return;
}
switch(message.command) {
switch (message.command) {
case 'biometricUnlock': {
await this.storageService.remove(ConstantsService.biometricAwaitingAcceptance);
@ -69,6 +72,9 @@ export class NativeMessagingBackground {
this.vaultTimeoutService.biometricLocked = false;
}
}
default:
// tslint:disable-next-line
console.error('NativeMessage, got unknown command.');
}
if (this.resolver) {