diff --git a/CHANGELOG b/CHANGELOG index 726d92c..ff72e14 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,12 @@ +0.2.7 (2017-07-31) +========================= +- Some Firefox related changes (credits to projectgus) +- Fixed Skip button function when choosing own credential fields +- Adjusted some callbacks +- Fixed showing an error message on the same tab when KeePassXC is instantly closed +- Added null checking for onDisconnected() +- Any Chrome related stuff is now disabled on options pages when using Firefox + 0.2.6 (2017-07-23) ========================= - Fixed error message variables diff --git a/README.md b/README.md index 05dd478..a535e47 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Chrome extension for [KeePassXC](https://keepassxc.org/) with Native Messaging. This is a heavily forked version of [pfn](https://github.com/pfn)'s [chromeIPass](https://github.com/pfn/passifox). +Some changes merged also from [projectgus'](https://github.com/projectgus/passifox) fork. For testing purposes, please use following unofficial KeePassXC [release's](https://github.com/varjolintu/keepassxc/releases). Get the extension for [Firefox](https://addons.mozilla.org/en-US/firefox/addon/keepassxc-browser/) or [Chrome/Chromium](https://chrome.google.com/webstore/detail/keepassxc-browser/iopaggbpplllidnfmcghoonnokmjoicf). diff --git a/com.varjolintu.keepassxc-browser-chrome-win.json b/com.varjolintu.keepassxc-browser-chrome-win.json index 608265f..acf8450 100644 --- a/com.varjolintu.keepassxc-browser-chrome-win.json +++ b/com.varjolintu.keepassxc-browser-chrome-win.json @@ -5,6 +5,7 @@ "type": "stdio", "allowed_origins": [ "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/", - "chrome-extension://fhakpkpdnjecjfceboihdjpfmgajebii/" + "chrome-extension://fhakpkpdnjecjfceboihdjpfmgajebii/", + "chrome-extension://jaikbblhommnkeialomogohhdlndpfbi/" ] } \ No newline at end of file diff --git a/com.varjolintu.keepassxc-browser-chrome.json b/com.varjolintu.keepassxc-browser-chrome.json index 9266fe9..0fb2adb 100644 --- a/com.varjolintu.keepassxc-browser-chrome.json +++ b/com.varjolintu.keepassxc-browser-chrome.json @@ -5,6 +5,7 @@ "type": "stdio", "allowed_origins": [ "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/", - "chrome-extension://fhakpkpdnjecjfceboihdjpfmgajebii/" + "chrome-extension://fhakpkpdnjecjfceboihdjpfmgajebii/", + "chrome-extension://jaikbblhommnkeialomogohhdlndpfbi/" ] } \ No newline at end of file diff --git a/keepassxc-browser/background/browserAction.js b/keepassxc-browser/background/browserAction.js index 310f14f..48a9951 100644 --- a/keepassxc-browser/background/browserAction.js +++ b/keepassxc-browser/background/browserAction.js @@ -249,7 +249,9 @@ function getValueOrDefault(settings, key, defaultVal, min) { val = defaultVal; } return val; - } catch(e) { return defaultVal; } + } catch(e) { + return defaultVal; + } } browserAction.generateIconName = function(iconType, icon) { diff --git a/keepassxc-browser/background/event.js b/keepassxc-browser/background/event.js index 4e4d208..8dcddcf 100644 --- a/keepassxc-browser/background/event.js +++ b/keepassxc-browser/background/event.js @@ -44,11 +44,6 @@ event.invoke = function(handler, callback, senderTabId, args, secondTime) { page.removePageInformationFromNotExistingTabs(); browser.tabs.get(senderTabId, (tab) => { - //browser.tabs.query({'active': true, 'windowId': browser.windows.WINDOW_ID_CURRENT}, function(tabs) { - //if (tabs.length === 0) - // return; // For example: only the background devtools or a popup are opened - //var tab = tabs[0]; - if (!tab) { return; } @@ -95,6 +90,7 @@ event.showStatus = function(configured, tab, callback) { } browserAction.showDefault(null, tab); + const errorMessage = page.tabs[tab.id].errorMessage; callback({ identifier: keyId, configured: configured, @@ -102,7 +98,7 @@ event.showStatus = function(configured, tab, callback) { keePassXCAvailable: keepass.isKeePassXCAvailable, encryptionKeyUnrecognized: keepass.isEncryptionKeyUnrecognized, associated: keepass.isAssociated(), - error: page.tabs[tab.id].errorMessage + error: errorMessage ? errorMessage : null }); } @@ -260,6 +256,5 @@ event.messageHandlers = { 'stack_add': browserAction.stackAdd, 'update_available_keepassxc': event.onUpdateAvailableKeePassXC, 'generate_password': keepass.generatePassword, - 'copy_password': keepass.copyPassword, 'reconnect': event.onReconnect }; \ No newline at end of file diff --git a/keepassxc-browser/background/init.js b/keepassxc-browser/background/init.js index 934777b..c50f71e 100644 --- a/keepassxc-browser/background/init.js +++ b/keepassxc-browser/background/init.js @@ -10,7 +10,9 @@ keepass.changePublicKeys(null, (pkRes) => { window.browser = (function () { return window.msBrowser || window.browser || window.chrome; })(); // Set initial tab-ID -browser.tabs.query({'active': true, 'windowId': browser.windows.WINDOW_ID_CURRENT}, (tabs) => { +//browser.tabs.query({'active': true, 'windowId': browser.windows.WINDOW_ID_CURRENT}, (tabs) => { +browser.tabs.query({"active": true, "currentWindow": true}, (tabs) => { +//browser.tabs.query({"active": true, "currentWindow": true}).then((tabs) => { if (tabs.length === 0) return; // For example: only the background devtools or a popup are opened page.currentTabId = tabs[0].id; diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index 6eda72b..d72b43d 100644 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -45,6 +45,7 @@ const kpErrors = { KEY_CHANGE_FAILED: 9, ENCRYPTION_KEY_UNRECOGNIZED: 10, NO_SAVED_DATABASES_FOUND: 11, + errorMessages : { 0: { msg: 'Unknown error' }, 1: { msg: 'Database not opened' }, @@ -58,6 +59,10 @@ const kpErrors = { 9: { msg: 'Key change was not successful.' }, 10: { msg: 'Encryption key is not recognized' }, 11: { msg: 'No saved databases found.' } + }, + + getError(errorCode) { + return this.errorMessages[errorCode].msg; } }; @@ -139,6 +144,7 @@ keepass.retrieveCredentials = function (callback, tab, url, submiturl, forceCall page.tabs[tab.id].errorMessage = null; if (!keepass.isConnected) { + callback([]); return; } @@ -199,7 +205,7 @@ keepass.retrieveCredentials = function (callback, tab, url, submiturl, forceCall // Redirects the callback to a listener (handleReply()) keepass.callbackOnId = function (ev, id, callback) { - let listener = ( (port, id) => { + let listener = ((port, id) => { let handler = (msg) => { if (msg && msg.action === id) { ev.removeListener(handler); @@ -273,37 +279,15 @@ keepass.generatePassword = function (callback, tab, forceCallback) { }, tab); } -keepass.copyPassword = function(callback, tab, password) { - browser.runtime.getBackgroundPage((bg) => { - let c2c = bg.document.getElementById('copy2clipboard'); - if (!c2c) { - let input = document.createElement('input'); - input.type = 'text'; - input.id = 'copy2clipboard'; - bg.document.getElementsByTagName('body')[0].appendChild(input); - c2c = bg.document.getElementById('copy2clipboard'); - } - - c2c.value = password; - c2c.select(); - try { - document.execCommand('copy'); - c2c.value = ''; - callback(true); - } - catch (err) { - console.log('Could not copy password to clipboard: ' + err); - } - }); -} - keepass.associate = function(callback, tab) { if (keepass.isAssociated()) { + callback([]); return; } keepass.getDatabaseHash((res) => { if (keepass.isDatabaseClosed || !keepass.isKeePassXCAvailable) { + callback([]); return; } @@ -511,6 +495,7 @@ keepass.getDatabaseHash = function (callback, tab, triggerUnlock) { keepass.changePublicKeys = function(tab, callback) { if (!keepass.isConnected) { + callback([]); return; } @@ -635,16 +620,14 @@ keepass.keePassXCUpdateAvailable = function() { keepass.checkForNewKeePassXCVersion = function() { let xhr = new XMLHttpRequest(); let version = -1; - xhr.open('GET', keepass.latestVersionUrl, true); + xhr.onload = function(e) { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - const json = JSON.parse(xhr.responseText); - if (json.tag_name) { - version = json.tag_name; - keepass.latestKeePassXC.version = version; - keepass.latestKeePassXC.versionParsed = Number(version.replace(/\./g, '')); - } + if (xhr.readyState === 4 && xhr.status === 200) { + const json = JSON.parse(xhr.responseText); + if (json.tag_name) { + version = json.tag_name; + keepass.latestKeePassXC.version = version; + keepass.latestKeePassXC.versionParsed = Number(version.replace(/\./g, '')); } } @@ -654,10 +637,16 @@ keepass.checkForNewKeePassXCVersion = function() { }; xhr.onerror = function(e) { - console.log('checkForNewKeePassXCVersion error: ${e}'); + console.log('checkForNewKeePassXCVersion error:' + e); } - xhr.send(); + try { + xhr.open('GET', keepass.latestVersionUrl, true); + xhr.send(); + } + catch (ex) { + console.log(ex); + } keepass.latestKeePassXC.lastChecked = new Date(); } @@ -672,11 +661,11 @@ keepass.onNativeMessage = function (response) { } function onDisconnected() { - console.log('Failed to connect: ' + browser.runtime.lastError.message); keepass.nativePort = null; keepass.isConnected = false; keepass.isDatabaseClosed = true; keepass.isKeePassXCAvailable = false; + console.log('Failed to connect: ' + (browser.runtime.lastError === null ? 'Unknown error' : browser.runtime.lastError.message)); } keepass.nativeConnect = function() { @@ -734,7 +723,7 @@ keepass.verifyResponse = function(response, nonce, id) { keepass.handleError = function(tab, errorCode, errorMessage = '') { if (errorMessage.length === 0) { - errorMessage = kpErrors.errorMessages[errorCode].msg; + errorMessage = kpErrors.getError(errorCode); } console.log('Error ' + errorCode + ': ' + errorMessage); if (tab && page.tabs[tab.id]) { diff --git a/keepassxc-browser/keepassxc-browser.js b/keepassxc-browser/keepassxc-browser.js index eb00503..6555a60 100644 --- a/keepassxc-browser/keepassxc-browser.js +++ b/keepassxc-browser/keepassxc-browser.js @@ -79,7 +79,6 @@ function _fs(fieldId) { } - var cipAutocomplete = {}; // objects of username + description for autocomplete @@ -271,10 +270,7 @@ cipPassword.createDialog = function() { id: 'cip-genpw-btn-clipboard', click: (e) => { e.preventDefault(); - browser.runtime.sendMessage({ - action: 'copy_password', - args: [jQuery('input#cip-genpw-textfield-password').val()] - }, cipPassword.callbackPasswordCopied); + cipPassword.copyPasswordToClipboard(); } }, 'Fill & copy': @@ -309,11 +305,7 @@ cipPassword.createDialog = function() { } } - // Copy password to clipboard - browser.runtime.sendMessage({ - action: 'copy_password', - args: [$password] - }, cipPassword.callbackPasswordCopied); + cipPassword.copyPasswordToClipboard(); } } } @@ -381,6 +373,26 @@ cipPassword.setIconPosition = function($icon, $field) { .css('left', $field.offset().left + $field.outerWidth() - $icon.data('size') - $icon.data('offset')) } +cipPassword.copyPasswordToClipboard = function(e) { + if (e) { + e.preventDefault(); + } + + const input = jQuery("input#cip-genpw-textfield-password"); + input.select() + try { + const success = document.execCommand('copy'); + if (success) { + jQuery("#cip-genpw-btn-clipboard").addClass("b2c-btn-success"); + } + jQuery("#cip-genpw-dialog").select(); + input.value = ''; + } + catch (err) { + console.log('Could not copy password to clipboard: ' + err); + } +} + cipPassword.callbackPasswordCopied = function(bool) { if (bool) { jQuery('#cip-genpw-btn-clipboard').addClass('btn-success'); @@ -549,12 +561,12 @@ cipDefine.initDescription = function() { .addClass('btn').addClass('btn-info') .css('margin-right', '5px') .click(function() { - if (jQuery(this).data('step') === 1) { + if (jQuery(this).data('step') === '1') { cipDefine.selection.username = null; cipDefine.prepareStep2(); cipDefine.markAllPasswordFields(jQuery('#b2c-cipDefine-fields')); } - else if (jQuery(this).data('step') === 2) { + else if (jQuery(this).data('step') === '2') { cipDefine.selection.password = null; cipDefine.prepareStep3(); cipDefine.markAllStringFields(jQuery('#b2c-cipDefine-fields')); diff --git a/keepassxc-browser/manifest.json b/keepassxc-browser/manifest.json index 46815eb..cee5a75 100644 --- a/keepassxc-browser/manifest.json +++ b/keepassxc-browser/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "keepassxc-browser", - "version": "0.2.6", + "version": "0.2.7", "description": "KeePassXC integration for modern web browsers", "author": "Sami Vänttinen", "icons": { @@ -36,9 +36,19 @@ }, "content_scripts": [ { - "matches": [ "http://*/*", "https://*/*" ], - "js": [ "jquery-3.2.1.min.js", "jquery-ui.min.js", "keepassxc-browser.js" ], - "css": [ "jquery-ui.min.css", "keepassxc-browser.css" ], + "matches": [ + "http://*/*", + "https://*/*" + ], + "js": [ + "jquery-3.2.1.min.js", + "jquery-ui.min.js", + "keepassxc-browser.js" + ], + "css": [ + "jquery-ui.min.css", + "keepassxc-browser.css" + ], "run_at": "document_idle", "all_frames": true } diff --git a/keepassxc-browser/options/options.html b/keepassxc-browser/options/options.html index af22cca..d0e9d93 100644 --- a/keepassxc-browser/options/options.html +++ b/keepassxc-browser/options/options.html @@ -2,7 +2,7 @@ Settings | keepassxc-browser - + @@ -29,7 +29,8 @@

If you just want to insert username + password into the fields where your focus is, press Ctrl + Shift + U.
- If you only want to insert the password, just press Ctrl + Shift + P. You can customize these shortcuts on chrome://extensions/configureCommands page + If you only want to insert the password, just press Ctrl + Shift + P. + You can customize these shortcuts on chrome://extensions/configureCommands page

diff --git a/keepassxc-browser/options/options.js b/keepassxc-browser/options/options.js index 7b44586..64cb05b 100644 --- a/keepassxc-browser/options/options.js +++ b/keepassxc-browser/options/options.js @@ -1,3 +1,8 @@ +var isFirefox = false; +if (typeof browser !== 'undefined') { + isFirefox = true; +} + window.browser = (function () { return window.msBrowser || window.browser || window.chrome; })(); if (jQuery) { @@ -36,7 +41,7 @@ options.saveSetting = function(name) { localStorage.settings = JSON.stringify(options.settings); - chrome.extension.sendMessage({ + browser.runtime.sendMessage({ action: 'load_settings' }); } @@ -257,4 +262,7 @@ options.initSpecifiedCredentialFields = function() { options.initAbout = function() { $('#tab-about em.versionCIP').text(browser.runtime.getManifest().version); + if (isFirefox) { + $('#chrome-only').remove(); + } } diff --git a/keepassxc-browser/popups/popup.html b/keepassxc-browser/popups/popup.html index 76576db..c9af685 100644 --- a/keepassxc-browser/popups/popup.html +++ b/keepassxc-browser/popups/popup.html @@ -1,6 +1,7 @@ KeePassXC - Popup + diff --git a/keepassxc-browser/popups/popup.js b/keepassxc-browser/popups/popup.js index 0f9d83c..779baf5 100644 --- a/keepassxc-browser/popups/popup.js +++ b/keepassxc-browser/popups/popup.js @@ -55,7 +55,7 @@ $(function() { }); $('#redetect-fields-button').click(function() { - browser.tabs.query({'active': true, 'windowId': browser.windows.WINDOW_ID_CURRENT}, (tabs) => { + browser.tabs.query({"active": true, "currentWindow": true}, (tabs) => { if (tabs.length === 0) return; // For example: only the background devtools or a popup are opened let tab = tabs[0]; diff --git a/keepassxc-browser/popups/popup_httpauth.html b/keepassxc-browser/popups/popup_httpauth.html index ff62344..afe2006 100644 --- a/keepassxc-browser/popups/popup_httpauth.html +++ b/keepassxc-browser/popups/popup_httpauth.html @@ -1,6 +1,7 @@ keepassxc-browser - Popup + diff --git a/keepassxc-browser/popups/popup_httpauth.js b/keepassxc-browser/popups/popup_httpauth.js index 445c4bd..aa839bf 100644 --- a/keepassxc-browser/popups/popup_httpauth.js +++ b/keepassxc-browser/popups/popup_httpauth.js @@ -2,8 +2,7 @@ window.browser = (function () { return window.msBrowser || window.browser || win $(function() { browser.runtime.getBackgroundPage(function(global) { - browser.tabs.query(null, (tab) => { - //const data = global.tab_httpauth_list['tab' + tab.id]; + browser.tabs.query({"active": true, "currentWindow": true}, (tab) => { const data = global.page.tabs[tab.id].loginList; let ul = document.getElementById('login-list'); for (let i = 0; i < data.logins.length; i++) { diff --git a/keepassxc-browser/popups/popup_login.html b/keepassxc-browser/popups/popup_login.html index 4f02afe..5882ce9 100644 --- a/keepassxc-browser/popups/popup_login.html +++ b/keepassxc-browser/popups/popup_login.html @@ -1,6 +1,7 @@ KeePassXC - Popup + diff --git a/keepassxc-browser/popups/popup_login.js b/keepassxc-browser/popups/popup_login.js index 11b152a..19b6d2d 100644 --- a/keepassxc-browser/popups/popup_login.js +++ b/keepassxc-browser/popups/popup_login.js @@ -2,7 +2,7 @@ window.browser = (function () { return window.msBrowser || window.browser || win $(function() { browser.runtime.getBackgroundPage(function(global) { - browser.tabs.query({'active': true, 'windowId': browser.windows.WINDOW_ID_CURRENT}, function(tabs) { + browser.tabs.query({"active": true, "currentWindow": true}, (tabs) => { if (tabs.length === 0) return; // For example: only the background devtools or a popup are opened const tab = tabs[0]; diff --git a/keepassxc-browser/popups/popup_multiple-fields.html b/keepassxc-browser/popups/popup_multiple-fields.html index f185875..2b6339c 100644 --- a/keepassxc-browser/popups/popup_multiple-fields.html +++ b/keepassxc-browser/popups/popup_multiple-fields.html @@ -1,6 +1,7 @@ keepassxc-browser - Popup + diff --git a/keepassxc-browser/popups/popup_remember.html b/keepassxc-browser/popups/popup_remember.html index 689f3ec..6f58a39 100644 --- a/keepassxc-browser/popups/popup_remember.html +++ b/keepassxc-browser/popups/popup_remember.html @@ -1,6 +1,7 @@ keepassxc-browser - Popup +