From 7104607e1d89e0f39cbddc2167ead41b1bb274c7 Mon Sep 17 00:00:00 2001 From: "kaie@kuix.de" Date: Wed, 3 Oct 2007 04:47:26 -0700 Subject: [PATCH] Bug 327181, Improve error reporting for invalid-certificate errors (error page for https, or combined dialog) Code in mozilla/security/manager: r=rrelyea Code elsewhere: r=mconnor, sr=dveditz blocking1.9=mconnor --- .../src/nsMicrosummaryService.js | 22 +- browser/components/search/nsSearchService.js | 19 - .../browser/gtk/src/EmbedCertificates.cpp | 121 ---- embedding/browser/gtk/src/EmbedCertificates.h | 12 - extensions/metrics/src/nsMetricsService.cpp | 95 --- .../locales/en-US/chrome/pippki/pippki.dtd | 8 - .../en-US/chrome/pippki/pippki.properties | 16 +- .../pki/resources/content/certManager.js | 152 +++- .../pki/resources/content/deletecert.js | 42 +- .../pki/resources/content/newserver.xul | 91 --- .../resources/content/serverCertExpired.js | 92 --- security/manager/pki/src/nsNSSDialogs.h | 3 - security/manager/pki/src/nsPKIModule.cpp | 7 - security/manager/ssl/public/Makefile.in | 3 +- .../manager/ssl/public/nsIBadCertListener.idl | 155 ---- security/manager/ssl/public/nsICertTree.idl | 13 +- security/manager/ssl/public/nsISSLStatus.idl | 17 +- security/manager/ssl/src/Makefile.in | 3 + security/manager/ssl/src/nsCertTree.cpp | 663 +++++++++++++++--- security/manager/ssl/src/nsCertTree.h | 59 +- security/manager/ssl/src/nsNSSCallbacks.cpp | 109 +-- security/manager/ssl/src/nsNSSIOLayer.h | 8 - security/manager/ssl/src/nsNSSModule.cpp | 9 + toolkit/mozapps/shared/src/badCertHandler.js | 19 - xpinstall/src/nsXPInstallManager.cpp | 33 +- xpinstall/src/nsXPInstallManager.h | 6 +- 26 files changed, 806 insertions(+), 971 deletions(-) diff --git a/browser/components/microsummaries/src/nsMicrosummaryService.js b/browser/components/microsummaries/src/nsMicrosummaryService.js index a5d3bc6babe..8861e8d9fa8 100644 --- a/browser/components/microsummaries/src/nsMicrosummaryService.js +++ b/browser/components/microsummaries/src/nsMicrosummaryService.js @@ -1767,8 +1767,7 @@ MicrosummaryResource.prototype = { // and abort loads for bad SSL certs and HTTP authorization requests. // Interfaces this component implements. - interfaces: [Ci.nsIBadCertListener, - Ci.nsIAuthPromptProvider, + interfaces: [Ci.nsIAuthPromptProvider, Ci.nsIAuthPrompt, Ci.nsIPrompt, Ci.nsIProgressEventSink, @@ -1800,25 +1799,6 @@ MicrosummaryResource.prototype = { return this.QueryInterface(iid); }, - // nsIBadCertListener - - // Suppress UI and abort secure loads from servers with bad SSL certificates. - - confirmUnknownIssuer: function MSR_confirmUnknownIssuer(socketInfo, cert, certAddType) { - return false; - }, - - confirmMismatchDomain: function MSR_confirmMismatchDomain(socketInfo, targetURL, cert) { - return false; - }, - - confirmCertExpired: function MSR_confirmCertExpired(socketInfo, cert) { - return false; - }, - - notifyCrlNextupdate: function MSR_notifyCrlNextupdate(socketInfo, targetURL, cert) { - }, - // Suppress UI and abort loads for files secured by authentication. // Auth requests appear to succeed when we cancel them (since the server diff --git a/browser/components/search/nsSearchService.js b/browser/components/search/nsSearchService.js index 51b3dba7aa6..ce000bd434e 100755 --- a/browser/components/search/nsSearchService.js +++ b/browser/components/search/nsSearchService.js @@ -293,7 +293,6 @@ loadListener.prototype = { aIID.equals(Ci.nsIStreamListener) || aIID.equals(Ci.nsIChannelEventSink) || aIID.equals(Ci.nsIInterfaceRequestor) || - aIID.equals(Ci.nsIBadCertListener) || // See FIXME comment below aIID.equals(Ci.nsIHttpEventSink) || aIID.equals(Ci.nsIProgressEventSink) || @@ -349,24 +348,6 @@ loadListener.prototype = { return this.QueryInterface(aIID); }, - // nsIBadCertListener - confirmUnknownIssuer: function SRCH_load_CUI(aSocketInfo, aCert, - aCertAddType) { - return false; - }, - - confirmMismatchDomain: function SRCH_load_CMD(aSocketInfo, aTargetURL, - aCert) { - return false; - }, - - confirmCertExpired: function SRCH_load_CCE(aSocketInfo, aCert) { - return false; - }, - - notifyCrlNextupdate: function SRCH_load_NCN(aSocketInfo, aTargetURL, aCert) { - }, - // FIXME: bug 253127 // nsIHttpEventSink onRedirect: function (aChannel, aNewChannel) {}, diff --git a/embedding/browser/gtk/src/EmbedCertificates.cpp b/embedding/browser/gtk/src/EmbedCertificates.cpp index 62a332955f9..f9bf297db77 100644 --- a/embedding/browser/gtk/src/EmbedCertificates.cpp +++ b/embedding/browser/gtk/src/EmbedCertificates.cpp @@ -87,10 +87,6 @@ NS_IMPL_THREADSAFE_ADDREF(EmbedCertificates) NS_IMPL_THREADSAFE_RELEASE(EmbedCertificates) NS_INTERFACE_MAP_BEGIN(EmbedCertificates) NS_INTERFACE_MAP_ENTRY(nsITokenPasswordDialogs) -NS_INTERFACE_MAP_ENTRY(nsIBadCertListener) -#ifdef BAD_CERT_LISTENER2 -NS_INTERFACE_MAP_ENTRY(nsIBadCertListener2) -#endif NS_INTERFACE_MAP_ENTRY(nsICertificateDialogs) NS_INTERFACE_MAP_ENTRY(nsIClientAuthDialogs) NS_INTERFACE_MAP_ENTRY(nsICertPickDialogs) @@ -129,40 +125,6 @@ EmbedCertificates::GetPassword(nsIInterfaceRequestor *ctx, return NS_OK; } -NS_IMETHODIMP -EmbedCertificates::ConfirmUnknownIssuer(nsIInterfaceRequestor *socketInfo, - nsIX509Cert *cert, PRInt16 *outAddType, - PRBool *_retval) -{ - *outAddType = ADD_TRUSTED_FOR_SESSION; - *_retval = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -EmbedCertificates::ConfirmMismatchDomain(nsIInterfaceRequestor *socketInfo, - const nsACString &targetURL, - nsIX509Cert *cert, PRBool *_retval) -{ - *_retval = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -EmbedCertificates::ConfirmCertExpired(nsIInterfaceRequestor *socketInfo, - nsIX509Cert *cert, PRBool *_retval) -{ - *_retval = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -EmbedCertificates::NotifyCrlNextupdate(nsIInterfaceRequestor *socketInfo, - const nsACString &targetURL, nsIX509Cert *cert) -{ - return NS_OK; -} - NS_IMETHODIMP EmbedCertificates::CrlImportStatusDialog(nsIInterfaceRequestor *ctx, nsICRLInfo *crl) { @@ -278,86 +240,3 @@ EmbedCertificates::ConfirmKeyEscrow(nsIX509Cert *escrowAuthority, PRBool *_retva return NS_OK; } -#ifdef BAD_CERT_LISTENER2 -NS_IMETHODIMP -EmbedCertificates::ConfirmBadCertificate( - nsIInterfaceRequestor *ctx, - nsIX509Cert *cert, - PRBool aSecSuccess, - PRUint32 aError, - PRBool *_retval) -{ - nsresult rv; - gpointer pCert = NULL; - guint messint = 0; - nsCOMPtr parent(do_GetInterface(ctx)); - - GtkMozEmbedCommon * common = nsnull; - GtkMozEmbed *parentWidget = GTK_MOZ_EMBED(GetGtkWidgetForDOMWindow(parent)); - - if (!parentWidget) { - EmbedCommon * embedcommon = EmbedCommon::GetInstance(); - if (embedcommon) - common = GTK_MOZ_EMBED_COMMON(embedcommon->mCommon); - } - - if (!(aError & nsIX509Cert::VERIFIED_OK)) { - pCert = (gpointer)cert; - messint = GTK_MOZ_EMBED_CERT_VERIFIED_OK; - if (aError & nsIX509Cert::NOT_VERIFIED_UNKNOWN) { - messint |= GTK_MOZ_EMBED_CERT_NOT_VERIFIED_UNKNOWN; - } - if (aError & nsIX509Cert::CERT_EXPIRED || aError & nsIX509Cert::CERT_REVOKED) { - nsCOMPtr validity; - rv = cert->GetValidity(getter_AddRefs(validity)); - if (NS_SUCCEEDED(rv)) { - PRTime notBefore, notAfter, timeToUse; - PRTime now = PR_Now(); - rv = validity->GetNotBefore(¬Before); - if (NS_FAILED(rv)) - return rv; - rv = validity->GetNotAfter(¬After); - if (NS_FAILED(rv)) - return rv; - if (LL_CMP(now, >, notAfter)) { - messint |= GTK_MOZ_EMBED_CERT_EXPIRED; - timeToUse = notAfter; - } else { - messint |= GTK_MOZ_EMBED_CERT_REVOKED; - timeToUse = notBefore; - } - } - } - if (aError & nsIX509Cert::CERT_NOT_TRUSTED) { - messint |= GTK_MOZ_EMBED_CERT_UNTRUSTED; - } - if (aError & nsIX509Cert::ISSUER_UNKNOWN) { - messint |= GTK_MOZ_EMBED_CERT_ISSUER_UNKNOWN; - } - if (aError & nsIX509Cert::ISSUER_NOT_TRUSTED) { - messint |= GTK_MOZ_EMBED_CERT_ISSUER_UNTRUSTED; - } - if (aError & nsIX509Cert::INVALID_CA) { - messint |= GTK_MOZ_EMBED_CERT_INVALID_CA; - } - if (aError & nsIX509Cert::USAGE_NOT_ALLOWED) { - } - PRBool retVal = PR_FALSE; - if (common) { - g_signal_emit_by_name(common, "certificate-error", pCert, messint, &retVal); - } - if (retVal == PR_TRUE) { - *_retval = PR_FALSE; - rv = NS_ERROR_FAILURE; - } else { - rv = NS_OK; - *_retval = PR_TRUE; - } - pCert = NULL; - } else { - rv = NS_OK; - *_retval = PR_TRUE; - } - return rv; -} -#endif diff --git a/embedding/browser/gtk/src/EmbedCertificates.h b/embedding/browser/gtk/src/EmbedCertificates.h index 0f93027d359..7d765493816 100644 --- a/embedding/browser/gtk/src/EmbedCertificates.h +++ b/embedding/browser/gtk/src/EmbedCertificates.h @@ -44,10 +44,6 @@ #ifndef __EmbedCertificates_h #define __EmbedCertificates_h #include "nsITokenPasswordDialogs.h" -#include "nsIBadCertListener.h" -#ifdef BAD_CERT_LISTENER2 -#include "nsIBadCertListener2.h" -#endif #include "nsICertificateDialogs.h" #include "nsIClientAuthDialogs.h" #include "nsICertPickDialogs.h" @@ -63,10 +59,6 @@ class EmbedPrivate; class EmbedCertificates : public nsITokenPasswordDialogs, - public nsIBadCertListener, -#ifdef BAD_CERT_LISTENER2 - public nsIBadCertListener2, -#endif public nsICertificateDialogs, public nsIClientAuthDialogs, public nsICertPickDialogs, @@ -77,10 +69,6 @@ class EmbedCertificates public: NS_DECL_ISUPPORTS NS_DECL_NSITOKENPASSWORDDIALOGS - NS_DECL_NSIBADCERTLISTENER -#ifdef BAD_CERT_LISTENER2 - NS_DECL_NSIBADCERTLISTENER2 -#endif NS_DECL_NSICERTIFICATEDIALOGS NS_DECL_NSICLIENTAUTHDIALOGS NS_DECL_NSICERTPICKDIALOGS diff --git a/extensions/metrics/src/nsMetricsService.cpp b/extensions/metrics/src/nsMetricsService.cpp index 2c2012697b3..c458aa83b97 100644 --- a/extensions/metrics/src/nsMetricsService.cpp +++ b/extensions/metrics/src/nsMetricsService.cpp @@ -81,7 +81,6 @@ #include "nsIDocShellTreeItem.h" #include "nsDocShellCID.h" #include "nsMemory.h" -#include "nsIBadCertListener.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsIX509Cert.h" @@ -195,95 +194,6 @@ CompressBZ2(nsIInputStream *src, PRFileDesc *outFd) //----------------------------------------------------------------------------- -class nsMetricsService::BadCertListener : public nsIBadCertListener, - public nsIInterfaceRequestor -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIBADCERTLISTENER - NS_DECL_NSIINTERFACEREQUESTOR - - BadCertListener() { } - - private: - ~BadCertListener() { } -}; - -// This object has to implement threadsafe addref and release, but this is -// only because the GetInterface call happens on the socket transport thread. -// The actual notifications are proxied to the main thread. -NS_IMPL_THREADSAFE_ISUPPORTS2(nsMetricsService::BadCertListener, - nsIBadCertListener, nsIInterfaceRequestor) - -NS_IMETHODIMP -nsMetricsService::BadCertListener::ConfirmUnknownIssuer( - nsIInterfaceRequestor *socketInfo, nsIX509Cert *cert, - PRInt16 *certAddType, PRBool *result) -{ - *result = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP -nsMetricsService::BadCertListener::ConfirmMismatchDomain( - nsIInterfaceRequestor *socketInfo, const nsACString &targetURL, - nsIX509Cert *cert, PRBool *result) -{ - *result = PR_FALSE; - - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); - NS_ENSURE_STATE(prefs); - - nsCString certHostOverride; - prefs->GetCharPref("metrics.upload.cert-host-override", - getter_Copies(certHostOverride)); - - if (!certHostOverride.IsEmpty()) { - // Accept the given alternate hostname (CN) for the certificate - nsString certHost; - cert->GetCommonName(certHost); - if (certHostOverride.Equals(NS_ConvertUTF16toUTF8(certHost))) { - *result = PR_TRUE; - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsMetricsService::BadCertListener::ConfirmCertExpired( - nsIInterfaceRequestor *socketInfo, nsIX509Cert *cert, PRBool *result) -{ - *result = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP -nsMetricsService::BadCertListener::NotifyCrlNextupdate( - nsIInterfaceRequestor *socketInfo, - const nsACString &targetURL, nsIX509Cert *cert) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsMetricsService::BadCertListener::GetInterface(const nsIID &uuid, - void **result) -{ - NS_ENSURE_ARG_POINTER(result); - - if (uuid.Equals(NS_GET_IID(nsIBadCertListener))) { - *result = static_cast(this); - NS_ADDREF_THIS(); - return NS_OK; - } - - *result = nsnull; - return NS_ERROR_NO_INTERFACE; -} - -//----------------------------------------------------------------------------- - nsMetricsService::nsMetricsService() : mMD5Context(nsnull), mEventCount(0), @@ -1327,11 +1237,6 @@ nsMetricsService::UploadData() NS_ENSURE_STATE(props); props->SetPropertyAsBool(NS_LITERAL_STRING("moz-metrics-request"), PR_TRUE); - nsCOMPtr certListener = new BadCertListener(); - NS_ENSURE_TRUE(certListener, NS_ERROR_OUT_OF_MEMORY); - - channel->SetNotificationCallbacks(certListener); - nsCOMPtr uploadChannel = do_QueryInterface(channel); NS_ENSURE_STATE(uploadChannel); diff --git a/security/manager/locales/en-US/chrome/pippki/pippki.dtd b/security/manager/locales/en-US/chrome/pippki/pippki.dtd index 2ff58c8105e..961745073f4 100644 --- a/security/manager/locales/en-US/chrome/pippki/pippki.dtd +++ b/security/manager/locales/en-US/chrome/pippki/pippki.dtd @@ -82,16 +82,8 @@ - - - - - - - - diff --git a/security/manager/locales/en-US/chrome/pippki/pippki.properties b/security/manager/locales/en-US/chrome/pippki/pippki.properties index 65baa063e34..bf70f866f72 100644 --- a/security/manager/locales/en-US/chrome/pippki/pippki.properties +++ b/security/manager/locales/en-US/chrome/pippki/pippki.properties @@ -54,9 +54,9 @@ issuerNotKnown=Because you do not know the certificate authority that issued thi issuerCertNotFound=Certificate for this certificate authority was not found #For Deleting Certificates -deleteSslCertConfirm=Are you sure you want to delete these web site certificates? -deleteSslCertImpact=If you delete a web site certificate, you will be asked to accept it again the next time you visit the web site. -deleteSslCertTitle=Delete Web Site Certificates +deleteSslCertConfirm2=Are you sure you want to delete these web site exceptions? +deleteSslCertImpact2=If you delete a web site exception, you restore the usual security checks for that site and require it uses a valid certificate. +deleteSslCertTitle2=Delete Web Site Certificate Exceptions deleteUserCertConfirm=Are you sure you want to delete these certificates? deleteUserCertImpact=If you delete one of your own certificates, you can no longer use it to identify yourself. @@ -79,16 +79,6 @@ chooseP12RestoreFileDialog=File Name to Restore chooseP12BackupFileDialog=File Name to Backup file_browse_PKCS12_spec=PKCS12 Files -#Mismatch Domain Dialg -mismatchDomainMsg1=You have attempted to establish a connection with "%S". However, the security certificate presented belongs to "%S". It is possible, though unlikely, that someone may be trying to intercept your communication with this web site. -mismatchDomainMsg2=If you suspect the certificate shown does not belong to "%S", please cancel the connection and notify the site administrator. - -#Server Cert expired -serverCertExpiredMsg1="%S" is a site that uses a security certificate to encrypt data during transmission, but its certificate expired on %S. -serverCertExpiredTitle=Server Certificate Expired -serverCertNotYetValedMsg1="%S" is a site that uses a security certificate to encrypt data during transmission, but its certificate will not be valid until %S. -serverCertNotYetValidTitle=Server Certificate Not Yet Valid -serverCertExpiredMsg2=You should check to make sure that your computer's time (currently set to %S) is correct. #Preferences resetPreferences=Use this button to reset %S's security preferences to their factory settings. diff --git a/security/manager/pki/resources/content/certManager.js b/security/manager/pki/resources/content/certManager.js index 042f6b7f115..c4760dcbd81 100644 --- a/security/manager/pki/resources/content/certManager.js +++ b/security/manager/pki/resources/content/certManager.js @@ -21,6 +21,7 @@ * Contributor(s): * Bob Lord * Ian McGreer + * Kai Engert * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -53,7 +54,8 @@ const nsNSSCertCache = "@mozilla.org/security/nsscertcache;1"; var key; var selected_certs = []; -var selected_cert_index = []; +var selected_tree_items = []; +var selected_index = []; var certdb; var caTreeView; @@ -157,7 +159,61 @@ function getSelectedCerts() if (cert) { var sc = selected_certs.length; selected_certs[sc] = cert; - selected_cert_index[sc] = j; + selected_index[sc] = j; + } + } + } + } +} + +function getSelectedTreeItems() +{ + var ca_tab = document.getElementById("ca_tab"); + var mine_tab = document.getElementById("mine_tab"); + var others_tab = document.getElementById("others_tab"); + var websites_tab = document.getElementById("websites_tab"); + var orphan_tab = document.getElementById("orphan_tab"); + var items = null; + if (ca_tab.selected) { + items = caTreeView.selection; + } else if (mine_tab.selected) { + items = userTreeView.selection; + } else if (others_tab.selected) { + items = emailTreeView.selection; + } else if (websites_tab.selected) { + items = serverTreeView.selection; + } else if (orphan_tab.selected) { + items = orphanTreeView.selection; + } + selected_certs = []; + selected_tree_items = []; + selected_index = []; + var tree_item = null; + var nr = 0; + if (items != null) nr = items.getRangeCount(); + if (nr > 0) { + for (var i=0; i 0) { + enable_delete = true; } + + if (count_ranges == 1) { + var o1 = {}; + var o2 = {}; + items.getRangeAt(0, o1, o2); // the first range + if (o1.value == o2.value) { + // only a single item is selected + try { + var ti = serverTreeView.getTreeItem(o1.value); + if (ti) { + if (ti.cert) { + enable_view = true; + } + // Trust editing is not possible for override + // entries that are bound to host:port, + // where the cert is stored for convenince only. + if (!ti.hostPort.length) { + enable_edit = true; + } + } + } + catch (e) { + } + } + } + var enableViewButton=document.getElementById('websites_viewButton'); - enableViewButton.setAttribute("disabled",toggle); + enableViewButton.setAttribute("disabled", !enable_view); var enableEditButton=document.getElementById('websites_editButton'); - enableEditButton.setAttribute("disabled",toggle); + enableEditButton.setAttribute("disabled", !enable_edit); var enableExportButton=document.getElementById('websites_exportButton'); - enableExportButton.setAttribute("disabled",toggle); + enableExportButton.setAttribute("disabled", !enable_edit); var enableDeleteButton=document.getElementById('websites_deleteButton'); - enableDeleteButton.setAttribute("disabled",toggle); + enableDeleteButton.setAttribute("disabled", !enable_delete); } function email_enableButtons() @@ -305,15 +392,17 @@ function editCerts() for (var t=0; t=0; t--) { - var s = params.GetString(t+1); - if (s.length) { - // This cert was deleted. - treeView.removeCert(selected_cert_index[t]); - } + treeView.deleteEntryObject(selected_index[t]); } + selected_tree_items = []; + selected_index = []; treeView.selection.clearSelection(); } } diff --git a/security/manager/pki/resources/content/deletecert.js b/security/manager/pki/resources/content/deletecert.js index 6f5069821dc..6c7add315bf 100644 --- a/security/manager/pki/resources/content/deletecert.js +++ b/security/manager/pki/resources/content/deletecert.js @@ -42,24 +42,14 @@ const nsIPKIParamBlock = Components.interfaces.nsIPKIParamBlock; const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock; var certdb; -var certs = []; var gParams; function setWindowName() { gParams = window.arguments[0].QueryInterface(nsIDialogParamBlock); - // Get the cert from the cert database - certdb = Components.classes[nsX509CertDB].getService(nsIX509CertDB); - var typeFlag = gParams.GetString(0); var numberOfCerts = gParams.GetInt(0); - var dbkey; - for(var x=0; x - - - - - -%newserverDTD; - -%pippkiDTD; -]> - - - -