From c66803ce1f44298e162fd1134cd82a8a0f21d709 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 28 Aug 2017 18:08:08 -0400 Subject: [PATCH] web vault url environment for U2F --- src/_locales/en/messages.json | 3 +++ .../accountsLoginTwoFactorController.js | 17 +++++++++++++++-- .../settings/settingsEnvironmentController.js | 9 +++++++++ .../app/settings/views/settingsEnvironment.html | 4 ++++ src/scripts/u2f.js | 5 +++-- src/services/constantsService.js | 1 + 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index a5994a03..08acd559 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -724,6 +724,9 @@ "apiUrl": { "message": "API Server URL" }, + "webVaultUrl": { + "message": "Web Vault Server URL" + }, "identityUrl": { "message": "Identity Server URL" }, diff --git a/src/popup/app/accounts/accountsLoginTwoFactorController.js b/src/popup/app/accounts/accountsLoginTwoFactorController.js index e0b6d5cb..ef16afef 100644 --- a/src/popup/app/accounts/accountsLoginTwoFactorController.js +++ b/src/popup/app/accounts/accountsLoginTwoFactorController.js @@ -2,11 +2,24 @@ .module('bit.accounts') .controller('accountsLoginTwoFactorController', function ($scope, $state, authService, toastr, utilsService, SweetAlert, - $analytics, i18nService, $stateParams, $filter, constantsService, $timeout, $window, cryptoService, apiService) { + $analytics, i18nService, $stateParams, $filter, constantsService, $timeout, $window, cryptoService, apiService, + $window) { $scope.i18n = i18nService; utilsService.initListSectionItemListeners($(document), angular); - var u2f = new U2f(function (data) { + var customWebVaultUrl = null; + var storedBaseUrl = $window.localStorage.getItem(constantsService.baseUrlKey); + if (storedBaseUrl) { + customWebVaultUrl = storedBaseUrl; + } + else { + var storedWebVaultUrl = $window.localStorage.getItem(constantsService.webVaultUrlKey); + if (storedWebVaultUrl) { + customWebVaultUrl = storedWebVaultUrl; + } + } + + var u2f = new U2f(customWebVaultUrl, function (data) { $timeout(function () { $scope.login(data); }); diff --git a/src/popup/app/settings/settingsEnvironmentController.js b/src/popup/app/settings/settingsEnvironmentController.js index ac9c2f6a..1fc6462d 100644 --- a/src/popup/app/settings/settingsEnvironmentController.js +++ b/src/popup/app/settings/settingsEnvironmentController.js @@ -8,6 +8,7 @@ utilsService.initListSectionItemListeners($(document), angular); $scope.baseUrl = $window.localStorage.getItem(constantsService.baseUrlKey) || ''; + $scope.webVaultUrl = $window.localStorage.getItem(constantsService.webVaultUrlKey) || ''; $scope.apiUrl = $window.localStorage.getItem(constantsService.apiUrlKey) || ''; $scope.identityUrl = $window.localStorage.getItem(constantsService.identityUrlKey) || ''; @@ -20,6 +21,14 @@ $window.localStorage.removeItem(constantsService.baseUrlKey); } + if ($scope.webVaultUrl && $scope.webVaultUrl !== '') { + $scope.webVaultUrl = formatUrl($scope.webVaultUrl); + $window.localStorage.setItem(constantsService.webVaultUrlKey, $scope.webVaultUrl); + } + else { + $window.localStorage.removeItem(constantsService.webVaultUrlKey); + } + if ($scope.apiUrl && $scope.apiUrl !== '') { $scope.apiUrl = formatUrl($scope.apiUrl); $window.localStorage.setItem(constantsService.apiUrlKey, $scope.apiUrl); diff --git a/src/popup/app/settings/views/settingsEnvironment.html b/src/popup/app/settings/views/settingsEnvironment.html index 7af6f5c7..b02bc5aa 100644 --- a/src/popup/app/settings/views/settingsEnvironment.html +++ b/src/popup/app/settings/views/settingsEnvironment.html @@ -30,6 +30,10 @@ {{i18n.customEnvironment}}
+
+ + +
diff --git a/src/scripts/u2f.js b/src/scripts/u2f.js index 9758d28d..81a831c2 100644 --- a/src/scripts/u2f.js +++ b/src/scripts/u2f.js @@ -1,9 +1,10 @@ -function U2f(successCallback, errorCallback, infoCallback) { +function U2f(webVaultUrl, successCallback, errorCallback, infoCallback) { this.success = successCallback; this.error = errorCallback; this.info = infoCallback; this.iframe = null; this.connectorLink = document.createElement('a'); + this.webVaultUrl = webVaultUrl && webVaultUrl !== '' ? webVaultUrl : 'https://vault.bitwarden.com'; } (function () { @@ -12,7 +13,7 @@ U2f.prototype.init = function (data) { var self = thisU2f = this; - self.connectorLink.href = 'https://vault.bitwarden.com/u2f-connector.html' + + self.connectorLink.href = self.webVaultUrl + '/u2f-connector.html' + '?data=' + this.base64Encode(JSON.stringify(data)) + '&parent=' + encodeURIComponent(document.location.href) + '&v=1'; diff --git a/src/services/constantsService.js b/src/services/constantsService.js index 42f07b09..12c05d95 100644 --- a/src/services/constantsService.js +++ b/src/services/constantsService.js @@ -1,6 +1,7 @@ function ConstantsService(i18nService) { return { baseUrlKey: 'baseUrl', + webVaultUrlKey: 'webVaultUrl', apiUrlKey: 'apiUrl', identityUrlKey: 'identityUrl', disableGaKey: 'disableGa',