Skip to content

Commit f6dee17

Browse files
author
Mike Perry
committed
Bug 6541: Delay SSL Observatory popup until successful Tor test.
Also tweak the dialog strings a tiny bit.
1 parent 6ceb565 commit f6dee17

4 files changed

Lines changed: 48 additions & 11 deletions

File tree

‎src/chrome/content/observatory-xul.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function observatory_prefs_init(doc) {
4040

4141
// But if the user hasn't turned the observatory on,
4242
// the default should be the maximally sensible one
43-
var torbutton_avail = ssl_observatory.torbutton_installed;
43+
var torbutton_avail = ssl_observatory.proxy_test_successful;
4444
if (!enabled) {
4545
set_obs_anon(torbutton_avail);
4646
obs_how.selectedItem = (torbutton_avail) ? anon_radio : nonanon_radio;
@@ -71,8 +71,8 @@ function set_observatory_configurability(enabled) {
7171
var ui_elements = document.querySelectorAll(".ssl-obs-conf");
7272
for (var i =0; i < ui_elements.length; i++)
7373
ui_elements[i].disabled = !enabled;
74-
// the "use tor" option can't be ungreyed unless torbutton is installed
75-
if (ssl_observatory.torbutton_installed == false) {
74+
// the "use tor" option can't be ungreyed unless tor is available
75+
if (ssl_observatory.proxy_test_successful == false) {
7676
var tor_opt = document.getElementById("ssl-obs-anon")
7777
tor_opt.disabled = true;
7878
tor_opt.label = tor_opt.getAttribute("alt_label");

‎src/chrome/locale/en/ssl-observatory.dtd‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ intrusive corporate network:">
3434

3535
<!ENTITY ssl-observatory.prefs.anonymous "Check certificates using Tor for anonymity">
3636
<!ENTITY ssl-observatory.prefs.anonymous_unavailable
37-
"Check certificates using Tor for anonymity (requires Torbutton)">
37+
"Check certificates using Tor for anonymity (requires Tor)">
3838
<!ENTITY ssl-observatory.prefs.anonymous_tooltip
39-
"This option requires Tor and Torbutton to be installed">
39+
"This option requires Tor to be installed and running">
4040

4141
<!ENTITY ssl-observatory.prefs.asn
4242
'When you see a new certificate, tell the Observatory which ISP you are connected to'>

‎src/components/https-everywhere.js‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,17 @@ HTTPSEverywhere.prototype = {
503503
// again.
504504
var shown = ssl_observatory.myGetBoolPref("popup_shown");
505505
var enabled = ssl_observatory.myGetBoolPref("enabled");
506-
if (!shown && !enabled)
507-
this.chrome_opener("chrome://https-everywhere/content/observatory-popup.xul");
506+
if (!shown && !enabled) {
507+
var that = this;
508+
ssl_observatory.registerProxyTestNotification(function(result) {
509+
if (result) {
510+
that.log(INFO, "Got positivie proxy test. Displaying observatory popup.");
511+
that.chrome_opener("chrome://https-everywhere/content/observatory-popup.xul");
512+
} else {
513+
that.log(INFO, "Got negative proxy test. Not displaying observatory popup.");
514+
}
515+
});
516+
}
508517
}
509518
return;
510519
},

‎src/components/ssl-observatory.js‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ function SSLObservatory() {
6767
} catch(e) {
6868
this.torbutton_installed = false;
6969
}
70-
this.proxy_test_successful = false;
70+
71+
/* The proxy test result starts out null until the test is attempted.
72+
* This is for UI notification purposes */
73+
this.proxy_test_successful = null;
74+
this.proxy_test_callback = null;
7175

7276
this.public_roots = root_ca_hashes;
7377

@@ -650,13 +654,24 @@ SSLObservatory.prototype = {
650654
"","chrome,centerscreen", warningObj, win, cert);
651655
},
652656

657+
registerProxyTestNotification: function(callback_fcn) {
658+
if (this.proxy_test_successful != null) {
659+
/* Proxy test already ran. Callback immediately. */
660+
callback_fcn(this.proxy_test_successful);
661+
this.proxy_test_callback = null;
662+
return;
663+
} else {
664+
this.proxy_test_callback = callback_fcn;
665+
}
666+
},
667+
653668
testProxySettings: function() {
654669
/* Plan:
655670
* 1. Launch an async XMLHttpRequest to check.tp.o with magic nonce
656671
* 3. Filter the nonce in protocolProxyFilter to use proxy settings
657672
* 4. Async result function sets test result status based on check.tp.o
658673
*/
659-
this.proxy_test_successful = false;
674+
this.proxy_test_successful = null;
660675

661676
try {
662677
var req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
@@ -668,6 +683,8 @@ SSLObservatory.prototype = {
668683
var that = this; // Scope gymnastics for async callback
669684
req.onreadystatechange = function (oEvent) {
670685
if (req.readyState === 4) {
686+
that.proxy_test_successful = false;
687+
671688
if(req.status == 200) {
672689
if(!req.responseXML) {
673690
that.log(INFO, "Tor check failed: No XML returned by check service.");
@@ -689,14 +706,25 @@ SSLObservatory.prototype = {
689706
} else {
690707
that.log(INFO, "Tor check failed: HTTP Error "+req.status);
691708
}
709+
710+
/* Notify the UI of the test result */
711+
if (that.proxy_test_callback) {
712+
that.proxy_test_callback(that.proxy_test_successful);
713+
that.proxy_test_callback = null;
714+
}
692715
}
693716
};
694717
req.send(null);
695718
} catch(e) {
719+
this.proxy_test_successful = false;
696720
if(e.result == 0x80004005) { // NS_ERROR_FAILURE
697-
that.log(INFO, "Tor check failed: Proxy not running.");
721+
this.log(INFO, "Tor check failed: Proxy not running.");
722+
}
723+
this.log(INFO, "Tor check failed: Internal error: "+e);
724+
if (this.proxy_test_callback) {
725+
this.proxy_test_callback(this.proxy_test_successful);
726+
this.proxy_test_callback = null;
698727
}
699-
that.log(INFO, "Tor check failed: Internal error: "+e);
700728
}
701729
},
702730

0 commit comments

Comments
 (0)