From d83e2bc117d5ee669d6e5e3171c5525b36cca35b Mon Sep 17 00:00:00 2001 From: Hinton Date: Mon, 12 Oct 2020 21:34:41 +0200 Subject: [PATCH] Use proper logging, fix linting errors. --- proxy/ipc.ts | 2 -- src/app/services.module.ts | 2 +- src/locales/en/messages.json | 2 +- src/services/nativeMessaging.service.ts | 17 +++++++++++------ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/proxy/ipc.ts b/proxy/ipc.ts index 097fe5455c..02de48d6cf 100644 --- a/proxy/ipc.ts +++ b/proxy/ipc.ts @@ -28,11 +28,9 @@ export default class IPC { this.onMessage(message); }); - /* ipc.of.bitwarden.on('error', (err: any) => { console.error('error', err); }); - */ }); } diff --git a/src/app/services.module.ts b/src/app/services.module.ts index d4ff88d740..d222a4a169 100644 --- a/src/app/services.module.ts +++ b/src/app/services.module.ts @@ -129,7 +129,7 @@ const environmentService = new EnvironmentService(apiService, storageService, no const eventService = new EventService(storageService, apiService, userService, cipherService); const systemService = new SystemService(storageService, vaultTimeoutService, messagingService, platformUtilsService, null); -const nativeMessagingService = new NativeMessagingService(cryptoService, platformUtilsService) +const nativeMessagingService = new NativeMessagingService(cryptoService, platformUtilsService, logService); const analytics = new Analytics(window, () => isDev(), platformUtilsService, storageService, appIdService); containerService.attachToGlobal(window); diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index 393896c96c..eaf6cd656c 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -1406,6 +1406,6 @@ "message": "Enable browser integration" }, "enableBrowserIntegrationDesc": { - "message": "" + "message": "Browser integration is used for biometrics in browser." } } diff --git a/src/services/nativeMessaging.service.ts b/src/services/nativeMessaging.service.ts index 962eb6903c..e490fc3334 100644 --- a/src/services/nativeMessaging.service.ts +++ b/src/services/nativeMessaging.service.ts @@ -1,9 +1,14 @@ -import { CryptoService } from 'jslib/abstractions/crypto.service'; -import { PlatformUtilsService } from 'jslib/abstractions'; import { ipcRenderer } from 'electron'; +import { CryptoService } from 'jslib/abstractions/crypto.service'; +import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; +import { LogService } from 'jslib/abstractions/log.service'; + +const MessageValidTimeout = 10 * 1000; + export class NativeMessagingService { - constructor(private cryptoService: CryptoService, private platformUtilService: PlatformUtilsService) { + + constructor(private cryptoService: CryptoService, private platformUtilService: PlatformUtilsService, private logService: LogService) { ipcRenderer.on('nativeMessaging', async (event: any, message: any) => { this.messageHandler(message); }); @@ -12,8 +17,8 @@ export class NativeMessagingService { private async messageHandler(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) { + this.logService.error('NativeMessage is to old, ignoring.'); return; } @@ -33,7 +38,7 @@ export class NativeMessagingService { break; default: - console.error('UNKNOWN COMMAND') + this.logService.error('NativeMessage, got unknown command.'); } }