diff --git a/README.md b/README.md index 79a72fe..7d37fb9 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Now the requests are encrypted by [TweetNaCl.js](https://github.com/dchest/tweet 3. All messages (excluding get-databasehash) are now encrypted. 4. When chromeKeePassXC sends a message it is encrypted with KeePassXC's public key, a random generated nonce and chromeKeePassXC's secret key. 5. When KeePassXC sends a message it is encrypted with chromeKeePassXC's public key etc. -6. Databases are stored based on the database hash instead of the key because a new key pair is generated each time chromeKeePassXC is launched. +6. Databases are stored based on the current public key used with `associate`. A new key pair for data transfer is generated each time chromeKeePassXC is launched. Encrypted messages are built with these JSON parameters: - action - `test-associate`, `associate`, `get-logins`, `get-logins-count`, `set-login`... @@ -56,7 +56,8 @@ Response (success): Unencrypted message: ```javascript { - "action": "associate" + "action": "associate", + "key": "" } ``` @@ -84,7 +85,8 @@ Response message data (success, decrypted): Unencrypted message: ```javascript { - "action": "test-associate" + "action": "test-associate", + "key": "" } ``` diff --git a/chromeKeePassXC/background/keepass.js b/chromeKeePassXC/background/keepass.js index 72679d6..5089393 100644 --- a/chromeKeePassXC/background/keepass.js +++ b/chromeKeePassXC/background/keepass.js @@ -299,7 +299,8 @@ keepass.associate = function(callback, tab) { var nonce = nacl.randomBytes(keepass.keySize); var messageData = { - action: "associate" + action: "associate", + key: key }; var request = { @@ -333,7 +334,7 @@ keepass.associate = function(callback, tab) { page.tabs[tab.id].errorMessage = "KeePassXC association failed, try again."; } else { - keepass.setCryptoKey(id, key); + keepass.setCryptoKey(id, key); // Save the current public key as id key for the database keepass.associated.value = true; keepass.associated.hash = parsed.hash || 0; } @@ -342,7 +343,6 @@ keepass.associate = function(callback, tab) { } } }); - keepass.nativePort.postMessage(request); } @@ -364,9 +364,11 @@ keepass.testAssociation = function (tab, triggerUnlock) { var key = keepass.b64e(keepass.keyPair.publicKey); var nonce = nacl.randomBytes(keepass.keySize); + var idkey = keepass.getCryptoKey(); var messageData = { - "action": "test-associate", + action: "test-associate", + key: idkey }; var request = { @@ -417,6 +419,7 @@ keepass.testAssociation = function (tab, triggerUnlock) { } } } + return keepass.isAssociated(); } }); keepass.nativePort.postMessage(request); @@ -571,7 +574,7 @@ keepass.saveKey = function(hash, id, key) { if (!(hash in keepass.keyRing)) { keepass.keyRing[hash] = { "id": id, - //"key": key, + "key": key, "hash": hash, "icon": "blue", "created": new Date(), @@ -580,7 +583,7 @@ keepass.saveKey = function(hash, id, key) { } else { keepass.keyRing[hash].id = id; - //keepass.keyRing[hash].key = key; + keepass.keyRing[hash].key = key; keepass.keyRing[hash].hash = hash; } localStorage.keyRing = JSON.stringify(keepass.keyRing); @@ -732,7 +735,7 @@ keepass.verifyKeyResponse = function(response, key, nonce) { keepass.verifyResponse = function(response, nonce, id) { keepass.associated.value = response.success; - if (!response.success) { + if (response.success != "true") { keepass.associated.hash = null; return false; } @@ -771,11 +774,11 @@ keepass.getCryptoKey = function() { var key = null; if (id) { - //key = keepass.keyRing[keepass.databaseHash].key; - key = keepass.b64e(keepass.keyPair.publicKey); + key = keepass.keyRing[keepass.databaseHash].key; } - return key ? [id, key] : null; + //return key ? [id, key] : null; + return key ? key : null; } keepass.setCryptoKey = function(id, key) { diff --git a/chromeKeePassXC/options/options.html b/chromeKeePassXC/options/options.html index b7e8a4d..9ebeb79 100644 --- a/chromeKeePassXC/options/options.html +++ b/chromeKeePassXC/options/options.html @@ -169,7 +169,7 @@ Identifier - Hash + Key Last used Created Delete diff --git a/chromeKeePassXC/options/options.js b/chromeKeePassXC/options/options.js index b98057d..c988bc9 100644 --- a/chromeKeePassXC/options/options.js +++ b/chromeKeePassXC/options/options.js @@ -181,7 +181,7 @@ options.initConnectedDatabases = function() { $("a.dropdown-toggle:first img:first", $tr).attr("src", "/icons/19x19/icon_normal_" + $icon + "_19x19.png"); $tr.children("td:first").text(options.keyRing[hash].id); - $tr.children("td:eq(1)").text(hash); + $tr.children("td:eq(1)").text(options.keyRing[hash].key); var lastUsed = (options.keyRing[hash].lastUsed) ? new Date(options.keyRing[hash].lastUsed).toLocaleString() : "unknown"; $tr.children("td:eq(2)").text(lastUsed); var date = (options.keyRing[hash].created) ? new Date(options.keyRing[hash].created).toLocaleDateString() : "unknown";