From efec41cb200b4878aa5dc7259c992c951ee75720 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sat, 14 Apr 2018 09:05:06 +0300 Subject: [PATCH 1/6] HTTP Auth fixes --- keepassxc-browser/background/httpauth.js | 2 +- keepassxc-browser/popups/popup.css | 28 ++------ keepassxc-browser/popups/popup_httpauth.html | 5 +- keepassxc-browser/popups/popup_httpauth.js | 72 +++++++++++++------- keepassxc-browser/popups/popup_login.html | 2 +- keepassxc-browser/popups/popup_login.js | 8 +-- 6 files changed, 60 insertions(+), 57 deletions(-) diff --git a/keepassxc-browser/background/httpauth.js b/keepassxc-browser/background/httpauth.js index cdd23ed..3209507 100755 --- a/keepassxc-browser/background/httpauth.js +++ b/keepassxc-browser/background/httpauth.js @@ -85,7 +85,7 @@ httpAuth.loginOrShowCredentials = function(logins, details, resolve, reject) { }); } else { if (page.settings.showNotifications) { - showNotification('Multiple credentials detected. Click on the extension icon to choose the correct one.'); + showNotification('HTTP authentication with multiple credentials detected. Click on the extension icon to choose the correct one.'); } kpxcEvent.onHTTPAuthPopup(null, { 'id': details.tabId }, { 'logins': logins, 'url': details.searchUrl, 'resolve': resolve }); } diff --git a/keepassxc-browser/popups/popup.css b/keepassxc-browser/popups/popup.css index baf8215..235a88b 100644 --- a/keepassxc-browser/popups/popup.css +++ b/keepassxc-browser/popups/popup.css @@ -7,33 +7,15 @@ body { font-size: 15px; padding: 8px; } -.credentials ul { - margin-left: 0; - margin-right: 0; - padding-left: 0; - padding-right: 0; - list-style-position: inside; +.list-group { + font-size: .9em !important; } -.credentials li { - list-style: none; - padding-top: 1px; - padding-bottom: 1px; - padding-left: 5px; - padding-right: 5px; - margin-left: 10px; - margin-right: 5px; +.list-group-item { + padding: 5px 10px !important; } -.credentials a { - color: #333; -} -.credentials a:hover { - text-decoration: none; -} -.credentials li:hover { +.list-group-item:hover { cursor: pointer; - background: #ddd; } - .settings { padding-bottom: 10px; margin-bottom: 10px; diff --git a/keepassxc-browser/popups/popup_httpauth.html b/keepassxc-browser/popups/popup_httpauth.html index 2f43070..8edb0ce 100644 --- a/keepassxc-browser/popups/popup_httpauth.html +++ b/keepassxc-browser/popups/popup_httpauth.html @@ -29,7 +29,10 @@

Select the login information you would like to get logged in with:

- +
+

+ +

diff --git a/keepassxc-browser/popups/popup_httpauth.js b/keepassxc-browser/popups/popup_httpauth.js index cd68d91..8ff0e13 100644 --- a/keepassxc-browser/popups/popup_httpauth.js +++ b/keepassxc-browser/popups/popup_httpauth.js @@ -1,37 +1,57 @@ 'use strict'; -$(function() { - browser.runtime.getBackgroundPage().then((global) => { - browser.tabs.query({'active': true, 'currentWindow': true}).then((tabs) => { - let tab = tabs[0]; - const data = global.page.tabs[tab.id].loginList; - let ul = document.getElementById('login-list'); - for (let i = 0; i < data.logins.length; i++) { - const li = document.createElement('li'); - const a = document.createElement('a'); - a.textContent = data.logins[i].login + " (" + data.logins[i].name + ")"; - li.appendChild(a); - $(a).data('creds', data.logins[i]); - $(a).click(function () { - if (data.resolve) { - const creds = $(this).data('creds'); - data.resolve({ - authCredentials: { - username: creds.login, - password: creds.password - } - }); - } - close(); - }); - ul.appendChild(li); - } +const getLoginData = function() { + return new Promise((resolve, reject) => { + browser.runtime.getBackgroundPage().then((global) => { + browser.tabs.query({'active': true, 'currentWindow': true}).then((tabs) => { + resolve(global.page.tabs[tabs[0].id].loginList); + }); }); }); +}; + +$(function() { + getLoginData().then((data) => { + let ll = document.getElementById('login-list'); + for (let i = 0; i < data.logins.length; ++i) { + const a = document.createElement('a'); + a.setAttribute('class', 'list-group-item'); + a.textContent = data.logins[i].login + " (" + data.logins[i].name + ")"; + $(a).data('creds', data.logins[i]); + $(a).click(function () { + if (data.resolve) { + const creds = $(this).data('creds'); + data.resolve({ + authCredentials: { + username: creds.login, + password: creds.password + } + }); + } + close(); + }); + ll.appendChild(a); + } + }); $('#lock-database-button').click(function() { browser.runtime.sendMessage({ action: 'lock-database' }).then(status_response); }); + + $('#btn-dismiss').click(function() { + getLoginData().then((data) => { + // Using reject won't work with every browser. So return empty credentials instead. + if (data.resolve) { + data.resolve({ + authCredentials: { + username: '', + password: '' + } + }); + } + close(); + }); + }); }); diff --git a/keepassxc-browser/popups/popup_login.html b/keepassxc-browser/popups/popup_login.html index 14d4584..09391e0 100644 --- a/keepassxc-browser/popups/popup_login.html +++ b/keepassxc-browser/popups/popup_login.html @@ -29,7 +29,7 @@

Select the login information you would like to get entered into the page:

- +
diff --git a/keepassxc-browser/popups/popup_login.js b/keepassxc-browser/popups/popup_login.js index b0c2f74..9ed3d02 100644 --- a/keepassxc-browser/popups/popup_login.js +++ b/keepassxc-browser/popups/popup_login.js @@ -9,13 +9,11 @@ $(function() { const tab = tabs[0]; const logins = global.page.tabs[tab.id].loginList; - let ul = document.getElementById('login-list'); + let ll = document.getElementById('login-list'); for (let i = 0; i < logins.length; i++) { - const li = document.createElement('li'); const a = document.createElement('a'); a.textContent = logins[i]; - li.setAttribute('class', 'list-group-item'); - li.appendChild(a); + a.setAttribute('class', 'list-group-item'); a.setAttribute('id', '' + i); a.addEventListener('click', (e) => { const id = e.target.id; @@ -25,7 +23,7 @@ $(function() { }); close(); }); - ul.appendChild(li); + ll.appendChild(a); } }); }); From 8fbf7a3ddd317bdbdff8643455854f1a8f3ad4a7 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Wed, 18 Apr 2018 14:36:52 +0300 Subject: [PATCH 2/6] Automatic reload --- keepassxc-browser/background/event.js | 18 +------- keepassxc-browser/background/init.js | 1 + keepassxc-browser/background/keepass.js | 56 ++++++++++++++++++------- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/keepassxc-browser/background/event.js b/keepassxc-browser/background/event.js index be7b1e6..8d1b39c 100755 --- a/keepassxc-browser/background/event.js +++ b/keepassxc-browser/background/event.js @@ -158,22 +158,8 @@ kpxcEvent.onReconnect = function(callback, tab) { // Add a small timeout after reconnecting. Just to make sure. It's not pretty, I know :( setTimeout(() => { - keepass.generateNewKeyPair(); - keepass.changePublicKeys(tab).then((pkRes) => { - keepass.getDatabaseHash((gdRes) => { - if (gdRes) { - keepass.testAssociation((response) => { - keepass.isConfigured().then((configured) => { - browser.tabs.sendMessage(tab.id, { - action: 'redetect_fields' - }); - kpxcEvent.showStatus(configured, tab, callback); - }).catch((e) => { - console.log(e); - }); - }, tab); - } - }, null); + keepass.reconnect(callback, tab).then((configured) => { + kpxcEvent.showStatus(configured, tab, callback); }); }, 500); }; diff --git a/keepassxc-browser/background/init.js b/keepassxc-browser/background/init.js index ce7fed7..0ecc02e 100644 --- a/keepassxc-browser/background/init.js +++ b/keepassxc-browser/background/init.js @@ -5,6 +5,7 @@ keepass.migrateKeyRing().then(() => { page.initOpenedTabs().then(() => { httpAuth.init(); keepass.connectToNative(); + keepass.enableAutomaticReconnect(); keepass.generateNewKeyPair(); keepass.changePublicKeys(null).then((pkRes) => { keepass.getDatabaseHash((gdRes) => {}, null); diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index 6dec6aa..e8fe811 100755 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -838,20 +838,7 @@ keepass.onNativeMessage = function(response) { if (response.action === kpActions.DATABASE_LOCKED || response.action === kpActions.DATABASE_UNLOCKED) { keepass.testAssociation((associationResponse) => { keepass.isConfigured().then((configured) => { - let data = page.tabs[page.currentTabId].stack[page.tabs[page.currentTabId].stack.length - 1]; - data.iconType = configured ? 'normal' : 'cross'; - browserAction.show(null, {'id': page.currentTabId}); - - // Send message to content script - browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { - if (tabs.length) { - browser.tabs.sendMessage(tabs[0].id, { - action: 'check_database_hash', - hash: {old: kpxcEvent.previousDatabaseHash, new: keepass.databaseHash} - }); - keepass.previousDatabaseHash = keepass.databaseHash; - } - }); + keepass.updatePopup(configured ? 'normal' : 'cross'); }); }, null); } @@ -864,6 +851,8 @@ function onDisconnected() { keepass.isKeePassXCAvailable = false; keepass.associated.value = false; keepass.associated.hash = null; + page.clearCredentials(page.currentTabId, true); + keepass.updatePopup('cross'); console.log('Failed to connect: ' + (browser.runtime.lastError === null ? 'Unknown error' : browser.runtime.lastError.message)); } @@ -1017,3 +1006,42 @@ keepass.decrypt = function(input, nonce) { const res = nacl.box.open(m, n, keepass.serverPublicKey, keepass.keyPair.secretKey); return res; }; + +keepass.enableAutomaticReconnect = function() { + setInterval(() => { + if (!keepass.isKeePassXCAvailable) { + keepass.connectToNative(); + keepass.reconnect(); + } + }, 1000); +}; + +keepass.reconnect = function(callback, tab) { + return new Promise((resolve, reject) => { + keepass.generateNewKeyPair(); + keepass.changePublicKeys(tab).then((pkRes) => { + // Database hash should be received if the reconnection succeeded + keepass.getDatabaseHash((gdRes) => { + if (!gdRes) { + reject(false); + return; + } + + keepass.testAssociation((response) => { + keepass.isConfigured().then((configured) => { + resolve(configured); + }).catch((e) => { + console.log(e); + reject(e); + }); + }, tab); + }, null); + }); + }); +}; + +keepass.updatePopup = function(iconType) { + const data = page.tabs[page.currentTabId].stack[page.tabs[page.currentTabId].stack.length - 1]; + data.iconType = iconType; + browserAction.show(null, {'id': page.currentTabId}); +}; From 9abcb2782fc1eadf1175bcb4ef248ec1e5bb5e48 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Thu, 10 May 2018 13:23:55 +0300 Subject: [PATCH 3/6] Fix for hiding update message --- keepassxc-browser/popups/popup.css | 1 + keepassxc-browser/popups/popup.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/keepassxc-browser/popups/popup.css b/keepassxc-browser/popups/popup.css index baf8215..998bf20 100644 --- a/keepassxc-browser/popups/popup.css +++ b/keepassxc-browser/popups/popup.css @@ -64,6 +64,7 @@ body { padding-bottom: 0px; margin-bottom: 0px; text-align: left; + display: none; } #update-available a:hover, #update-available a:active { diff --git a/keepassxc-browser/popups/popup.html b/keepassxc-browser/popups/popup.html index fa1bd0c..83340d8 100644 --- a/keepassxc-browser/popups/popup.html +++ b/keepassxc-browser/popups/popup.html @@ -18,7 +18,7 @@ -