mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Merge pull request #630 from keepassxreboot/fix/connection_issues
Fix connection issues
This commit is contained in:
commit
936510ccbd
5 changed files with 48 additions and 32 deletions
|
|
@ -6,7 +6,7 @@
|
|||
await page.initSettings();
|
||||
await page.initOpenedTabs();
|
||||
await httpAuth.init();
|
||||
await keepass.reconnect();
|
||||
await keepass.reconnect(null, 5000); // 5 second timeout for the first connect
|
||||
await keepass.enableAutomaticReconnect();
|
||||
} catch (e) {
|
||||
console.log('init.js failed');
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ browser.storage.local.get({ 'latestKeePassXC': { 'version': '', 'lastChecked': n
|
|||
keepass.keyRing = item.keyRing;
|
||||
});
|
||||
|
||||
keepass.sendNativeMessage = function(request, enableTimeout = false) {
|
||||
keepass.sendNativeMessage = function(request, enableTimeout = false, timeoutValue) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let timeout;
|
||||
const requestAction = request.action;
|
||||
|
|
@ -106,6 +106,7 @@ keepass.sendNativeMessage = function(request, enableTimeout = false) {
|
|||
})(ev, requestAction);
|
||||
ev.addListener(listener);
|
||||
|
||||
let messageTimeout = timeoutValue || keepass.messageTimeout;
|
||||
|
||||
// Handle timeouts
|
||||
if (enableTimeout) {
|
||||
|
|
@ -118,7 +119,7 @@ keepass.sendNativeMessage = function(request, enableTimeout = false) {
|
|||
keepass.isKeePassXCAvailable = false;
|
||||
ev.removeListener(listener.handler);
|
||||
resolve(errorMessage);
|
||||
}, keepass.messageTimeout);
|
||||
}, messageTimeout);
|
||||
}
|
||||
|
||||
// Send the request
|
||||
|
|
@ -571,7 +572,7 @@ keepass.getDatabaseHash = async function(tab, args = []) {
|
|||
}
|
||||
};
|
||||
|
||||
keepass.changePublicKeys = async function(tab, enableTimeout = false) {
|
||||
keepass.changePublicKeys = async function(tab, enableTimeout = false, connectionTimeout) {
|
||||
if (!keepass.isConnected) {
|
||||
keepass.handleError(tab, kpErrors.TIMEOUT_OR_NOT_CONNECTED);
|
||||
return false;
|
||||
|
|
@ -590,19 +591,19 @@ keepass.changePublicKeys = async function(tab, enableTimeout = false) {
|
|||
};
|
||||
|
||||
try {
|
||||
const response = await keepass.sendNativeMessage(request, enableTimeout);
|
||||
const response = await keepass.sendNativeMessage(request, enableTimeout, connectionTimeout);
|
||||
keepass.setcurrentKeePassXCVersion(response.version);
|
||||
|
||||
if (!keepass.verifyKeyResponse(response, key, incrementedNonce)) {
|
||||
if (tab && page.tabs[tab.id]) {
|
||||
keepass.handleError(tab, kpErrors.KEY_CHANGE_FAILED);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
keepass.isKeePassXCAvailable = true;
|
||||
console.log('Server public key: ' + nacl.util.encodeBase64(keepass.serverPublicKey));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
keepass.isKeePassXCAvailable = true;
|
||||
console.log('Server public key: ' + nacl.util.encodeBase64(keepass.serverPublicKey));
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.log('changePublicKeys failed: ', err);
|
||||
|
|
@ -987,17 +988,15 @@ keepass.verifyKeyResponse = function(response, key, nonce) {
|
|||
return false;
|
||||
}
|
||||
|
||||
let reply = false;
|
||||
if (!keepass.checkNonceLength(response.nonce)) {
|
||||
console.log('Error: Invalid nonce length');
|
||||
return false;
|
||||
}
|
||||
|
||||
reply = (response.nonce === nonce);
|
||||
|
||||
if (response.publicKey) {
|
||||
const reply = (response.nonce === nonce);
|
||||
if (response.publicKey && reply) {
|
||||
keepass.serverPublicKey = nacl.util.decodeBase64(response.publicKey);
|
||||
reply = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return reply;
|
||||
|
|
@ -1126,24 +1125,27 @@ keepass.disableAutomaticReconnect = function() {
|
|||
keepass.reconnectLoop = null;
|
||||
};
|
||||
|
||||
keepass.reconnect = function(tab) {
|
||||
return new Promise(async (resolve) => {
|
||||
keepass.connectToNative();
|
||||
keepass.generateNewKeyPair();
|
||||
await keepass.changePublicKeys(tab, true).catch((e) => {
|
||||
resolve(false);
|
||||
});
|
||||
|
||||
const hash = await keepass.getDatabaseHash(tab);
|
||||
if (hash !== '' && tab && page.tabs[tab.id]) {
|
||||
delete page.tabs[tab.id].errorMessage;
|
||||
}
|
||||
|
||||
await keepass.testAssociation();
|
||||
await keepass.isConfigured();
|
||||
keepass.updateDatabaseHashToContent();
|
||||
resolve(true);
|
||||
keepass.reconnect = async function(tab, connectionTimeout) {
|
||||
keepass.connectToNative();
|
||||
keepass.generateNewKeyPair();
|
||||
const keyChangeResult = await keepass.changePublicKeys(tab, true, connectionTimeout).catch((e) => {
|
||||
return false;
|
||||
});
|
||||
|
||||
// Change public keys timeout
|
||||
if (!keyChangeResult) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const hash = await keepass.getDatabaseHash(tab);
|
||||
if (hash !== '' && tab && page.tabs[tab.id]) {
|
||||
delete page.tabs[tab.id].errorMessage;
|
||||
}
|
||||
|
||||
await keepass.testAssociation();
|
||||
await keepass.isConfigured();
|
||||
keepass.updateDatabaseHashToContent();
|
||||
return true;
|
||||
};
|
||||
|
||||
keepass.updatePopup = function(iconType) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,20 @@ body {
|
|||
max-width: 460px;
|
||||
width: auto;
|
||||
}
|
||||
.loader {
|
||||
animation: spin 2s linear infinite;
|
||||
border: 4px solid #f3f3f3;
|
||||
border-radius: 50%;
|
||||
border-top: 4px solid #28a745;
|
||||
float: left;
|
||||
height: 1.4em;
|
||||
margin-right: 1em;
|
||||
width: 1.4em;
|
||||
}
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
.list-group {
|
||||
font-size: .9em !important;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
</div>
|
||||
|
||||
<div id="initial-state">
|
||||
<p><img style="margin-right: 1em" src="throbber.gif"/> <span data-i18n="popupCheckingStatus"/></p>
|
||||
<p><div class="loader"></div> <span data-i18n="popupCheckingStatus"/></p>
|
||||
</div>
|
||||
|
||||
<div id="not-configured" style="display: none">
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 673 B |
Loading…
Reference in a new issue