From 92efdc513a46af869cf2fac6a03d02e0a17b5855 Mon Sep 17 00:00:00 2001 From: Kathy Brade Date: Tue, 12 Nov 2019 16:11:05 -0500 Subject: [PATCH] Bug 30237: Add v3 onion services client authentication prompt When Tor informs the browser that client authentication is needed, temporarily load about:blank instead of about:neterror and prompt for the user's key. If a correctly formatted key is entered, use Tor's ONION_CLIENT_AUTH_ADD control port command to add the key (via Torbutton's control port module) and reload the page. If the user cancels the prompt, display the standard about:neterror "Unable to connect" page. This requires a small change to browser/actors/NetErrorChild.jsm to account for the fact that the docShell no longer has the failedChannel information. The failedChannel is used to extract TLS-related error info, which is not applicable in the case of a canceled .onion authentication prompt. Add a leaveOpen option to PopupNotifications.show so we can display error messages within the popup notification doorhanger without closing the prompt. Add support for onion services strings to the TorStrings module. Add support for Tor extended SOCKS errors (Tor proposal 304) to the socket transport and SOCKS layers. Improved display of all of these errors will be implemented as part of bug 30025. squash! Bug 30237: Add v3 onion services client authentication prompt Also fixes bug 19757: Add a "Remember this key" checkbox to the client auth prompt. Add an "Onion Services Authentication" section within the about:preferences "Privacy & Security section" to allow viewing and removal of v3 onion client auth keys that have been stored on disk. squash! Bug 30237: Add v3 onion services client authentication prompt Also fixes bug 19251: use enhanced error pages for onion service errors. --- browser/actors/NetErrorChild.jsm | 12 +- browser/base/content/browser.js | 10 + browser/base/content/browser.xul | 3 + browser/base/content/tab-content.js | 5 + browser/components/moz.build | 1 + .../content/authNotificationIcon.inc.xul | 6 + .../onionservices/content/authPopup.inc.xul | 16 + .../onionservices/content/authPreferences.css | 20 ++ .../content/authPreferences.inc.xul | 20 ++ .../onionservices/content/authPreferences.js | 63 ++++ .../onionservices/content/authPrompt.js | 312 ++++++++++++++++++ .../onionservices/content/authUtil.jsm | 47 +++ .../content/netError/browser.svg | 3 + .../content/netError/network.svg | 3 + .../content/netError/onionNetError.css | 65 ++++ .../content/netError/onionNetError.jsm | 253 ++++++++++++++ .../content/netError/onionsite.svg | 7 + .../onionservices/content/onionservices.css | 69 ++++ .../onionservices/content/savedKeysDialog.js | 259 +++++++++++++++ .../onionservices/content/savedKeysDialog.xul | 42 +++ browser/components/onionservices/jar.mn | 9 + browser/components/onionservices/moz.build | 1 + .../preferences/in-content/preferences.xul | 1 + .../preferences/in-content/privacy.js | 7 + .../preferences/in-content/privacy.xul | 2 + browser/modules/TorStrings.jsm | 135 +++++++- .../themes/shared/notification-icons.inc.css | 3 + docshell/base/nsDocShell.cpp | 81 +++++ dom/ipc/BrowserParent.cpp | 23 ++ dom/ipc/BrowserParent.h | 3 + dom/ipc/PBrowser.ipdl | 9 + js/xpconnect/src/xpc.msg | 10 + netwerk/base/nsSocketTransport2.cpp | 6 + netwerk/socket/nsSOCKSIOLayer.cpp | 41 +++ toolkit/modules/PopupNotifications.jsm | 6 + xpcom/base/ErrorList.py | 22 ++ 36 files changed, 1569 insertions(+), 6 deletions(-) create mode 100644 browser/components/onionservices/content/authNotificationIcon.inc.xul create mode 100644 browser/components/onionservices/content/authPopup.inc.xul create mode 100644 browser/components/onionservices/content/authPreferences.css create mode 100644 browser/components/onionservices/content/authPreferences.inc.xul create mode 100644 browser/components/onionservices/content/authPreferences.js create mode 100644 browser/components/onionservices/content/authPrompt.js create mode 100644 browser/components/onionservices/content/authUtil.jsm create mode 100644 browser/components/onionservices/content/netError/browser.svg create mode 100644 browser/components/onionservices/content/netError/network.svg create mode 100644 browser/components/onionservices/content/netError/onionNetError.css create mode 100644 browser/components/onionservices/content/netError/onionNetError.jsm create mode 100644 browser/components/onionservices/content/netError/onionsite.svg create mode 100644 browser/components/onionservices/content/onionservices.css create mode 100644 browser/components/onionservices/content/savedKeysDialog.js create mode 100644 browser/components/onionservices/content/savedKeysDialog.xul create mode 100644 browser/components/onionservices/jar.mn create mode 100644 browser/components/onionservices/moz.build diff --git a/browser/actors/NetErrorChild.jsm b/browser/actors/NetErrorChild.jsm index dcdc77a7010b0..66f9c7c8a9880 100644 --- a/browser/actors/NetErrorChild.jsm +++ b/browser/actors/NetErrorChild.jsm @@ -23,6 +23,11 @@ ChromeUtils.defineModuleGetter( "WebNavigationFrames", "resource://gre/modules/WebNavigationFrames.jsm" ); +ChromeUtils.defineModuleGetter( + this, + "OnionServicesAboutNetError", + "chrome://browser/content/onionservices/netError/onionNetError.jsm" +); XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]); @@ -849,7 +854,7 @@ class NetErrorChild extends ActorChild { } if (this.isAboutNetError(win.document)) { let docShell = win.docShell; - if (docShell) { + if (docShell && docShell.failedChannel) { let { securityInfo } = docShell.failedChannel; // We don't have a securityInfo when this is for example a DNS error. if (securityInfo) { @@ -863,6 +868,11 @@ class NetErrorChild extends ActorChild { let learnMoreLink = win.document.getElementById("learnMoreLink"); let baseURL = Services.urlFormatter.formatURLPref("app.support.baseURL"); learnMoreLink.setAttribute("href", baseURL + "connection-not-secure"); + + // Initialize the onion services error module, which customizes the + // content on the error page when an onion service error is being + // displayed. + OnionServicesAboutNetError.initPage(win.document); } let automatic = Services.prefs.getBoolPref( diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 0141aedc0f171..3f9bf006f5626 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -214,6 +214,11 @@ XPCOMUtils.defineLazyScriptGetter( ["SecurityLevelButton"], "chrome://browser/content/securitylevel/securityLevel.js" ); +XPCOMUtils.defineLazyScriptGetter( + this, + ["OnionAuthPrompt"], + "chrome://browser/content/onionservices/authPrompt.js" +); XPCOMUtils.defineLazyScriptGetter( this, "gEditItemOverlay", @@ -1855,6 +1860,9 @@ var gBrowserInit = { // Init the SecuritySettingsButton SecurityLevelButton.init(); + // Init the OnionAuthPrompt + OnionAuthPrompt.init(); + // Certain kinds of automigration rely on this notification to complete // their tasks BEFORE the browser window is shown. SessionStore uses it to // restore tabs into windows AFTER important parts like gMultiProcessBrowser @@ -2492,6 +2500,8 @@ var gBrowserInit = { SecurityLevelButton.uninit(); + OnionAuthPrompt.uninit(); + gAccessibilityServiceIndicator.uninit(); AccessibilityRefreshBlocker.uninit(); diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 8e47fd36fb751..d2f72eea8edb9 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -33,6 +33,7 @@ + # All DTD information is stored in a separate file so that it can be shared by # hiddenWindow.xul. @@ -623,6 +624,7 @@ #include ../../components/controlcenter/content/protectionsPanel.inc.xul #include ../../components/downloads/content/downloadsPanel.inc.xul #include ../../components/securitylevel/content/securityLevelPanel.inc.xul +#include ../../components/onionservices/content/authPopup.inc.xul #include browser-allTabsMenu.inc.xul @@ -922,6 +924,7 @@ tooltiptext="&urlbar.indexedDBNotificationAnchor.tooltip;"/> +#include ../../components/onionservices/content/authNotificationIcon.inc.xul diff --git a/browser/base/content/tab-content.js b/browser/base/content/tab-content.js index 57f3925a1ca5a..14311242f5d1b 100644 --- a/browser/base/content/tab-content.js +++ b/browser/base/content/tab-content.js @@ -19,6 +19,9 @@ ChromeUtils.defineModuleGetter( "BrowserUtils", "resource://gre/modules/BrowserUtils.jsm" ); +var { OnionAuthUtil } = ChromeUtils.import( + "chrome://browser/content/onionservices/authUtil.jsm" +); var { ActorManagerChild } = ChromeUtils.import( "resource://gre/modules/ActorManagerChild.jsm" @@ -118,3 +121,5 @@ addEventListener("MozAfterPaint", function onFirstNonBlankPaint() { removeEventListener("MozAfterPaint", onFirstNonBlankPaint); sendAsyncMessage("Browser:FirstNonBlankPaint"); }); + +OnionAuthUtil.addCancelMessageListener(this, docShell); diff --git a/browser/components/moz.build b/browser/components/moz.build index c0c9629cac653..3331a51fbe88e 100644 --- a/browser/components/moz.build +++ b/browser/components/moz.build @@ -42,6 +42,7 @@ DIRS += [ 'library', 'migration', 'newtab', + 'onionservices', 'originattributes', 'places', 'pocket', diff --git a/browser/components/onionservices/content/authNotificationIcon.inc.xul b/browser/components/onionservices/content/authNotificationIcon.inc.xul new file mode 100644 index 0000000000000..91274d6127392 --- /dev/null +++ b/browser/components/onionservices/content/authNotificationIcon.inc.xul @@ -0,0 +1,6 @@ +# Copyright (c) 2020, The Tor Project, Inc. + + diff --git a/browser/components/onionservices/content/authPopup.inc.xul b/browser/components/onionservices/content/authPopup.inc.xul new file mode 100644 index 0000000000000..bd0ec3aa0b007 --- /dev/null +++ b/browser/components/onionservices/content/authPopup.inc.xul @@ -0,0 +1,16 @@ +# Copyright (c) 2020, The Tor Project, Inc. + + diff --git a/browser/components/onionservices/content/authPreferences.css b/browser/components/onionservices/content/authPreferences.css new file mode 100644 index 0000000000000..b3fb79b26ddce --- /dev/null +++ b/browser/components/onionservices/content/authPreferences.css @@ -0,0 +1,20 @@ +/* Copyright (c) 2020, The Tor Project, Inc. */ + +#torOnionServiceKeys-overview-container { + margin-right: 30px; +} + +#onionservices-savedkeys-tree treechildren::-moz-tree-cell-text { + font-size: 80%; +} + +#onionservices-savedkeys-errorContainer { + margin-top: 4px; + min-height: 3em; +} + +#onionservices-savedkeys-errorIcon { + margin-right: 4px; + list-style-image: url("chrome://browser/skin/warning.svg"); + visibility: hidden; +} diff --git a/browser/components/onionservices/content/authPreferences.inc.xul b/browser/components/onionservices/content/authPreferences.inc.xul new file mode 100644 index 0000000000000..0b6ce98efa318 --- /dev/null +++ b/browser/components/onionservices/content/authPreferences.inc.xul @@ -0,0 +1,20 @@ +# Copyright (c) 2020, The Tor Project, Inc. + +