From 9a6d3404f1868dce50de6aeb83a280cc182281d9 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Mon, 25 Jan 2021 17:24:33 +0100 Subject: [PATCH] Make nativeMessaging optional on all platforms except firefox (#1565) Make nativeMessaging optional on all platforms except firefox --- gulpfile.js | 11 +++++++++++ src/_locales/en/messages.json | 6 ++++++ src/popup/settings/settings.component.ts | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index c90d6361ef..541d4def69 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -75,6 +75,7 @@ function distOpera() { delete manifest.applications; delete manifest.content_security_policy; removeShortcuts(manifest); + moveNativeMessagingToOptional(manifest); return manifest; }); } @@ -85,6 +86,7 @@ function distChrome() { delete manifest.content_security_policy; delete manifest.sidebar_action; delete manifest.commands._execute_sidebar_action; + moveNativeMessagingToOptional(manifest); return manifest; }); } @@ -95,6 +97,7 @@ function distEdge() { delete manifest.content_security_policy; delete manifest.sidebar_action; delete manifest.commands._execute_sidebar_action; + moveNativeMessagingToOptional(manifest); return manifest; }); } @@ -108,6 +111,14 @@ function removeShortcuts(manifest) { } } +function moveNativeMessagingToOptional(manifest) { + const index = manifest.permissions.indexOf("nativeMessaging"); + index > -1 ? manifest.permissions.splice(index, 1) : false + manifest.optional_permissions = [ + "nativeMessaging" + ]; +} + function distSafariMas(cb) { return distSafariApp(cb, 'mas'); } diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index a1b4aa76d2..02c4279727 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -1438,6 +1438,12 @@ "biometricsNotSupportedDesc": { "message": "Browser biometrics is not supported on this device." }, + "nativeMessaginPermissionErrorTitle": { + "message": "Permission not provided" + }, + "nativeMessaginPermissionErrorDesc": { + "message": "Without permission to communicate with the Bitwarden Desktop Application we cannot provide biometrics in the browser extension. Please try again." + }, "personalOwnershipSubmitError": { "message": "Due to an Enterprise Policy, you are restricted from saving items to your personal vault. Change the Ownership option to an organization and choose from available Collections." }, diff --git a/src/popup/settings/settings.component.ts b/src/popup/settings/settings.component.ts index 0cf3972dce..b61dedd9b2 100644 --- a/src/popup/settings/settings.component.ts +++ b/src/popup/settings/settings.component.ts @@ -23,6 +23,7 @@ import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { StorageService } from 'jslib/abstractions/storage.service'; import { UserService } from 'jslib/abstractions/user.service'; import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; +import { resolve } from '@angular/compiler-cli/src/ngtsc/file_system'; const RateUrls = { [DeviceType.ChromeExtension]: @@ -208,6 +209,24 @@ export class SettingsComponent implements OnInit { async updateBiometric() { if (this.biometric) { + + // Request permission to use the optional permission for nativeMessaging + if (!this.platformUtilsService.isFirefox()) { + const granted = await new Promise((resolve, reject) => { + chrome.permissions.request({permissions: ['nativeMessaging']}, function(granted) { + resolve(granted); + }); + }); + + if (!granted) { + await this.platformUtilsService.showDialog( + this.i18nService.t('nativeMessaginPermissionErrorDesc'), this.i18nService.t('nativeMessaginPermissionErrorTitle'), + this.i18nService.t('ok'), null); + this.biometric = false; + return; + } + } + const submitted = Swal.fire({ heightAuto: false, buttonsStyling: false,