From df4d9e93a60af50dc591dee75cc6bfa4e9690d7d Mon Sep 17 00:00:00 2001 From: idk Date: Mon, 28 Oct 2019 01:11:16 -0400 Subject: [PATCH] add option to re-enable WebRTC --- Makefile | 5 +- README.md | 2 +- background.js | 49 +++++-------- content.js | 19 +++++ info.js | 8 ++ manifest.json | 1 - platform.js | 30 +++----- privacy.js | 200 +++++++++++++++++++++++--------------------------- proxy.js | 59 ++++++--------- scrub.js | 35 +++++++++ window.html | 8 +- 11 files changed, 209 insertions(+), 207 deletions(-) diff --git a/Makefile b/Makefile index 1d9f634..61e9183 100644 --- a/Makefile +++ b/Makefile @@ -34,8 +34,9 @@ clean: ## EVEN RELEASES are AMO RELEASES ## ODD RELEASES are SELFHOSTED RELEASES -MOZ_VERSION=0.36 -VERSION=0.37 +MOZ_VERSION=0.38 +VERSION=0.39 +VERSION=$(MOZ_VERSION) #VERSION=1.27 xpi: diff --git a/README.md b/README.md index ad1b75d..34614be 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ for the new plugin has been made at a new location on addons.mozilla.org. Android usage: -------------- -Open the following link [Github Releases Version](https://github.com/eyedeekay/i2psetproxy.js/releases/download/1.26/i2psetproxy.js@eyedeekay.github.io.xpi) +Open the following link [Github Releases Version](https://github.com/eyedeekay/i2psetproxy.js/releases/) in the browser you want to use for I2P. Firefox will warn you that it is about to install an extension and indicate the permissions required. Read them over and when you're ready, accept them. That's all it should take, your browser is diff --git a/background.js b/background.js index f44fe37..d1320e4 100644 --- a/background.js +++ b/background.js @@ -6,13 +6,6 @@ function onGot(contexts) { } console.log("Checking new contexts"); if (ids.indexOf("i2pbrowser") == -1) { - function onCreated(context) { - console.log(`New identity's ID: ${context.cookieStoreId}.`); - } - - function onError(e) { - console.error(e); - } browser.contextualIdentities .create({ name: "i2pbrowser", @@ -22,13 +15,6 @@ function onGot(contexts) { .then(onCreated, onError); } if (ids.indexOf("routerconsole") == -1) { - function onCreated(context) { - console.log(`New identity's ID: ${context.cookieStoreId}.`); - } - - function onError(e) { - console.error(e); - } browser.contextualIdentities .create({ name: "routerconsole", @@ -39,6 +25,10 @@ function onGot(contexts) { } } +function onCreated(context) { + console.log(`New identity's ID: ${context.cookieStoreId}.`); +} + function onError(e) { console.error(e); } @@ -47,6 +37,8 @@ browser.contextualIdentities.query({}).then(onGot, onError); if (!isDroid()) { chrome.windows.onCreated.addListener(themeWindow); + chrome.windows.onFocusChanged.addListener(themeWindow); + chrome.windows.onRemoved.addListener(themeWindow); chrome.tabs.onUpdated.addListener(themeWindowByTab); chrome.tabs.onActivated.addListener(themeWindowByTab); } @@ -54,16 +46,22 @@ if (!isDroid()) { var titlepref = chrome.i18n.getMessage("titlePreface"); var titleprefpriv = chrome.i18n.getMessage("titlePrefacePrivate"); -function themeWindowByTab(tab) { - getwindow = browser.windows.get(tab.windowId); - getwindow.then(themeWindow); +function themeWindowByTab(tabId) { + function tabWindow(tab) { + getwindow = browser.windows.get(tab.windowId); + getwindow.then(themeWindow); + } + if (typeof tabId === "number") { + tab = browser.tabs.get(tabId); + tab.then(tabWindow); + } else { + tabWindow(tabId); + } } function themeWindow(window) { // Check if the window is in private browsing function logTabs(tabInfo) { - console.log(tabInfo); - function onGot(context) { if (context.name == "i2pbrowser") { console.log("Active in I2P window"); @@ -103,10 +101,6 @@ function themeWindow(window) { console.log("Not active in I2P window"); } } - - function onError(e) { - console.error(e); - } if (tabInfo[0].cookieStoreId != "firefox-default") { browser.contextualIdentities .get(tabInfo[0].cookieStoreId) @@ -116,9 +110,6 @@ function themeWindow(window) { } } - function onError(error) { - console.log(`Error: ${error}`); - } var querying = browser.tabs.query({ currentWindow: true, active: true @@ -147,18 +138,12 @@ function setTitle(window) { } } - function onError(e) { - console.error(e); - } if (tabInfo[0].cookieStoreId != "firefox-default") browser.contextualIdentities .get(tabInfo[0].cookieStoreId) .then(onGot, onError); } - function onError(error) { - console.log(`Error: ${error}`); - } var querying = browser.tabs.query({ currentWindow: true, active: true diff --git a/content.js b/content.js index c7cf74e..417b4cf 100644 --- a/content.js +++ b/content.js @@ -15,3 +15,22 @@ newsMessage.textContent = chrome.i18n.getMessage("newsMessage"); var clearData = document.getElementById("clear-browser-data"); clearData.textContent = chrome.i18n.getMessage("clearData"); +/* +document.addEventListener("click", e => { + browser.runtime.sendMessage({ url: "http://proxy.i2p" }); +}); + +function proxyContent(message) { + var proxyData = document.getElementById("proxy-health"); + proxyData.textContent = message; + console.log("Event occurred", message); +} + +browser.runtime.onMessage.addListener(proxyContent); +*/ + +/* +function signalWebRTC(val){ + console.log("signal", val) +} +*/ diff --git a/info.js b/info.js index 347c4c6..1876fdb 100644 --- a/info.js +++ b/info.js @@ -44,7 +44,15 @@ document.addEventListener("click", e => { forgetBrowsingData(); } else if (e.target.id === "check-i2p-control") { echo("I2P Router Detected", "panel-section-i2pcontrol-check"); + } else if (e.target.id === "enable-web-rtc") { + if (e.target.checked){ + browser.runtime.sendMessage({ rtc: "enableWebRTC" }); + }else{ + browser.runtime.sendMessage({ rtc: "disableWebRTC" }); + } + return } e.preventDefault(); }); + diff --git a/manifest.json b/manifest.json index 7a29c49..c9e286d 100644 --- a/manifest.json +++ b/manifest.json @@ -39,7 +39,6 @@ }, "background": { "scripts": [ - "chromium/browser-polyfill.js", "privacy.js", "platform.js", "background.js", diff --git a/platform.js b/platform.js index 1521db9..a298fa5 100644 --- a/platform.js +++ b/platform.js @@ -1,23 +1,13 @@ -function getChrome() { - if (browser.runtime.getBrowserInfo == undefined) { - console.log("Running in Chrome detected"); - return true; - } - return false; -} - function isDroid() { - if (!getChrome()) { - var gettingInfo = browser.runtime.getPlatformInfo(); - gettingInfo.then(got => { - if (got.os == "android") { - console.log("Running in Android detected"); - return true; - } else { - console.log("Running in Desktop detected"); - return false; - } - }); - } + var gettingInfo = browser.runtime.getPlatformInfo(); + gettingInfo.then(got => { + if (got.os == "android") { + console.log("Running in Android detected"); + return true; + } else { + console.log("Running in Desktop detected"); + return false; + } + }); return false; } diff --git a/privacy.js b/privacy.js index d813625..cf8f304 100644 --- a/privacy.js +++ b/privacy.js @@ -1,10 +1,3 @@ -function getChrome() { - if (chrome.runtime.getBrowserInfo == undefined) { - return true; - } - return false; -} - function onSet(result) { if (result) { console.log("->: Value was updated"); @@ -16,52 +9,46 @@ function onSet(result) { // This disables queries to centralized databases of bad URLs to screen for // risky sites in your browser function disableHyperlinkAuditing() { - if (!getChrome()) { - var setting = browser.privacy.websites.hyperlinkAuditingEnabled.set({ - value: false - }); - console.log("Disabling hyperlink auditing/val=", { - value: false - }); - setting.then(onSet); - } + var setting = browser.privacy.websites.hyperlinkAuditingEnabled.set({ + value: false + }); + console.log("Disabling hyperlink auditing/val=", { + value: false + }); + setting.then(onSet); } // This enables first-party isolation function enableFirstPartyIsolation() { - if (!getChrome()) { - var setting = browser.privacy.websites.firstPartyIsolate.set({ - value: true - }); - console.log("Enabling first party isolation/val=", { - value: true - }); - setting.then(onSet); - } + var setting = browser.privacy.websites.firstPartyIsolate.set({ + value: true + }); + 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 function disableEvilCookies() { - if (!getChrome()) { - var getting = browser.privacy.websites.cookieConfig.get({}); - getting.then(got => { - var setting = browser.privacy.websites.cookieConfig.set({ - value: { - behavior: "reject_third_party", - nonPersistentCookies: got.value.nonPersistentCookies - } - }); - console.log("Setting cookie behavior/val=", { - value: { - behavior: "reject_third_party", - nonPersistentCookies: got.value.nonPersistentCookies - } - }); - setting.then(onSet); + var getting = browser.privacy.websites.cookieConfig.get({}); + getting.then(got => { + var setting = browser.privacy.websites.cookieConfig.set({ + value: { + behavior: "reject_third_party", + nonPersistentCookies: got.value.nonPersistentCookies + } }); - } + console.log("Setting cookie behavior/val=", { + value: { + behavior: "reject_third_party", + nonPersistentCookies: got.value.nonPersistentCookies + } + }); + setting.then(onSet); + }); } // Make sure that they're gone @@ -77,63 +64,55 @@ function disableEvilCookies() { // this disables the use of referrer headers function disableReferrers() { - if (!getChrome()) { - var setting = browser.privacy.websites.referrersEnabled.set({ - value: false - }); - console.log("Disabling referrer headers/val=", { - value: false - }); - setting.then(onSet); - } + var setting = browser.privacy.websites.referrersEnabled.set({ + value: false + }); + console.log("Disabling referrer headers/val=", { + value: false + }); + setting.then(onSet); } // enable fingerprinting resistent features(letterboxing and stuff) function enableResistFingerprinting() { - if (!getChrome()) { - var setting = browser.privacy.websites.referrersEnabled.set({ - value: true - }); - console.log("Enabling resist fingerprinting/val=", { - value: true - }); - setting.then(onSet); - } + var setting = browser.privacy.websites.referrersEnabled.set({ + value: true + }); + console.log("Enabling resist fingerprinting/val=", { + value: true + }); + setting.then(onSet); } // This is essentially a blocklist of clearnet web-sites known to do bad tracking function enableTrackingProtection() { - if (!getChrome()) { - var setting = browser.privacy.websites.trackingProtectionMode.set({ - value: "always" - }); - console.log("Enabling tracking protection/val=", { - value: "always" - }); - setting.then(onSet); - } + var setting = browser.privacy.websites.trackingProtectionMode.set({ + value: "always" + }); + 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() { - if (!getChrome()) { - var gettingInfo = browser.runtime.getPlatformInfo(); - gettingInfo.then(got => { - if (got.os == "win") { - var setting = browser.privacy.websites.protectedContentEnabled.set({ + var gettingInfo = browser.runtime.getPlatformInfo(); + gettingInfo.then(got => { + if (got.os == "win") { + var setting = browser.privacy.websites.protectedContentEnabled.set({ + value: false + }); + console.log( + "Setting Protected Content(Digital Restrictions Management) false/val=", + { value: false - }); - console.log( - "Setting Protected Content(Digital Restrictions Management) false/val=", - { - value: false - } - ); - setting.then(onSet); - } - }); - } + } + ); + setting.then(onSet); + } + }); } function setAllPrivacy() { @@ -149,14 +128,12 @@ function setAllPrivacy() { setAllPrivacy(); function ResetPeerConnection() { - if (!getChrome()) { - browser.privacy.network.peerConnectionEnabled.set({ - value: false - }); - browser.privacy.network.networkPredictionEnabled.set({ - value: false - }); - } + browser.privacy.network.peerConnectionEnabled.set({ + value: false + }); + browser.privacy.network.networkPredictionEnabled.set({ + value: false + }); chrome.privacy.network.webRTCIPHandlingPolicy.set({ value: "disable_non_proxied_udp" }); @@ -164,14 +141,12 @@ function ResetPeerConnection() { } function EnablePeerConnection() { - if (!getChrome()) { - browser.privacy.network.peerConnectionEnabled.set({ - value: true - }); - browser.privacy.network.networkPredictionEnabled.set({ - value: false - }); - } + browser.privacy.network.peerConnectionEnabled.set({ + value: true + }); + browser.privacy.network.networkPredictionEnabled.set({ + value: false + }); chrome.privacy.network.webRTCIPHandlingPolicy.set({ value: "disable_non_proxied_udp" }); @@ -214,10 +189,8 @@ function checkStoredSettings(storedSettings) { chrome.storage.local.set(appSettings); } -if (!getChrome()) { - const gettingStoredSettings = browser.storage.local.get(); - gettingStoredSettings.then(checkStoredSettings, onError); -} +const gettingStoredSettings = browser.storage.local.get(); +gettingStoredSettings.then(checkStoredSettings, onError); function clearCookiesContext(cookieStoreId) {} @@ -315,7 +288,7 @@ function forgetBrowsingData(storedSettings) { }); removing.then(onGot, onError); } - console.log("Cleared cookies") + console.log("Cleared cookies"); } function deepCleanContext(cookieStoreIds) { @@ -368,8 +341,15 @@ function onGot(contexts) { } } -function onError(e) { - console.error(e); -} +browser.runtime.onMessage.addListener(message); -//browser.contextualIdentities.query("i2pbrowser").then(clearCookiesContext, onError); +function message(message){ + console.log(message) + if (message.rtc === "enableWebRTC") { + console.log("enableWebRTC") + EnablePeerConnection() + } else { + console.log("disableWebRTC") + ResetPeerConnection() + } +} \ No newline at end of file diff --git a/proxy.js b/proxy.js index fdd8871..6b4d8cb 100644 --- a/proxy.js +++ b/proxy.js @@ -1,9 +1,7 @@ -if (!getChrome()) { - browser.privacy.network.peerConnectionEnabled.set({ - value: false - }); - console.log("Preliminarily disabled WebRTC."); -} +browser.privacy.network.peerConnectionEnabled.set({ + value: false +}); +console.log("Preliminarily disabled WebRTC."); chrome.privacy.network.networkPredictionEnabled.set({ value: false @@ -73,7 +71,13 @@ var handleContextProxyRequest = async function(requestDetails) { }; if (requestDetails.tabId > 0) { - if (i2pHost(requestDetails.url)) { + if (proxyHost(requestDetails.url)) { + return { + type: getScheme(), + host: getHost(), + port: getPort() + }; + } else if (i2pHost(requestDetails.url)) { console.log("(Proxy)I2P URL detected, "); var tab = tabGet(requestDetails.tabId); var mtab = tab.then(tabFind); @@ -160,33 +164,14 @@ function setupProxy() { var Host = getHost(); var Port = getPort(); var Scheme = getScheme(); - if (!getChrome()) { - /**/ - console.log("Setting up Firefox WebExtension proxy"); - browser.proxy.onRequest.addListener(handleContextProxyRequest, { - urls: [""] - }); - console.log("i2p settings created for WebExtension Proxy"); - /**/ - } else { - var config = { - mode: "fixed_servers", - rules: { - singleProxy: { - scheme: Scheme, - host: Host, - port: parseInt(Port) - } - } - }; - chrome.proxy.settings.set( - { - value: config, - scope: "regular" - }, - function() {} - ); - } + + /**/ + console.log("Setting up Firefox WebExtension proxy"); + browser.proxy.onRequest.addListener(handleContextProxyRequest, { + urls: [""] + }); + console.log("i2p settings created for WebExtension Proxy"); + /**/ } function checkStoredSettings(storedSettings) { @@ -229,8 +214,6 @@ chrome.storage.local.get(function(got) { }); // Theme all currently open windows -if (!getChrome()) { - if (!isDroid()) { - browser.windows.getAll().then(wins => wins.forEach(themeWindow)); - } +if (!isDroid()) { + browser.windows.getAll().then(wins => wins.forEach(themeWindow)); } diff --git a/scrub.js b/scrub.js index 2cd3664..8d21204 100644 --- a/scrub.js +++ b/scrub.js @@ -197,6 +197,19 @@ function i2pHost(url) { return hostname.endsWith(".i2p"); } +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; +} + function routerHost(url) { let hostname = ""; if (url.indexOf("://") > -1) { @@ -230,3 +243,25 @@ browser.webRequest.onBeforeSendHeaders.addListener( { urls: [""] }, ["blocking", "requestHeaders"] ); + +/* +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); + }; +} +*/ \ No newline at end of file diff --git a/window.html b/window.html index d9ce811..00b2d88 100644 --- a/window.html +++ b/window.html @@ -27,14 +27,16 @@ Clear all browsing data
-
Visit the I2P Forums
Get the latest I2P News
+
+ + +
Check I2P Router Health
-
@@ -45,7 +47,7 @@ - +