mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-27 20:03:45 +03:00
Start adding auth support
This commit is contained in:
parent
5f3da48cc9
commit
98cbd5fd02
|
@ -71,6 +71,19 @@
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getOrDie(cb = self.mandatory()) {
|
||||||
|
|
||||||
|
return self.chromified((err, ...args) => {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
cb(...args);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
getProp(obj, path = self.mandatory()) {
|
getProp(obj, path = self.mandatory()) {
|
||||||
|
|
||||||
const props = path.split('.');
|
const props = path.split('.');
|
||||||
|
|
|
@ -12,6 +12,73 @@
|
||||||
const ifIncontinence = 'if-incontinence';
|
const ifIncontinence = 'if-incontinence';
|
||||||
const modsKey = 'mods';
|
const modsKey = 'mods';
|
||||||
|
|
||||||
|
const proxyHostToCredsList = {
|
||||||
|
// One host may be used several times with different creds.
|
||||||
|
'blablabla:6110': [
|
||||||
|
{ username: 'foo', password: 'bar' },
|
||||||
|
{ username: 'foo1', password: 'bar' },
|
||||||
|
{ username: 'foo2', password: 'bar' },
|
||||||
|
{ username: 'foo3', password: 'bar' },
|
||||||
|
{ username: 'foo4', password: 'bar' },
|
||||||
|
{ username: 'foo5', password: 'bar' },
|
||||||
|
{ username: 'foo6', password: 'bar' },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const ifAuthSupported = chrome.webRequest && chrome.webRequest.onAuthRequired && !window.apis.version.ifMini;
|
||||||
|
if (ifAuthSupported) {
|
||||||
|
|
||||||
|
console.log('WebRequest is supported!');
|
||||||
|
const requestIdToTries = {};
|
||||||
|
|
||||||
|
chrome.webRequest.onAuthRequired.addListener(
|
||||||
|
window.utils.getOrDie((details) => {
|
||||||
|
|
||||||
|
console.log('AUTH REQUIRED.');
|
||||||
|
if (!details.isProxy) {
|
||||||
|
console.log('Not from proxy.');
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const proxyHost = `${details.challenger.host}:${details.challenger.port}`;
|
||||||
|
const credsList = proxyHostToCredsList[proxyHost];
|
||||||
|
if (!credsList) {
|
||||||
|
console.log('Creds list is empty.');
|
||||||
|
return {}; // No creds found for this proxy.
|
||||||
|
}
|
||||||
|
const requestId = details.requestId;
|
||||||
|
const tries = requestIdToTries[requestId] || 0;
|
||||||
|
if (tries > credsList.length) {
|
||||||
|
return {}; // All creds for this proxy were tried already.
|
||||||
|
}
|
||||||
|
requestIdToTries[requestId] = tries + 1;
|
||||||
|
console.log('TRIES=', tries, 'for', requestId);
|
||||||
|
return {
|
||||||
|
authCredentials: credsList[tries],
|
||||||
|
};
|
||||||
|
|
||||||
|
}),
|
||||||
|
{urls: ['<all_urls>']},
|
||||||
|
['blocking'],
|
||||||
|
);
|
||||||
|
|
||||||
|
const forgetRequestId = (details) => {
|
||||||
|
|
||||||
|
delete requestIdToTries[details.requestId];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
chrome.webRequest.onCompleted.addListener(
|
||||||
|
forgetRequestId,
|
||||||
|
{urls: ['<all_urls>']},
|
||||||
|
);
|
||||||
|
|
||||||
|
chrome.webRequest.onErrorOccurred.addListener(
|
||||||
|
forgetRequestId,
|
||||||
|
{urls: ['<all_urls>']},
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const getDefaultConfigs = () => ({// Configs user may mutate them and we don't care!
|
const getDefaultConfigs = () => ({// Configs user may mutate them and we don't care!
|
||||||
|
|
||||||
ifProxyHttpsUrlsOnly: {
|
ifProxyHttpsUrlsOnly: {
|
||||||
|
@ -143,8 +210,10 @@
|
||||||
.every((dProp) => {
|
.every((dProp) => {
|
||||||
|
|
||||||
const ifDflt = (
|
const ifDflt = (
|
||||||
!(dProp in mods) ||
|
!(
|
||||||
Boolean(configs[dProp].dflt) === Boolean(mods[dProp])
|
dProp in mods &&
|
||||||
|
Boolean(configs[dProp].dflt) !== Boolean(mods[dProp])
|
||||||
|
)
|
||||||
);
|
);
|
||||||
const ifMods = configs[dProp].ifDfltMods; // If default value implies PAC-script modification.
|
const ifMods = configs[dProp].ifDfltMods; // If default value implies PAC-script modification.
|
||||||
return ifDflt ? !ifMods : ifMods;
|
return ifDflt ? !ifMods : ifMods;
|
||||||
|
@ -382,7 +451,7 @@ ${ pacMods.filteredCustomsString
|
||||||
|
|
||||||
details
|
details
|
||||||
? resolve(details)
|
? resolve(details)
|
||||||
: chrome.proxy.settings.get({}, timeouted(resolve) )
|
: chrome.proxy.settings.get({}, timeouted(resolve) ),
|
||||||
|
|
||||||
).then((details) => {
|
).then((details) => {
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,13 @@ const commonContext = {
|
||||||
|
|
||||||
exports.contexts = {};
|
exports.contexts = {};
|
||||||
|
|
||||||
|
const extra_permissions = ', "webRequest", "webRequestBlocking", "webNavigation"';
|
||||||
|
|
||||||
exports.contexts.full = Object.assign({}, commonContext, {
|
exports.contexts.full = Object.assign({}, commonContext, {
|
||||||
versionSuffix: '',
|
versionSuffix: '',
|
||||||
nameSuffixEn: '',
|
nameSuffixEn: '',
|
||||||
nameSuffixRu: '',
|
nameSuffixRu: '',
|
||||||
extra_permissions: ', "webRequest", "webNavigation"',
|
extra_permissions,
|
||||||
persistent: '',
|
persistent: '',
|
||||||
scripts_2x: ', "20-ip-to-host-api.js"',
|
scripts_2x: ', "20-ip-to-host-api.js"',
|
||||||
scripts_8x: ', "80-error-menu.js", "83-last-errors.js", "85-block-informer.js"',
|
scripts_8x: ', "80-error-menu.js", "83-last-errors.js", "85-block-informer.js"',
|
||||||
|
@ -49,7 +51,7 @@ exports.contexts.beta = Object.assign({}, commonContext, {
|
||||||
versionSuffix: '',
|
versionSuffix: '',
|
||||||
nameSuffixEn: ' FOR TESTING',
|
nameSuffixEn: ' FOR TESTING',
|
||||||
nameSuffixRu: ' ДЛЯ ТЕСТОВ',
|
nameSuffixRu: ' ДЛЯ ТЕСТОВ',
|
||||||
extra_permissions: ', "webRequest", "webNavigation"',
|
extra_permissions,
|
||||||
persistent: '',
|
persistent: '',
|
||||||
scripts_2x: ', "20-ip-to-host-api.js"',
|
scripts_2x: ', "20-ip-to-host-api.js"',
|
||||||
scripts_8x: ', "80-error-menu.js", "83-last-errors.js", "85-block-informer.js"',
|
scripts_8x: ', "80-error-menu.js", "83-last-errors.js", "85-block-informer.js"',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user