diff --git a/keepassxc-browser/background/event.js b/keepassxc-browser/background/event.js index 8cba08c..14a1f7b 100755 --- a/keepassxc-browser/background/event.js +++ b/keepassxc-browser/background/event.js @@ -87,7 +87,7 @@ kpxcEvent.onShowNotification = function(callback, tab, message) { kpxcEvent.showStatus = function(configured, tab, callback) { let keyId = null; - if (configured) { + if (configured && keepass.databaseHash !== '') { keyId = keepass.keyRing[keepass.databaseHash].id; } diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index d1a050a..48d8b66 100755 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -17,8 +17,8 @@ keepass.nativePort = null; keepass.keySize = 24; 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.previousDatabaseHash = 'no-hash'; +keepass.databaseHash = ''; +keepass.previousDatabaseHash = ''; keepass.keyId = 'keepassxc-browser-cryptokey-name'; keepass.keyBody = 'keepassxc-browser-key'; keepass.messageTimeout = 500; // milliseconds @@ -559,7 +559,7 @@ keepass.getDatabaseHash = function(callback, tab, enableTimeout = false, trigger const res = keepass.decrypt(response.message, response.nonce); if (!res) { keepass.handleError(tab, kpErrors.CANNOT_DECRYPT_MESSAGE); - callback('no-hash'); + callback(''); return; } @@ -568,7 +568,7 @@ keepass.getDatabaseHash = function(callback, tab, enableTimeout = false, trigger if (keepass.verifyDatabaseResponse(parsed, incrementedNonce) && parsed.hash) { const oldDatabaseHash = keepass.databaseHash; keepass.setcurrentKeePassXCVersion(parsed.version); - keepass.databaseHash = parsed.hash || 'no-hash'; + keepass.databaseHash = parsed.hash || ''; if (oldDatabaseHash && oldDatabaseHash != keepass.databaseHash) { keepass.associated.value = false; @@ -581,7 +581,7 @@ keepass.getDatabaseHash = function(callback, tab, enableTimeout = false, trigger return; } else if (parsed.errorCode) { - keepass.databaseHash = 'no-hash'; + keepass.databaseHash = ''; keepass.isDatabaseClosed = true; keepass.handleError(tab, kpErrors.DATABASE_NOT_OPENED); callback(keepass.databaseHash); @@ -589,7 +589,7 @@ keepass.getDatabaseHash = function(callback, tab, enableTimeout = false, trigger } } else { - keepass.databaseHash = 'no-hash'; + keepass.databaseHash = ''; keepass.isDatabaseClosed = true; if (response.message && response.message === '') { keepass.isKeePassXCAvailable = false; @@ -679,6 +679,7 @@ keepass.lockDatabase = function(tab) { if (keepass.verifyResponse(parsed, incrementedNonce)) { keepass.isDatabaseClosed = true; + keepass.updateDatabase(); // Display error message in the popup keepass.handleError(tab, kpErrors.DATABASE_NOT_OPENED); @@ -844,22 +845,7 @@ keepass.onNativeMessage = function(response) { // Handle database lock/unlock status if (response.action === kpActions.DATABASE_LOCKED || response.action === kpActions.DATABASE_UNLOCKED) { - keepass.testAssociation((associationResponse) => { - keepass.isConfigured().then((configured) => { - keepass.updatePopup(configured ? 'normal' : 'cross'); - - // 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: keepass.previousDatabaseHash, new: keepass.databaseHash} - }); - keepass.previousDatabaseHash = keepass.databaseHash; - } - }); - }); - }, null); + keepass.updateDatabase(); } }; @@ -969,7 +955,7 @@ keepass.verifyDatabaseResponse = function(response, nonce) { } keepass.associated.hash = response.hash; - return response.hash !== 'no-hash' && response.success === 'true'; + return response.hash !== '' && response.success === 'true'; }; keepass.checkNonceLength = function(nonce) { @@ -1066,3 +1052,23 @@ keepass.updatePopup = function(iconType) { browserAction.show(null, {'id': page.currentTabId}); } }; + +// Updates the database hashes to content script +keepass.updateDatabase = function() { + keepass.testAssociation((associationResponse) => { + keepass.isConfigured().then((configured) => { + keepass.updatePopup(configured ? 'normal' : 'cross'); + + // 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: keepass.previousDatabaseHash, new: keepass.databaseHash} + }); + keepass.previousDatabaseHash = keepass.databaseHash; + } + }); + }); + }, null); +}; diff --git a/keepassxc-browser/keepassxc-browser.js b/keepassxc-browser/keepassxc-browser.js index 911d704..0b78451 100755 --- a/keepassxc-browser/keepassxc-browser.js +++ b/keepassxc-browser/keepassxc-browser.js @@ -1402,7 +1402,7 @@ cip.init = function() { // Switch credentials if database is changed or closed cip.detectDatabaseChange = function(response) { if (document.visibilityState !== 'hidden') { - if (response.new === 'no-hash' && response.old !== 'no-hash') { + if (response.new === '' && response.old !== '') { cipEvents.clearCredentials(); browser.runtime.sendMessage({ @@ -1414,7 +1414,7 @@ cip.detectDatabaseChange = function(response) { action: 'get_status', args: [ true ] // Set polling to true, this is an internal function call }); - } else if (response.new !== 'no-hash' && response.new !== response.old) { + } else if (response.new !== '' && response.new !== response.old) { _called.retrieveCredentials = false; browser.runtime.sendMessage({ action: 'load_settings', diff --git a/keepassxc-browser/popups/popup_httpauth.html b/keepassxc-browser/popups/popup_httpauth.html index 883b152..1d8a53a 100644 --- a/keepassxc-browser/popups/popup_httpauth.html +++ b/keepassxc-browser/popups/popup_httpauth.html @@ -1,6 +1,6 @@ - KeePassXC-Browser - Popup + diff --git a/keepassxc-browser/popups/popup_login.html b/keepassxc-browser/popups/popup_login.html index 8d36314..902d4e8 100644 --- a/keepassxc-browser/popups/popup_login.html +++ b/keepassxc-browser/popups/popup_login.html @@ -1,6 +1,6 @@ - KeePassXC - Popup + @@ -25,7 +25,7 @@ -
+

+ +
diff --git a/keepassxc-browser/popups/popup_login.js b/keepassxc-browser/popups/popup_login.js index 37d9113..adc3d36 100644 --- a/keepassxc-browser/popups/popup_login.js +++ b/keepassxc-browser/popups/popup_login.js @@ -49,5 +49,15 @@ $(function() { browser.runtime.sendMessage({ action: 'lock-database' }); + $('#credentialsList').hide(); + $('#database-not-opened').show(); + $('#database-error-message').html(tr('errorMessageDatabaseNotOpened')); + }); + + $('#reopen-database-button').click(function() { + browser.runtime.sendMessage({ + action: 'get_status', + args: [ false, true ] // Set forcePopup to true + }); }); }); diff --git a/keepassxc-browser/popups/popup_multiple-fields.html b/keepassxc-browser/popups/popup_multiple-fields.html index 4429bcb..10a2c89 100644 --- a/keepassxc-browser/popups/popup_multiple-fields.html +++ b/keepassxc-browser/popups/popup_multiple-fields.html @@ -1,6 +1,6 @@ - KeePassXC-Browser - Popup + diff --git a/keepassxc-browser/popups/popup_remember.html b/keepassxc-browser/popups/popup_remember.html index 3bba57b..6778892 100644 --- a/keepassxc-browser/popups/popup_remember.html +++ b/keepassxc-browser/popups/popup_remember.html @@ -1,6 +1,6 @@ - KeePassXC-Browser - Popup +