From cc7539e195c3c8ff772527e0fc62a8faeb787508 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Fri, 23 Jun 2017 14:34:57 +0300 Subject: [PATCH 1/6] Added experimental support for UDP port sending and updated README --- README.md | 11 +++++++++++ keepassxc-browser/background/keepass.js | 2 ++ keepassxc-browser/manifest.json | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06ad9d0..0ff43a0 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,17 @@ For testing purposes, please use following unofficial KeePassXC [release's](http 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). +## How it works +There are two methods which you can use keepassxc-browser to connect to KeePassXC: + +1. keepassxc-browser communicates directly with KeePassXC via stdin/stdout. This method launches KeePassXC every time you start the browser and closes when you exit. +This can cause unsaved changes not to be saved. If you use this method it's important to enable `Automatically save after every change` from KeePassXC's preferences. + +2. keepassxc-browser communicated with KeePassXC through [keepassxc-proxy](https://github.com/varjolintu/keepassxc-proxy). The proxy handles listening stdin/stdout +and transfers these messages through a localhost UDP port 19700 (configurable) to KeePassXC. This means KeePassXC can be used and started normally without inteference from +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. + ## Protocol Transmitting messages between KeePassXC and keepassxc-browser is totally rewritten. This is still under development. diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index 5ea2538..ebe1344 100644 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -13,6 +13,7 @@ keepass.requiredKeePassXC = 214; keepass.nativeHostName = "com.varjolintu.keepassxc_browser"; keepass.nativePort = null; keepass.keySize = 24; +keepass.proxyPort = 19700; keepass.latestVersionUrl = "https://raw.githubusercontent.com/keepassxreboot/keepassxc/develop/CHANGELOG"; keepass.cacheTimeout = 30 * 1000; // milliseconds keepass.databaseHash = "no-hash"; //no-hash = KeePassXC is too old and does not return a hash value @@ -500,6 +501,7 @@ keepass.changePublicKeys = function(tab, callback) { var message = { "action": "change-public-keys", "publicKey": key, + "proxyPort": keepass.proxyPort, "nonce": nonce } diff --git a/keepassxc-browser/manifest.json b/keepassxc-browser/manifest.json index ba93f8c..9abb9d3 100644 --- a/keepassxc-browser/manifest.json +++ b/keepassxc-browser/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "keepassxc-browser", - "version": "0.1.10", + "version": "0.2.0", "description": "KeePassXC integration for modern web browsers", "author": "Sami Vänttinen", "icons": { From 78de88f31dd47c21829c45bd760d8dde83a38b75 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sun, 25 Jun 2017 15:52:32 +0300 Subject: [PATCH 2/6] Added JSON install files and script for Windows --- CHANGELOG | 6 +++- ...rjolintu.keepassxc-browser-chrome-win.json | 10 ++++++ ...jolintu.keepassxc-browser-firefox-win.json | 9 +++++ install.bat | 34 +++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 com.varjolintu.keepassxc-browser-chrome-win.json create mode 100644 com.varjolintu.keepassxc-browser-firefox-win.json create mode 100644 install.bat diff --git a/CHANGELOG b/CHANGELOG index b02d80c..12300b9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,8 @@ -0.1.10 (2017-06.14) +0.2.0 (2017-xx-xx) +========================= +- Added JSON install files and script for Windows + +0.1.10 (2017-06-14) ========================= - Updated manifest and json files up to date diff --git a/com.varjolintu.keepassxc-browser-chrome-win.json b/com.varjolintu.keepassxc-browser-chrome-win.json new file mode 100644 index 0000000..608265f --- /dev/null +++ b/com.varjolintu.keepassxc-browser-chrome-win.json @@ -0,0 +1,10 @@ +{ + "name": "com.varjolintu.keepassxc_browser", + "description": "KeepassXC integration with Chrome with Native Messaging support", + "path" : "keepassxc-proxy.bat", + "type": "stdio", + "allowed_origins": [ + "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/", + "chrome-extension://fhakpkpdnjecjfceboihdjpfmgajebii/" + ] +} \ No newline at end of file diff --git a/com.varjolintu.keepassxc-browser-firefox-win.json b/com.varjolintu.keepassxc-browser-firefox-win.json new file mode 100644 index 0000000..6c4b9c4 --- /dev/null +++ b/com.varjolintu.keepassxc-browser-firefox-win.json @@ -0,0 +1,9 @@ +{ + "name": "com.varjolintu.keepassxc_browser", + "description": "KeepassXC integration with Firefox with Native Messaging support", + "path" : "keepassxc-proxy.bat", + "type": "stdio", + "allowed_extensions": [ + "keepassxc-browser@sami.vanttinen" + ] +} \ No newline at end of file diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..954957b --- /dev/null +++ b/install.bat @@ -0,0 +1,34 @@ +:: Copyright 2014 The Chromium Authors. All rights reserved. +:: Copyright 2017 Sami Vänttinen +:: Use of this source code is governed by a BSD-style license that can be +:: found in the LICENSE file. +:: Change HKCU to HKLM if you want to install globally. +:: %~dp0 is the directory containing this bat script and ends with a backslash. +@echo off +echo. +echo Select your browser: +echo ==================== +echo 1) Chrome +echo 2) Chromium +echo 3) Firefox +echo 4) Vivaldi +set choice= +set /p choice=1-4: +if '%choice%'=='1' goto chrome +if '%choice%'=='2' goto chromium +if '%choice%'=='3' goto firefox +if '%choice%'=='3' goto vivaldi +goto end +:chrome +REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.varjolintu.keepassxc_browser" /ve /t REG_SZ /d "%~dp0com.varjolintu.keepassxc-browser-chrome.win.json" /f +goto end +:chromium +REG ADD "HKCU\Software\Chromium\NativeMessagingHosts\com.varjolintu.keepassxc_browser" /ve /t REG_SZ /d "%~dp0com.varjolintu.keepassxc-browser-chrome.win.json" /f +goto end +:firefox +REG ADD "HKCU\Software\Mozilla\NativeMessagingHosts\com.varjolintu.keepassxc_browser" /ve /t REG_SZ /d "%~dp0com.varjolintu.keepassxc-browser-firefox.win.json" /f +goto end +:vivaldi +REG ADD "HKCU\Software\Vivaldi\NativeMessagingHosts\com.varjolintu.keepassxc_browser" /ve /t REG_SZ /d "%~dp0com.varjolintu.keepassxc-browser-chrome.win.json" /f +goto end +:end \ No newline at end of file From a99dc9901cbbdf9b06127cb93099727baee3d253 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Mon, 26 Jun 2017 07:46:44 +0300 Subject: [PATCH 3/6] Updated minimum Firefox version --- keepassxc-browser/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keepassxc-browser/manifest.json b/keepassxc-browser/manifest.json index 9abb9d3..cd03c88 100644 --- a/keepassxc-browser/manifest.json +++ b/keepassxc-browser/manifest.json @@ -75,7 +75,7 @@ "applications": { "gecko": { "id": "keepassxc-browser@sami.vanttinen", - "strict_min_version": "53.0" + "strict_min_version": "56.0" } } } From 645779932808d80d62a3cdbb78600d3a0366e5ae Mon Sep 17 00:00:00 2001 From: varjolintu Date: Mon, 26 Jun 2017 12:07:37 +0300 Subject: [PATCH 4/6] New version checking function --- CHANGELOG | 1 + keepassxc-browser/background/keepass.js | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 12300b9..bcbdca2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ 0.2.0 (2017-xx-xx) ========================= - Added JSON install files and script for Windows +- New version checking function 0.1.10 (2017-06-14) ========================= diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index ebe1344..1524311 100644 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -14,7 +14,7 @@ keepass.nativeHostName = "com.varjolintu.keepassxc_browser"; keepass.nativePort = null; keepass.keySize = 24; keepass.proxyPort = 19700; -keepass.latestVersionUrl = "https://raw.githubusercontent.com/keepassxreboot/keepassxc/develop/CHANGELOG"; +keepass.latestVersionUrl = "https://api.github.com/repos/keepassxreboot/keepassxc/releases/latest"; keepass.cacheTimeout = 30 * 1000; // milliseconds keepass.databaseHash = "no-hash"; //no-hash = KeePassXC is too old and does not return a hash value keepass.keyRing = (typeof(localStorage.keyRing) == 'undefined') ? {} : JSON.parse(localStorage.keyRing); @@ -622,23 +622,21 @@ keepass.keePassXCUpdateAvailable = function() { keepass.checkForNewKeePassXCVersion = function() { var xhr = new XMLHttpRequest(); + var version = -1; xhr.open("GET", keepass.latestVersionUrl, true); xhr.onload = function(e) { if (xhr.readyState == 4) { if (xhr.status == 200) { - var $version = xhr.responseText; - if ($version.substring(0, 1) == "2") { - $version = $version.substring(0, $version.indexOf(" ")); - keepass.latestKeePassXC.version = $version; - keepass.latestKeePassXC.versionParsed = parseInt($version.replace(/\./g,"")); + var json = JSON.parse(xhr.responseText); + if (json.tag_name) { + version = json.tag_name; + keepass.latestKeePassXC.version = version; + keepass.latestKeePassXC.versionParsed = parseInt(version.replace(/\./g,"")); } } - else { - $version = -1; - } } - if ($version != -1) { + if (version != -1) { localStorage.latestKeePassXC = JSON.stringify(keepass.latestKeePassXC); } }; From 022a03aedb9b29bd888f25c49066d071342c726c Mon Sep 17 00:00:00 2001 From: varjolintu Date: Mon, 26 Jun 2017 13:08:22 +0300 Subject: [PATCH 5/6] Added error message handling and support for reloading KeePassXC or proxy with new public keys --- CHANGELOG | 2 ++ keepassxc-browser/background/keepass.js | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index bcbdca2..6c943e6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,8 @@ ========================= - Added JSON install files and script for Windows - New version checking function +- Added error message handling +- Added reloading KeePassXC with new public key retrieval (with keepassxc-proxy too) 0.1.10 (2017-06-14) ========================= diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index 1524311..79e2256 100644 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -9,7 +9,7 @@ keepass.isKeePassXCAvailable = false; keepass.isEncryptionKeyUnrecognized = false; keepass.currentKeePassXC = {"version": 0, "versionParsed": 0}; keepass.latestKeePassXC = (typeof(localStorage.latestKeePassXC) == 'undefined') ? {"version": 0, "versionParsed": 0, "lastChecked": null} : JSON.parse(localStorage.latestKeePassXC); -keepass.requiredKeePassXC = 214; +keepass.requiredKeePassXC = 220; keepass.nativeHostName = "com.varjolintu.keepassxc_browser"; keepass.nativePort = null; keepass.keySize = 24; @@ -94,6 +94,9 @@ keepass.updateCredentials = function(callback, tab, entryId, username, password, callback(code); } } + else if (response.error && response.errorCode) { + keepass.handleError(tab.id, response.error, response.errorCode); + } else { browserAction.showDefault(null, tab); } @@ -173,6 +176,9 @@ keepass.retrieveCredentials = function (callback, tab, url, submiturl, forceCall page.debug("keepass.retrieveCredentials() => entries.length = {1}", entries.length); } } + else if (response.error && response.errorCode) { + keepass.handleError(tab.id, response.error, response.errorCode); + } else { browserAction.showDefault(null, tab); } @@ -253,6 +259,9 @@ keepass.generatePassword = function (callback, tab, forceCallback) { callback(passwords); } } + else if (response.error && response.errorCode) { + keepass.handleError(tab.id, response.error, response.errorCode); + } }); keepass.nativePort.postMessage(request); }, tab); @@ -334,6 +343,9 @@ keepass.associate = function(callback, tab) { browserAction.show(callback, tab); } } + else if (response.error && response.errorCode) { + keepass.handleError(tab.id, response.error, response.errorCode); + } }); keepass.nativePort.postMessage(request); }, tab); @@ -433,6 +445,9 @@ keepass.testAssociation = function (callback, tab, triggerUnlock) { } } } + else if (response.error && response.errorCode) { + keepass.handleError(tab.id, response.error, response.errorCode); + } callback(keepass.isAssociated()); }); keepass.nativePort.postMessage(request); @@ -727,6 +742,11 @@ keepass.verifyResponse = function(response, nonce, id) { } +keepass.handleError = function(tabId, errorMessage, errorCode) { + console.log("Received error " + errorCode + ": " + errorMessage); + page.tabs[tabId].errorMessage = errorMessage; +} + keepass.b64e = function(d) { return nacl.util.encodeBase64(d); } From c65c4576c0ab473cf88cb261e503654532c1482a Mon Sep 17 00:00:00 2001 From: varjolintu Date: Mon, 26 Jun 2017 13:09:05 +0300 Subject: [PATCH 6/6] Added error message handling and support for reloading KeePassXC or proxy with new public keys --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 6c943e6..c20681a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,7 @@ - Added JSON install files and script for Windows - New version checking function - Added error message handling -- Added reloading KeePassXC with new public key retrieval (with keepassxc-proxy too) +- Added support for reloading KeePassXC (or proxy) with new public keys 0.1.10 (2017-06-14) =========================