2019-10-06 13:58:26 -04:00
|
|
|
var contextScrub = async function(requestDetails) {
|
2019-10-06 15:18:10 -04:00
|
|
|
console.log("(scrub)Scrubbing info from contextualized request");
|
|
|
|
try {
|
|
|
|
var headerScrub = function(context) {
|
|
|
|
if (!context) {
|
|
|
|
console.error("Context not found");
|
2019-11-10 20:28:31 -05:00
|
|
|
} else if (context.name == "i2pbrowser") {
|
|
|
|
var ua = "MYOB/6.66 (AN/ON)";
|
|
|
|
if (i2pHost(requestDetails.url)) {
|
|
|
|
for (var header of requestDetails.requestHeaders) {
|
|
|
|
if (header.name.toLowerCase() === "user-agent") {
|
|
|
|
header.value = ua;
|
|
|
|
console.log("(scrub)User-Agent header modified", header.value);
|
2019-10-06 13:58:26 -04:00
|
|
|
}
|
2019-10-06 15:18:10 -04:00
|
|
|
}
|
2019-10-06 13:58:26 -04:00
|
|
|
}
|
2019-11-10 20:28:31 -05:00
|
|
|
return {
|
|
|
|
requestHeaders: requestDetails.requestHeaders
|
|
|
|
};
|
|
|
|
} else if (context.name == "routerconsole") {
|
|
|
|
var ua = "MYOB/6.66 (AN/ON)";
|
|
|
|
if (i2pHost(requestDetails.url)) {
|
|
|
|
for (var header of requestDetails.requestHeaders) {
|
|
|
|
if (header.name.toLowerCase() === "user-agent") {
|
|
|
|
header.value = ua;
|
|
|
|
console.log("(scrub)User-Agent header modified", header.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (routerHost(requestDetails.url)) {
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
requestHeaders: requestDetails.requestHeaders
|
|
|
|
};
|
2019-10-06 15:18:10 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var contextGet = async function(tabInfo) {
|
|
|
|
try {
|
|
|
|
console.log("(scrub)Tab info from Function", tabInfo);
|
|
|
|
context = await browser.contextualIdentities.get(tabInfo.cookieStoreId);
|
|
|
|
return context;
|
|
|
|
} catch (error) {
|
|
|
|
console.log("(scrub)Conext Error", error);
|
|
|
|
}
|
|
|
|
};
|
2019-10-07 18:45:52 -04:00
|
|
|
var tabFind = async function(tabId) {
|
|
|
|
try {
|
2019-10-07 21:26:52 -04:00
|
|
|
context = await browser.contextualIdentities.query({
|
|
|
|
name: "i2pbrowser"
|
|
|
|
});
|
|
|
|
tabId.cookieStoreId = context[0].cookieStoreId;
|
2019-10-07 20:52:03 -04:00
|
|
|
console.log("(scrub) forcing context", tabId.cookieStoreId);
|
2019-10-07 18:45:52 -04:00
|
|
|
return tabId;
|
|
|
|
} catch (error) {
|
2019-10-07 20:52:03 -04:00
|
|
|
console.log("(scrub)Context Error", error);
|
2019-10-07 18:45:52 -04:00
|
|
|
}
|
|
|
|
};
|
2019-10-06 15:18:10 -04:00
|
|
|
var tabGet = async function(tabId) {
|
|
|
|
try {
|
|
|
|
console.log("(scrub)Tab ID from Request", tabId);
|
|
|
|
let tabInfo = await browser.tabs.get(tabId);
|
|
|
|
return tabInfo;
|
|
|
|
} catch (error) {
|
|
|
|
console.log("(scrub)Tab error", error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (requestDetails.tabId > 0) {
|
2019-11-10 20:28:31 -05:00
|
|
|
var tab = {};
|
|
|
|
var context = {};
|
|
|
|
var req = {};
|
2019-10-08 19:10:13 -04:00
|
|
|
if (i2pHost(requestDetails.url)) {
|
2019-10-07 18:45:52 -04:00
|
|
|
console.log("(Proxy)I2P URL detected, ");
|
2019-11-10 20:28:31 -05:00
|
|
|
tab = tabGet(requestDetails.tabId);
|
2019-10-07 18:45:52 -04:00
|
|
|
var mtab = tab.then(tabFind);
|
2019-10-07 21:26:52 -04:00
|
|
|
requestDetails.tabId = mtab;
|
2019-11-10 20:28:31 -05:00
|
|
|
context = mtab.then(contextGet);
|
|
|
|
req = await context.then(headerScrub);
|
2019-10-07 20:52:03 -04:00
|
|
|
console.log("(scrub)Scrubbing I2P Request", req);
|
|
|
|
return req;
|
2019-10-07 18:45:52 -04:00
|
|
|
} else {
|
2019-11-10 20:28:31 -05:00
|
|
|
tab = tabGet(requestDetails.tabId);
|
|
|
|
context = tab.then(contextGet);
|
|
|
|
req = await context.then(headerScrub);
|
2019-11-10 22:24:10 -05:00
|
|
|
console.log("(scrub)Scrubbing non-I2P Request", req);
|
2019-10-07 18:45:52 -04:00
|
|
|
return req;
|
|
|
|
}
|
2019-10-06 13:58:26 -04:00
|
|
|
}
|
2019-10-06 15:18:10 -04:00
|
|
|
} catch (error) {
|
2019-10-07 20:52:03 -04:00
|
|
|
console.log("(scrub)Not scrubbing non-I2P request.", error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var contextSetup = async function(requestDetails) {
|
|
|
|
console.log("(isolate)Forcing I2P requests into context");
|
|
|
|
try {
|
|
|
|
var tabFind = async function(tabId) {
|
|
|
|
try {
|
2019-11-10 20:28:31 -05:00
|
|
|
var context = await browser.contextualIdentities.query({
|
2019-10-07 21:26:52 -04:00
|
|
|
name: "i2pbrowser"
|
|
|
|
});
|
2019-10-07 20:52:03 -04:00
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
2019-10-07 21:26:52 -04:00
|
|
|
console.log(
|
|
|
|
"(isolate) forcing",
|
|
|
|
requestDetails.url,
|
|
|
|
" context",
|
|
|
|
tabId.cookieStoreId,
|
|
|
|
context[0].cookieStoreId
|
|
|
|
);
|
|
|
|
function Create(window) {
|
|
|
|
function onCreated(tab) {
|
2019-11-10 20:28:31 -05:00
|
|
|
console.log("(isolate) Closing old, un-isolated tab", window);
|
2019-10-07 21:26:52 -04:00
|
|
|
browser.tabs.remove(tabId.id);
|
2019-10-08 19:10:13 -04:00
|
|
|
browser.tabs.remove(window.tabs[0].id);
|
|
|
|
}
|
|
|
|
function onError(error) {
|
|
|
|
console.log(`Error: ${error}`);
|
|
|
|
}
|
2019-11-10 20:28:31 -05:00
|
|
|
var created = browser.tabs.create({
|
2019-10-08 19:10:13 -04:00
|
|
|
active: true,
|
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
|
|
|
url: requestDetails.url,
|
|
|
|
windowId: window.id
|
|
|
|
});
|
|
|
|
created.then(onCreated, onError);
|
|
|
|
}
|
2019-11-10 20:28:31 -05:00
|
|
|
var getting = browser.windows.getCurrent();
|
2019-10-08 19:10:13 -04:00
|
|
|
getting.then(Create);
|
|
|
|
return tabId;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var routerTabFind = async function(tabId) {
|
|
|
|
try {
|
2019-11-10 20:28:31 -05:00
|
|
|
var context = await browser.contextualIdentities.query({
|
2019-10-08 19:10:13 -04:00
|
|
|
name: "routerconsole"
|
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
|
|
|
console.log(
|
|
|
|
"(isolate) forcing",
|
|
|
|
requestDetails.url,
|
|
|
|
" context",
|
|
|
|
tabId.cookieStoreId,
|
|
|
|
context[0].cookieStoreId
|
|
|
|
);
|
|
|
|
function Create(window) {
|
|
|
|
function onCreated(tab) {
|
|
|
|
console.log("(isolate) Closing old, un-isolated tab");
|
|
|
|
browser.tabs.remove(tabId.id);
|
|
|
|
browser.tabs.remove(window.tabs[0].id);
|
2019-10-07 21:26:52 -04:00
|
|
|
}
|
|
|
|
function onError(error) {
|
|
|
|
console.log(`Error: ${error}`);
|
|
|
|
}
|
2019-11-10 20:28:31 -05:00
|
|
|
var created = browser.tabs.create({
|
2019-10-07 21:26:52 -04:00
|
|
|
active: true,
|
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
|
|
|
url: requestDetails.url,
|
|
|
|
windowId: window.id
|
|
|
|
});
|
|
|
|
created.then(onCreated, onError);
|
2019-10-07 20:52:03 -04:00
|
|
|
}
|
2019-11-10 20:28:31 -05:00
|
|
|
var getting = browser.windows.getCurrent();
|
2019-10-07 21:26:52 -04:00
|
|
|
getting.then(Create);
|
2019-10-07 20:52:03 -04:00
|
|
|
return tabId;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
};
|
2019-11-10 22:24:10 -05:00
|
|
|
var anyTabFind = async function(tabId) {
|
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
2019-11-11 00:03:24 -05:00
|
|
|
name: "fenced-default"
|
2019-11-10 22:24:10 -05:00
|
|
|
});
|
2019-11-11 00:03:24 -05:00
|
|
|
console.log("(ISOLATE)", tabId.cookieStoreId);
|
|
|
|
if (tabId.cookieStoreId == "firefox-default") {
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
|
|
|
console.log(
|
|
|
|
"(isolate) forcing",
|
|
|
|
requestDetails.url,
|
|
|
|
" context",
|
|
|
|
tabId.cookieStoreId,
|
|
|
|
context[0].cookieStoreId
|
|
|
|
);
|
|
|
|
function Create(window) {
|
|
|
|
function onCreated(tab) {
|
|
|
|
console.log("(isolate) Closing old, un-isolated tab");
|
|
|
|
browser.tabs.remove(tabId.id);
|
|
|
|
browser.tabs.remove(window.tabs[0].id);
|
|
|
|
}
|
|
|
|
function onError(error) {
|
|
|
|
console.log(`Error: ${error}`);
|
|
|
|
}
|
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
|
|
|
url: requestDetails.url,
|
|
|
|
windowId: window.id
|
|
|
|
});
|
|
|
|
created.then(onCreated, onError);
|
2019-11-10 22:24:10 -05:00
|
|
|
}
|
2019-11-11 00:03:24 -05:00
|
|
|
var getting = browser.windows.getCurrent();
|
|
|
|
getting.then(Create);
|
|
|
|
return tabId;
|
2019-11-10 22:24:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
};
|
2019-10-07 20:52:03 -04:00
|
|
|
var tabGet = async function(tabId) {
|
|
|
|
try {
|
|
|
|
console.log("(isolate)Tab ID from Request", tabId);
|
|
|
|
let tabInfo = await browser.tabs.get(tabId);
|
|
|
|
return tabInfo;
|
|
|
|
} catch (error) {
|
|
|
|
console.log("(isolate)Tab error", error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (requestDetails.tabId > 0) {
|
2019-11-10 22:36:32 -05:00
|
|
|
if (proxyHost(requestDetails.url)) {
|
2019-11-10 22:24:10 -05:00
|
|
|
return requestDetails;
|
|
|
|
}
|
2019-10-08 19:10:13 -04:00
|
|
|
if (i2pHost(requestDetails.url)) {
|
2019-10-07 20:52:03 -04:00
|
|
|
var tab = tabGet(requestDetails.tabId);
|
|
|
|
var mtab = tab.then(tabFind);
|
|
|
|
return requestDetails;
|
2019-10-08 19:10:13 -04:00
|
|
|
}
|
|
|
|
if (routerHost(requestDetails.url)) {
|
2019-10-07 20:52:03 -04:00
|
|
|
var tab = tabGet(requestDetails.tabId);
|
2019-10-08 19:10:13 -04:00
|
|
|
var mtab = tab.then(routerTabFind);
|
2019-10-07 20:52:03 -04:00
|
|
|
return requestDetails;
|
|
|
|
}
|
2019-11-10 22:24:10 -05:00
|
|
|
var tab = tabGet(requestDetails.tabId);
|
|
|
|
var mtab = tab.then(anyTabFind);
|
|
|
|
return requestDetails;
|
2019-10-07 20:52:03 -04:00
|
|
|
}
|
2019-11-10 22:36:32 -05:00
|
|
|
//var tab = tabGet(requestDetails.tabId);
|
|
|
|
//var mtab = tab.then(anyTabFind);
|
|
|
|
return requestDetails;
|
2019-10-07 20:52:03 -04:00
|
|
|
} catch (error) {
|
2019-11-10 20:28:31 -05:00
|
|
|
console.log("(isolate)Not an I2P request, blackholing", error);
|
2019-10-06 15:18:10 -04:00
|
|
|
}
|
|
|
|
};
|
2019-10-06 13:58:26 -04:00
|
|
|
|
2019-10-16 15:31:30 -04:00
|
|
|
function i2pHostName(url) {
|
2019-10-08 19:10:13 -04:00
|
|
|
let hostname = "";
|
|
|
|
if (url.indexOf("://") > -1) {
|
|
|
|
hostname = url.split("/")[2];
|
|
|
|
} else {
|
|
|
|
hostname = url.split("/")[0];
|
|
|
|
}
|
2019-10-16 15:31:30 -04:00
|
|
|
return hostname;
|
|
|
|
}
|
|
|
|
|
|
|
|
function i2pHost(url) {
|
|
|
|
let hostname = i2pHostName(url);
|
2019-10-08 19:10:13 -04:00
|
|
|
return hostname.endsWith(".i2p");
|
|
|
|
}
|
|
|
|
|
2019-10-28 01:11:16 -04:00
|
|
|
function proxyHost(url) {
|
|
|
|
let hostname = "";
|
|
|
|
if (url.indexOf("://") > -1) {
|
|
|
|
hostname = url.split("/")[2];
|
|
|
|
} else {
|
|
|
|
hostname = url.split("/")[0];
|
|
|
|
}
|
|
|
|
if (hostname == "proxy.i2p") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-10 22:24:10 -05:00
|
|
|
function localHost(url) {
|
|
|
|
let hostname = "";
|
|
|
|
if (url.indexOf("://") > -1) {
|
|
|
|
hostname = url.split("/")[2];
|
|
|
|
} else {
|
|
|
|
hostname = url.split("/")[0];
|
|
|
|
}
|
|
|
|
hostname = hostname.split(":")[0];
|
|
|
|
if (hostname === "127.0.0.1") {
|
|
|
|
return true;
|
|
|
|
} else if (hostname === "localhost") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-08 19:10:13 -04:00
|
|
|
function routerHost(url) {
|
|
|
|
let hostname = "";
|
|
|
|
if (url.indexOf("://") > -1) {
|
|
|
|
hostname = url.split("/")[2];
|
|
|
|
} else {
|
|
|
|
hostname = url.split("/")[0];
|
|
|
|
}
|
|
|
|
if (hostname === "127.0.0.1:7657") {
|
|
|
|
return true;
|
|
|
|
} else if (hostname === "localhost:7657") {
|
|
|
|
return true;
|
|
|
|
}
|
2019-10-09 17:48:38 -04:00
|
|
|
|
|
|
|
if (hostname === "127.0.0.1:7070") {
|
|
|
|
return true;
|
|
|
|
} else if (hostname === "localhost:7070") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-08 19:10:13 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-07 20:52:03 -04:00
|
|
|
browser.webRequest.onBeforeRequest.addListener(
|
|
|
|
contextSetup,
|
|
|
|
{ urls: ["<all_urls>"] },
|
|
|
|
["blocking"]
|
|
|
|
);
|
|
|
|
|
2019-10-06 13:58:26 -04:00
|
|
|
browser.webRequest.onBeforeSendHeaders.addListener(
|
2019-10-06 15:18:10 -04:00
|
|
|
contextScrub,
|
|
|
|
{ urls: ["<all_urls>"] },
|
|
|
|
["blocking", "requestHeaders"]
|
2019-10-06 13:58:26 -04:00
|
|
|
);
|
2019-10-28 01:11:16 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
function notify(message) {
|
|
|
|
var response = await fetch('https://proxy.i2p', {
|
|
|
|
credentials: 'include'
|
|
|
|
});
|
|
|
|
const myJson = await response.json();
|
|
|
|
console.log(JSON.stringify(myJson));
|
|
|
|
|
|
|
|
console.log(message);
|
|
|
|
const Http = new XMLHttpRequest();
|
|
|
|
Http.mozAnon = true;
|
|
|
|
Http.withCredentials = true;
|
|
|
|
const url = "http://proxy.i2p";
|
|
|
|
Http.open("GET", url);
|
|
|
|
Http.send();
|
|
|
|
Http.onreadystatechange = e => {
|
|
|
|
console.log(Http.responseText);
|
|
|
|
browser.runtime.sendMessage(Http.responseText);
|
|
|
|
};
|
|
|
|
}
|
2019-10-28 01:12:40 -04:00
|
|
|
*/
|