Bug 1547096 - Remove use of nsIBadCertListener2 in comm-central. r=mkmelin
authorKai Engert <kaie@kuix.de>
Wed, 23 Oct 2019 11:38:41 +0200
changeset 37357 dee2511f17fb354c6cfcc06b0c0ec2a2066d5f24
parent 37356 80a194afbb0f2c034e190e5db73ba3b3d0badd18
child 37358 3834c3b9390008ae060ae886534cc4e3e8347fe9
push id396
push userclokep@gmail.com
push dateMon, 06 Jan 2020 23:11:57 +0000
reviewersmkmelin
bugs1547096
Bug 1547096 - Remove use of nsIBadCertListener2 in comm-central. r=mkmelin
calendar/base/modules/utils/calProviderUtils.jsm
chat/modules/socket.jsm
mail/base/content/mailWindow.js
mail/components/accountcreation/content/MyBadCertHandler.js
mail/components/accountcreation/content/emailWizard.js
mail/components/accountcreation/content/emailWizard.xul
mail/components/accountcreation/content/guessConfig.js
mail/components/accountcreation/content/verifyConfig.js
mail/components/accountcreation/jar.mn
mail/components/newmailaccount/content/uriListener.js
--- a/calendar/base/modules/utils/calProviderUtils.jsm
+++ b/calendar/base/modules/utils/calProviderUtils.jsm
@@ -154,37 +154,29 @@ var calprovider = {
       // Support Auth Prompt Interfaces
       if (aIID.equals(Ci.nsIAuthPrompt2)) {
         if (!this.calAuthPrompt) {
           this.calAuthPrompt = new cal.auth.Prompt();
         }
         return this.calAuthPrompt;
       } else if (aIID.equals(Ci.nsIAuthPromptProvider) || aIID.equals(Ci.nsIPrompt)) {
         return Services.ww.getNewPrompter(null);
-      } else if (aIID.equals(Ci.nsIBadCertListener2)) {
-        if (!this.badCertHandler) {
-          this.badCertHandler = new cal.provider.BadCertHandler(this);
-        }
-        return this.badCertHandler;
       } else {
         Components.returnCode = e;
       }
     }
     return null;
   },
 
+  // TODO: Add new error handling that uses this code. See bug 1547096.
   /**
    * Bad Certificate Handler for Network Requests. Shows the Network Exception
    * Dialog if a certificate Problem occurs.
    */
   BadCertHandler: class {
-    QueryInterface() {
-      return ChromeUtils.generateQI([Ci.nsIBadCertListener2]);
-    }
-
     constructor(thisProvider) {
       this.thisProvider = thisProvider;
       this.timer = null;
     }
 
     notifyCertProblem(socketInfo, secInfo, targetSite) {
       // Unfortunately we can't pass js objects using the window watcher, so
       // we'll just take the first available calendar window. We also need to
--- a/chat/modules/socket.jsm
+++ b/chat/modules/socket.jsm
@@ -2,18 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Combines a lot of the Mozilla networking interfaces into a sane interface for
  * simple(r) use of sockets code.
  *
  * This implements nsIServerSocketListener, nsIStreamListener,
- * nsIRequestObserver, nsITransportEventSink, nsIBadCertListener2,
- * and nsIProtocolProxyCallback.
+ * nsIRequestObserver, nsITransportEventSink and nsIProtocolProxyCallback.
  *
  * This uses nsIRoutedSocketTransportService, nsIServerSocket, nsIThreadManager,
  * nsIBinaryInputStream, nsIScriptableInputStream, nsIInputStreamPump,
  * nsIProxyService, nsIProxyInfo.
  *
  * High-level methods:
  *   connect(<originHost>, <originPort>[, ("starttls" | "ssl" | "udp")
  *           [, <proxy>[, <host>, <port>]]])
@@ -545,26 +544,16 @@ var Socket = {
         );
         return;
       }
     }
     this.onConnectionClosed();
   },
 
   /*
-   * nsIBadCertListener2
-   */
-  // Called when there's an error, return true to suppress the modal alert.
-  // Whatever this function returns, NSS will close the connection.
-  notifyCertProblem(aSocketInfo, aSecInfo, aTargetSite) {
-    this.secInfo = aSecInfo;
-    return true;
-  },
-
-  /*
    * nsITransportEventSink methods
    */
   onTransportStatus(aTransport, aStatus, aProgress, aProgressmax) {
     // Don't send status change notifications after the socket has been closed.
     // The event sink can't be removed after opening the transport, so we can't
     // do better than adding a null check here.
     if (!this.transport) {
       return;
@@ -621,18 +610,17 @@ var Socket = {
       this.proxy
     );
 
     this._openStreams();
   },
 
   // Open the incoming and outgoing streams, and init the nsISocketTransport.
   _openStreams() {
-    // Security notification callbacks (must support nsIBadCertListener2
-    // for SSL connections, and possibly other interfaces).
+    // TODO: is this still required after bug 1547096?
     this.transport.securityCallbacks = this;
 
     // Set the timeouts for the nsISocketTransport for both a connect event and
     // a read/write. Only set them if the user has provided them.
     if (this.connectTimeout) {
       this.transport.setTimeout(
         Ci.nsISocketTransport.TIMEOUT_CONNECT,
         this.connectTimeout
@@ -727,16 +715,15 @@ var Socket = {
   // should be sent on the socket.
   sendPing() {},
 
   /* QueryInterface and nsIInterfaceRequestor implementations */
   QueryInterface: ChromeUtils.generateQI([
     "nsIStreamListener",
     "nsIRequestObserver",
     "nsITransportEventSink",
-    "nsIBadCertListener2",
     "nsIProtocolProxyCallback",
   ]),
 
   getInterface(iid) {
     return this.QueryInterface(iid);
   },
 };
--- a/mail/base/content/mailWindow.js
+++ b/mail/base/content/mailWindow.js
@@ -205,18 +205,16 @@ function CreateMailWindowGlobals() {
 
   // Create message window object
   // eslint-disable-next-line no-global-assign
   msgWindow = Cc["@mozilla.org/messenger/msgwindow;1"].createInstance(
     Ci.nsIMsgWindow
   );
 
   accountManager = MailServices.accounts;
-
-  msgWindow.notificationCallbacks = new BadCertHandler();
 }
 
 function InitMsgWindow() {
   msgWindow.windowCommands = new nsMsgWindowCommands();
   // set the domWindow before setting the status feedback and header sink objects
   msgWindow.domWindow = window;
   msgWindow.statusFeedback = statusFeedback;
   msgWindow.msgHeaderSink = messageHeaderSink;
@@ -671,43 +669,17 @@ function OpenInboxForServer(server) {
 }
 
 /** Update state of zoom type (text vs. full) menu item. */
 function UpdateFullZoomMenu() {
   let cmdItem = document.getElementById("cmd_fullZoomToggle");
   cmdItem.setAttribute("checked", !ZoomManager.useFullZoom);
 }
 
-/**
- * This class implements nsIBadCertListener2.  Its job is to prevent "bad cert"
- * security dialogs from being shown to the user.  Currently it puts up the
- * cert override dialog, though we'd like to give the user more detailed
- * information in the future.
- */
-function BadCertHandler() {}
-
-BadCertHandler.prototype = {
-  // Suppress any certificate errors
-  notifyCertProblem(socketInfo, status, targetSite) {
-    setTimeout(InformUserOfCertError, 0, socketInfo, status, targetSite);
-    return true;
-  },
-
-  // nsIInterfaceRequestor
-  getInterface(iid) {
-    return this.QueryInterface(iid);
-  },
-
-  // nsISupports
-  QueryInterface: ChromeUtils.generateQI([
-    "nsIBadCertListener2",
-    "nsIInterfaceRequestor",
-  ]),
-};
-
+// TODO: Add new error handling that uses this code. See bug 1547096.
 function InformUserOfCertError(socketInfo, secInfo, targetSite) {
   let params = {
     exceptionAdded: false,
     securityInfo: secInfo,
     prefetchCert: true,
     location: targetSite,
   };
   window.openDialog(
deleted file mode 100644
--- a/mail/components/accountcreation/content/MyBadCertHandler.js
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/**
- * This class implements nsIBadCertListener.  It's job is to prevent "bad cert"
- * security dialogs from being shown to the user.  We call back to the
- * 'callback' object's method "processCertError" so that it can deal with it as
- * needed (in the case of autoconfig, setting up temporary overrides).
- */
-function BadCertHandler(callback) {
-  this._init(callback);
-}
-
-BadCertHandler.prototype = {
-  _init(callback) {
-    this._callback = callback;
-  },
-
-  // Suppress any certificate errors
-  notifyCertProblem(socketInfo, status, targetSite) {
-    return this._callback.processCertError(socketInfo, status, targetSite);
-  },
-
-  // nsIInterfaceRequestor
-  getInterface(iid) {
-    return this.QueryInterface(iid);
-  },
-
-  // nsISupports
-  QueryInterface: ChromeUtils.generateQI([
-    "nsIBadCertListener2",
-    "nsIInterfaceRequestor",
-  ]),
-};
--- a/mail/components/accountcreation/content/emailWizard.js
+++ b/mail/components/accountcreation/content/emailWizard.js
@@ -6,17 +6,16 @@
 /* import-globals-from ../../../../mailnews/base/prefs/content/accountUtils.js */
 /* import-globals-from accountConfig.js */
 /* import-globals-from createInBackend.js */
 /* import-globals-from emailWizard.js */
 /* import-globals-from exchangeAutoDiscover.js */
 /* import-globals-from fetchConfig.js */
 /* import-globals-from fetchhttp.js */
 /* import-globals-from guessConfig.js */
-/* import-globals-from MyBadCertHandler.js */
 /* import-globals-from readFromXML.js */
 /* import-globals-from sanitizeDatatypes.js */
 /* import-globals-from util.js */
 /* import-globals-from verifyConfig.js */
 
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { MailServices } = ChromeUtils.import(
   "resource:///modules/MailServices.jsm"
--- a/mail/components/accountcreation/content/emailWizard.xul
+++ b/mail/components/accountcreation/content/emailWizard.xul
@@ -43,17 +43,16 @@
   <script src="chrome://messenger/content/accountcreation/sanitizeDatatypes.js"/>
   <script src="chrome://messenger/content/accountcreation/fetchhttp.js"/>
   <script src="chrome://messenger/content/accountcreation/readFromXML.js"/>
   <script src="chrome://messenger/content/accountcreation/guessConfig.js"/>
   <script src="chrome://messenger/content/accountcreation/verifyConfig.js"/>
   <script src="chrome://messenger/content/accountcreation/fetchConfig.js"/>
   <script src="chrome://messenger/content/accountcreation/exchangeAutoDiscover.js"/>
   <script src="chrome://messenger/content/accountcreation/createInBackend.js"/>
-  <script src="chrome://messenger/content/accountcreation/MyBadCertHandler.js"/>
   <script src="chrome://messenger/content/accountUtils.js"/>
 
   <keyset id="mailKeys">
     <key keycode="VK_ESCAPE" oncommand="window.close();"/>
   </keyset>
 
   <vbox id="mainContainer" class="hub-container" flex="1">
 
--- a/mail/components/accountcreation/content/guessConfig.js
+++ b/mail/components/accountcreation/content/guessConfig.js
@@ -997,19 +997,18 @@ function protocolToString(type) {
     return "smtp";
   }
   throw new NotReached("unexpected protocol");
 }
 
 // ----------------------
 // SSL cert error handler
 
+// TODO: Add new error handling that uses this code. See bug 1547096.
 /**
- * Called by MyBadCertHandler.js, which called by PSM
- * to tell us about SSL certificate errors.
  * @param thisTry {HostTry}
  * @param logger {Log4Moz logger}
  */
 function SSLErrorHandler(thisTry, logger) {
   this._try = thisTry;
   this._log = logger;
   // _ gotCertError will be set to an error code (one of those defined in
   // nsICertOverrideService)
@@ -1173,21 +1172,17 @@ function SocketUtil(
     socketTypeName,
     hostname,
     port,
     proxy
   );
 
   transport.setTimeout(Ci.nsISocketTransport.TIMEOUT_CONNECT, timeout);
   transport.setTimeout(Ci.nsISocketTransport.TIMEOUT_READ_WRITE, timeout);
-  try {
-    transport.securityCallbacks = new BadCertHandler(sslErrorHandler);
-  } catch (e) {
-    _error(e);
-  }
+
   var outstream = transport.openOutputStream(0, 0, 0);
   var stream = transport.openInputStream(0, 0, 0);
   var instream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
     Ci.nsIScriptableInputStream
   );
   instream.init(stream);
 
   var dataListener = {
--- a/mail/components/accountcreation/content/verifyConfig.js
+++ b/mail/components/accountcreation/content/verifyConfig.js
@@ -198,23 +198,16 @@ function verifyLogon(
     gEmailWizardLogger.error("verifyLogon failed: " + e);
     throw e;
   } finally {
     // restore them
     msgWindow.notificationCallbacks = saveCallbacks;
   }
 }
 
-/**
- * The url listener also implements nsIBadCertListener2.  Its job is to prevent
- * "bad cert" security dialogs from being shown to the user.  Currently it puts
- * up the cert override dialog, though we'd like to give the user more detailed
- * information in the future.
- */
-
 function urlListener(
   config,
   server,
   alter,
   msgWindow,
   successCallback,
   errorCallback
 ) {
@@ -382,31 +375,17 @@ urlListener.prototype = {
         "chrome://messenger/locale/accountCreationModel.properties"
       ).GetStringFromName("cannot_login.error");
     }
     var ex = new Exception(msg);
     ex.code = code;
     this.mErrorCallback(ex);
   },
 
-  // Suppress any certificate errors
-  notifyCertProblem(socketInfo, status, targetSite) {
-    this.mCertError = true;
-    this._log.error("cert error");
-    let self = this;
-    setTimeout(function() {
-      try {
-        self.informUserOfCertError(socketInfo, status, targetSite);
-      } catch (e) {
-        logException(e);
-      }
-    }, 0);
-    return true;
-  },
-
+  // TODO: Add new error handling that uses this code. See bug 1547096.
   informUserOfCertError(socketInfo, secInfo, targetSite) {
     var params = {
       exceptionAdded: false,
       securityInfo: secInfo,
       prefetchCert: true,
       location: targetSite,
     };
     window.openDialog(
@@ -438,13 +417,12 @@ urlListener.prototype = {
 
   // nsIInterfaceRequestor
   getInterface(iid) {
     return this.QueryInterface(iid);
   },
 
   // nsISupports
   QueryInterface: ChromeUtils.generateQI([
-    "nsIBadCertListener2",
     "nsIInterfaceRequestor",
     "nsIUrlListener",
   ]),
 };
--- a/mail/components/accountcreation/jar.mn
+++ b/mail/components/accountcreation/jar.mn
@@ -6,13 +6,12 @@ messenger.jar:
   content/messenger/accountcreation/accountConfig.js      (content/accountConfig.js)
   content/messenger/accountcreation/createInBackend.js    (content/createInBackend.js)
   content/messenger/accountcreation/emailWizard.js        (content/emailWizard.js)
   content/messenger/accountcreation/emailWizard.xul       (content/emailWizard.xul)
   content/messenger/accountcreation/exchangeAutoDiscover.js        (content/exchangeAutoDiscover.js)
   content/messenger/accountcreation/fetchConfig.js        (content/fetchConfig.js)
   content/messenger/accountcreation/fetchhttp.js          (content/fetchhttp.js)
   content/messenger/accountcreation/guessConfig.js        (content/guessConfig.js)
-  content/messenger/accountcreation/MyBadCertHandler.js   (content/MyBadCertHandler.js)
   content/messenger/accountcreation/readFromXML.js        (content/readFromXML.js)
   content/messenger/accountcreation/sanitizeDatatypes.js  (content/sanitizeDatatypes.js)
   content/messenger/accountcreation/util.js               (content/util.js)
   content/messenger/accountcreation/verifyConfig.js       (content/verifyConfig.js)
--- a/mail/components/newmailaccount/content/uriListener.js
+++ b/mail/components/newmailaccount/content/uriListener.js
@@ -176,20 +176,16 @@ TracingListener.prototype = {
     Services.scriptloader.loadSubScript(
       "chrome://messenger/content/accountcreation/fetchConfig.js",
       accountCreationFuncs
     );
     Services.scriptloader.loadSubScript(
       "chrome://messenger/content/accountcreation/createInBackend.js",
       accountCreationFuncs
     );
-    Services.scriptloader.loadSubScript(
-      "chrome://messenger/content/accountcreation/MyBadCertHandler.js",
-      accountCreationFuncs
-    );
 
     let tabmail = document.getElementById("tabmail");
     let success = false;
     let account;
 
     try {
       // Attempt to construct the downloaded data into XML
       let data = this.chunks.join("");