Bug 813418 - Centralize certificate validation into CertVerifier part1(cviecco) r=bsmith
authorBrian Smith <bsmith@mozilla.com>
Sat, 27 Oct 2012 00:11:35 -0700
changeset 20387 fa30857eeb1f55b8443e9d27bdeab800c934a7d1
parent 20386 5122d01943a17d3db02d3c8d3408e573a4243798
child 20388 8fdf801967270795ec211b28775c7ec1fa3bd310
push id1209
push usermbanner@mozilla.com
push dateTue, 02 Sep 2014 16:59:36 +0000
treeherdercomm-beta@842e0fd167ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmith
bugs813418
Bug 813418 - Centralize certificate validation into CertVerifier part1(cviecco) r=bsmith
mailnews/mime/src/nsCMS.cpp
--- a/mailnews/mime/src/nsCMS.cpp
+++ b/mailnews/mime/src/nsCMS.cpp
@@ -1,29 +1,30 @@
 /* -*- 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/. */
 
 #include "nsISupports.h"
 #include "nsCMS.h"
+#include "CertVerifier.h"
 #include "nsNSSHelper.h"
 #include "nsNSSCertificate.h"
 #include "smime.h"
 #include "cms.h"
 #include "nsICMSMessageErrors.h"
 #include "nsIArray.h"
 #include "nsArrayUtils.h"
 #include "nsCertVerificationThread.h"
-#include "nsCERTValInParamWrapper.h"
 #include "ScopedNSSTypes.h"
 
 #include "prlog.h"
 
-#include "nsNSSComponent.h"
+using namespace mozilla;
+using namespace mozilla::psm;
 
 #ifdef PR_LOGGING
 extern PRLogModuleInfo* gPIPNSSLog;
 #endif
 
 using namespace mozilla;
 
 static NS_DEFINE_CID(kNSSComponentCID, NS_NSSCOMPONENT_CID);
@@ -213,19 +214,18 @@ nsresult nsCMSMessage::CommonVerifySigna
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CommonVerifySignature, content level count %d\n", NSS_CMSMessage_ContentLevelCount(m_cmsMsg)));
   NSSCMSContentInfo *cinfo = nullptr;
   NSSCMSSignedData *sigd = nullptr;
   NSSCMSSignerInfo *si;
   int32_t nsigners;
+  RefPtr<CertVerifier> certVerifier;
   nsresult rv = NS_ERROR_FAILURE;
-  RefPtr<nsCERTValInParamWrapper> survivingParams;
-  nsCOMPtr<nsINSSComponent> inss;
 
   if (!NSS_CMSMessage_IsSigned(m_cmsMsg)) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CommonVerifySignature - not signed\n"));
     return NS_ERROR_CMS_VERIFY_NOT_SIGNED;
   } 
 
   cinfo = NSS_CMSMessage_ContentLevel(m_cmsMsg, 0);
   if (cinfo) {
@@ -259,50 +259,30 @@ nsresult nsCMSMessage::CommonVerifySigna
 
   nsigners = NSS_CMSSignedData_SignerInfoCount(sigd);
   PR_ASSERT(nsigners > 0);
   si = NSS_CMSSignedData_GetSignerInfo(sigd, 0);
 
   // See bug 324474. We want to make sure the signing cert is 
   // still valid at the current time.
 
-#ifndef NSS_NO_LIBPKIX
-  if (!nsNSSComponent::globalConstFlagUsePKIXVerification) {
-#endif
-    if (CERT_VerifyCertificateNow(CERT_GetDefaultCertDB(), si->cert, true, 
-                                  certificateUsageEmailSigner,
-                                  si->cmsg->pwfn_arg, nullptr) != SECSuccess) {
-      PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CommonVerifySignature - signing cert not trusted now\n"));
-      rv = NS_ERROR_CMS_VERIFY_UNTRUSTED;
-      goto loser;
-    }
-#ifndef NSS_NO_LIBPKIX
-  }
-  else {
-    CERTValOutParam cvout[1];
-    cvout[0].type = cert_po_end;
+  certVerifier = GetDefaultCertVerifier();
+  NS_ENSURE_TRUE(certVerifier, NS_ERROR_UNEXPECTED);
 
-    inss = do_GetService(kNSSComponentCID, &rv);
-    if (!inss) {
-      goto loser;
-    }
-
-    if (NS_FAILED(inss->GetDefaultCERTValInParam(survivingParams))) {
-      goto loser;
-    }
-    SECStatus stat = CERT_PKIXVerifyCert(si->cert, certificateUsageEmailSigner,
-			    survivingParams->GetRawPointerForNSS(),
-			    cvout, si->cmsg->pwfn_arg);
-    if (stat != SECSuccess) {
-      PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CommonVerifySignature - signing cert not trusted now\n"));
+  {
+    SECStatus srv = certVerifier->VerifyCert(si->cert,
+                                             certificateUsageEmailSigner,
+                                             PR_Now(), nullptr /*XXX pinarg*/);
+    if (srv != SECSuccess) {
+      PR_LOG(gPIPNSSLog, PR_LOG_DEBUG,
+             ("nsCMSMessage::CommonVerifySignature - signing cert not trusted now\n"));
       rv = NS_ERROR_CMS_VERIFY_UNTRUSTED;
       goto loser;
     }
   }
-#endif
 
   // We verify the first signer info,  only //
   if (NSS_CMSSignedData_VerifySignerInfo(sigd, 0, CERT_GetDefaultCertDB(), certUsageEmailSigner) != SECSuccess) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CommonVerifySignature - unable to verify signature\n"));
 
     if (NSSCMSVS_SigningCertNotFound == si->verificationStatus) {
       PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CommonVerifySignature - signing cert not found\n"));
       rv = NS_ERROR_CMS_VERIFY_NOCERT;