[tor-commits] [meek/master] Prototype of making an HTTPS request with domain fronting.

dcf at torproject.org dcf at torproject.org
Wed Apr 9 05:56:56 UTC 2014


commit d966f770d89ff850efa319d6f9d1f4327e00a89c
Author: David Fifield <david at bamsoftware.com>
Date:   Sun Mar 9 22:49:11 2014 -0700

    Prototype of making an HTTPS request with domain fronting.
---
 firefox/chrome/content/main.js  |   48 +++++++++++++++++++++++++++++++++++++++
 firefox/chrome/content/main.xul |    1 +
 2 files changed, 49 insertions(+)

diff --git a/firefox/chrome/content/main.js b/firefox/chrome/content/main.js
new file mode 100644
index 0000000..6cb10d0
--- /dev/null
+++ b/firefox/chrome/content/main.js
@@ -0,0 +1,48 @@
+var FRONT_URL = "https://www.google.com/";
+var HOST = "meek-reflect.appspot.com";
+
+// Create a "direct" nsIProxyInfo that bypasses the default proxy.
+// https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIProtocolProxyService
+var pps = Components.classes["@mozilla.org/network/protocol-proxy-service;1"]
+	.getService(Components.interfaces.nsIProtocolProxyService);
+// https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIProxyInfo
+var proxy = pps.newProxyInfo("direct", "", 0, 0, 0xffffffff, null);
+
+// https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIIOService
+var ioService = Components.classes["@mozilla.org/network/io-service;1"]
+	.getService(Components.interfaces.nsIIOService);
+var httpProtocolHandler = ioService.getProtocolHandler("http")
+	.QueryInterface(Components.interfaces.nsIHttpProtocolHandler);
+var uri = ioService.newURI(FRONT_URL, null, null);
+// Construct an HTTP channel with the proxy bypass.
+// https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIHttpChannel
+var channel = httpProtocolHandler.newProxiedChannel(uri, proxy, 0, null)
+	.QueryInterface(Components.interfaces.nsIHttpChannel);
+// Set the host we really want.
+channel.setRequestHeader("Host", HOST, false);
+channel.redirectionLimit = 0;
+// https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIUploadChannel
+// channel.requestMethod = "POST";
+
+var listener = new StreamListener();
+channel.asyncOpen(listener, null);
+
+// https://developer.mozilla.org/en-US/docs/Creating_Sandboxed_HTTP_Connections
+function StreamListener() {
+	this.onStartRequest = function(aRequest, aContext) {
+		console.log("onStartRequest\n");
+		dump("onStartRequest\n");
+	};
+	this.onStopRequest = function(aRequest, aContext, aStatus) {
+		dump("onStopRequest\n");
+	};
+	this.onDataAvailable = function(aRequest, aContext, aStream, aSourceOffset, aLength) {
+		dump("onDataAvailable\n");
+		var a = new Uint8Array(aLength);
+		var input = Components.classes["@mozilla.org/binaryinputstream;1"]
+			.createInstance(Components.interfaces.nsIBinaryInputStream);
+		input.setInputStream(aStream);
+		input.readByteArray(aLength, a);
+		dump(aLength + ":" + a + "\n");
+	};
+}
diff --git a/firefox/chrome/content/main.xul b/firefox/chrome/content/main.xul
index 1afd5fe..c93a89e 100644
--- a/firefox/chrome/content/main.xul
+++ b/firefox/chrome/content/main.xul
@@ -1,4 +1,5 @@
 <?xml version="1.0"?>
 
 <overlay id="main" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+	<script src="chrome://meek-http-helper/content/main.js"></script>
 </overlay>





More information about the tor-commits mailing list