1+ // XXX: This service uses prefs we have not set defaults for yet.
2+ // We should begin including a defaults/preferences/preferences.js
13const Ci = Components . interfaces ;
24const Cc = Components . classes ;
35const Cr = Components . results ;
46
7+ const CI = Components . interfaces ;
8+ const CC = Components . classes ;
9+ const CR = Components . results ;
10+
11+ // Log levels
12+ VERB = 1 ;
13+ DBUG = 2 ;
14+ INFO = 3 ;
15+ NOTE = 4 ;
16+ WARN = 5 ;
17+
18+ // XXX: We should make the _observatory_prefs tree relative.
19+ LLVAR = "extensions.https_everywhere.LogLevel" ;
20+
521Components . utils . import ( "resource://gre/modules/XPCOMUtils.jsm" ) ;
622const OS = Cc [ '@mozilla.org/observer-service;1' ] . getService ( CI . nsIObserverService ) ;
723
@@ -10,24 +26,43 @@ const SERVICE_ID=Components.ID("{0f9ab521-986d-4ad8-9c1f-6934e195c15c}");
1026const SERVICE_NAME = "Anonymously Submits strange SSL certificates to EFF." ;
1127
1228function SSLObservatory ( ) {
13- // XXX: Check prefs and save to boolean values
14- // 1. use_tor
15- // 2. use_nontor
16- // 3. submit_private_certs
29+ this . prefs = Components . classes [ "@mozilla.org/preferences-service;1" ]
30+ . getService ( Components . interfaces . nsIPrefBranch ) ;
31+
32+ dump ( "Dump: Loaded observatory component\n" ) ;
33+ this . log ( DBUG , "Loaded observatory component!" ) ;
1734
1835 try {
1936 // Check for torbutton
20- this . logger = Components . classes [ "@torproject.org/torbutton-logger;1" ]
37+ this . tor_logger = Components . classes [ "@torproject.org/torbutton-logger;1" ]
2138 . getService ( Components . interfaces . nsISupports ) . wrappedJSObject ;
39+
2240 this . torbutton_installed = true ;
23- // XXX: We probably want to run the full test of tor functionality here
24- // but that involves a https request to check.torproject.org, so we shouldn't
25- // do it every time... Or maybe we should?
41+
42+ // If the user wants to use their Tor proxy, grab it automatically
43+ if ( this . prefs . getBoolPref ( "extensions.https_everywhere._prefs.use_tor_proxy" ) ) {
44+ // extract torbutton proxy settings
45+ this . proxy_port = this . prefs . getIntPref ( "extensions.torbutton.https_port" ) ;
46+ this . proxy_host = this . prefs . getCharPref ( "extensions.torbutton.https_proxy" ) ;
47+ this . proxy_type = "http" ;
48+
49+ if ( ! this . proxy_port ) {
50+ this . proxy_host = this . prefs . getCharPref ( "extensions.torbutton.socks_host" ) ;
51+ this . proxy_port = this . prefs . getIntPref ( "extensions.torbutton.socks_port" ) ;
52+ this . proxy_type = "socks" ;
53+ }
54+ }
2655 } catch ( e ) {
2756 dump ( "Torbutton not found\n" ) ;
2857 this . torbutton_installed = false ;
2958 }
3059
60+ if ( this . prefs . getBoolPref ( "extensions.https_everywhere._observatory_prefs.use_custom_proxy" ) ) {
61+ this . proxy_host = this . prefs . getCharPref ( "extensions.https_everywhere._observatory_prefs.proxy_host" ) ;
62+ this . proxy_port = this . prefs . getIntPref ( "extensions.https_everywhere._observatory_prefs.proxy_port" ) ;
63+ this . proxy_type = this . prefs . getCharPref ( "extensions.https_everywhere._observatory_prefs.proxy_type" ) ;
64+ }
65+
3166 // Generate nonce for request
3267 this . csrf_nonce = "#" + Math . random ( ) . toString ( ) + Math . random ( ) . toString ( ) ;
3368
@@ -59,7 +94,7 @@ SSLObservatory.prototype = {
5994 getSSLCert : function ( channel ) {
6095 try {
6196 // Do we have a valid channel argument?
62- if ( ! channel instanceof Ci . nsIChannel ) {
97+ if ( ! channel instanceof Ci . nsIChannel ) {
6398 return null ;
6499 }
65100 var secInfo = channel . securityInfo ;
@@ -82,26 +117,75 @@ SSLObservatory.prototype = {
82117 } ,
83118
84119 observe : function ( subject , topic , data ) {
120+ if ( this . torbutton_installed ) {
121+ // Allow Tor users to choose if they want to submit
122+ // during tor and/or non-tor
123+ if ( ! this . prefs . getBoolPref ( "extensions.https_everywhere._observatory_prefs.submit_during_tor" )
124+ && this . prefs . getBoolPref ( "extensions.torbutton.tor_enabled" ) ) {
125+ return ;
126+ }
127+ if ( ! this . prefs . getBoolPref ( "extensions.https_everywhere._observatory_prefs.submit_during_nontor" )
128+ && ! this . prefs . getBoolPref ( "extensions.torbutton.tor_enabled" ) ) {
129+ return ;
130+ }
131+ }
132+
85133 if ( "http-on-examine-response" == topic ) {
86134 aSubject . QueryInterface ( Ci . nsIHttpChannel ) ;
87- cert = this . getSSLCert ( aSubject ) ;
135+ var certchain = this . getSSLCert ( aSubject ) ;
136+ if ( certchain ) {
137+ for ( cert in certchain . getChain ( ) ) {
138+ var fp = cert . md5Fingerprint + ":" + cert . sha1Fingerprint ;
139+ var der = cert . getRawDER ( ) ;
140+
141+ dump ( der ) ;
142+
143+ // XXX: Use an async XMLHTTPRequest:
144+ // XXX: Ask to submit cert
145+ // XXX: AS number??
146+ }
147+ }
88148 }
89149 } ,
90150
91- applyFilter ( aProxyService , aURI , aProxy ) {
151+ applyFilter : function ( aProxyService , aURI , aProxy ) {
92152 // XXX: This check may be wrong. Have not tested it
93153 if ( aURI . spec . search ( "^https://observatory.eff.org/submit.py" ) != - 1 &&
94- aURI . path . search ( this . nonce + "$" ) != - 1 ) {
95- // This is for us!
96- // XXX: Send it through tor by creating an nsIProxy instance
154+ aURI . path . search ( this . csrf_nonce + "$" ) != - 1 ) {
155+
156+ // Send it through tor by creating an nsIProxy instance
97157 // for the torbutton proxy settings.
158+ var proxy = this . pps . newProxyInfo ( this . proxy_type , this . proxy_host ,
159+ this . proxy_port ,
160+ Ci . nsIProxyInfo . TRANSPARENT_PROXY_RESOLVES_HOST ,
161+ 0xFFFFFFFF , null ) ;
162+
163+ // TODO: Use new identity or socks u/p to ensure we get a unique
164+ // tor circuit for this request
165+ return proxy ;
98166 }
167+ return aProxy ;
99168 } ,
100169
101170 // [optional] an array of categories to register this component in.
102171 // Hack to cause us to get instantiate early
103172 _xpcom_categories : [ { category : "profile-after-change" } , ] ,
104173
174+
175+ log : function ( level , str ) {
176+ var econsole = Components . classes [ "@mozilla.org/consoleservice;1" ]
177+ . getService ( Components . interfaces . nsIConsoleService ) ;
178+ try {
179+ var threshold = this . prefs . getIntPref ( LLVAR ) ;
180+ } catch ( e ) {
181+ econsole . logStringMessage ( "SSL Observatory: Failed to read about:config LogLevel" ) ;
182+ threshold = WARN ;
183+ }
184+ if ( level >= threshold ) {
185+ dump ( str + "\n" ) ;
186+ econsole . logStringMessage ( "SSL Observatory: " + str ) ;
187+ }
188+ }
105189} ;
106190
107191/**
0 commit comments