Skip to content

Commit 599f270

Browse files
committed
Add HTTP Nowhere mode for 4.0 branch
1 parent fc764d0 commit 599f270

File tree

8 files changed

+130
-36
lines changed

8 files changed

+130
-36
lines changed

src/chrome/content/code/HTTPS.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,23 @@ const HTTPS = {
3030
httpsForcedExceptions: null,
3131
httpsRewrite: null,
3232

33-
replaceChannel: function(applicable_list, channel) {
33+
replaceChannel: function(applicable_list, channel, httpNowhereEnabled) {
3434
var blob = HTTPSRules.rewrittenURI(applicable_list, channel.URI.clone());
35-
if (null == blob) return false; // no rewrite
35+
if (null === blob) {
36+
// Abort insecure requests when HTTP Nowhere is on
37+
if (httpNowhereEnabled && channel.URI.schemeIs("http")) {
38+
IOUtil.abort(channel);
39+
}
40+
return false; // no rewrite
41+
}
3642
var uri = blob.newuri;
3743
if (!uri) this.log(WARN, "OH NO BAD ARGH\nARGH");
3844

45+
// Abort downgrading if HTTP Nowhere is on
46+
if (httpNowhereEnabled && uri.schemeIs("http")) {
47+
IOUtil.abort(channel);
48+
}
49+
3950
var c2 = channel.QueryInterface(CI.nsIHttpChannel);
4051
this.log(DBUG, channel.URI.spec+": Redirection limit is " + c2.redirectionLimit);
4152
// XXX This used to be (c2.redirectionLimit == 1), but that's very

src/chrome/content/toolbar_button.js

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ const CI = Components.interfaces;
1010
const CC = Components.classes;
1111

1212
// LOG LEVELS ---
13-
VERB=1;
14-
DBUG=2;
15-
INFO=3;
16-
NOTE=4;
17-
WARN=5;
13+
let VERB=1;
14+
let DBUG=2;
15+
let INFO=3;
16+
let NOTE=4;
17+
let WARN=5;
1818

19-
HTTPSEverywhere = CC["@eff.org/https-everywhere;1"]
19+
let HTTPSEverywhere = CC["@eff.org/https-everywhere;1"]
2020
.getService(Components.interfaces.nsISupports)
2121
.wrappedJSObject;
2222

@@ -37,6 +37,11 @@ httpsEverywhere.toolbarButton = {
3737
*/
3838
COUNTER_PREF: "extensions.https_everywhere.show_counter",
3939

40+
/**
41+
* Name of preference for whether HTTP Nowhere is on.
42+
*/
43+
HTTP_NOWHERE_PREF: "extensions.https_everywhere.http_nowhere.enabled",
44+
4045
/**
4146
* Used to determine if a hint has been previously shown.
4247
* TODO: Probably extraneous, look into removing
@@ -53,14 +58,22 @@ httpsEverywhere.toolbarButton = {
5358

5459
var tb = httpsEverywhere.toolbarButton;
5560

56-
// make sure icon is proper color during init
57-
tb.changeIcon();
58-
5961
// make sure the checkbox for showing counter is properly set
6062
var showCounter = tb.shouldShowCounter();
6163
var counterItem = document.getElementById('https-everywhere-counter-item');
6264
counterItem.setAttribute('checked', showCounter ? 'true' : 'false');
6365

66+
// make sure UI for HTTP Nowhere mode is properly set
67+
var httpNowhereItem = document.getElementById('http-nowhere-item');
68+
var showHttpNowhere = tb.shouldShowHttpNowhere();
69+
var toolbarbutton = document.getElementById('https-everywhere-button');
70+
httpNowhereItem.setAttribute('checked', showHttpNowhere ? 'true' : 'false');
71+
toolbarbutton.setAttribute('http_nowhere',
72+
showHttpNowhere ? 'true' : 'false');
73+
74+
// make sure UI is set depending on whether HTTPS-E is enabled
75+
toggleEnabledUI();
76+
6477
// show ruleset counter when a tab is changed
6578
tb.updateRulesetsApplied();
6679
gBrowser.tabContainer.addEventListener(
@@ -119,20 +132,6 @@ httpsEverywhere.toolbarButton = {
119132
gBrowser.removeEventListener("DOMContentLoaded", tb.handleShowHint, true);
120133
},
121134

122-
/**
123-
* Changes HTTPS Everywhere toolbar icon based on whether HTTPS Everywhere
124-
* is enabled or disabled.
125-
*/
126-
changeIcon: function() {
127-
var enabled = HTTPSEverywhere.prefs.getBoolPref("globalEnabled");
128-
129-
var toolbarbutton = document.getElementById('https-everywhere-button');
130-
if (enabled) {
131-
toolbarbutton.setAttribute('status', 'enabled');
132-
} else {
133-
toolbarbutton.setAttribute('status', 'disabled');
134-
}
135-
},
136135

137136
/**
138137
* Update the rulesets applied counter for the current tab.
@@ -186,6 +185,17 @@ httpsEverywhere.toolbarButton = {
186185
return !prefExists || sp.getBoolPref(tb.COUNTER_PREF);
187186
},
188187

188+
/**
189+
* Gets whether to show HTTP Nowhere UI.
190+
*
191+
* @return {boolean}
192+
*/
193+
shouldShowHttpNowhere: function() {
194+
var tb = httpsEverywhere.toolbarButton;
195+
var sp = Services.prefs;
196+
return sp.getBoolPref(tb.HTTP_NOWHERE_PREF);
197+
},
198+
189199
/**
190200
* Toggles the user's preference for displaying the rulesets applied counter
191201
* and updates the UI.
@@ -198,8 +208,22 @@ httpsEverywhere.toolbarButton = {
198208
sp.setBoolPref(tb.COUNTER_PREF, !showCounter);
199209

200210
tb.updateRulesetsApplied();
201-
}
211+
},
212+
213+
/**
214+
* Toggles whether HTTP Nowhere mode is active, updates the toolbar icon.
215+
*/
216+
toggleHttpNowhere: function() {
217+
HTTPSEverywhere.toggleHttpNowhere();
218+
var tb = httpsEverywhere.toolbarButton;
219+
var showHttpNowhere = tb.shouldShowHttpNowhere();
202220

221+
// Change icon color to red if HTTP nowhere is enabled
222+
var toolbarbutton = document.getElementById('https-everywhere-button');
223+
toolbarbutton.setAttribute('http_nowhere',
224+
showHttpNowhere ? 'true' : 'false');
225+
reload_window();
226+
}
203227
};
204228

205229
function https_everywhere_load() {
@@ -307,17 +331,29 @@ function reload_window() {
307331
HTTPSEverywhere.log(WARN,"failed to get webNav");
308332
return null;
309333
}
310-
// This choice of flags comes from NoScript's quickReload function; not sure
311-
// if it's optimal
312-
webNav.reload(webNav.LOAD_FLAGS_CHARSET_CHANGE);
334+
// The choice of LOAD_FLAGS_CHARSET_CHANGE comes from NoScript's quickReload
335+
// function; not sure if it's optimal
336+
let flags = webNav.LOAD_FLAGS_BYPASS_CACHE & webNav.LOAD_FLAGS_CHARSET_CHANGE;
337+
webNav.reload(flags);
313338
}
314339

315340
function toggleEnabledState(){
316341
HTTPSEverywhere.toggleEnabledState();
317-
reload_window();
342+
reload_window();
343+
toggleEnabledUI();
344+
}
345+
346+
function toggleEnabledUI() {
347+
// Add/remove menu items depending on whether HTTPS-E is enabled
348+
var items = document.querySelectorAll(".hide-on-disable");
349+
var enabled = HTTPSEverywhere.prefs.getBoolPref("globalEnabled");
350+
for (let i = 0; i < items.length; i++) {
351+
items[i].hidden = !enabled;
352+
}
318353

319354
// Change icon depending on enabled state
320-
httpsEverywhere.toolbarButton.changeIcon();
355+
var toolbarbutton = document.getElementById('https-everywhere-button');
356+
toolbarbutton.setAttribute('status', enabled ? 'enabled' : 'disabled');
321357
}
322358

323359
function open_in_tab(url) {

src/chrome/content/toolbar_button.xul

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@
4242

4343
<menupopup id="https-everywhere-context" onpopupshowing="show_applicable_list(this)">
4444
<!-- entries will be written here by ApplicableList.populate_menu() -->
45-
<menuseparator />
45+
<menuseparator class="hide-on-disable"/>
46+
<menuitem type="checkbox" id="http-nowhere-item" label="Block all HTTP requests"
47+
oncommand="httpsEverywhere.toolbarButton.toggleHttpNowhere()" class="hide-on-disable"/>
48+
<menuseparator class="hide-on-disable"/>
4649
<menuitem type="checkbox" id="https-everywhere-counter-item" label="&https-everywhere.menu.showCounter;"
47-
oncommand="httpsEverywhere.toolbarButton.toggleShowCounter()" />
50+
oncommand="httpsEverywhere.toolbarButton.toggleShowCounter()" class="hide-on-disable"/>
4851
<menuseparator />
4952
<menuitem label="&https-everywhere.menu.observatory;" command="https-everywhere-menuitem-observatory" />
5053
<menuitem label="&https-everywhere.menu.about;" command="https-everywhere-menuitem-about" />
724 Bytes
Loading
1.21 KB
Loading

src/chrome/skin/https-everywhere.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ toolbar #https-everywhere-button > .https-everywhere-button {
1616
}
1717

1818
/* Use CSS attribute selector for changing icon */
19+
#https-everywhere-button[http_nowhere="true"] > .https-everywhere-button {
20+
list-style-image: url("chrome://https-everywhere/skin/https-everywhere-24-red.png");
21+
}
1922
#https-everywhere-button[status="disabled"] > .https-everywhere-button {
2023
list-style-image: url("chrome://https-everywhere/skin/https-everywhere-24-gray.png");
2124
}
22-
25+
toolbar[iconsize="small"] #https-everywhere-button[http_nowhere="true"] > .https-everywhere-button {
26+
list-style-image: url("chrome://https-everywhere/skin/https-everywhere-16-red.png");
27+
}
2328
toolbar[iconsize="small"] #https-everywhere-button[status="disabled"] > .https-everywhere-button {
2429
list-style-image: url("chrome://https-everywhere/skin/https-everywhere-16-gray.png");
2530
}

src/components/https-everywhere.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ function HTTPSEverywhere() {
191191
this.prefs = this.get_prefs();
192192
this.rule_toggle_prefs = this.get_prefs(PREFBRANCH_RULE_TOGGLE);
193193

194+
this.httpNowhereEnabled = this.prefs.getBoolPref("http_nowhere.enabled");
194195
this.isMobile = this.doMobileCheck();
195196

196197
// We need to use observers instead of categories for FF3.0 for these:
@@ -456,7 +457,7 @@ HTTPSEverywhere.prototype = {
456457
else this.log(NOTE,"Failed to indicate breakage in content menu");
457458
return;
458459
}
459-
HTTPS.replaceChannel(lst, channel);
460+
HTTPS.replaceChannel(lst, channel, this.httpNowhereEnabled);
460461
} else if (topic == "http-on-examine-response") {
461462
this.log(DBUG, "Got http-on-examine-response @ "+ (channel.URI ? channel.URI.spec : '') );
462463
HTTPS.handleSecureCookies(channel);
@@ -624,7 +625,7 @@ HTTPSEverywhere.prototype = {
624625
return;
625626
}
626627
var alist = this.juggleApplicableListsDuringRedirection(oldChannel, newChannel);
627-
HTTPS.replaceChannel(alist,newChannel);
628+
HTTPS.replaceChannel(alist,newChannel, this.httpNowhereEnabled);
628629
},
629630

630631
juggleApplicableListsDuringRedirection: function(oldChannel, newChannel) {
@@ -784,6 +785,40 @@ HTTPSEverywhere.prototype = {
784785
this.log(WARN, "Couldn't add observers: " + e);
785786
}
786787
}
788+
},
789+
790+
toggleHttpNowhere: function() {
791+
let prefService = Services.prefs;
792+
let thisBranch =
793+
prefService.getBranch("extensions.https_everywhere.http_nowhere.");
794+
let securityBranch = prefService.getBranch("security.");
795+
796+
// Whether cert is treated as invalid when OCSP connection fails
797+
let OCSP_REQUIRED = "OCSP.require";
798+
799+
// Branch to save original settings
800+
let ORIG_OCSP_REQUIRED = "orig.ocsp.required";
801+
802+
803+
if (thisBranch.getBoolPref("enabled")) {
804+
// Restore original OCSP settings. TODO: What if user manually edits
805+
// these while HTTP Nowhere is enabled?
806+
let origOcspRequired = thisBranch.getBoolPref(ORIG_OCSP_REQUIRED);
807+
securityBranch.setBoolPref(OCSP_REQUIRED, origOcspRequired);
808+
809+
thisBranch.setBoolPref("enabled", false);
810+
this.httpNowhereEnabled = false;
811+
} else {
812+
// Save original OCSP settings in HTTP Nowhere preferences branch.
813+
let origOcspRequired = securityBranch.getBoolPref(OCSP_REQUIRED);
814+
thisBranch.setBoolPref(ORIG_OCSP_REQUIRED, origOcspRequired);
815+
816+
// Disable OCSP enforcement
817+
securityBranch.setBoolPref(OCSP_REQUIRED, false);
818+
819+
thisBranch.setBoolPref("enabled", true);
820+
this.httpNowhereEnabled = true;
821+
}
787822
}
788823
};
789824

src/defaults/preferences/preferences.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pref("extensions.https_everywhere.performance_tests", false);
1515
// enable rulesets that trigger mixed content blocking
1616
pref("extensions.https_everywhere.enable_mixed_rulesets", false);
1717

18+
// HTTP Nowhere preferences
19+
pref("extensions.https_everywhere.http_nowhere.enabled", false);
20+
pref("extensions.https_everywhere.http_nowhere.orig.ocsp.required", false);
21+
1822

1923
// SSl Observatory preferences
2024
pref("extensions.https_everywhere._observatory.enabled",false);

0 commit comments

Comments
 (0)