mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Fix unlocking the database
This commit is contained in:
parent
278eaaf48d
commit
322979dfd7
8 changed files with 57 additions and 31 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>KeePassXC-Browser - Popup</title>
|
||||
<title data-i18n="popupTitle"></title>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="popup.css" />
|
||||
<link rel="stylesheet" href="../options/bootstrap.min.css" />
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>KeePassXC - Popup</title>
|
||||
<title data-i18n="popupTitle"></title>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="popup.css" />
|
||||
<link rel="stylesheet" href="../options/bootstrap.min.css" />
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="credentials">
|
||||
<div id="credentialsList" class="credentials">
|
||||
<p data-i18n="popupLoginText"></p>
|
||||
<div id="filter-block" style="display: none;">
|
||||
<label for="login-filter" data-i18n="popupFilterText"></label>
|
||||
|
|
@ -33,6 +33,16 @@
|
|||
</div>
|
||||
<div id="login-list" class="list-group"></div>
|
||||
</div>
|
||||
|
||||
<div id="database-not-opened" style="display: none">
|
||||
<p data-i18n="popupErrorEncountered"/>
|
||||
<p style="margin-left: 1em">
|
||||
<code id="database-error-message"></code>
|
||||
</p>
|
||||
<div style="text-align: right">
|
||||
<button id="reopen-database-button" class="btn btn-sm btn-primary"><span class="glyphicon glyphicon-lock"></span><span data-i18n="popupReopenButton"/></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="../translate.js"></script>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>KeePassXC-Browser - Popup</title>
|
||||
<title data-i18n="popupTitle"></title>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="popup.css" />
|
||||
<link rel="stylesheet" href="../options/bootstrap.min.css" />
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>KeePassXC-Browser - Popup</title>
|
||||
<title data-i18n="popupTitle"></title>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="popup.css" />
|
||||
<link rel="stylesheet" href="../options/bootstrap.min.css" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue