diff --git a/CHANGELOG b/CHANGELOG index 95cde52..6049e28 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,9 @@ 0.3.0 (2017-??-??) ========================= - Added Mozilla's browser-polyfill -- Merged changes from the latest passifox (credits to smorks) +- Merged changes from the latest passifox (credits to smorks/passifox) - HTTP auth works with all browsers -- Fixed showing credentials from previous logins in the popup (credits to smorks) +- Fixed showing credentials from previous logins in the popup (credits to smorks/passifox) - Automatic detection of div's with forms that are non-hidden by user interaction 0.2.9 (2017-08-27) diff --git a/keepassxc-browser/background/httpauth.js b/keepassxc-browser/background/httpauth.js index 04f64e9..efb3892 100644 --- a/keepassxc-browser/background/httpauth.js +++ b/keepassxc-browser/background/httpauth.js @@ -1,90 +1,62 @@ var httpAuth = httpAuth || {}; +httpAuth.requests = []; httpAuth.pendingCallbacks = []; -httpAuth.requestId = ''; -httpAuth.tabId = 0; -httpAuth.url = null; -httpAuth.isProxy = false; -httpAuth.proxyUrl = null; -httpAuth.resolve = null; -httpAuth.reject = null; -httpAuth.handleRequest = function(details) { +httpAuth.requestCompleted = function(details) { + let index = httpAuth.requests.indexOf(details.requestId); + if (index > -1) { + httpAuth.requests.splice(index, 1); + } +} + +httpAuth.handleRequestPromise = function(details) { return new Promise((resolve, reject) => { - if (httpAuth.requestId == details.requestId || !page.tabs[details.tabId]) { - reject({}); - } - else { - httpAuth.requestId = details.requestId; - httpAuth.resolve = resolve; - httpAuth.reject = reject; - httpAuth.processPendingCallbacks(details); - } + httpAuth.processPendingCallbacks(details, resolve, reject); }); } -httpAuth.handleRequestChrome = function(details, callback) { - if (httpAuth.requestId == details.requestId || !page.tabs[details.tabId]) { - callback({}); - } - else { - httpAuth.requestId = details.requestId; - httpAuth.pendingCallbacks.push(callback); - httpAuth.processPendingCallbacks(details); - } +httpAuth.handleRequestCallback = function(details, callback) { + httpAuth.processPendingCallbacks(details, callback, callback); } -httpAuth.processPendingCallbacks = function(details) { - if (!isFirefox) { - httpAuth.callback = httpAuth.pendingCallbacks.pop(); +httpAuth.processPendingCallbacks = function(details, resolve, reject) { + if (httpAuth.requests.indexOf(details.requestId) >= 0 || !page.tabs[details.tabId]) { + reject({}); } - httpAuth.tabId = details.tabId; - httpAuth.url = details.url; - httpAuth.isProxy = details.isProxy; + + httpAuth.requests.push(details.requestId); if (details.challenger) { - httpAuth.proxyUrl = details.challenger.host; + details.proxyUrl = details.challenger.host; } - // WORKAROUND: second parameter should be tab, but is an own object with tab-id - // but in background.js only tab.id is used. To get tabs we could use - // chrome.tabs.get(tabId, callback) <-- but what should callback be? + details.searchUrl = (details.isProxy && details.proxyUrl) ? details.proxyUrl : details.url; - const url = (httpAuth.isProxy && httpAuth.proxyUrl) ? httpAuth.proxyUrl : httpAuth.url; - keepass.retrieveCredentials(httpAuth.loginOrShowCredentials, { "id" : details.tabId }, url, url, true); + keepass.retrieveCredentials((logins) => { + httpAuth.loginOrShowCredentials(logins, details, resolve, reject); + }, { "id": details.tabId }, details.searchUrl, details.searchUrl, true); } -httpAuth.loginOrShowCredentials = function(logins) { +httpAuth.loginOrShowCredentials = function(logins, details, resolve, reject) { // at least one login found --> use first to login if (logins.length > 0) { - const url = (httpAuth.isProxy && httpAuth.proxyUrl) ? httpAuth.proxyUrl : httpAuth.url; - event.onHTTPAuthPopup(null, {'id': httpAuth.tabId}, {'logins': logins, 'url': url}); + event.onHTTPAuthPopup(null, { "id": details.tabId }, { "logins": logins, "url": details.searchUrl }); //generate popup-list for HTTP Auth usernames + descriptions if (page.settings.autoFillAndSend) { - if (isFirefox) { - httpAuth.resolve({ - authCredentials: { - username: logins[0].login, - password: logins[0].password - } - }); - } - else { - httpAuth.callback({ - authCredentials: { - username: logins[0].login, - password: logins[0].password - } - }); - } - } - else { - isFirefox ? httpAuth.reject({}) : httpAuth.callback({}); + resolve({ + authCredentials: { + username: logins[0].login, + password: logins[0].password + } + }); + } else { + reject({}); } } // no logins found else { - isFirefox ? httpAuth.reject({}) : httpAuth.callback({}); + reject({}); } -} \ No newline at end of file +} diff --git a/keepassxc-browser/background/init.js b/keepassxc-browser/background/init.js index e9ee7e4..f9754ef 100644 --- a/keepassxc-browser/background/init.js +++ b/keepassxc-browser/background/init.js @@ -1,14 +1,3 @@ -/* -keepass.convertKeyToKeyRing(); -page.initSettings(); -page.initOpenedTabs(); -keepass.connectToNative(); -keepass.generateNewKeyPair(); -keepass.changePublicKeys(null, (pkRes) => { - keepass.getDatabaseHash((gdRes) => {}, null); -}); -*/ - // since version 2.0 the extension is using a keyRing instead of a single key-name-pair keepass.migrateKeyRing().then(() => { // load settings @@ -98,14 +87,18 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { // Retrieve Credentials and try auto-login for HTTPAuth requests if (browser.webRequest.onAuthRequired) { - if (isFirefox) { - browser.webRequest.onAuthRequired.addListener(httpAuth.handleRequest, - { urls: [""] }, ["blocking"]); - } - else { - browser.webRequest.onAuthRequired.addListener(httpAuth.handleRequestChrome, - { urls: [""] }, ["asyncBlocking"]); + let handleReq = httpAuth.handleRequestPromise; + let reqType = 'blocking'; + let opts = { urls: [''] }; + + if (!isFirefox) { + handleReq = httpAuth.handleRequestCallback; + reqType = 'asyncBlocking'; } + + browser.webRequest.onAuthRequired.addListener(handleReq, opts, [reqType]); + browser.webRequest.onCompleted.addListener(httpAuth.requestCompleted, opts); + browser.webRequest.onErrorOccurred.addListener(httpAuth.requestCompleted, opts); } browser.runtime.onMessage.addListener(event.onMessage); diff --git a/keepassxc-browser/background/page.js b/keepassxc-browser/background/page.js index 09a17a6..abdf32e 100644 --- a/keepassxc-browser/background/page.js +++ b/keepassxc-browser/background/page.js @@ -104,7 +104,6 @@ page.clearLogins = function(tabId) { } page.createTabEntry = function(tabId) { - //console.log('page.createTabEntry('+tabId+')'); page.tabs[tabId] = { 'stack': [], 'errorMessage': null, diff --git a/keepassxc-browser/keepassxc-browser.js b/keepassxc-browser/keepassxc-browser.js index 807f07e..ccd1107 100644 --- a/keepassxc-browser/keepassxc-browser.js +++ b/keepassxc-browser/keepassxc-browser.js @@ -1707,4 +1707,4 @@ $(function() { clearInterval(divDetect); } }, 1000); -}); \ No newline at end of file +});