From c1d354a6fbb7ce2130997c7245cbc8d9aff57780 Mon Sep 17 00:00:00 2001 From: antelle Date: Fri, 5 Jun 2020 20:37:13 +0200 Subject: [PATCH] added an error when usb is disabled --- app/scripts/comp/app/chal-resp-calculator.js | 18 +++++++++++++++++- app/scripts/locales/base.json | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/scripts/comp/app/chal-resp-calculator.js b/app/scripts/comp/app/chal-resp-calculator.js index f3dc8094..c8dfc6a0 100644 --- a/app/scripts/comp/app/chal-resp-calculator.js +++ b/app/scripts/comp/app/chal-resp-calculator.js @@ -6,6 +6,7 @@ import { Alerts } from 'comp/ui/alerts'; import { Locale } from 'util/locale'; import { Timeouts } from 'const/timeouts'; import { Launcher } from 'comp/launcher'; +import { AppSettingsModel } from 'models/app-settings-model'; const logger = new Logger('chal-resp'); @@ -32,6 +33,21 @@ const ChalRespCalculator = { return resolve(Buffer.from(respFromCache, 'hex')); } + if (!AppSettingsModel.enableUsb) { + logger.debug('USB is disabled'); + Alerts.error({ + header: Locale.yubiKeyDisabledErrorHeader, + body: Locale.yubiKeyDisabledErrorBody, + complete() { + const err = new Error(Locale.yubiKeyDisabledErrorHeader); + err.userCanceled = true; + + reject(err); + } + }); + return; + } + logger.debug('Calculating ChalResp using a YubiKey', params); this._calc(params, challenge, (err, response) => { @@ -105,7 +121,7 @@ const ChalRespCalculator = { let deviceEnumerationTimer; const onUsbDevicesChanged = () => { - if (UsbListener.attachedYubiKeys.length === 0) { + if (!UsbListener.attachedYubiKeys) { return; } deviceEnumerationTimer = setTimeout(() => { diff --git a/app/scripts/locales/base.json b/app/scripts/locales/base.json index da39e5ca..f317cf76 100644 --- a/app/scripts/locales/base.json +++ b/app/scripts/locales/base.json @@ -684,5 +684,7 @@ "yubiKeyNoKeyBody": "Please insert your YubiKey with serial number {}", "yubiKeySlot": "slot", "yubiKeyTouchRequestedHeader": "Touch your YubiKey", - "yubiKeyTouchRequestedBody": "Please touch your YubiKey with serial number {}" + "yubiKeyTouchRequestedBody": "Please touch your YubiKey with serial number {}", + "yubiKeyDisabledErrorHeader": "USB is disabled", + "yubiKeyDisabledErrorBody": "YubiKey is required to open this file, please enable USB devices in settings." }