mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
HTTP auth fixes
This commit is contained in:
parent
4d11ce7b5f
commit
b78ee812e6
5 changed files with 48 additions and 84 deletions
|
|
@ -1,9 +1,9 @@
|
|||
0.3.0 (2017-??-??)
|
||||
=========================
|
||||
- Added Mozilla's browser-polyfill
|
||||
- Merged changes from the latest passifox (credits to smorks)
|
||||
- Merged changes from the latest passifox (credits to smorks/passifox)
|
||||
- HTTP auth works with all browsers
|
||||
- Fixed showing credentials from previous logins in the popup (credits to smorks)
|
||||
- Fixed showing credentials from previous logins in the popup (credits to smorks/passifox)
|
||||
- Automatic detection of div's with forms that are non-hidden by user interaction
|
||||
|
||||
0.2.9 (2017-08-27)
|
||||
|
|
|
|||
|
|
@ -1,90 +1,62 @@
|
|||
var httpAuth = httpAuth || {};
|
||||
|
||||
httpAuth.requests = [];
|
||||
httpAuth.pendingCallbacks = [];
|
||||
httpAuth.requestId = '';
|
||||
httpAuth.tabId = 0;
|
||||
httpAuth.url = null;
|
||||
httpAuth.isProxy = false;
|
||||
httpAuth.proxyUrl = null;
|
||||
httpAuth.resolve = null;
|
||||
httpAuth.reject = null;
|
||||
|
||||
httpAuth.handleRequest = function(details) {
|
||||
httpAuth.requestCompleted = function(details) {
|
||||
let index = httpAuth.requests.indexOf(details.requestId);
|
||||
if (index > -1) {
|
||||
httpAuth.requests.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
httpAuth.handleRequestPromise = function(details) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (httpAuth.requestId == details.requestId || !page.tabs[details.tabId]) {
|
||||
reject({});
|
||||
}
|
||||
else {
|
||||
httpAuth.requestId = details.requestId;
|
||||
httpAuth.resolve = resolve;
|
||||
httpAuth.reject = reject;
|
||||
httpAuth.processPendingCallbacks(details);
|
||||
}
|
||||
httpAuth.processPendingCallbacks(details, resolve, reject);
|
||||
});
|
||||
}
|
||||
|
||||
httpAuth.handleRequestChrome = function(details, callback) {
|
||||
if (httpAuth.requestId == details.requestId || !page.tabs[details.tabId]) {
|
||||
callback({});
|
||||
}
|
||||
else {
|
||||
httpAuth.requestId = details.requestId;
|
||||
httpAuth.pendingCallbacks.push(callback);
|
||||
httpAuth.processPendingCallbacks(details);
|
||||
}
|
||||
httpAuth.handleRequestCallback = function(details, callback) {
|
||||
httpAuth.processPendingCallbacks(details, callback, callback);
|
||||
}
|
||||
|
||||
httpAuth.processPendingCallbacks = function(details) {
|
||||
if (!isFirefox) {
|
||||
httpAuth.callback = httpAuth.pendingCallbacks.pop();
|
||||
httpAuth.processPendingCallbacks = function(details, resolve, reject) {
|
||||
if (httpAuth.requests.indexOf(details.requestId) >= 0 || !page.tabs[details.tabId]) {
|
||||
reject({});
|
||||
}
|
||||
httpAuth.tabId = details.tabId;
|
||||
httpAuth.url = details.url;
|
||||
httpAuth.isProxy = details.isProxy;
|
||||
|
||||
httpAuth.requests.push(details.requestId);
|
||||
|
||||
if (details.challenger) {
|
||||
httpAuth.proxyUrl = details.challenger.host;
|
||||
details.proxyUrl = details.challenger.host;
|
||||
}
|
||||
|
||||
// WORKAROUND: second parameter should be tab, but is an own object with tab-id
|
||||
// but in background.js only tab.id is used. To get tabs we could use
|
||||
// chrome.tabs.get(tabId, callback) <-- but what should callback be?
|
||||
details.searchUrl = (details.isProxy && details.proxyUrl) ? details.proxyUrl : details.url;
|
||||
|
||||
const url = (httpAuth.isProxy && httpAuth.proxyUrl) ? httpAuth.proxyUrl : httpAuth.url;
|
||||
keepass.retrieveCredentials(httpAuth.loginOrShowCredentials, { "id" : details.tabId }, url, url, true);
|
||||
keepass.retrieveCredentials((logins) => {
|
||||
httpAuth.loginOrShowCredentials(logins, details, resolve, reject);
|
||||
}, { "id": details.tabId }, details.searchUrl, details.searchUrl, true);
|
||||
}
|
||||
|
||||
httpAuth.loginOrShowCredentials = function(logins) {
|
||||
httpAuth.loginOrShowCredentials = function(logins, details, resolve, reject) {
|
||||
// at least one login found --> use first to login
|
||||
if (logins.length > 0) {
|
||||
const url = (httpAuth.isProxy && httpAuth.proxyUrl) ? httpAuth.proxyUrl : httpAuth.url;
|
||||
event.onHTTPAuthPopup(null, {'id': httpAuth.tabId}, {'logins': logins, 'url': url});
|
||||
event.onHTTPAuthPopup(null, { "id": details.tabId }, { "logins": logins, "url": details.searchUrl });
|
||||
//generate popup-list for HTTP Auth usernames + descriptions
|
||||
|
||||
if (page.settings.autoFillAndSend) {
|
||||
if (isFirefox) {
|
||||
httpAuth.resolve({
|
||||
authCredentials: {
|
||||
username: logins[0].login,
|
||||
password: logins[0].password
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
httpAuth.callback({
|
||||
authCredentials: {
|
||||
username: logins[0].login,
|
||||
password: logins[0].password
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
isFirefox ? httpAuth.reject({}) : httpAuth.callback({});
|
||||
resolve({
|
||||
authCredentials: {
|
||||
username: logins[0].login,
|
||||
password: logins[0].password
|
||||
}
|
||||
});
|
||||
} else {
|
||||
reject({});
|
||||
}
|
||||
}
|
||||
// no logins found
|
||||
else {
|
||||
isFirefox ? httpAuth.reject({}) : httpAuth.callback({});
|
||||
reject({});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,3 @@
|
|||
/*
|
||||
keepass.convertKeyToKeyRing();
|
||||
page.initSettings();
|
||||
page.initOpenedTabs();
|
||||
keepass.connectToNative();
|
||||
keepass.generateNewKeyPair();
|
||||
keepass.changePublicKeys(null, (pkRes) => {
|
||||
keepass.getDatabaseHash((gdRes) => {}, null);
|
||||
});
|
||||
*/
|
||||
|
||||
// since version 2.0 the extension is using a keyRing instead of a single key-name-pair
|
||||
keepass.migrateKeyRing().then(() => {
|
||||
// load settings
|
||||
|
|
@ -98,14 +87,18 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
|||
|
||||
// Retrieve Credentials and try auto-login for HTTPAuth requests
|
||||
if (browser.webRequest.onAuthRequired) {
|
||||
if (isFirefox) {
|
||||
browser.webRequest.onAuthRequired.addListener(httpAuth.handleRequest,
|
||||
{ urls: ["<all_urls>"] }, ["blocking"]);
|
||||
}
|
||||
else {
|
||||
browser.webRequest.onAuthRequired.addListener(httpAuth.handleRequestChrome,
|
||||
{ urls: ["<all_urls>"] }, ["asyncBlocking"]);
|
||||
let handleReq = httpAuth.handleRequestPromise;
|
||||
let reqType = 'blocking';
|
||||
let opts = { urls: ['<all_urls>'] };
|
||||
|
||||
if (!isFirefox) {
|
||||
handleReq = httpAuth.handleRequestCallback;
|
||||
reqType = 'asyncBlocking';
|
||||
}
|
||||
|
||||
browser.webRequest.onAuthRequired.addListener(handleReq, opts, [reqType]);
|
||||
browser.webRequest.onCompleted.addListener(httpAuth.requestCompleted, opts);
|
||||
browser.webRequest.onErrorOccurred.addListener(httpAuth.requestCompleted, opts);
|
||||
}
|
||||
|
||||
browser.runtime.onMessage.addListener(event.onMessage);
|
||||
|
|
|
|||
|
|
@ -104,7 +104,6 @@ page.clearLogins = function(tabId) {
|
|||
}
|
||||
|
||||
page.createTabEntry = function(tabId) {
|
||||
//console.log('page.createTabEntry('+tabId+')');
|
||||
page.tabs[tabId] = {
|
||||
'stack': [],
|
||||
'errorMessage': null,
|
||||
|
|
|
|||
|
|
@ -1707,4 +1707,4 @@ $(function() {
|
|||
clearInterval(divDetect);
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue