From 47b69346997a36d57fee12100b5b38300c2e10d6 Mon Sep 17 00:00:00 2001 From: Hinton Date: Fri, 18 Dec 2020 16:06:36 +0100 Subject: [PATCH] Make checking fingerprint optional --- src/background/nativeMessaging.background.ts | 27 ++++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/background/nativeMessaging.background.ts b/src/background/nativeMessaging.background.ts index 0f76615406..68e6d70a08 100644 --- a/src/background/nativeMessaging.background.ts +++ b/src/background/nativeMessaging.background.ts @@ -24,6 +24,7 @@ export class NativeMessagingBackground { private resolver: any = null; private privateKey: ArrayBuffer = null; + private publicKey: ArrayBuffer = null; private secureSetupResolve: any = null; private sharedSecret: SymmetricCryptoKey; private appId: string; @@ -89,6 +90,12 @@ export class NativeMessagingBackground { confirmText: this.i18nService.t('ok'), type: 'error', }); + case 'verifyFingerprint': { + if (this.sharedSecret == null) { + this.showFingerprintDialog(); + } + return; + } default: // Ignore since it belongs to another device if (message.appId !== this.appId) { @@ -208,17 +215,10 @@ export class NativeMessagingBackground { private async secureCommunication() { const [publicKey, privateKey] = await this.cryptoFunctionService.rsaGenerateKeyPair(2048); + this.publicKey = publicKey; this.privateKey = privateKey; this.sendUnencrypted({command: 'setupEncryption', publicKey: Utils.fromBufferToB64(publicKey)}); - const fingerprint = (await this.cryptoService.getFingerprint(await this.userService.getUserId(), publicKey)).join(' '); - - this.messagingService.send('showDialog', { - html: `${this.i18nService.t('desktopIntegrationVerificationText')}

${fingerprint}`, - title: this.i18nService.t('desktopSyncVerificationTitle'), - confirmText: this.i18nService.t('ok'), - type: 'warning', - }); return new Promise((resolve, reject) => this.secureSetupResolve = resolve); } @@ -232,4 +232,15 @@ export class NativeMessagingBackground { this.port.postMessage({appId: this.appId, message: message}); } + + private async showFingerprintDialog() { + const fingerprint = (await this.cryptoService.getFingerprint(await this.userService.getUserId(), this.publicKey)).join(' '); + + this.messagingService.send('showDialog', { + html: `${this.i18nService.t('desktopIntegrationVerificationText')}

${fingerprint}`, + title: this.i18nService.t('desktopSyncVerificationTitle'), + confirmText: this.i18nService.t('ok'), + type: 'warning', + }); + } }