diff options
author | varjolintu <sami.vanttinen@gmail.com> | 2017-10-19 15:48:26 +0300 |
---|---|---|
committer | varjolintu <sami.vanttinen@gmail.com> | 2017-10-19 15:48:26 +0300 |
commit | a9994549550b75c89c4d0d954076fe681331268e (patch) | |
tree | 90dc9f099bf4c4fd97f33ec065abc925ad0174a4 | |
parent | 80228d0b6aa70a420da347f6d81c455262315553 (diff) | |
parent | aec3aa2314de652827045fd880b2b216edaf80c3 (diff) |
Merge branch 'develop'0.3.5
-rw-r--r-- | CHANGELOG | 5 | ||||
-rw-r--r-- | README.md | 13 | ||||
-rw-r--r-- | keepassxc-browser/background/browserAction.js | 19 | ||||
-rw-r--r-- | keepassxc-browser/background/event.js | 112 | ||||
-rw-r--r-- | keepassxc-browser/background/httpauth.js | 2 | ||||
-rw-r--r-- | keepassxc-browser/background/init.js | 12 | ||||
-rw-r--r-- | keepassxc-browser/background/keepass.js | 19 | ||||
-rw-r--r-- | keepassxc-browser/background/page.js | 2 | ||||
-rw-r--r-- | keepassxc-browser/keepassxc-browser.js | 40 | ||||
-rw-r--r-- | keepassxc-browser/manifest.json | 2 |
10 files changed, 141 insertions, 85 deletions
@@ -1,3 +1,8 @@ +0.3.5 (19-10-2017) +========================= +- Removed database locked/unlocked status polling and replaced it with message handling from KeePassXC signals +- Clear or change page credentials if a database is changed or locked + 0.3.4 (14-10-2017) ========================= - Added support for Lock Database button @@ -22,6 +22,19 @@ and transfers these messages through a localhost UDP port 19700 (configurable) t Native Messaging API. keepassxc-browser starts only the proxy application and there's no risk of shutting down KeePassXC or losing any unsaved changes. keepassxc-proxy is still under development. If you want, you are free to write your own proxy that handles the traffic. +## Improvements +The following improvements and features have been made after the fork. At this point some features are only available with the KeePassXC fork: +- Real-time detection of database status (locked/unlocked) +- Credentials on a page are cleared or received automatically again if database is locked or changed to another +- It is possible to lock the active database from the popup (using the red lock icon) +- Input forms are detected even if the login div has been hidden or is created after the page was loaded +- It is possible to use the active database from multiple browsers at the same time with [keepassxc-proxy](https://github.com/varjolintu/keepassxc-proxy) application. +- Deprecated JavaScript functions are removed and everything is asynchronous +- Updated Bootstrap to version 3.3.7 and jQuery to version 3.2.1 +- New buttons, icons and settings page graphics +- Redesigned password generator dialog +- Password generator supports diceware passphrases and extended ASCII characters + ## Protocol Transmitting messages between KeePassXC and keepassxc-browser is totally rewritten. This is still under development. diff --git a/keepassxc-browser/background/browserAction.js b/keepassxc-browser/background/browserAction.js index 12dd782..3a67a12 100644 --- a/keepassxc-browser/background/browserAction.js +++ b/keepassxc-browser/background/browserAction.js @@ -3,8 +3,6 @@ var browserAction = {}; const BLINK_TIMEOUT_DEFAULT = 7500; const BLINK_TIMEOUT_REDIRECT_THRESHOLD_TIME_DEFAULT = -1; const BLINK_TIMEOUT_REDIRECT_COUNT_DEFAULT = 1; -const MAXIMUM_POLL_COUNT = 8; // _interval (250 ms) * 8 = 2 sec -let databasePollCount = 0; browserAction.show = function(callback, tab) { let data = {}; @@ -36,21 +34,6 @@ browserAction.update = function(interval) { let data = page.tabs[page.currentTabId].stack[page.tabs[page.currentTabId].stack.length - 1]; - // Poll the database if it's open or closed - if (databasePollCount >= MAXIMUM_POLL_COUNT) { - if (keepass.isKeePassXCAvailable) { - keepass.testAssociation((response) => { - keepass.isConfigured((configured) => { - data.iconType = configured ? 'normal' : 'cross'; - browserAction.show(null, {'id': page.currentTabId}); - }); - }, null); - } - databasePollCount = 0; - } else { - databasePollCount += 1; - } - if (typeof data.visibleForMilliSeconds !== 'undefined') { if (data.visibleForMilliSeconds <= 0) { browserAction.stackPop(page.currentTabId); @@ -279,4 +262,4 @@ browserAction.generateIconName = function(iconType, icon) { name += '_19x19.png'; return name; -};
\ No newline at end of file +}; diff --git a/keepassxc-browser/background/event.js b/keepassxc-browser/background/event.js index ef75bd4..a0de69b 100644 --- a/keepassxc-browser/background/event.js +++ b/keepassxc-browser/background/event.js @@ -1,14 +1,14 @@ -var event = {}; +var kpxcEvent = {}; -event.onMessage = function(request, sender, callback) { - if (request.action in event.messageHandlers) { +kpxcEvent.onMessage = function(request, sender, callback) { + if (request.action in kpxcEvent.messageHandlers) { //console.log('onMessage(' + request.action + ') for #' + sender.tab.id); if (!sender.hasOwnProperty('tab') || sender.tab.id < 1) { sender.tab = {}; sender.tab.id = page.currentTabId; } - event.invoke(event.messageHandlers[request.action], callback, sender.tab.id, request.args); + kpxcEvent.invoke(kpxcEvent.messageHandlers[request.action], callback, sender.tab.id, request.args); // onMessage closes channel for callback automatically // if this method does not return true @@ -29,7 +29,7 @@ event.onMessage = function(request, sender, callback) { * @param {bool} secondTime * @returns null (asynchronous) */ -event.invoke = function(handler, callback, senderTabId, args, secondTime) { +kpxcEvent.invoke = function(handler, callback, senderTabId, args, secondTime) { if (senderTabId < 1) { return; } @@ -51,7 +51,7 @@ event.invoke = function(handler, callback, senderTabId, args, secondTime) { // using window.open() if (!secondTime) { window.setTimeout(function() { - event.invoke(handler, callback, senderTabId, args, true); + kpxcEvent.invoke(handler, callback, senderTabId, args, true); }, 250); } return; @@ -75,12 +75,12 @@ event.invoke = function(handler, callback, senderTabId, args, secondTime) { }); }; -event.onShowAlert = function(callback, tab, message) { +kpxcEvent.onShowAlert = function(callback, tab, message) { if (page.settings.supressAlerts) { console.log(message); } else { alert(message); } }; -event.showStatus = function(configured, tab, callback) { +kpxcEvent.showStatus = function(configured, tab, callback) { let keyId = null; if (configured) { keyId = keepass.keyRing[keepass.databaseHash].id; @@ -99,11 +99,11 @@ event.showStatus = function(configured, tab, callback) { }); }; -event.onLoadSettings = function(callback, tab) { +kpxcEvent.onLoadSettings = function(callback, tab) { page.settings = (typeof(localStorage.settings) === 'undefined') ? {} : JSON.parse(localStorage.settings); }; -event.onLoadKeyRing = function(callback, tab) { +kpxcEvent.onLoadKeyRing = function(callback, tab) { keepass.keyRing = (typeof(localStorage.keyRing) === 'undefined') ? {} : JSON.parse(localStorage.keyRing); if (keepass.isAssociated() && !keepass.keyRing[keepass.associated.hash]) { keepass.associated = { @@ -113,25 +113,25 @@ event.onLoadKeyRing = function(callback, tab) { } }; -event.onGetSettings = function(callback, tab) { - event.onLoadSettings(); +kpxcEvent.onGetSettings = function(callback, tab) { + kpxcEvent.onLoadSettings(); callback({ data: page.settings }); }; -event.onSaveSettings = function(callback, tab, settings) { +kpxcEvent.onSaveSettings = function(callback, tab, settings) { localStorage.settings = JSON.stringify(settings); - event.onLoadSettings(); + kpxcEvent.onLoadSettings(); }; -event.onGetStatus = function(callback, tab) { +kpxcEvent.onGetStatus = function(callback, tab) { keepass.testAssociation((response) => { keepass.isConfigured((configured) => { - event.showStatus(configured, tab, callback); + kpxcEvent.showStatus(configured, tab, callback); }); }, tab, true); }; -event.onReconnect = function(callback, tab) { +kpxcEvent.onReconnect = function(callback, tab) { keepass.connectToNative(); // Add a small timeout after reconnecting. Just to make sure. It's not pretty, I know :( @@ -142,7 +142,7 @@ event.onReconnect = function(callback, tab) { if (gdRes) { keepass.testAssociation((response) => { keepass.isConfigured((configured) => { - event.showStatus(configured, tab, callback); + kpxcEvent.showStatus(configured, tab, callback); }); }, tab); } @@ -151,30 +151,30 @@ event.onReconnect = function(callback, tab) { }, 2000); }; -event.lockDatabase = function(callback, tab) { +kpxcEvent.lockDatabase = function(callback, tab) { keepass.lockDatabase((response) => { - event.showStatus(true, tab, callback); + kpxcEvent.showStatus(true, tab, callback); }, tab); }; -event.onPopStack = function(callback, tab) { +kpxcEvent.onPopStack = function(callback, tab) { browserAction.stackPop(tab.id); browserAction.show(null, tab); }; -event.onGetTabInformation = function(callback, tab) { +kpxcEvent.onGetTabInformation = function(callback, tab) { const id = tab.id || page.currentTabId; callback(page.tabs[id]); }; -event.onGetConnectedDatabase = function(callback, tab) { +kpxcEvent.onGetConnectedDatabase = function(callback, tab) { callback({ count: Object.keys(keepass.keyRing).length, identifier: (keepass.keyRing[keepass.associated.hash]) ? keepass.keyRing[keepass.associated.hash].id : null }); }; -event.onGetKeePassXCVersions = function(callback, tab) { +kpxcEvent.onGetKeePassXCVersions = function(callback, tab) { if (keepass.currentKeePassXC.version === 0) { keepass.getDatabaseHash((response) => { callback({current: keepass.currentKeePassXC.version, latest: keepass.latestKeePassXC.version}); @@ -183,25 +183,25 @@ event.onGetKeePassXCVersions = function(callback, tab) { callback({current: keepass.currentKeePassXC.version, latest: keepass.latestKeePassXC.version}); }; -event.onCheckUpdateKeePassXC = function(callback, tab) { +kpxcEvent.onCheckUpdateKeePassXC = function(callback, tab) { keepass.checkForNewKeePassXCVersion(); callback({current: keepass.currentKeePassXC.version, latest: keepass.latestKeePassXC.version}); }; -event.onUpdateAvailableKeePassXC = function(callback, tab) { +kpxcEvent.onUpdateAvailableKeePassXC = function(callback, tab) { callback(keepass.keePassXCUpdateAvailable()); }; -event.onRemoveCredentialsFromTabInformation = function(callback, tab) { +kpxcEvent.onRemoveCredentialsFromTabInformation = function(callback, tab) { const id = tab.id || page.currentTabId; page.clearCredentials(id); }; -event.onSetRememberPopup = function(callback, tab, username, password, url, usernameExists, credentialsList) { +kpxcEvent.onSetRememberPopup = function(callback, tab, username, password, url, usernameExists, credentialsList) { browserAction.setRememberPopup(tab.id, username, password, url, usernameExists, credentialsList); }; -event.onLoginPopup = function(callback, tab, logins) { +kpxcEvent.onLoginPopup = function(callback, tab, logins) { let stackData = { level: 1, iconType: 'questionmark', @@ -212,7 +212,7 @@ event.onLoginPopup = function(callback, tab, logins) { browserAction.show(null, tab); }; -event.onHTTPAuthPopup = function(callback, tab, data) { +kpxcEvent.onHTTPAuthPopup = function(callback, tab, data) { let stackData = { level: 1, iconType: 'questionmark', @@ -223,7 +223,7 @@ event.onHTTPAuthPopup = function(callback, tab, data) { browserAction.show(null, tab); }; -event.onMultipleFieldsPopup = function(callback, tab) { +kpxcEvent.onMultipleFieldsPopup = function(callback, tab) { let stackData = { level: 1, iconType: 'normal', @@ -233,38 +233,46 @@ event.onMultipleFieldsPopup = function(callback, tab) { browserAction.show(null, tab); }; -event.pageClearLogins = function(callback, tab) { +kpxcEvent.pageClearLogins = function(callback, tab) { page.clearLogins(tab.id); callback(); }; +kpxcEvent.oldDatabaseHash = 'no-hash'; +kpxcEvent.checkDatabaseHash = function(callback, tab) { + keepass.getDatabaseHash((response) => { + callback({old: kpxcEvent.oldDatabaseHash, new: response}); + kpxcEvent.oldDatabaseHash = response; + }); +}; // all methods named in this object have to be declared BEFORE this! -event.messageHandlers = { +kpxcEvent.messageHandlers = { 'add_credentials': keepass.addCredentials, - 'alert': event.onShowAlert, + 'alert': kpxcEvent.onShowAlert, 'associate': keepass.associate, - 'check_update_keepassxc': event.onCheckUpdateKeePassXC, - 'get_connected_database': event.onGetConnectedDatabase, - 'get_keepassxc_versions': event.onGetKeePassXCVersions, - 'get_settings': event.onGetSettings, - 'get_status': event.onGetStatus, - 'get_tab_information': event.onGetTabInformation, - 'load_keyring': event.onLoadKeyRing, - 'load_settings': event.onLoadSettings, - 'page_clear_logins': event.pageClearLogins, - 'pop_stack': event.onPopStack, - 'popup_login': event.onLoginPopup, - 'popup_multiple-fields': event.onMultipleFieldsPopup, - 'remove_credentials_from_tab_information': event.onRemoveCredentialsFromTabInformation, + 'check_update_keepassxc': kpxcEvent.onCheckUpdateKeePassXC, + 'get_connected_database': kpxcEvent.onGetConnectedDatabase, + 'get_keepassxc_versions': kpxcEvent.onGetKeePassXCVersions, + 'get_settings': kpxcEvent.onGetSettings, + 'get_status': kpxcEvent.onGetStatus, + 'get_tab_information': kpxcEvent.onGetTabInformation, + 'load_keyring': kpxcEvent.onLoadKeyRing, + 'load_settings': kpxcEvent.onLoadSettings, + 'page_clear_logins': kpxcEvent.pageClearLogins, + 'pop_stack': kpxcEvent.onPopStack, + 'popup_login': kpxcEvent.onLoginPopup, + 'popup_multiple-fields': kpxcEvent.onMultipleFieldsPopup, + 'remove_credentials_from_tab_information': kpxcEvent.onRemoveCredentialsFromTabInformation, 'retrieve_credentials': keepass.retrieveCredentials, 'show_default_browseraction': browserAction.showDefault, 'update_credentials': keepass.updateCredentials, - 'save_settings': event.onSaveSettings, - 'set_remember_credentials': event.onSetRememberPopup, + 'save_settings': kpxcEvent.onSaveSettings, + 'set_remember_credentials': kpxcEvent.onSetRememberPopup, 'stack_add': browserAction.stackAdd, - 'update_available_keepassxc': event.onUpdateAvailableKeePassXC, + 'update_available_keepassxc': kpxcEvent.onUpdateAvailableKeePassXC, 'generate_password': keepass.generatePassword, - 'reconnect': event.onReconnect, - 'lock-database': event.lockDatabase + 'reconnect': kpxcEvent.onReconnect, + 'lock-database': kpxcEvent.lockDatabase, + 'check_databasehash': kpxcEvent.checkDatabaseHash }; diff --git a/keepassxc-browser/background/httpauth.js b/keepassxc-browser/background/httpauth.js index 06936d6..f1ad0ba 100644 --- a/keepassxc-browser/background/httpauth.js +++ b/keepassxc-browser/background/httpauth.js @@ -41,7 +41,7 @@ httpAuth.processPendingCallbacks = function(details, resolve, reject) { httpAuth.loginOrShowCredentials = function(logins, details, resolve, reject) { // at least one login found --> use first to login if (logins.length > 0) { - event.onHTTPAuthPopup(null, { "id": details.tabId }, { "logins": logins, "url": details.searchUrl }); + kpxcEvent.onHTTPAuthPopup(null, { "id": details.tabId }, { "logins": logins, "url": details.searchUrl }); //generate popup-list for HTTP Auth usernames + descriptions if (page.settings.autoFillAndSend) { diff --git a/keepassxc-browser/background/init.js b/keepassxc-browser/background/init.js index 72b4b9d..6bc33c1 100644 --- a/keepassxc-browser/background/init.js +++ b/keepassxc-browser/background/init.js @@ -22,7 +22,7 @@ browser.tabs.onCreated.addListener((tab) => { //console.log('browser.tabs.onCreated(' + tab.id+ ')'); if (tab.selected) { page.currentTabId = tab.id; - event.invoke(page.switchTab, null, tab.id, []); + kpxcEvent.invoke(page.switchTab, null, tab.id, []); } } }); @@ -53,8 +53,8 @@ browser.tabs.onActivated.addListener((activeInfo) => { if (info && info.id) { page.currentTabId = info.id; if (info.status === 'complete') { - //console.log('event.invoke(page.switchTab, null, '+info.id + ', []);'); - event.invoke(page.switchTab, null, info.id, []); + //console.log('kpxcEvent.invoke(page.switchTab, null, '+info.id + ', []);'); + kpxcEvent.invoke(page.switchTab, null, info.id, []); } } }); @@ -67,7 +67,7 @@ browser.tabs.onActivated.addListener((activeInfo) => { */ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (changeInfo.status === 'complete') { - event.invoke(browserAction.removeRememberPopup, null, tabId, []); + kpxcEvent.invoke(browserAction.removeRememberPopup, null, tabId, []); } }); @@ -87,7 +87,7 @@ if (browser.webRequest.onAuthRequired) { browser.webRequest.onErrorOccurred.addListener(httpAuth.requestCompleted, opts); } -browser.runtime.onMessage.addListener(event.onMessage); +browser.runtime.onMessage.addListener(kpxcEvent.onMessage); const contextMenuItems = [ {title: 'Fill &User + Pass', action: 'fill_user_pass'}, @@ -131,4 +131,4 @@ browser.commands.onCommand.addListener((command) => { // Interval which updates the browserAction (e.g. blinking icon) window.setInterval(function() { browserAction.update(_interval); -}, _interval);
\ No newline at end of file +}, _interval); diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index 917a589..69fb55b 100644 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -1,3 +1,5 @@ +'use strict'; + var keepass = {}; keepass.associated = {'value': false, 'hash': null}; @@ -20,7 +22,7 @@ keepass.databaseHash = 'no-hash'; //no-hash = KeePassXC is too old and does not keepass.keyRing = (typeof(localStorage.keyRing) === 'undefined') ? {} : JSON.parse(localStorage.keyRing); keepass.keyId = 'keepassxc-browser-cryptokey-name'; keepass.keyBody = 'keepassxc-browser-key'; -keepass.messageTimeout = 1000; // milliseconds +keepass.messageTimeout = 500; // milliseconds const kpActions = { SET_LOGIN: 'set-login', @@ -30,7 +32,9 @@ const kpActions = { TEST_ASSOCIATE: 'test-associate', GET_DATABASE_HASH: 'get-databasehash', CHANGE_PUBLIC_KEYS: 'change-public-keys', - LOCK_DATABASE: 'lock-database' + LOCK_DATABASE: 'lock-database', + DATABASE_LOCKED: 'database-locked', + DATABASE_UNLOCKED: 'database-unlocked' }; const kpErrors = { @@ -742,6 +746,17 @@ keepass.connectToNative = function() { keepass.onNativeMessage = function(response) { //console.log('Received message: ' + JSON.stringify(response)); + + // Handle database lock/unlock status + if (response.action === kpActions.DATABASE_LOCKED || response.action === kpActions.DATABASE_UNLOCKED) { + keepass.testAssociation((response) => { + keepass.isConfigured((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}); + }); + }, null); + } }; function onDisconnected() { diff --git a/keepassxc-browser/background/page.js b/keepassxc-browser/background/page.js index 0a6baba..8ffd51e 100644 --- a/keepassxc-browser/background/page.js +++ b/keepassxc-browser/background/page.js @@ -16,7 +16,7 @@ page.settings = (typeof(localStorage.settings) === 'undefined') ? {} : JSON.pars page.blockedTabs = {}; page.initSettings = function() { - event.onLoadSettings(); + kpxcEvent.onLoadSettings(); if (!('checkUpdateKeePassXC' in page.settings)) { page.settings.checkUpdateKeePassXC = defaultSettings.checkUpdateKeePassXC; } diff --git a/keepassxc-browser/keepassxc-browser.js b/keepassxc-browser/keepassxc-browser.js index 7de7bea..e3857f9 100644 --- a/keepassxc-browser/keepassxc-browser.js +++ b/keepassxc-browser/keepassxc-browser.js @@ -202,7 +202,7 @@ cipPassword.createDialog = function() { const $dialog = jQuery('<div>')
.addClass('dialog-form')
.attr('id', 'cip-genpw-dialog');
-
+
const $inputDiv = jQuery('<div>').addClass('form-group');
const $inputGroup = jQuery('<div>').addClass('genpw-input-group');
const $textfieldPassword = jQuery('<input>')
@@ -220,7 +220,7 @@ cipPassword.createDialog = function() { .attr('id', 'cip-genpw-quality')
.text('123 Bits');
$inputGroup.append($textfieldPassword).append($quality);
-
+
const $checkGroup = jQuery('<div>').addClass('genpw-input-group');
const $checkboxNextField = jQuery('<input>')
.attr('id', 'cip-genpw-checkbox-next-field')
@@ -246,7 +246,7 @@ cipPassword.createDialog = function() { title: 'Password Generator',
classes: {'ui-dialog': 'ui-corner-all'},
buttons: {
- 'Generate':
+ 'Generate':
{
text: 'Generate',
id: 'cip-genpw-btn-generate',
@@ -266,7 +266,7 @@ cipPassword.createDialog = function() { cipPassword.copyPasswordToClipboard();
}
},
- 'Fill & copy':
+ 'Fill & copy':
{
text: 'Fill & copy',
id: 'cip-genpw-btn-fillin',
@@ -1102,6 +1102,7 @@ cip.credentials = []; jQuery(function() {
cip.init();
cip.detectNewActiveFields();
+ cip.detectDatabaseChange();
});
cip.init = function() {
@@ -1128,6 +1129,37 @@ cip.detectNewActiveFields = function() { //}
};
+// Switch credentials if database is changed or closed
+cip.detectDatabaseChange = function() {
+ const dbDetectInterval = setInterval(function() {
+ browser.runtime.sendMessage({
+ action: 'check_databasehash'
+ }).then((response) => {
+ if (response.new === 'no-hash') {
+ cipEvents.clearCredentials();
+
+ browser.runtime.sendMessage({
+ action: 'page_clear_logins'
+ });
+
+ // Switch back to default popup
+ browser.runtime.sendMessage({
+ action: 'get_status'
+ });
+ } else {
+ if (response.new !== 'no-hash' && response.new !== response.old) {
+ browser.runtime.sendMessage({
+ action: 'get_settings',
+ }).then((response) => {
+ cip.settings = response.data;
+ cip.initCredentialFields(true);
+ });
+ }
+ }
+ });
+ }, 1000);
+};
+
cip.initCredentialFields = function(forceCall) {
if (_called.initCredentialFields && !forceCall) {
return;
diff --git a/keepassxc-browser/manifest.json b/keepassxc-browser/manifest.json index 944d50f..c90921c 100644 --- a/keepassxc-browser/manifest.json +++ b/keepassxc-browser/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "keepassxc-browser", - "version": "0.3.4", + "version": "0.3.5", "description": "KeePassXC integration for modern web browsers", "author": "Sami Vänttinen", "icons": { |