[or-cvs] [torbutton/master] Fixed multiple cookie protection bugs
mikeperry at seul.org
mikeperry at seul.org
Tue Oct 13 02:56:38 UTC 2009
Author: Kory Kirk <kory.kirk at gmail.com>
Date: Mon, 12 Oct 2009 21:40:28 -0400
Subject: Fixed multiple cookie protection bugs
Commit: 66644c57256181f08c0309d2b6c80ffbe22d25fa
---
src/chrome/content/preferences.js | 14 +-
src/chrome/content/torbutton.js | 6 +-
src/components/cookie-jar-selector.js | 10 +-
src/components/tor-protocol.js | 278 +++++++++++++++---------------
src/components/torRefSpoofer.js | 308 ++++++++++++++++----------------
src/components/tors-protocol.js | 278 +++++++++++++++---------------
6 files changed, 449 insertions(+), 445 deletions(-)
diff --git a/src/chrome/content/preferences.js b/src/chrome/content/preferences.js
index 5780e03..77eb8ee 100644
--- a/src/chrome/content/preferences.js
+++ b/src/chrome/content/preferences.js
@@ -187,10 +187,8 @@ function torbutton_prefs_init(doc) {
o_torprefs.setBoolPref('cookie_jars', false);
o_torprefs.setBoolPref('dual_cookie_jars', true);
o_torprefs.setBoolPref('clear_cookies', false);
- o_torprefs.setBoolPref('tor_memory_jar', false);
- o_torprefs.setBoolPref('nontor_memory_jar', false);
- doc.getElementById('torbutton_torMemoryJar').disabled = true;
- doc.getElementById('torbutton_nonTorMemoryJar').disabled = true;
+ doc.getElementById('torbutton_torMemoryJar').disabled = false;
+ doc.getElementById('torbutton_nonTorMemoryJar').disabled = false;
}
else if(o_torprefs.getBoolPref('dual_cookie_jars')) {
doc.getElementById('torbutton_cookieGroup').selectedItem =
@@ -322,10 +320,10 @@ function torbutton_cookie_update(doc) {
} else if(doc.getElementById('torbutton_cookieGroup').selectedItem
== doc.getElementById('torbutton_cookieProtections')) {
- doc.getElementById('torbutton_torMemoryJar').checked = false;
- doc.getElementById('torbutton_nonTorMemoryJar').checked = false;
- doc.getElementById('torbutton_torMemoryJar').disabled = true;
- doc.getElementById('torbutton_nonTorMemoryJar').disabled = true;
+ doc.getElementById('torbutton_torMemoryJar').checked = o_torprefs.getBoolPref('tor_memory_jar');
+ doc.getElementById('torbutton_nonTorMemoryJar').checked = o_torprefs.getBoolPref('nontor_memory_jar');
+ doc.getElementById('torbutton_torMemoryJar').disabled = false;
+ doc.getElementById('torbutton_nonTorMemoryJar').disabled = false;
}
}
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index 27192c6..976f564 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -1410,7 +1410,7 @@ function torbutton_close_on_toggle(mode) {
function checkProtections()
{
- var pref = m_tb_prefs.getBoolPref("extensions.torbutton.cookie_protections");
+ var pref = m_tb_prefs.getBoolPref("extensions.torbutton.cookie_protections") && ((!m_tb_prefs.getBoolPref("extensions.torbutton.tor_memory_jar") && m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")) || (!m_tb_prefs.getBoolPref("extensions.torbutton.nontor_memory_jar") && !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")));
document.getElementById("torbutton-cookie-protector").disabled = !pref;
}
@@ -1566,7 +1566,7 @@ function torbutton_jar_cookies(mode) {
var writeTor = !m_tb_prefs.getBoolPref('extensions.torbutton.tor_memory_jar');
var writeNontor = !m_tb_prefs.getBoolPref('extensions.torbutton.nontor_memory_jar');
if(mode) {
- if (protectcookies)
+ if (protectcookies && writeNontor)
selector.clearUnprotectedCookies("nontor");
if (writeNontor)
selector.saveCookies("nontor");
@@ -1574,7 +1574,7 @@ function torbutton_jar_cookies(mode) {
if(m_tb_prefs.getBoolPref('extensions.torbutton.dual_cookie_jars'))
selector.loadCookies("tor", false);
} else {
- if (protectcookies)
+ if (protectcookies && writeTor)
selector.clearUnprotectedCookies("tor");
if(m_tb_prefs.getBoolPref('extensions.torbutton.dual_cookie_jars') && writeTor)
selector.saveCookies("tor");
diff --git a/src/components/cookie-jar-selector.js b/src/components/cookie-jar-selector.js
index d8d4401..d771fed 100644
--- a/src/components/cookie-jar-selector.js
+++ b/src/components/cookie-jar-selector.js
@@ -174,6 +174,9 @@ function CookieJarSelector() {
var tor_enabled = this.prefs.getBoolPref("extensions.torbutton.tor_enabled");
var name = tor_enabled? "tor" : "nontor";
var cookies = this.getProtectedCookies(name);
+
+ if (cookies.toString() == "" || cookies == null)
+ cookies = new XML('<cookies/>');
var xml = <cookie>{cookie.value}</cookie>;
xml. at name = cookie.name;
xml. at host = cookie.host;
@@ -551,8 +554,11 @@ CookieJarSelector.prototype =
case "cookie-changed":
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
this.timerCallback.cookie_changed = true;
- if (aData = "added" && prefs.getBoolPref("extensions.torbutton.cookie_auto_protect"))
- this.addProtectedCookie(aSubject.QueryInterface(Components.interfaces.nsICookie2));//protect the new cookie!
+
+ if (aData == "added" && prefs.getBoolPref("extensions.torbutton.cookie_auto_protect") && ((!prefs.getBoolPref("extensions.torbutton.tor_memory_jar") && prefs.getBoolPref("extensions.torbutton.tor_enabled")) || (!prefs.getBoolPref("extensions.torbutton.nontor_memory_jar") && !prefs.getBoolPref("extensions.torbutton.tor_enabled"))))
+ {
+ this.addProtectedCookie(aSubject.QueryInterface(Components.interfaces.nsICookie2));//protect the new cookie!
+ }
break;
case "app-startup":
var obsSvc = Components.classes["@mozilla.org/observer-service;1"].getService(nsIObserverService);
diff --git a/src/components/tor-protocol.js b/src/components/tor-protocol.js
index 6b9d66a..111112c 100644
--- a/src/components/tor-protocol.js
+++ b/src/components/tor-protocol.js
@@ -1,139 +1,139 @@
-// Test protocol related
-const kSCHEME = "tor";
-const kPROTOCOL_NAME = "tor";
-const kPROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + kSCHEME;
-const kPROTOCOL_CID = Components.ID("52183e20-4d4b-11de-8a39-0800200c9a66");
-
-// Mozilla defined
-const kSIMPLEURI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
-const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
-const nsISupports = Components.interfaces.nsISupports;
-const nsIIOService = Components.interfaces.nsIIOService;
-const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;
-const nsIURI = Components.interfaces.nsIURI;
-
-function Protocol()
-{
-}
-
-Protocol.prototype =
-{
- QueryInterface: function(iid)
- {
- if (!iid.equals(nsIProtocolHandler) &&
- !iid.equals(nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- },
-
- scheme: kSCHEME,
- defaultPort: -1,
- protocolFlags: nsIProtocolHandler.URI_NORELATIVE |
- nsIProtocolHandler.URI_NOAUTH,
-
- allowPort: function(port, scheme)
- {
- return false;
- },
-
- newURI: function(spec, charset, baseURI)
- {
- const nsIStandardURL = Components.interfaces.nsIStandardURL;
- var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(nsIStandardURL);
- uri.init(nsIStandardURL.URLTYPE_STANDARD, 80, spec, charset, baseURI);
-
- return uri.QueryInterface(Components.interfaces.nsIURI);
-
- },
-
- newChannel: function(aURI)
- {
- /*The protocol has been called, therefore we want to enable tor, wait for it to activate return the new channel with the scheme of http.*/
- var ios = Components.classes[kIOSERVICE_CONTRACTID].getService(nsIIOService);
- var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- var prefs = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- var tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
- var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator);
- var chrome = wm.getMostRecentWindow("navigator:browser");
- if (!ios.allowPort(aURI.port, aURI.scheme))
- throw Components.results.NS_ERROR_FAILURE;
-
- if (!tor_enabled)
- {
- var result = prompt.confirm(null, "Allow Tor toggle?", "Do you want to enable Tor and navigate to " + aURI.spec + "?");
- if (!result)
- throw Components.results.NS_ERROR_UNEXPECTED;
- chrome.torbutton_enable_tor(true);
- }
-
- //if tor is turned on then, else we should throw exception of some sort.
- tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
- if (!tor_enabled)
- throw Components.results.NS_ERROR_UNEXPECTED;
- else
- {
- aURI.scheme = "http";
- return ios.newChannelFromURI(aURI);
- }
- },
-}
-
-var ProtocolFactory = new Object();
-
-ProtocolFactory.createInstance = function (outer, iid)
-{
- if (outer != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
-
- if (!iid.equals(nsIProtocolHandler) &&
- !iid.equals(nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
-
- return new Protocol();
-}
-
-
-/**
- * JS XPCOM component registration goop:
- *
- * We set ourselves up to observe the xpcom-startup category. This provides
- * us with a starting point.
- */
-
-var TestModule = new Object();
-
-TestModule.registerSelf = function (compMgr, fileSpec, location, type)
-{
- compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compMgr.registerFactoryLocation(kPROTOCOL_CID,
- kPROTOCOL_NAME,
- kPROTOCOL_CONTRACTID,
- fileSpec,
- location,
- type);
-}
-
-TestModule.getClassObject = function (compMgr, cid, iid)
-{
- if (!cid.equals(kPROTOCOL_CID))
- throw Components.results.NS_ERROR_NO_INTERFACE;
-
- if (!iid.equals(Components.interfaces.nsIFactory))
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
-
- return ProtocolFactory;
-}
-
-TestModule.canUnload = function (compMgr)
-{
- return true;
-}
-
-function NSGetModule(compMgr, fileSpec)
-{
- return TestModule;
-}
-
+// Test protocol related
+const kSCHEME = "tor";
+const kPROTOCOL_NAME = "tor";
+const kPROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + kSCHEME;
+const kPROTOCOL_CID = Components.ID("52183e20-4d4b-11de-8a39-0800200c9a66");
+
+// Mozilla defined
+const kSIMPLEURI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
+const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
+const nsISupports = Components.interfaces.nsISupports;
+const nsIIOService = Components.interfaces.nsIIOService;
+const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;
+const nsIURI = Components.interfaces.nsIURI;
+
+function Protocol()
+{
+}
+
+Protocol.prototype =
+{
+ QueryInterface: function(iid)
+ {
+ if (!iid.equals(nsIProtocolHandler) &&
+ !iid.equals(nsISupports))
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ return this;
+ },
+
+ scheme: kSCHEME,
+ defaultPort: -1,
+ protocolFlags: nsIProtocolHandler.URI_NORELATIVE |
+ nsIProtocolHandler.URI_NOAUTH,
+
+ allowPort: function(port, scheme)
+ {
+ return false;
+ },
+
+ newURI: function(spec, charset, baseURI)
+ {
+ const nsIStandardURL = Components.interfaces.nsIStandardURL;
+ var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(nsIStandardURL);
+ uri.init(nsIStandardURL.URLTYPE_STANDARD, 80, spec, charset, baseURI);
+
+ return uri.QueryInterface(Components.interfaces.nsIURI);
+
+ },
+
+ newChannel: function(aURI)
+ {
+ /*The protocol has been called, therefore we want to enable tor, wait for it to activate return the new channel with the scheme of http.*/
+ var ios = Components.classes[kIOSERVICE_CONTRACTID].getService(nsIIOService);
+ var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Components.interfaces.nsIPromptService);
+ var prefs = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefBranch);
+ var tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
+ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator);
+ var chrome = wm.getMostRecentWindow("navigator:browser");
+ if (!ios.allowPort(aURI.port, aURI.scheme))
+ throw Components.results.NS_ERROR_FAILURE;
+
+ if (!tor_enabled)
+ {
+ var result = prompt.confirm(null, "Allow Tor toggle?", "Do you want to enable Tor and navigate to " + aURI.spec + "?");
+ if (!result)
+ throw Components.results.NS_ERROR_UNEXPECTED;
+ chrome.torbutton_enable_tor(true);
+ }
+
+ //if tor is turned on then, else we should throw exception of some sort.
+ tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
+ if (!tor_enabled)
+ throw Components.results.NS_ERROR_UNEXPECTED;
+ else
+ {
+ aURI.scheme = "http";
+ return ios.newChannelFromURI(aURI);
+ }
+ },
+}
+
+var ProtocolFactory = new Object();
+
+ProtocolFactory.createInstance = function (outer, iid)
+{
+ if (outer != null)
+ throw Components.results.NS_ERROR_NO_AGGREGATION;
+
+ if (!iid.equals(nsIProtocolHandler) &&
+ !iid.equals(nsISupports))
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+
+ return new Protocol();
+}
+
+
+/**
+ * JS XPCOM component registration goop:
+ *
+ * We set ourselves up to observe the xpcom-startup category. This provides
+ * us with a starting point.
+ */
+
+var TestModule = new Object();
+
+TestModule.registerSelf = function (compMgr, fileSpec, location, type)
+{
+ compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+ compMgr.registerFactoryLocation(kPROTOCOL_CID,
+ kPROTOCOL_NAME,
+ kPROTOCOL_CONTRACTID,
+ fileSpec,
+ location,
+ type);
+}
+
+TestModule.getClassObject = function (compMgr, cid, iid)
+{
+ if (!cid.equals(kPROTOCOL_CID))
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+
+ if (!iid.equals(Components.interfaces.nsIFactory))
+ throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+
+ return ProtocolFactory;
+}
+
+TestModule.canUnload = function (compMgr)
+{
+ return true;
+}
+
+function NSGetModule(compMgr, fileSpec)
+{
+ return TestModule;
+}
+
diff --git a/src/components/torRefSpoofer.js b/src/components/torRefSpoofer.js
index 13c2269..dcf0dfc 100644
--- a/src/components/torRefSpoofer.js
+++ b/src/components/torRefSpoofer.js
@@ -1,154 +1,154 @@
-function LOG(text)
-{
- var logger = Components.classes["@torproject.org/torbutton-logger;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
- logger.log("RefSpoof " + text);
- /*var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- prompt.alert(null, "debug", text);
- */
-}
-
-
-
-var refObserver = {
- observe: function(subject, topic, data)
- {
- if (topic == "http-on-modify-request") {
- //LOG("----------------------------> (" + subject + ") mod request");
- var prefs = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- var tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
-
- if (!tor_enabled)
- return;
-
- subject.QueryInterface(Components.interfaces.nsIHttpChannel);
- this.onModifyRequest(subject);
- return;
- }
- if (topic == "app-startup") {
- //LOG("----------------------------> app-startup");
- var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
- os.addObserver(this, "http-on-modify-request", false);
- return;
- }
- },
- onModifyRequest: function(oHttpChannel)
- {
- var prefs = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- var fake_refresh = prefs.getBoolPref("extensions.torbutton.fakerefresh");
- var spoofmode = prefs.getIntPref("extensions.torbutton.refererspoof");
- try {
- oHttpChannel.QueryInterface(Components.interfaces.nsIChannel);
- var requestURI = oHttpChannel.URI;
-
-
- switch(spoofmode)
- {
- //no spoof, should give the regular referer (not recommended)
- case 0:
- return;
- //spoof document root
- case 1:
- var path = requestURI.path.substr(0,requestURI.path.lastIndexOf("/")+1);
- this.adjustRef(oHttpChannel, requestURI.scheme + "://" + requestURI.host + path);
- break;
- //spoof domain
- case 2:
- this.adjustRef(oHttpChannel, requestURI.scheme + "://" + requestURI.host);
- break;
- //spoof no referer
- case 3:
- this.adjustRef(oHttpChannel, "");
- break;
- case 4:
- this.adjustRef(oHttpChannel, prefs.getCharPref("extensions.torbutton.customref"));
- break;
- }
- if (fake_refresh)
- oHttpChannel.setRequestHeader("If-Modified-Since","Sat, 29 Oct 1989 19:43:31 GMT",false);
- //this will make the server think it is a refresh
-
-
- } catch (ex) {
- LOG("onModifyRequest: " + ex);
- }
- },
- adjustRef: function(oChannel, sRef)
- {
- try {
- if (oChannel.referrer)
- {
- oChannel.referrer.spec = sRef;
- oChannel.setRequestHeader("Referer", sRef, false);
- }
- return true;
- }
- catch (ex) {
- LOG("adjustRef: " + ex);
- }
- return false;
- },
- QueryInterface: function(iid)
- {
- if (!iid.equals(Components.interfaces.nsISupports) &&
- !iid.equals(Components.interfaces.nsIObserver) &&
- !iid.equals(Components.interfaces.nsISupportsWeakReference))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- }
-};
-
-var myModule = {
-
- myCID: Components.ID("65be2be0-ceb4-44c2-91a5-9c75c53430bf"),
- myProgID: "@torproject.org/torRefSpoofer;1",
- myName: "RefSpoofComp",
- registerSelf: function (compMgr, fileSpec, location, type) {
- var compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compMgr.registerFactoryLocation(this.myCID,this.myName,this.myProgID,fileSpec,location,type);
- //LOG("----------------------------> registerSelf");
- var catMgr = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
- catMgr.addCategoryEntry("app-startup", this.myName, this.myProgID, true, true);
- },
-
- getClassObject: function (compMgr, cid, iid) {
- //LOG("----------------------------> getClassObject");
- return this.myFactory;
- },
-
- canUnload: function(compMgr) {
- return true;
- },
-
- unregisterSelf: function(compMgr, fileSpec, location) {
- // Remove the auto-startup
- compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compMgr.unregisterFactoryLocation(this.myCID, fileSpec);
- var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
- catMan.deleteCategoryEntry("app-startup", this.myProgID, true);
- },
-
- getClassObject: function(compMgr, cid, iid) {
- if (!cid.equals(this.myCID))
- throw Components.results.NS_ERROR_FACTORY_NOT_REGISTERED;
- if (!iid.equals(Components.interfaces.nsIFactory))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this.myFactory;
- },
-
- myFactory: {
- // Implement nsIFactory
- createInstance: function(outer, iid)
- {
- if (outer != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- return refObserver.QueryInterface(iid);
- }
- }
-};
-
-function NSGetModule(compMgr, fileSpec) {
- return myModule;
-}
+function LOG(text)
+{
+ var logger = Components.classes["@torproject.org/torbutton-logger;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
+ logger.log("RefSpoof " + text);
+ /*var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Components.interfaces.nsIPromptService);
+ prompt.alert(null, "debug", text);
+ */
+}
+
+
+
+var refObserver = {
+ observe: function(subject, topic, data)
+ {
+ if (topic == "http-on-modify-request") {
+ //LOG("----------------------------> (" + subject + ") mod request");
+ var prefs = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefBranch);
+ var tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
+
+ if (!tor_enabled)
+ return;
+
+ subject.QueryInterface(Components.interfaces.nsIHttpChannel);
+ this.onModifyRequest(subject);
+ return;
+ }
+ if (topic == "app-startup") {
+ //LOG("----------------------------> app-startup");
+ var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
+ os.addObserver(this, "http-on-modify-request", false);
+ return;
+ }
+ },
+ onModifyRequest: function(oHttpChannel)
+ {
+ var prefs = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefBranch);
+ var fake_refresh = prefs.getBoolPref("extensions.torbutton.fakerefresh");
+ var spoofmode = prefs.getIntPref("extensions.torbutton.refererspoof");
+ try {
+ oHttpChannel.QueryInterface(Components.interfaces.nsIChannel);
+ var requestURI = oHttpChannel.URI;
+
+
+ switch(spoofmode)
+ {
+ //no spoof, should give the regular referer (not recommended)
+ case 0:
+ return;
+ //spoof document root
+ case 1:
+ var path = requestURI.path.substr(0,requestURI.path.lastIndexOf("/")+1);
+ this.adjustRef(oHttpChannel, requestURI.scheme + "://" + requestURI.host + path);
+ break;
+ //spoof domain
+ case 2:
+ this.adjustRef(oHttpChannel, requestURI.scheme + "://" + requestURI.host);
+ break;
+ //spoof no referer
+ case 3:
+ this.adjustRef(oHttpChannel, "");
+ break;
+ case 4:
+ this.adjustRef(oHttpChannel, prefs.getCharPref("extensions.torbutton.customref"));
+ break;
+ }
+ if (fake_refresh)
+ oHttpChannel.setRequestHeader("If-Modified-Since","Sat, 29 Oct 1989 19:43:31 GMT",false);
+ //this will make the server think it is a refresh
+
+
+ } catch (ex) {
+ LOG("onModifyRequest: " + ex);
+ }
+ },
+ adjustRef: function(oChannel, sRef)
+ {
+ try {
+ if (oChannel.referrer)
+ {
+ oChannel.referrer.spec = sRef;
+ oChannel.setRequestHeader("Referer", sRef, false);
+ }
+ return true;
+ }
+ catch (ex) {
+ LOG("adjustRef: " + ex);
+ }
+ return false;
+ },
+ QueryInterface: function(iid)
+ {
+ if (!iid.equals(Components.interfaces.nsISupports) &&
+ !iid.equals(Components.interfaces.nsIObserver) &&
+ !iid.equals(Components.interfaces.nsISupportsWeakReference))
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ return this;
+ }
+};
+
+var myModule = {
+
+ myCID: Components.ID("65be2be0-ceb4-44c2-91a5-9c75c53430bf"),
+ myProgID: "@torproject.org/torRefSpoofer;1",
+ myName: "RefSpoofComp",
+ registerSelf: function (compMgr, fileSpec, location, type) {
+ var compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+ compMgr.registerFactoryLocation(this.myCID,this.myName,this.myProgID,fileSpec,location,type);
+ //LOG("----------------------------> registerSelf");
+ var catMgr = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
+ catMgr.addCategoryEntry("app-startup", this.myName, this.myProgID, true, true);
+ },
+
+ getClassObject: function (compMgr, cid, iid) {
+ //LOG("----------------------------> getClassObject");
+ return this.myFactory;
+ },
+
+ canUnload: function(compMgr) {
+ return true;
+ },
+
+ unregisterSelf: function(compMgr, fileSpec, location) {
+ // Remove the auto-startup
+ compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+ compMgr.unregisterFactoryLocation(this.myCID, fileSpec);
+ var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
+ catMan.deleteCategoryEntry("app-startup", this.myProgID, true);
+ },
+
+ getClassObject: function(compMgr, cid, iid) {
+ if (!cid.equals(this.myCID))
+ throw Components.results.NS_ERROR_FACTORY_NOT_REGISTERED;
+ if (!iid.equals(Components.interfaces.nsIFactory))
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ return this.myFactory;
+ },
+
+ myFactory: {
+ // Implement nsIFactory
+ createInstance: function(outer, iid)
+ {
+ if (outer != null)
+ throw Components.results.NS_ERROR_NO_AGGREGATION;
+ return refObserver.QueryInterface(iid);
+ }
+ }
+};
+
+function NSGetModule(compMgr, fileSpec) {
+ return myModule;
+}
diff --git a/src/components/tors-protocol.js b/src/components/tors-protocol.js
index bfced4c..1470301 100644
--- a/src/components/tors-protocol.js
+++ b/src/components/tors-protocol.js
@@ -1,139 +1,139 @@
-// Test protocol related
-const kSCHEME = "tors";
-const kPROTOCOL_NAME = "tors";
-const kPROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + kSCHEME;
-const kPROTOCOL_CID = Components.ID("a5a4bc50-5e8d-11de-8a39-0800200c9a66");
-
-// Mozilla defined
-const kSIMPLEURI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
-const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
-const nsISupports = Components.interfaces.nsISupports;
-const nsIIOService = Components.interfaces.nsIIOService;
-const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;
-const nsIURI = Components.interfaces.nsIURI;
-
-function Protocol()
-{
-}
-
-Protocol.prototype =
-{
- QueryInterface: function(iid)
- {
- if (!iid.equals(nsIProtocolHandler) &&
- !iid.equals(nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- },
-
- scheme: kSCHEME,
- defaultPort: -1,
- protocolFlags: nsIProtocolHandler.URI_NORELATIVE |
- nsIProtocolHandler.URI_NOAUTH,
-
- allowPort: function(port, scheme)
- {
- return false;
- },
-
- newURI: function(spec, charset, baseURI)
- {
- const nsIStandardURL = Components.interfaces.nsIStandardURL;
- var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(nsIStandardURL);
- uri.init(nsIStandardURL.URLTYPE_STANDARD, 433, spec, charset, baseURI);
-
- return uri.QueryInterface(Components.interfaces.nsIURI);
-
- },
-
- newChannel: function(aURI)
- {
- /*The protocol has been called, therefore we want to enable tor, wait for it to activate return the new channel with the scheme of https.*/
- var ios = Components.classes[kIOSERVICE_CONTRACTID].getService(nsIIOService);
- var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- var prefs = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- var tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
- var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator);
- var chrome = wm.getMostRecentWindow("navigator:browser");
- if (!ios.allowPort(aURI.port, aURI.scheme))
- throw Components.results.NS_ERROR_FAILURE;
-
- if (!tor_enabled)
- {
- var result = prompt.confirm(null, "Allow Tor toggle?", "Do you want to enable Tor and navigate to " + aURI.spec + "?");
- if (!result)
- throw Components.results.NS_ERROR_UNEXPECTED;
- chrome.torbutton_enable_tor(true);
- }
-
- //if tor is turned on then, else we should throw exception of some sort.
- tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
- if (!tor_enabled)
- throw Components.results.NS_ERROR_UNEXPECTED;
- else
- {
- aURI.scheme = "https";
- return ios.newChannelFromURI(aURI);
- }
- },
-}
-
-var ProtocolFactory = new Object();
-
-ProtocolFactory.createInstance = function (outer, iid)
-{
- if (outer != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
-
- if (!iid.equals(nsIProtocolHandler) &&
- !iid.equals(nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
-
- return new Protocol();
-}
-
-
-/**
- * JS XPCOM component registration goop:
- *
- * We set ourselves up to observe the xpcom-startup category. This provides
- * us with a starting point.
- */
-
-var TestModule = new Object();
-
-TestModule.registerSelf = function (compMgr, fileSpec, location, type)
-{
- compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compMgr.registerFactoryLocation(kPROTOCOL_CID,
- kPROTOCOL_NAME,
- kPROTOCOL_CONTRACTID,
- fileSpec,
- location,
- type);
-}
-
-TestModule.getClassObject = function (compMgr, cid, iid)
-{
- if (!cid.equals(kPROTOCOL_CID))
- throw Components.results.NS_ERROR_NO_INTERFACE;
-
- if (!iid.equals(Components.interfaces.nsIFactory))
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
-
- return ProtocolFactory;
-}
-
-TestModule.canUnload = function (compMgr)
-{
- return true;
-}
-
-function NSGetModule(compMgr, fileSpec)
-{
- return TestModule;
-}
-
+// Test protocol related
+const kSCHEME = "tors";
+const kPROTOCOL_NAME = "tors";
+const kPROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + kSCHEME;
+const kPROTOCOL_CID = Components.ID("a5a4bc50-5e8d-11de-8a39-0800200c9a66");
+
+// Mozilla defined
+const kSIMPLEURI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
+const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
+const nsISupports = Components.interfaces.nsISupports;
+const nsIIOService = Components.interfaces.nsIIOService;
+const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;
+const nsIURI = Components.interfaces.nsIURI;
+
+function Protocol()
+{
+}
+
+Protocol.prototype =
+{
+ QueryInterface: function(iid)
+ {
+ if (!iid.equals(nsIProtocolHandler) &&
+ !iid.equals(nsISupports))
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ return this;
+ },
+
+ scheme: kSCHEME,
+ defaultPort: -1,
+ protocolFlags: nsIProtocolHandler.URI_NORELATIVE |
+ nsIProtocolHandler.URI_NOAUTH,
+
+ allowPort: function(port, scheme)
+ {
+ return false;
+ },
+
+ newURI: function(spec, charset, baseURI)
+ {
+ const nsIStandardURL = Components.interfaces.nsIStandardURL;
+ var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(nsIStandardURL);
+ uri.init(nsIStandardURL.URLTYPE_STANDARD, 433, spec, charset, baseURI);
+
+ return uri.QueryInterface(Components.interfaces.nsIURI);
+
+ },
+
+ newChannel: function(aURI)
+ {
+ /*The protocol has been called, therefore we want to enable tor, wait for it to activate return the new channel with the scheme of https.*/
+ var ios = Components.classes[kIOSERVICE_CONTRACTID].getService(nsIIOService);
+ var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Components.interfaces.nsIPromptService);
+ var prefs = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefBranch);
+ var tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
+ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator);
+ var chrome = wm.getMostRecentWindow("navigator:browser");
+ if (!ios.allowPort(aURI.port, aURI.scheme))
+ throw Components.results.NS_ERROR_FAILURE;
+
+ if (!tor_enabled)
+ {
+ var result = prompt.confirm(null, "Allow Tor toggle?", "Do you want to enable Tor and navigate to " + aURI.spec + "?");
+ if (!result)
+ throw Components.results.NS_ERROR_UNEXPECTED;
+ chrome.torbutton_enable_tor(true);
+ }
+
+ //if tor is turned on then, else we should throw exception of some sort.
+ tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
+ if (!tor_enabled)
+ throw Components.results.NS_ERROR_UNEXPECTED;
+ else
+ {
+ aURI.scheme = "https";
+ return ios.newChannelFromURI(aURI);
+ }
+ },
+}
+
+var ProtocolFactory = new Object();
+
+ProtocolFactory.createInstance = function (outer, iid)
+{
+ if (outer != null)
+ throw Components.results.NS_ERROR_NO_AGGREGATION;
+
+ if (!iid.equals(nsIProtocolHandler) &&
+ !iid.equals(nsISupports))
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+
+ return new Protocol();
+}
+
+
+/**
+ * JS XPCOM component registration goop:
+ *
+ * We set ourselves up to observe the xpcom-startup category. This provides
+ * us with a starting point.
+ */
+
+var TestModule = new Object();
+
+TestModule.registerSelf = function (compMgr, fileSpec, location, type)
+{
+ compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+ compMgr.registerFactoryLocation(kPROTOCOL_CID,
+ kPROTOCOL_NAME,
+ kPROTOCOL_CONTRACTID,
+ fileSpec,
+ location,
+ type);
+}
+
+TestModule.getClassObject = function (compMgr, cid, iid)
+{
+ if (!cid.equals(kPROTOCOL_CID))
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+
+ if (!iid.equals(Components.interfaces.nsIFactory))
+ throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+
+ return ProtocolFactory;
+}
+
+TestModule.canUnload = function (compMgr)
+{
+ return true;
+}
+
+function NSGetModule(compMgr, fileSpec)
+{
+ return TestModule;
+}
+
--
1.5.6.5
More information about the tor-commits
mailing list