From bb14021bc08d0a84ba60b59398ac634d6622fd4c Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 14:19:59 -0500 Subject: [PATCH 01/18] make it so we only launch containers out of firefox-default, rather than re-checking every single request --- Makefile | 10 +- bookmarks.js | 2 +- i2ppb@eyedeekay.github.io.xpi.torrent | Bin 2443 -> 2443 bytes index.html | 2 +- manifest.json | 2 +- releases.atom | 43 +++---- scrub.js | 162 +++++++++++--------------- 7 files changed, 104 insertions(+), 117 deletions(-) diff --git a/Makefile b/Makefile index 524c263..a85f034 100644 --- a/Makefile +++ b/Makefile @@ -339,7 +339,15 @@ snark-mirror: seed: cp -v "./i2ppb-$(VERSION)@eyedeekay.github.io.xpi.torrent" "$(HOME)/.i2p/i2psnark" cp -v "../i2ppb-$(VERSION)@eyedeekay.github.io.xpi" "$(HOME)/.i2p/i2psnark" - + wire: cp -v "./i2ppb-$(VERSION)@eyedeekay.github.io.xpi.torrent" "$(HOME)/i2p/MuWireDownloads/" cp -v "../i2ppb-$(VERSION)@eyedeekay.github.io.xpi" "$(HOME)/i2p/MuWireDownloads/" + +test: + web-ext run -u about:debugging \ + -u http://127.0.0.1:7657/home \ + -u http://127.0.0.1:7657/i2ptunnel \ + -u http://127.0.0.1:7657/i2psnark \ + -u http://127.0.0.1:7657/webmail \ + -u http://idk.i2p diff --git a/bookmarks.js b/bookmarks.js index 62223a9..854515a 100644 --- a/bookmarks.js +++ b/bookmarks.js @@ -182,6 +182,7 @@ function bookmarksSetup() { title: 'I2P Console', }); b4.then(bookConsole, onRejected); + defaultSettings['bookmarks_state'] = true; } var bt = browser.bookmarks.search({ @@ -190,7 +191,6 @@ function bookmarksSetup() { function toolDir(bookmarkToolbar) { let defaultSettings = {}; - defaultSettings['bookmarks_state'] = true; chrome.storage.local.set(defaultSettings); console.log('(bookmarks) created'); var ibbt = browser.bookmarks.search('I2P Toolbar'); diff --git a/i2ppb@eyedeekay.github.io.xpi.torrent b/i2ppb@eyedeekay.github.io.xpi.torrent index fb3b3d94280a1712177987527eb6974b304d2ac7..4ace44f93324b176c512ae6bb3b386b98e1d224f 100644 GIT binary patch delta 517 zcmV+g0{Z=n6N?kD-v%=`GB_|aGBIT|I%#fZZ)7$)Y-Mg|bZBWcHa0UgG&yB7I&NWY zWivE7X)?~(WR(?0+NNEM4)6Rx~^|v?fi&0TIU~ zdl;cCW}hY#X^=NI`vs~X1V(svx5ro)4es+WeFE3uUx2w}jBxOWf#B@Gle{CJ(%a{yx{a5-I6RmtgYTOWhYz>@7-W1$es>)}gR zQSrIMn0XIarwEw&vC!4ZXs+=+2kjenVsk$yA68|9aj%c9Csh)gG4cfBr<+#;L_wZH zI9M@<$-&dT#ee3ps`0=t3597ExDg710k6@n)l%}+A^tg{IDk#h)H(h4XR}hK^ zs~Jpy#4NYl>b8NTm7s~eVuwj7gbfwM-Yb3L!ds(rx|{#)AE{sw(?De z+cSL$(t>XRhtdPr@l{32{<(bvL|iX4I&NWY zWivE7X)Qv?>Dr@SoB=T}a(rH|fp8$CzisX^l-MN&FIF4UgK@??kJPiVYPL-EIKlwg<)mCvyKgb8JcjrCXyMlIya-xFSpeB
  • - Magnet Link + Magnet Link
  • diff --git a/manifest.json b/manifest.json index 3018c00..83f279a 100644 --- a/manifest.json +++ b/manifest.json @@ -27,7 +27,7 @@ ], "manifest_version": 2, "name": "__MSG_extensionName__", - "version": "0.85", + "version": "0.87", "description": "__MSG_extensionDescription__", "homepage_url": "https://github.com/eyedeekay/I2P-in-Private-Browsing-Mode-Firefox", "icons": { diff --git a/releases.atom b/releases.atom index 5d9db30..5fa9269 100644 --- a/releases.atom +++ b/releases.atom @@ -4,13 +4,33 @@ Release notes from I2P-in-Private-Browsing-Mode-Firefox - 2020-11-11T06:44:09Z + 2020-12-06T17:13:52Z + + tag:github.com,2008:Repository/169256012/0.87 + 2020-12-06T18:37:57Z + + 0.87 + + <p>Browsing to a single contextual identity, thus creating an I2P in Private<br> +Browsing mode. It requires the use of a pre-installed I2P Router.<br> +i2psetproxy.js (0.87-1) UNRELEASED; urgency=low</p> +<ul> +<li>Disable searching for i2p sites in non-i2p search engines</li> +<li>Add contexts for i2pbote and Dispatch</li> +<li>Remain in tighter control of x-i2p-torrentlocation priority</li> +</ul> +<p>-- idk <a href="mailto:hankhill19580@gmail.com">hankhill19580@gmail.com</a> Sat, 10 NOV 2020 1:33:50 -0400</p> +<p>i2psetproxy.js (0.85-1) UNRELEASED; urgency=low</p> + + eyedeekay + + + tag:github.com,2008:Repository/169256012/0.85 2020-11-11T06:44:44Z 0.85 - <p>A simple plugin for configuring a Firefox based web browser to isolate I2P<br> Browsing to a single contextual identity, thus creating an I2P in Private<br> Browsing mode. It requires the use of a pre-installed I2P Router.<br> @@ -176,23 +196,4 @@ i2psetproxy.js (0.69-1) UNRELEASED; urgency=low</p> - - tag:github.com,2008:Repository/169256012/0.67 - 2020-03-18T04:27:30Z - - 0.67 - <p>A simple plugin for configuring a Firefox based web browser to isolate I2P<br> -Browsing to a single contextual identity, thus creating an I2P in Private<br> -Browsing mode. It requires the use of a pre-installed I2P Router.<br> -i2psetproxy.js (0.67-1) UNRELEASED; urgency=low</p> -<ul> -<li>Tweak some default settings that should have gone into 65</li> -</ul> -<p>-- idk <a href="mailto:hankhill19580@gmail.com">hankhill19580@gmail.com</a> Tue, 17 MAR 2020 22:58:55 -0400</p> -<p>i2psetproxy.js (0.65-1) UNRELEASED; urgency=low</p> - - eyedeekay - - - diff --git a/scrub.js b/scrub.js index 74e54f3..6bb424c 100644 --- a/scrub.js +++ b/scrub.js @@ -13,30 +13,17 @@ var contextScrub = async function(requestDetails) { function onHeaderError() { console.log('Header scrub error'); } - //console.log("(scrub)Scrubbing info from contextualized request"); + console.log('(scrub)Scrubbing info from contextualized request'); try { var headerScrub = function(context) { var ua = 'MYOB/6.66 (AN/ON)'; + console.log('(scrub) uah', context); if (!context) { } else if (context.name == titlepref) { - 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); - } - } - } - return { - requestHeaders: requestDetails.requestHeaders, - }; - } else if (context.name == routerpref) { - 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); - } + for (var header of requestDetails.requestHeaders) { + if (header.name.toLowerCase() === 'user-agent') { + header.value = ua; + console.log('(scrub)User-Agent header modified', header.value); } } return { @@ -65,23 +52,11 @@ var contextScrub = async function(requestDetails) { } }; if (requestDetails.tabId > 0) { - var tab = {}; - var context = {}; - var req = {}; - if (i2pHost(requestDetails.url)) { - //console.log("(scrub)I2P URL detected, "); - tab = tabGet(requestDetails.tabId); - context = tab.then(contextGet, onHeaderError); - req = await context.then(headerScrub, onHeaderError); - //console.log("(scrub)Scrubbing I2P Request", req); - return req; - } else if (routerHost(requestDetails.url)) { - tab = tabGet(requestDetails.tabId); - context = tab.then(contextGet, onHeaderError); - req = await context.then(headerScrub, onHeaderError); - //console.log("(scrub)Scrubbing non-I2P Request", req); - return req; - } + console.log('(scrub) uah', requestDetails); + tab = tabGet(requestDetails.tabId); + context = tab.then(contextGet, onHeaderError); + req = context.then(headerScrub, onHeaderError); + //console.log("(scrub)Scrubbing I2P Request", req); return req; } } catch (error) { @@ -617,57 +592,63 @@ var contextSetup = function(requestDetails) { if (requestDetails.tabId > 0) { var tab = tabGet(requestDetails.tabId); - if (i2pHost(requestDetails.url)) { - var thn = i2pHostName(requestDetails.url); - if (requestDetails.url.includes('=' + thn)) { - console.log('(scrub)checking search hostnames =' + thn); - var tpt = requestDetails.url.split('=' + thn, 2); - requestDetails.url = - 'http://' + thn + '/' + tpt[1].replace('%2F', ''); + tab.then(isolate); + function isolate(oldtab) { + console.log('(scrub)tab discovered:', oldtab); + if (oldtab.cookieStoreId == 'firefox-default') { + if (i2pHost(requestDetails.url)) { + var thn = i2pHostName(requestDetails.url); + if (requestDetails.url.includes('=' + thn)) { + console.log('(scrub)checking search hostnames =' + thn); + var tpt = requestDetails.url.split('=' + thn, 2); + requestDetails.url = + 'http://' + thn + '/' + tpt[1].replace('%2F', ''); + } + console.log('(scrub) new hostname', requestDetails.url); + var setcookie = browser.cookies.set({ + firstPartyDomain: i2pHostName(requestDetails.url), + url: requestDetails.url, + secure: true, + }); + setcookie.then(onContextGotLog, onContextError); + var i2ptab = tab.then(i2pTabFind, onContextError); + return requestDetails; + } + if (extensionHost(requestDetails)) { + return requestDetails; + } + let localhost = localHost(requestDetails.url); + let routerhost = routerHost(requestDetails.url); + if (routerhost) { + if (routerhost === 'i2ptunnelmgr') { + var tunneltab = tab.then(i2ptunnelTabFind, onContextError); + return requestDetails; + } else if (routerhost === 'i2psnark') { + var snarktab = tab.then(snarkTabFind, onContextError); + return requestDetails; + } else if (routerhost === 'webmail') { + var mailtab = tab.then(mailTabFind, onContextError); + return requestDetails; + } else if (routerhost === 'muwire') { + var routertab = tab.then(muwireTabFind, onContextError); + return requestDetails; + } else if (routerhost === 'i2pbote') { + var routertab = tab.then(i2pboteTabFind, onContextError); + return requestDetails; + } else if (routerhost === 'routerconsole') { + var routertab = tab.then(routerTabFind, onContextError); + return requestDetails; + } + } else { + if (localhost) { + var irctab = tab.then(ircTabFind, onContextError); + return requestDetails; + } + var normalTab = tab.then(normalTabFind, onContextError); + return requestDetails; + //return requestDetails; + } } - console.log('(scrub) new hostname', requestDetails.url); - var setcookie = browser.cookies.set({ - firstPartyDomain: i2pHostName(requestDetails.url), - url: requestDetails.url, - secure: true, - }); - setcookie.then(onContextGotLog, onContextError); - var i2ptab = tab.then(i2pTabFind, onContextError); - return requestDetails; - } - if (extensionHost(requestDetails)) { - return requestDetails; - } - let localhost = localHost(requestDetails.url); - let routerhost = routerHost(requestDetails.url); - if (routerhost) { - if (routerhost === 'i2ptunnelmgr') { - var tunneltab = tab.then(i2ptunnelTabFind, onContextError); - return requestDetails; - } else if (routerhost === 'i2psnark') { - var snarktab = tab.then(snarkTabFind, onContextError); - return requestDetails; - } else if (routerhost === 'webmail') { - var mailtab = tab.then(mailTabFind, onContextError); - return requestDetails; - } else if (routerhost === 'muwire') { - var routertab = tab.then(muwireTabFind, onContextError); - return requestDetails; - } else if (routerhost === 'i2pbote') { - var routertab = tab.then(i2pboteTabFind, onContextError); - return requestDetails; - } else if (routerhost === 'routerconsole') { - var routertab = tab.then(routerTabFind, onContextError); - return requestDetails; - } - } else { - if (localhost) { - var irctab = tab.then(ircTabFind, onContextError); - return requestDetails; - } - var normalTab = tab.then(normalTabFind, onContextError); - return requestDetails; - //return requestDetails; } } } catch (error) { @@ -840,7 +821,6 @@ var coolheadersSetup = function(e) { }; function getTabURL(tab) { - console.log("(scrub)", tab); if (tab.url.startsWith("https")) { try { browser.tabs @@ -933,9 +913,7 @@ browser.tabs.onCreated.addListener(getClearTab); browser.tabs.onDetached.addListener(getClearTab); browser.tabs.onHighlighted.addListener(getClearTab); browser.tabs.onMoved.addListener(getClearTab); -browser.tabs.onRemoved.addListener(getClearTab); browser.tabs.onReplaced.addListener(getClearTab); -browser.tabs.onZoomChange.addListener(getClearTab); browser.pageAction.onClicked.addListener(getClearTab); @@ -969,16 +947,16 @@ browser.webNavigation.onBeforeNavigate.addListener(getClearTab, filter); browser.webNavigation.onCommitted.addListener(getClearTab, filter); browser.webNavigation.onCompleted.addListener(getClearTab, filter); -window.setInterval(getClearTab, 1500); +window.setInterval(getClearTab, 2000); browser.webRequest.onBeforeRequest.addListener( contextSetup, { urls: [""] }, - ["blocking"] + //["blocking"] ); browser.webRequest.onBeforeSendHeaders.addListener( contextScrub, { urls: [""] }, - ["blocking", "requestHeaders"] + ["requestHeaders"] ); From 1946669b822db9c977a2bf0a27a81dfc563adea0 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 14:36:59 -0500 Subject: [PATCH 02/18] pre-filter URL's for so we don't try to run isolator checks on domains that have no chance of needing isolation --- Makefile | 8 ++++++++ scrub.js | 10 ++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a85f034..f3923ce 100644 --- a/Makefile +++ b/Makefile @@ -351,3 +351,11 @@ test: -u http://127.0.0.1:7657/i2psnark \ -u http://127.0.0.1:7657/webmail \ -u http://idk.i2p + +lht-test: + web-ext run -u about:debugging \ + -u http://localhost:7657/home \ + -u http://localhost:7657/i2ptunnel \ + -u http://localhost:7657/i2psnark \ + -u http://localhost:7657/webmail \ + -u http://idk.i2p diff --git a/scrub.js b/scrub.js index 6bb424c..286ff58 100644 --- a/scrub.js +++ b/scrub.js @@ -949,14 +949,12 @@ browser.webNavigation.onCompleted.addListener(getClearTab, filter); window.setInterval(getClearTab, 2000); -browser.webRequest.onBeforeRequest.addListener( - contextSetup, - { urls: [""] }, - //["blocking"] -); +browser.webRequest.onBeforeRequest.addListener(contextSetup, { + urls: ["*://*.i2p/*", "*://localhost/*", "*://127.0.0.1/*", "*://*/*i2p*"], +}); browser.webRequest.onBeforeSendHeaders.addListener( contextScrub, - { urls: [""] }, + { urls: ["*://*.i2p/*"] }, ["requestHeaders"] ); From 7b2216a12fc4f692f65f8ef422120dc14025031a Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 16:43:08 -0500 Subject: [PATCH 03/18] Nix timed x-i2p-torrentlocation stuff entirely --- Makefile | 1 + background.js | 1 + proxy.js | 171 +++++++++++++++++++++++++++++--------------------- script.js | 165 ++++++++++++++++++++++++------------------------ scrub.js | 3 +- 5 files changed, 185 insertions(+), 156 deletions(-) diff --git a/Makefile b/Makefile index f3923ce..c28d21c 100644 --- a/Makefile +++ b/Makefile @@ -358,4 +358,5 @@ lht-test: -u http://localhost:7657/i2ptunnel \ -u http://localhost:7657/i2psnark \ -u http://localhost:7657/webmail \ + -u http://localhost:7657/MuWire/ \ -u http://idk.i2p diff --git a/background.js b/background.js index 94ffdb7..a6db5a2 100644 --- a/background.js +++ b/background.js @@ -14,6 +14,7 @@ var ircpref = chrome.i18n.getMessage('ircPreface'); var ircprefpriv = chrome.i18n.getMessage('ircPrefacePrivate'); var extensionpref = chrome.i18n.getMessage('extensionPreface'); var muwirepref = chrome.i18n.getMessage('muwirePreface'); +var muwireprefpriv = chrome.i18n.getMessage('muwirePrefacePrivate'); var botepref = chrome.i18n.getMessage('botePreface'); function onContextsGot(contexts) { diff --git a/proxy.js b/proxy.js index 389dbd8..389cdca 100644 --- a/proxy.js +++ b/proxy.js @@ -1,6 +1,7 @@ var titlepref = chrome.i18n.getMessage('titlePreface'); var webpref = chrome.i18n.getMessage('webPreface'); var ircpref = chrome.i18n.getMessage('ircPreface'); +var torrentpref = chrome.i18n.getMessage('torrentPreface'); var routerpref = chrome.i18n.getMessage('routerPreface'); var routerprefpriv = chrome.i18n.getMessage('routerPrefacePrivate'); var ircpref = chrome.i18n.getMessage('ircPreface'); @@ -22,6 +23,71 @@ function shouldProxyRequest(requestInfo) { } var handleContextProxyRequest = async function(requestDetails) { + function ircProxy() { + if (!requestDetails.url.includes('7669')) { + proxy = { + type: getScheme(), + host: getHost(), + port: getPort(), + }; + return proxy; + } + if (requestDetails.url.includes(':7669')) { + proxy = null; + return proxy; + } + } + function btProxy() { + proxy = null; + if (i2phost(requestDetails.url)) { + proxy = { + type: getScheme(), + host: getHost(), + port: getPort(), + }; + return proxy; + } + if (!requestDetails.url.includes('7662')) { + proxy = { + type: getScheme(), + host: getHost(), + port: getPort(), + }; + return proxy; + } + if (requestDetails.url.includes(':7662')) { + proxy = null; + return proxy; + } + return proxy; + } + function mainProxy() { + proxy = { + type: getScheme(), + host: getHost(), + port: getPort(), + }; + if (requestDetails.url.includes('/i2psnark/')) { + proxy = null; + } + if (requestDetails.url.includes('/MuWire/')) { + proxy = null; + } + return proxy; + } + function routerProxy() { + if (routerHost(requestDetails.url)) { + proxy = null; + return proxy; + } else if (!routerHost(requestDetails.url)) { + proxy = { + type: getScheme(), + host: getHost(), + port: getPort(), + }; + return proxy; + } + } try { var handleProxyRequest = function(context) { proxy = { @@ -32,85 +98,54 @@ var handleContextProxyRequest = async function(requestDetails) { proxy = null; return proxy; } - console.log('(proxy), context', context); + //console.log('(proxy), context', context); if (context != undefined) { + proxy = routerProxy(); if (context.name == ircpref) { - if (!requestDetails.url.includes('7669')) { - proxy = { - type: getScheme(), - host: getHost(), - port: getPort(), - }; - } + proxy = ircProxy(); + return proxy; } if (context.name == titlepref) { - if (!requestDetails.url.includes('/i2psnark/')) { - console.log('URL', requestDetails.url); - proxy = { - type: getScheme(), - host: getHost(), - port: getPort(), - }; - } + proxy = mainProxy(); return proxy; - } else if (context.name == ircpref) { + } + if (context.name == routerpref) { + proxy = routerProxy(); + return proxy; + } + if (context.name == torrentpref) { + proxy = btProxy(); + return proxy; + } + return proxy; + } else { + if (!routerHost(requestDetails.url)) { + if (localHost(requestDetails.url)) { + if (requestDetails.url.includes(':7669')) { + proxy = null; + } else if (requestDetails.url.includes(':7662')) { + proxy = null; + } else { + console.log( + '(proxy) non-routerconsole localhost url, will not interfere', + requestDetails.url + ); + } + } + } else if (i2pHost(requestDetails.url)) { proxy = { type: getScheme(), host: getHost(), port: getPort(), }; - if (requestDetails.url.includes(':7669')) { - proxy = null; - } - } else if (context.name == routerpref) { - if (routerHost(requestDetails.url)) { - proxy = null; - } else if (!routerHost(requestDetails.url)) { - proxy = { - type: getScheme(), - host: getHost(), - port: getPort(), - }; - } - return proxy; - } else if (context.name == webpref) { - if (localHost(requestDetails.url)) { - if (!routerHost(requestDetails.url)) { - proxy = { - type: 'http', - host: 'localhost', - port: '65535', - }; - } - } - return proxy; } + //var tab = tabGet(requestDetails.tabId); + //tab.then(handleTabRequest,) + return proxy; } - if (!routerHost(requestDetails.url)) { - if (localHost(requestDetails.url)) { - if (requestDetails.url.includes(':7669')) { - proxy = null; - } else { - console.log( - '(proxy) non-routerconsole localhost url, will not interfere', - requestDetails.url - ); - } - } - } else if (i2pHost(requestDetails.url)) { - proxy = { - type: getScheme(), - host: getHost(), - port: getPort(), - }; - } - //var tab = tabGet(requestDetails.tabId); - //tab.then(handleTabRequest,) - return proxy; }; var contextGet = async function(tabInfo) { try { - console.log('(proxy)Tab info from Function', tabInfo); context = await browser.contextualIdentities.get(tabInfo.cookieStoreId); return context; } catch (error) { @@ -136,10 +171,6 @@ var handleContextProxyRequest = async function(requestDetails) { return proxy; } if (requestDetails.originUrl == browser.runtime.getURL('security.html')) { - console.log( - '(proxy) extension security URL', - browser.runtime.getURL('security.html') - ); proxy = { type: getScheme(), host: getHost(), @@ -168,7 +199,7 @@ var handleContextProxyRequest = async function(requestDetails) { requestDetails.tabId = tab; var context = tab.then(contextGet); var proxy = await context.then(handleProxyRequest); - console.log('(proxy)Returning I2P Proxy', proxy); + //console.log('(proxy)Returning I2P Proxy', proxy); return proxy; } else { var tab = tabGet(requestDetails.tabId); @@ -315,7 +346,7 @@ function getConsolePort() { function setupProxy() { console.log('Setting up Firefox WebExtension proxy'); browser.proxy.onRequest.addListener(handleContextProxyRequest, { - urls: [''], + urls: ['*://*.i2p/*', '*://localhost/*', '*://127.0.0.1/*', '*://*/*i2p*'], }); console.log('i2p settings created for WebExtension Proxy'); } diff --git a/script.js b/script.js index 4912836..4e87b74 100644 --- a/script.js +++ b/script.js @@ -1,102 +1,99 @@ browser.runtime.onMessage.addListener((request) => { - var response = ''; + var response = 'no-alt-location'; console.log(request); if (request.req === 'i2p-location') { - response = 'no-alt-location'; - const metas = document.getElementsByTagName('meta'); - for (let i = 0; i < metas.length; i++) { - try { - tag = metas[i].getAttribute('http-equiv'); - if (tag.toUpperCase() === 'I2P-LOCATION') { - response = metas[i].getAttribute('content'); - } - if (tag.toUpperCase() === 'X-I2P-LOCATION') { - response = metas[i].getAttribute('content'); - } - } catch {}; - } + var tag = document.querySelector('meta[http-equiv="i2p-location"]'); + console.log(tag); + if (tag) response = tag.content; + return response; } if (request.req === 'i2p-torrentlocation') { - response = 'no-alt-location'; const metas = document.getElementsByTagName('meta'); var tag = document.querySelector('meta[http-equiv="i2p-torrentlocation"]'); console.log(tag); - if (tag) { - response = tag.content; - var imgs = document.getElementsByTagName('img'); - console.log('rewriting torrent link'); - for (let img of imgs) { - let tmpsrc = new URL(img.src); - if (tmpsrc.host == location.host) { - img.src = - 'http://127.0.0.1:7657/i2psnark/' + tmpsrc.host + tmpsrc.pathname; - img.onerror = function() { - img.src = tmpsrc; + response = i2pTorrent(tag); + return response; + } + return Promise.resolve({ content: response }); +}); + +function i2pTorrent(tag) { + let response = "no-alt-location"; + if (tag) { + response = tag.content; + var imgs = document.getElementsByTagName("img"); + console.log("rewriting torrent link"); + for (let img of imgs) { + let tmpsrc = new URL(img.src); + if (tmpsrc.host == location.host) { + img.src = + "http://127.0.0.1:7657/i2psnark/" + tmpsrc.host + tmpsrc.pathname; + img.onerror = function () { + img.src = tmpsrc; + }; + } + } + var videos = document.getElementsByTagName("video"); + for (let video of videos) { + video.setAttribute("preload", "none"); + let tmpsrc = new URL(video.currentSrc); + if (tmpsrc.host == location.host) { + if (!video.innerHTML.includes("127.0.0.1")) { + innerHTML = video.innerHTML; + topInnerHTML = video.innerHTML.replace( + 'src="', + 'src="http://127.0.0.1:7657/i2psnark/' + location.host + "/" + ); + video.innerHTML = topInnerHTML; // + innerHTML; + video.onerror = function () { + video.innerHTML = topInnerHTML + innerHTML; }; } } - var videos = document.getElementsByTagName('video'); - for (let video of videos) { - video.setAttribute('preload', 'none'); - let tmpsrc = new URL(video.currentSrc); - if (tmpsrc.host == location.host) { - if (!video.innerHTML.includes('127.0.0.1')) { - innerHTML = video.innerHTML; - topInnerHTML = video.innerHTML.replace( - 'src="', - 'src="http://127.0.0.1:7657/i2psnark/' + location.host + '/' - ); - video.innerHTML = topInnerHTML; // + innerHTML; - video.onerror = function() { - video.innerHTML = topInnerHTML + innerHTML; - }; - } + } + var audios = document.getElementsByTagName("audio"); + for (let audio of audios) { + audio.setAttribute("preload", "none"); + let tmpsrc = new URL(audio.currentSrc); + if (tmpsrc.host == location.host) { + if (!audio.innerHTML.includes("127.0.0.1")) { + innerHTML = audio.innerHTML; + topInnerHTML = audio.innerHTML.replace( + 'src="', + 'src="http://127.0.0.1:7657/i2psnark/' + location.host + "/" + ); + audio.innerHTML = topInnerHTML; // + innerHTML; + audio.onerror = function () { + audio.innerHTML = topInnerHTML + innerHTML; + }; } } - var audios = document.getElementsByTagName('audio'); - for (let audio of audios) { - audio.setAttribute('preload', 'none'); - let tmpsrc = new URL(audio.currentSrc); - if (tmpsrc.host == location.host) { - if (!audio.innerHTML.includes('127.0.0.1')) { - innerHTML = audio.innerHTML; - topInnerHTML = audio.innerHTML.replace( - 'src="', - 'src="http://127.0.0.1:7657/i2psnark/' + location.host + '/' - ); - audio.innerHTML = topInnerHTML; // + innerHTML; - audio.onerror = function() { - audio.innerHTML = topInnerHTML + innerHTML; - }; - } - } - } - var links = document.getElementsByTagName('a'); - for (let link of links) { - let tmpsrc = new URL(link.href); - if (tmpsrc.host == location.host) { - if ( - !tmpsrc.pathname.endsWith('html') && - !tmpsrc.pathname.endsWith('htm') && - !tmpsrc.pathname.endsWith('php') && - !tmpsrc.pathname.endsWith('jsp') && - !tmpsrc.pathname.endsWith('asp') && - !tmpsrc.pathname.endsWith('aspx') && - !tmpsrc.pathname.endsWith('atom') && - !tmpsrc.pathname.endsWith('rss') && - !tmpsrc.pathname.endsWith('/') && - tmpsrc.pathname.includes('.') - ) { - link.href = - 'http://127.0.0.1:7657/i2psnark/' + tmpsrc.host + tmpsrc.pathname; - link.onerror = function() { - window.location.href = tmpsrc.href; - }; - } + } + var links = document.getElementsByTagName("a"); + for (let link of links) { + let tmpsrc = new URL(link.href); + if (tmpsrc.host == location.host) { + if ( + !tmpsrc.pathname.endsWith("html") && + !tmpsrc.pathname.endsWith("htm") && + !tmpsrc.pathname.endsWith("php") && + !tmpsrc.pathname.endsWith("jsp") && + !tmpsrc.pathname.endsWith("asp") && + !tmpsrc.pathname.endsWith("aspx") && + !tmpsrc.pathname.endsWith("atom") && + !tmpsrc.pathname.endsWith("rss") && + !tmpsrc.pathname.endsWith("/") && + tmpsrc.pathname.includes(".") + ) { + link.href = + "http://127.0.0.1:7657/i2psnark/" + tmpsrc.host + tmpsrc.pathname; + link.onerror = function () { + window.location.href = tmpsrc.href; + }; } } } } - return Promise.resolve({ content: response }); -}); + return response; +} diff --git a/scrub.js b/scrub.js index 286ff58..40267eb 100644 --- a/scrub.js +++ b/scrub.js @@ -119,7 +119,6 @@ var contextSetup = function(requestDetails) { function onContextError() { console.log('Context launcher error'); } - console.log('(scrub) host', requestDetails.url); //console.log("(isolate)Forcing I2P requests into context"); try { var i2pTabFind = async function(tabId) { @@ -947,7 +946,7 @@ browser.webNavigation.onBeforeNavigate.addListener(getClearTab, filter); browser.webNavigation.onCommitted.addListener(getClearTab, filter); browser.webNavigation.onCompleted.addListener(getClearTab, filter); -window.setInterval(getClearTab, 2000); +//window.setInterval(getClearTab, 2000); browser.webRequest.onBeforeRequest.addListener(contextSetup, { urls: ["*://*.i2p/*", "*://localhost/*", "*://127.0.0.1/*", "*://*/*i2p*"], From 9cd6ce888ebcb7aa721eca25a27342385bef68c6 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 17:09:54 -0500 Subject: [PATCH 04/18] Try and bail out of all proxy-setting in the Wire Web App --- handler.js | 8 +++---- proxy.js | 4 +++- scrub.js | 61 ++++++++++++++++++++++++++++-------------------------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/handler.js b/handler.js index b1113b2..b0c6fc1 100644 --- a/handler.js +++ b/handler.js @@ -110,8 +110,6 @@ var handlerSetup = function(requestDetails) { return requestDetails; }; -browser.webRequest.onBeforeRequest.addListener( - handlerSetup, - { urls: [''] }, - ['blocking'] -); +browser.webRequest.onBeforeRequest.addListener(handlerSetup, { + urls: [''], +}); diff --git a/proxy.js b/proxy.js index 389cdca..b8e7571 100644 --- a/proxy.js +++ b/proxy.js @@ -155,7 +155,6 @@ var handleContextProxyRequest = async function(requestDetails) { }; var tabGet = async function(tabId) { try { - console.log('(proxy)Tab ID from Request', tabId); let tabInfo = await browser.tabs.get(tabId); return tabInfo; } catch (error) { @@ -185,6 +184,9 @@ var handleContextProxyRequest = async function(requestDetails) { return browser.proxy.settings.get({}); } if (requestDetails.tabId > 0) { + if (requestDetails.url.includes('MuWire')) { + return; + } if (proxyHost(requestDetails.url)) { proxy = { type: getScheme(), diff --git a/scrub.js b/scrub.js index 40267eb..2dce950 100644 --- a/scrub.js +++ b/scrub.js @@ -593,7 +593,6 @@ var contextSetup = function(requestDetails) { var tab = tabGet(requestDetails.tabId); tab.then(isolate); function isolate(oldtab) { - console.log('(scrub)tab discovered:', oldtab); if (oldtab.cookieStoreId == 'firefox-default') { if (i2pHost(requestDetails.url)) { var thn = i2pHostName(requestDetails.url); @@ -825,20 +824,22 @@ function getTabURL(tab) { browser.tabs .sendMessage(tab.id, { req: "i2p-location" }) .then((response) => { - if (response.content.toUpperCase() != "NO-ALT-LOCATION") { - browser.pageAction.setPopup({ - tabId: tab.id, - popup: "location.html", - }); - browser.pageAction.setIcon({ - path: "icons/i2plogo.png", - tabId: tab.id, - }); - browser.pageAction.setTitle({ - tabId: tab.id, - title: response.content, - }); - browser.pageAction.show(tab.id); + if (response != undefined) { + if (response.content.toUpperCase() != "NO-ALT-LOCATION") { + browser.pageAction.setPopup({ + tabId: tab.id, + popup: "location.html", + }); + browser.pageAction.setIcon({ + path: "icons/i2plogo.png", + tabId: tab.id, + }); + browser.pageAction.setTitle({ + tabId: tab.id, + title: response.content, + }); + browser.pageAction.show(tab.id); + } } }); console.log("(pageaction)", tab.id, tab.url); @@ -850,20 +851,22 @@ function getTabURL(tab) { browser.tabs .sendMessage(tab.id, { req: "i2p-torrentlocation" }) .then((response) => { - if (response.content.toUpperCase() != "NO-ALT-LOCATION") { - browser.pageAction.setPopup({ - tabId: tab.id, - popup: "torrent.html", - }); - browser.pageAction.setIcon({ - path: "icons/i2plogo.png", - tabId: tab.id, - }); - browser.pageAction.setTitle({ - tabId: tab.id, - title: response.content, - }); - browser.pageAction.show(tab.id); + if (response != undefined) { + if (response.content.toUpperCase() != "NO-ALT-LOCATION") { + browser.pageAction.setPopup({ + tabId: tab.id, + popup: "torrent.html", + }); + browser.pageAction.setIcon({ + path: "icons/i2plogo.png", + tabId: tab.id, + }); + browser.pageAction.setTitle({ + tabId: tab.id, + title: response.content, + }); + browser.pageAction.show(tab.id); + } } }); console.log("(pageaction)", tab.id, tab.url); From 3b3744ffff95386f1feb5ead77883c1159c94334 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 17:49:36 -0500 Subject: [PATCH 05/18] Cheat at excluding MuWire from ! --- background.js | 34 ++++++++++++++++++---------------- handler.js | 3 ++- proxy.js | 23 +++++++---------------- scrub.js | 13 ++++--------- 4 files changed, 31 insertions(+), 42 deletions(-) diff --git a/background.js b/background.js index a6db5a2..6247899 100644 --- a/background.js +++ b/background.js @@ -371,29 +371,31 @@ function handleUpdated(updateInfo) { them.originalTheme.images == null && them.originalTheme.properties == null) ) { - if ( - updateInfo.theme.colors.frame != "#4456B7" && - updateInfo.theme.colors.frame != "#363A68" - ) { - function onSet() { - console.log("stored theme:", updateInfo.theme); - } + if (updateInfo.theme.colors != null) { if ( - updateInfo.theme.colors != null || - updateInfo.theme.images != null || - updateInfo.theme.properties != null + updateInfo.theme.colors.frame != "#4456B7" && + updateInfo.theme.colors.frame != "#363A68" ) { - console.log("storing theme:", updateInfo.theme); - browser.storage.local - .set({ originalTheme: updateInfo.theme }) - .then(onSet, onError); + function onSet() { + console.log("stored theme:", updateInfo.theme); + } + if ( + updateInfo.theme.colors != null && + updateInfo.theme.images != null && + updateInfo.theme.properties != null + ) { + console.log("storing theme:", updateInfo.theme); + browser.storage.local + .set({ originalTheme: updateInfo.theme }) + .then(onSet, onError); + } } } } else { console.log("keeping stored theme:", them); } - } catch { - console.log("theme storage error"); + } catch (e) { + console.log("theme storage error", e); } } browser.storage.local.get("originalTheme").then(maybeSet, onError); diff --git a/handler.js b/handler.js index b0c6fc1..740132f 100644 --- a/handler.js +++ b/handler.js @@ -109,7 +109,8 @@ var handlerSetup = function(requestDetails) { } return requestDetails; }; - +/* browser.webRequest.onBeforeRequest.addListener(handlerSetup, { urls: [''], }); +*/ diff --git a/proxy.js b/proxy.js index b8e7571..1e9a84e 100644 --- a/proxy.js +++ b/proxy.js @@ -38,15 +38,7 @@ var handleContextProxyRequest = async function(requestDetails) { } } function btProxy() { - proxy = null; - if (i2phost(requestDetails.url)) { - proxy = { - type: getScheme(), - host: getHost(), - port: getPort(), - }; - return proxy; - } + proxy = routerProxy(); if (!requestDetails.url.includes('7662')) { proxy = { type: getScheme(), @@ -59,6 +51,7 @@ var handleContextProxyRequest = async function(requestDetails) { proxy = null; return proxy; } + console.log('(bt proxy)', proxy); return proxy; } function mainProxy() { @@ -98,22 +91,20 @@ var handleContextProxyRequest = async function(requestDetails) { proxy = null; return proxy; } - //console.log('(proxy), context', context); + if (context != undefined) { + console.log('(proxy), context', context); proxy = routerProxy(); if (context.name == ircpref) { proxy = ircProxy(); return proxy; - } - if (context.name == titlepref) { + } else if (context.name == titlepref) { proxy = mainProxy(); return proxy; - } - if (context.name == routerpref) { + } else if (context.name == routerpref) { proxy = routerProxy(); return proxy; - } - if (context.name == torrentpref) { + } else if (context.name == torrentpref) { proxy = btProxy(); return proxy; } diff --git a/scrub.js b/scrub.js index 2dce950..27d0587 100644 --- a/scrub.js +++ b/scrub.js @@ -13,17 +13,14 @@ var contextScrub = async function(requestDetails) { function onHeaderError() { console.log('Header scrub error'); } - console.log('(scrub)Scrubbing info from contextualized request'); try { var headerScrub = function(context) { var ua = 'MYOB/6.66 (AN/ON)'; - console.log('(scrub) uah', context); if (!context) { } else if (context.name == titlepref) { for (var header of requestDetails.requestHeaders) { if (header.name.toLowerCase() === 'user-agent') { header.value = ua; - console.log('(scrub)User-Agent header modified', header.value); } } return { @@ -52,7 +49,6 @@ var contextScrub = async function(requestDetails) { } }; if (requestDetails.tabId > 0) { - console.log('(scrub) uah', requestDetails); tab = tabGet(requestDetails.tabId); context = tab.then(contextGet, onHeaderError); req = context.then(headerScrub, onHeaderError); @@ -906,10 +902,9 @@ function logOnDOMContentLoaded(details) { console.log(`onDOMContentLoaded: ${details.url}`); } -browser.webNavigation.onDOMContentLoaded.addListener(getClearTab, filter); +//browser.webNavigation.onDOMContentLoaded.addListener(getClearTab, filter); browser.tabs.onActivated.addListener(getClearTab); -browser.tabs.onUpdated.addListener(getClearTab); browser.tabs.onAttached.addListener(getClearTab); browser.tabs.onCreated.addListener(getClearTab); browser.tabs.onDetached.addListener(getClearTab); @@ -936,7 +931,7 @@ querying.then(reloadTabs, onError); // Set "blocking" and "responseHeaders". browser.webRequest.onHeadersReceived.addListener( coolheadersSetup, - { urls: [""] }, + { urls: ["*://*.i2p/*", "https://*/*"] }, ["responseHeaders"] ); @@ -945,9 +940,9 @@ browser.webNavigation.onDOMContentLoaded.addListener( logOnDOMContentLoaded, filter ); -browser.webNavigation.onBeforeNavigate.addListener(getClearTab, filter); +/*browser.webNavigation.onBeforeNavigate.addListener(getClearTab, filter); browser.webNavigation.onCommitted.addListener(getClearTab, filter); -browser.webNavigation.onCompleted.addListener(getClearTab, filter); +browser.webNavigation.onCompleted.addListener(getClearTab, filter);*/ //window.setInterval(getClearTab, 2000); From bc88ca80fd35d81033a4b7d7766b0a2778fb2897 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 17:53:31 -0500 Subject: [PATCH 06/18] re-enable tab-to-tab isolation --- scrub.js | 104 +++++++++++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/scrub.js b/scrub.js index 27d0587..b5fc547 100644 --- a/scrub.js +++ b/scrub.js @@ -589,60 +589,60 @@ var contextSetup = function(requestDetails) { var tab = tabGet(requestDetails.tabId); tab.then(isolate); function isolate(oldtab) { - if (oldtab.cookieStoreId == 'firefox-default') { - if (i2pHost(requestDetails.url)) { - var thn = i2pHostName(requestDetails.url); - if (requestDetails.url.includes('=' + thn)) { - console.log('(scrub)checking search hostnames =' + thn); - var tpt = requestDetails.url.split('=' + thn, 2); - requestDetails.url = - 'http://' + thn + '/' + tpt[1].replace('%2F', ''); - } - console.log('(scrub) new hostname', requestDetails.url); - var setcookie = browser.cookies.set({ - firstPartyDomain: i2pHostName(requestDetails.url), - url: requestDetails.url, - secure: true, - }); - setcookie.then(onContextGotLog, onContextError); - var i2ptab = tab.then(i2pTabFind, onContextError); - return requestDetails; - } - if (extensionHost(requestDetails)) { - return requestDetails; - } - let localhost = localHost(requestDetails.url); - let routerhost = routerHost(requestDetails.url); - if (routerhost) { - if (routerhost === 'i2ptunnelmgr') { - var tunneltab = tab.then(i2ptunnelTabFind, onContextError); - return requestDetails; - } else if (routerhost === 'i2psnark') { - var snarktab = tab.then(snarkTabFind, onContextError); - return requestDetails; - } else if (routerhost === 'webmail') { - var mailtab = tab.then(mailTabFind, onContextError); - return requestDetails; - } else if (routerhost === 'muwire') { - var routertab = tab.then(muwireTabFind, onContextError); - return requestDetails; - } else if (routerhost === 'i2pbote') { - var routertab = tab.then(i2pboteTabFind, onContextError); - return requestDetails; - } else if (routerhost === 'routerconsole') { - var routertab = tab.then(routerTabFind, onContextError); - return requestDetails; - } - } else { - if (localhost) { - var irctab = tab.then(ircTabFind, onContextError); - return requestDetails; - } - var normalTab = tab.then(normalTabFind, onContextError); - return requestDetails; - //return requestDetails; + // if (oldtab.cookieStoreId == 'firefox-default') { + if (i2pHost(requestDetails.url)) { + var thn = i2pHostName(requestDetails.url); + if (requestDetails.url.includes('=' + thn)) { + console.log('(scrub)checking search hostnames =' + thn); + var tpt = requestDetails.url.split('=' + thn, 2); + requestDetails.url = + 'http://' + thn + '/' + tpt[1].replace('%2F', ''); } + console.log('(scrub) new hostname', requestDetails.url); + var setcookie = browser.cookies.set({ + firstPartyDomain: i2pHostName(requestDetails.url), + url: requestDetails.url, + secure: true, + }); + setcookie.then(onContextGotLog, onContextError); + var i2ptab = tab.then(i2pTabFind, onContextError); + return requestDetails; } + if (extensionHost(requestDetails)) { + return requestDetails; + } + let localhost = localHost(requestDetails.url); + let routerhost = routerHost(requestDetails.url); + if (routerhost) { + if (routerhost === 'i2ptunnelmgr') { + var tunneltab = tab.then(i2ptunnelTabFind, onContextError); + return requestDetails; + } else if (routerhost === 'i2psnark') { + var snarktab = tab.then(snarkTabFind, onContextError); + return requestDetails; + } else if (routerhost === 'webmail') { + var mailtab = tab.then(mailTabFind, onContextError); + return requestDetails; + } else if (routerhost === 'muwire') { + var routertab = tab.then(muwireTabFind, onContextError); + return requestDetails; + } else if (routerhost === 'i2pbote') { + var routertab = tab.then(i2pboteTabFind, onContextError); + return requestDetails; + } else if (routerhost === 'routerconsole') { + var routertab = tab.then(routerTabFind, onContextError); + return requestDetails; + } + } else { + if (localhost) { + var irctab = tab.then(ircTabFind, onContextError); + return requestDetails; + } + var normalTab = tab.then(normalTabFind, onContextError); + return requestDetails; + //return requestDetails; + } + //} } } } catch (error) { From 40899889a0737b433039c77cafb89dff7247de5d Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 17:59:53 -0500 Subject: [PATCH 07/18] correct promise resolution on scripts.js --- script.js | 3 --- scrub.js | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index 4e87b74..e6b0ea2 100644 --- a/script.js +++ b/script.js @@ -5,15 +5,12 @@ browser.runtime.onMessage.addListener((request) => { var tag = document.querySelector('meta[http-equiv="i2p-location"]'); console.log(tag); if (tag) response = tag.content; - return response; } - if (request.req === 'i2p-torrentlocation') { const metas = document.getElementsByTagName('meta'); var tag = document.querySelector('meta[http-equiv="i2p-torrentlocation"]'); console.log(tag); response = i2pTorrent(tag); - return response; } return Promise.resolve({ content: response }); }); diff --git a/scrub.js b/scrub.js index b5fc547..9562a00 100644 --- a/scrub.js +++ b/scrub.js @@ -821,6 +821,7 @@ function getTabURL(tab) { .sendMessage(tab.id, { req: "i2p-location" }) .then((response) => { if (response != undefined) { + console.log("(scrub) i2p-location response object", response); if (response.content.toUpperCase() != "NO-ALT-LOCATION") { browser.pageAction.setPopup({ tabId: tab.id, @@ -848,6 +849,7 @@ function getTabURL(tab) { .sendMessage(tab.id, { req: "i2p-torrentlocation" }) .then((response) => { if (response != undefined) { + console.log("(scrub) i2p-location response object", response); if (response.content.toUpperCase() != "NO-ALT-LOCATION") { browser.pageAction.setPopup({ tabId: tab.id, From 8bfb7cdd276a39328b5913e25c0b6f4468ed3099 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 18:20:48 -0500 Subject: [PATCH 08/18] search the headers backward and break on the first one since the non-standard header is usually near the end --- scrub.js | 112 ++++++++++--------------------------------------------- 1 file changed, 19 insertions(+), 93 deletions(-) diff --git a/scrub.js b/scrub.js index 9562a00..1cf9491 100644 --- a/scrub.js +++ b/scrub.js @@ -653,93 +653,26 @@ var contextSetup = function(requestDetails) { var coolheadersSetup = function(e) { var asyncSetPageAction = new Promise((resolve, reject) => { window.setTimeout(() => { - for (i = 0; i < e.responseHeaders.length; i++) { + for (i = e.responseHeaders.length - 1; i >= 0; i--) { let header = e.responseHeaders[i]; - if (e.url.startsWith('https')) { - if ( - header.name.toUpperCase() === 'I2P-LOCATION' || - header.name.toUpperCase() === 'X-I2P-LOCATION' - ) { - browser.pageAction.setPopup({ - tabId: e.tabId, - popup: 'location.html', - }); - browser.pageAction.setIcon({ - path: 'icons/i2plogo.png', - tabId: e.tabId, - }); - browser.pageAction.setTitle({ - tabId: e.tabId, - title: header.value, - }); - browser.pageAction.show(e.tabId); - break; - } - if ( - header.name.toUpperCase() === 'I2P-TORRENTLOCATION' || - header.name.toUpperCase() === 'X-I2P-TORRENTLOCATION' - ) { - var imgs = document.getElementsByTagName('img'); - for (let img of imgs) { - if (tmpsrc.host == location.host) { - img.src = - 'http://127.0.0.1:7657/i2psnark/' + - tmpsrc.host + - tmpsrc.pathname; - img.onerror = function() { - img.src = tmpsrc; - }; - } - } - var videos = document.getElementsByTagName('video'); - for (let video of videos) { - let tmpsrc = new URL(video.currentSrc); - if (tmpsrc.host == location.host) { - if (!video.innerHTML.includes('127.0.0.1')) { - innerHTML = video.innerHTML; - topInnerHTML = video.innerHTML.replace( - 'src="', - 'src="http://127.0.0.1:7657/i2psnark/' + location.host + '/' - ); - video.innerHTML = topInnerHTML; // + innerHTML; - video.onerror = function() { - video.innerHTML = topInnerHTML + innerHTML; - }; - } - } - } - var audios = document.getElementsByTagName('audio'); - for (let audio of audios) { - let tmpsrc = new URL(audio.currentSrc); - if (tmpsrc.host == location.host) { - if (!audio.innerHTML.includes('127.0.0.1')) { - innerHTML = audio.innerHTML; - topInnerHTML = audio.innerHTML.replace( - 'src="', - 'src="http://127.0.0.1:7657/i2psnark/' + location.host + '/' - ); - audio.innerHTML = topInnerHTML; // + innerHTML; - audio.onerror = function() { - audio.innerHTML = topInnerHTML + innerHTML; - }; - } - } - } - browser.pageAction.setPopup({ - tabId: tabId.id, - popup: 'torrent.html', - }); - browser.pageAction.setIcon({ - path: 'icons/i2plogo.png', - tabId: e.tabId, - }); - browser.pageAction.setTitle({ - tabId: e.tabId, - title: header.value, - }); - browser.pageAction.show(e.tabId); - break; - } + if ( + header.name.toUpperCase() === 'I2P-LOCATION' || + header.name.toUpperCase() === 'X-I2P-LOCATION' + ) { + browser.pageAction.setPopup({ + tabId: e.tabId, + popup: 'location.html', + }); + browser.pageAction.setIcon({ + path: 'icons/i2plogo.png', + tabId: e.tabId, + }); + browser.pageAction.setTitle({ + tabId: e.tabId, + title: header.value, + }); + browser.pageAction.show(e.tabId); + break; } else { if ( header.name.toUpperCase() === 'I2P-TORRENTLOCATION' || @@ -904,8 +837,6 @@ function logOnDOMContentLoaded(details) { console.log(`onDOMContentLoaded: ${details.url}`); } -//browser.webNavigation.onDOMContentLoaded.addListener(getClearTab, filter); - browser.tabs.onActivated.addListener(getClearTab); browser.tabs.onAttached.addListener(getClearTab); browser.tabs.onCreated.addListener(getClearTab); @@ -942,11 +873,6 @@ browser.webNavigation.onDOMContentLoaded.addListener( logOnDOMContentLoaded, filter ); -/*browser.webNavigation.onBeforeNavigate.addListener(getClearTab, filter); -browser.webNavigation.onCommitted.addListener(getClearTab, filter); -browser.webNavigation.onCompleted.addListener(getClearTab, filter);*/ - -//window.setInterval(getClearTab, 2000); browser.webRequest.onBeforeRequest.addListener(contextSetup, { urls: ["*://*.i2p/*", "*://localhost/*", "*://127.0.0.1/*", "*://*/*i2p*"], From 531963c1c093e823006c85479a52b5abaceee6e1 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 20:13:20 -0500 Subject: [PATCH 09/18] filter the headers before we search them --- scrub.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/scrub.js b/scrub.js index 1cf9491..c0a9a88 100644 --- a/scrub.js +++ b/scrub.js @@ -653,12 +653,12 @@ var contextSetup = function(requestDetails) { var coolheadersSetup = function(e) { var asyncSetPageAction = new Promise((resolve, reject) => { window.setTimeout(() => { - for (i = e.responseHeaders.length - 1; i >= 0; i--) { - let header = e.responseHeaders[i]; - if ( - header.name.toUpperCase() === 'I2P-LOCATION' || - header.name.toUpperCase() === 'X-I2P-LOCATION' - ) { + let headers = e.responseHeaders.filter((word) => + word.name.toUpperCase().startsWith('X-I2P') + ); + for (i = headers.length - 1; i >= 0; i--) { + let header = headers[i]; + if (header.name.toUpperCase().endsWith('I2P-LOCATION')) { browser.pageAction.setPopup({ tabId: e.tabId, popup: 'location.html', @@ -674,10 +674,7 @@ var coolheadersSetup = function(e) { browser.pageAction.show(e.tabId); break; } else { - if ( - header.name.toUpperCase() === 'I2P-TORRENTLOCATION' || - header.name.toUpperCase() === 'X-I2P-TORRENTLOCATION' - ) { + if (header.name.toUpperCase().endsWith('I2P-TORRENTLOCATION')) { var imgs = document.getElementsByTagName('img'); for (let img of imgs) { if (tmpsrc.host == location.host) { From 12992c461b07532317718b7682f49c13c7fb9a05 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 20:45:49 -0500 Subject: [PATCH 10/18] get ready to clean up after the extension when it uninstalls --- background.js | 11 +++++ info.js | 2 +- privacy.js | 121 +++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 116 insertions(+), 18 deletions(-) diff --git a/background.js b/background.js index 6247899..fa25303 100644 --- a/background.js +++ b/background.js @@ -17,6 +17,17 @@ var muwirepref = chrome.i18n.getMessage('muwirePreface'); var muwireprefpriv = chrome.i18n.getMessage('muwirePrefacePrivate'); var botepref = chrome.i18n.getMessage('botePreface'); +function onError(err){ + console.log("(background)", err) +} + + +function onContextGotLog(contexts) { + if (contexts != null) { + console.log(contexts); + } +} + function onContextsGot(contexts) { var ids = []; for (let context of contexts) { diff --git a/info.js b/info.js index ea2c3b9..4784ed5 100644 --- a/info.js +++ b/info.js @@ -14,7 +14,7 @@ function checkSnowflake() { try { function snowflake(snowflake) { console.log("snowflake plugin found, leaving WebRTC alone", snowflake); - EnablePeerConnection(); + AssurePeerConnection(); } var snowflakeInfo = browser.management.get( "{b11bea1f-a888-4332-8d8a-cec2be7d24b9}" // string diff --git a/privacy.js b/privacy.js index 33b3b2f..aee4183 100644 --- a/privacy.js +++ b/privacy.js @@ -20,6 +20,15 @@ function disableHyperlinkAuditing() { setting.then(onSet); } +// UNINSTALL ONLY +function enableHyperlinkAuditing() { + var setting = browser.privacy.websites.hyperlinkAuditingEnabled.clear(); + console.log('Disabling hyperlink auditing/val=', { + value: false, + }); + setting.then(onSet); +} + // This enables first-party isolation function enableFirstPartyIsolation() { var setting = browser.privacy.websites.firstPartyIsolate.set({ @@ -31,6 +40,15 @@ function enableFirstPartyIsolation() { setting.then(onSet); } +// UNINSTALL ONLY +function disableFirstPartyIsolation() { + var setting = browser.privacy.websites.firstPartyIsolate.clear(); + console.log('Enabling first party isolation/val=', { + value: true, + }); + setting.then(onSet); +} + /* This rejects tracking cookies and third-party cookies but it LEAVES "Persistent" Cookies unmodified in favor of an option in the content interface for now */ @@ -75,6 +93,15 @@ function disableReferrers() { setting.then(onSet); } +// UNINSATALL ONLY +function enableReferrers() { + var setting = browser.privacy.websites.referrersEnabled.clear(); + console.log("Disabling referrer headers/val=", { + value: false, + }); + setting.then(onSet); +} + // enable fingerprinting resistent features(letterboxing and stuff) function enableResistFingerprinting() { var setting = browser.privacy.websites.resistFingerprinting.set({ @@ -86,6 +113,15 @@ function enableResistFingerprinting() { setting.then(onSet); } +// UNINSTALL ONLY +function disableResistFingerprinting() { + var setting = browser.privacy.websites.resistFingerprinting.clear(); + console.log("Enabling resist fingerprinting/val=", { + value: false, + }); + setting.then(onSet); +} + // This is essentially a blocklist of clearnet web-sites known to do bad tracking function enableTrackingProtection() { var setting = browser.privacy.websites.trackingProtectionMode.set({ @@ -97,6 +133,15 @@ function enableTrackingProtection() { setting.then(onSet); } +// UNINSTALL ONLY +function disableTrackingProtection() { + var setting = browser.privacy.websites.trackingProtectionMode.clear(); + console.log("Enabling tracking protection/val=", { + value: "always", + }); + setting.then(onSet); +} + /* This disables protected content, which is a form of digital restrictions management dependent on identifying information */ function disableDigitalRestrictionsManagement() { @@ -117,6 +162,48 @@ function disableDigitalRestrictionsManagement() { }); } +// UNINSTALL ONLY +function disableDigitalRestrictionsManagement() { + var gettingInfo = browser.runtime.getPlatformInfo(); + gettingInfo.then((got) => { + if (got.os == "win") { + var setting = browser.privacy.websites.protectedContentEnabled.clear(); + console.log( + "Setting Protected Content(Digital Restrictions Management) false/val=", + { + value: true, + } + ); + setting.then(onSet); + } + }); +} + + +function unsetAllPrivacy() { + enableHyperlinkAuditing(); + disableFirstPartyIsolation(); + enableEvilCookies(); + enableReferrers(); + disableTrackingProtection(); + disableResistFingerprinting(); + enableDigitalRestrictionsManagement(); + UnsetPeerConnection(); + EnableSavePasswords() +} + + + + +browser.management.onUninstalled.addListener((info) => { + function gotSelf(selfinfo) { + console.log("Add-on name: " info.name + selfinfo.name); + } + + var gettingSelf = browser.management.getSelf(); + gettingSelf.then(gotSelf); +}); + function setAllPrivacy() { disableHyperlinkAuditing(); enableFirstPartyIsolation(); @@ -140,7 +227,7 @@ function ResetPeerConnection() { } function snowflake(snowflake) { console.log("snowflake plugin found, leaving WebRTC alone", snowflake); - EnablePeerConnection(); + AssurePeerConnection(); } var snowflakeInfo = browser.management.get( "{b11bea1f-a888-4332-8d8a-cec2be7d24b9}" // string @@ -148,23 +235,11 @@ function ResetPeerConnection() { snowflakeInfo.then(snowflake, reset); } -function EnablePeerConnection() { - var webrtc = true; - var rtc = browser.privacy.network.peerConnectionEnabled.set({ - value: webrtc, - }); - rtc.then(AssurePeerConnection); - console.log("Enabled WebRTC"); -} - function AssurePeerConnection() { function assure(webrtc) { browser.privacy.network.peerConnectionEnabled.set({ value: true, }); - browser.privacy.network.networkPredictionEnabled.set({ - value: false, - }); chrome.privacy.network.webRTCIPHandlingPolicy.set({ value: "disable_non_proxied_udp", }); @@ -173,6 +248,20 @@ function AssurePeerConnection() { rtc.then(assure); } +// UNINSTALL ONLY +function UnsetPeerConnection(){ + function assure(webrtc) { + browser.privacy.network.peerConnectionEnabled.set({ + value: true, + }); + chrome.privacy.network.webRTCIPHandlingPolicy.set({ + value: "default", + }); + } + let rtc = browser.privacy.network.peerConnectionEnabled.get({}); + rtc.then(assure); +} + var gettingInfo = browser.runtime.getPlatformInfo(); gettingInfo.then((got) => { if (got.os == "android") { @@ -191,9 +280,7 @@ function ResetDisableSavePasswords() { } function EnableSavePasswords() { - browser.privacy.services.passwordSavingEnabled.set({ - value: true, - }); + browser.privacy.services.passwordSavingEnabled.clear(); console.log("Enabled saved passwords"); } @@ -401,7 +488,7 @@ function message(recieved) { console.log(recieved); if (recieved.rtc === "enableWebRTC") { console.log("enableWebRTC"); - EnablePeerConnection(); + AssurePeerConnection(); } else if (recieved.rtc === "disableWebRTC") { console.log("disableWebRTC"); ResetPeerConnection(); From 6d0cda9e67e148d277e7787438cdb91184800512 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 20:51:08 -0500 Subject: [PATCH 11/18] get ready to clean up after the extension when it uninstalls --- background.js | 5 ++--- privacy.js | 13 +++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/background.js b/background.js index fa25303..bb10c5e 100644 --- a/background.js +++ b/background.js @@ -17,11 +17,10 @@ var muwirepref = chrome.i18n.getMessage('muwirePreface'); var muwireprefpriv = chrome.i18n.getMessage('muwirePrefacePrivate'); var botepref = chrome.i18n.getMessage('botePreface'); -function onError(err){ - console.log("(background)", err) +function onError(err) { + console.log('(background)', err); } - function onContextGotLog(contexts) { if (contexts != null) { console.log(contexts); diff --git a/privacy.js b/privacy.js index aee4183..1faeda0 100644 --- a/privacy.js +++ b/privacy.js @@ -179,7 +179,6 @@ function disableDigitalRestrictionsManagement() { }); } - function unsetAllPrivacy() { enableHyperlinkAuditing(); disableFirstPartyIsolation(); @@ -189,17 +188,15 @@ function unsetAllPrivacy() { disableResistFingerprinting(); enableDigitalRestrictionsManagement(); UnsetPeerConnection(); - EnableSavePasswords() + EnableSavePasswords(); } - - - browser.management.onUninstalled.addListener((info) => { function gotSelf(selfinfo) { - console.log("Add-on name: " info.name + selfinfo.name); + if (info.name == selfinfo.name) { + unsetAllPrivacy(); + } } - var gettingSelf = browser.management.getSelf(); gettingSelf.then(gotSelf); }); @@ -249,7 +246,7 @@ function AssurePeerConnection() { } // UNINSTALL ONLY -function UnsetPeerConnection(){ +function UnsetPeerConnection() { function assure(webrtc) { browser.privacy.network.peerConnectionEnabled.set({ value: true, From 8230fe92a73524a46d0b3519c3956e2029ab8ddc Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 20:53:15 -0500 Subject: [PATCH 12/18] uninstall process --- privacy.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/privacy.js b/privacy.js index 1faeda0..852a9ad 100644 --- a/privacy.js +++ b/privacy.js @@ -71,6 +71,10 @@ function disableEvilCookies() { }); } +function enableEvilCookies() { + var getting = browser.privacy.websites.cookieConfig.clear(); +} + // Make sure that they're gone /*function disableBadCookies(){ var setting = browser.privacy.websites.thirdPartyCookiesAllowed.set({ From 26c4152bf619dcc5b53b07edf5550b7250a6a2d1 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 20:55:04 -0500 Subject: [PATCH 13/18] fix btProxy --- proxy.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/proxy.js b/proxy.js index 1e9a84e..2b8b584 100644 --- a/proxy.js +++ b/proxy.js @@ -39,14 +39,6 @@ var handleContextProxyRequest = async function(requestDetails) { } function btProxy() { proxy = routerProxy(); - if (!requestDetails.url.includes('7662')) { - proxy = { - type: getScheme(), - host: getHost(), - port: getPort(), - }; - return proxy; - } if (requestDetails.url.includes(':7662')) { proxy = null; return proxy; From a6aba7b5f79b33c185624ab83847d6d3916e74a7 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 20:55:57 -0500 Subject: [PATCH 14/18] fix btProxy --- proxy.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/proxy.js b/proxy.js index 2b8b584..20e1c99 100644 --- a/proxy.js +++ b/proxy.js @@ -55,9 +55,6 @@ var handleContextProxyRequest = async function(requestDetails) { if (requestDetails.url.includes('/i2psnark/')) { proxy = null; } - if (requestDetails.url.includes('/MuWire/')) { - proxy = null; - } return proxy; } function routerProxy() { From 3a30961cd10492239855454124f63b07f709fbd0 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 9 Dec 2020 21:58:58 -0500 Subject: [PATCH 15/18] fix btProxy --- proxy.js | 4 ++++ script.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/proxy.js b/proxy.js index 20e1c99..31520bf 100644 --- a/proxy.js +++ b/proxy.js @@ -52,7 +52,11 @@ var handleContextProxyRequest = async function(requestDetails) { host: getHost(), port: getPort(), }; + let url = new URL(requestDetails.url); + console.log('(proxy) URL', url); if (requestDetails.url.includes('/i2psnark/')) { + //+url.host)) { + console.log('(proxy) URL 2', url); proxy = null; } return proxy; diff --git a/script.js b/script.js index e6b0ea2..e20c30b 100644 --- a/script.js +++ b/script.js @@ -3,18 +3,59 @@ browser.runtime.onMessage.addListener((request) => { console.log(request); if (request.req === 'i2p-location') { var tag = document.querySelector('meta[http-equiv="i2p-location"]'); - console.log(tag); - if (tag) response = tag.content; + if (tag != undefined) { + console.log(tag); + if (tag) response = tag.content; + } + var tag = document.querySelector('meta[http-equiv="x-i2p-location"]'); + if (tag != undefined) { + console.log(tag); + if (tag) response = tag.content; + } } if (request.req === 'i2p-torrentlocation') { - const metas = document.getElementsByTagName('meta'); var tag = document.querySelector('meta[http-equiv="i2p-torrentlocation"]'); - console.log(tag); - response = i2pTorrent(tag); + if (tag != undefined) { + console.log(tag); + response = i2pTorrent(tag); + } + var tag = document.querySelector( + 'meta[http-equiv="x-i2p-torrentlocation"]' + ); + if (tag != undefined) { + console.log(tag); + response = i2pTorrent(tag); + } } return Promise.resolve({ content: response }); }); +window.document.onload = function (e) { + console.log("presetting x-i2p-torrentlocation"); + var tag = document.querySelector('meta[http-equiv="i2p-torrentlocation"]'); + if (tag != undefined) { + console.log(tag); + response = i2pTorrent(tag); + } + var tag = document.querySelector('meta[http-equiv="x-i2p-torrentlocation"]'); + if (tag != undefined) { + console.log(tag); + response = i2pTorrent(tag); + } +}; + +console.log("presetting x-i2p-torrentlocation"); +var tag = document.querySelector('meta[http-equiv="i2p-torrentlocation"]'); +if (tag != undefined) { + console.log(tag); + response = i2pTorrent(tag); +} +var tag = document.querySelector('meta[http-equiv="x-i2p-torrentlocation"]'); +if (tag != undefined) { + console.log(tag); + response = i2pTorrent(tag); +} + function i2pTorrent(tag) { let response = "no-alt-location"; if (tag) { @@ -42,8 +83,14 @@ function i2pTorrent(tag) { 'src="', 'src="http://127.0.0.1:7657/i2psnark/' + location.host + "/" ); + // let url = new URL("http://127.0.0.1:7657/i2psnark/"+location.host+"/"location.path) + console.log( + "http://127.0.0.1:7657/i2psnark/" + tmpsrc.host + tmpsrc.pathname + ); //+"/"location.path) + //video.src = "http://127.0.0.1:7657/i2psnark/"+location.replace("http://") video.innerHTML = topInnerHTML; // + innerHTML; video.onerror = function () { + console.log("video error"); video.innerHTML = topInnerHTML + innerHTML; }; } @@ -60,8 +107,14 @@ function i2pTorrent(tag) { 'src="', 'src="http://127.0.0.1:7657/i2psnark/' + location.host + "/" ); + //console.log("http://127.0.0.1:7657/i2psnark/" + location); //.host+"/"location.path) + console.log( + "http://127.0.0.1:7657/i2psnark/" + tmpsrc.host + tmpsrc.pathname + ); //+"/"location.path) + //audio.src = "http://127.0.0.1:7657/i2psnark/"+location.replace("http://") audio.innerHTML = topInnerHTML; // + innerHTML; audio.onerror = function () { + console.log("audio error"); audio.innerHTML = topInnerHTML + innerHTML; }; } From a992553ffb239a2bfd8c0587ed02f742ed64cba5 Mon Sep 17 00:00:00 2001 From: idk Date: Thu, 10 Dec 2020 10:15:48 -0500 Subject: [PATCH 16/18] make embedding torrents in pages faster --- script.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/script.js b/script.js index e20c30b..600cd7c 100644 --- a/script.js +++ b/script.js @@ -87,7 +87,8 @@ function i2pTorrent(tag) { console.log( "http://127.0.0.1:7657/i2psnark/" + tmpsrc.host + tmpsrc.pathname ); //+"/"location.path) - //video.src = "http://127.0.0.1:7657/i2psnark/"+location.replace("http://") + video.src = + "http://127.0.0.1:7657/i2psnark/" + tmpsrc.host + tmpsrc.pathname; video.innerHTML = topInnerHTML; // + innerHTML; video.onerror = function () { console.log("video error"); @@ -111,7 +112,8 @@ function i2pTorrent(tag) { console.log( "http://127.0.0.1:7657/i2psnark/" + tmpsrc.host + tmpsrc.pathname ); //+"/"location.path) - //audio.src = "http://127.0.0.1:7657/i2psnark/"+location.replace("http://") + audio.src = + "http://127.0.0.1:7657/i2psnark/" + tmpsrc.host + tmpsrc.pathname; audio.innerHTML = topInnerHTML; // + innerHTML; audio.onerror = function () { console.log("audio error"); From aa9805e1072d2f9ade2ad0fa45c3c7e737aeadcd Mon Sep 17 00:00:00 2001 From: idk Date: Fri, 11 Dec 2020 15:42:28 -0500 Subject: [PATCH 17/18] Fix torrent-proxy sanity check --- proxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy.js b/proxy.js index 31520bf..54873a5 100644 --- a/proxy.js +++ b/proxy.js @@ -54,7 +54,7 @@ var handleContextProxyRequest = async function(requestDetails) { }; let url = new URL(requestDetails.url); console.log('(proxy) URL', url); - if (requestDetails.url.includes('/i2psnark/')) { + if (requestDetails.url.includes('/i2psnark/'+url.host)) { //+url.host)) { console.log('(proxy) URL 2', url); proxy = null; From 78a17945688e8930b139b08086e7ff4de581130a Mon Sep 17 00:00:00 2001 From: idk Date: Fri, 11 Dec 2020 16:30:22 -0500 Subject: [PATCH 18/18] fix sanity check on torrent proxy --- proxy.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/proxy.js b/proxy.js index 54873a5..1c31df3 100644 --- a/proxy.js +++ b/proxy.js @@ -47,16 +47,25 @@ var handleContextProxyRequest = async function(requestDetails) { return proxy; } function mainProxy() { + console.log('(proxy) mainproxy 0'); proxy = { type: getScheme(), host: getHost(), port: getPort(), }; let url = new URL(requestDetails.url); - console.log('(proxy) URL', url); - if (requestDetails.url.includes('/i2psnark/'+url.host)) { + console.log( + '(proxy) mainproxy 1', + requestDetails.url, + 'http://' + getHost() + ':' + getConsolePort() + '/i2psnark/' + ); + if ( + requestDetails.url.startsWith( + 'http://' + getHost() + ':' + getConsolePort() + '/i2psnark/' + ) + ) { //+url.host)) { - console.log('(proxy) URL 2', url); + console.log('(proxy) mainproxy 2', url); proxy = null; } return proxy; @@ -324,9 +333,9 @@ function getConsolePort() { if (control_port == undefined) { var scheme = getScheme(); if (scheme == 'socks') proxy_port = '7657'; - else proxy_port = '7657'; + else control_port = '7657'; } - return proxy_port; + return control_port; } function setupProxy() {