Blame SOURCES/pki-core-CA-OCSP-SystemCertsVerification.patch

5348b8
From da51b869a4ad3e558689c4dfa054605495c96485 Mon Sep 17 00:00:00 2001
5348b8
From: jmagne <jmagne@redhat.com>
5348b8
Date: Thu, 8 Nov 2018 17:07:40 -0800
5348b8
Subject: [PATCH] Resolve: Bug 1641119 - CC: CA/OCSP startup fail on
5348b8
 SystemCertsVerification if enableOCSP is true. (#87)
5348b8
5348b8
The approach taken by this patch is quite simple. The SystemCertsVerification self test has been modified to
5348b8
optionally act differently when verifying the system certs of both ca and ocsp instances.
5348b8
5348b8
Previously, the test would do a full cert verification , which results in an ocsp check being done at the nss level, if ocsp has been enabled in the server.xml. The past result was to have the server hang on startup , due to the fact that an ocsp check of a given cert would loop back to the ca or ocsp server itself to do the work. In the case of the self test /startup scenario, the server will not be sufficiently ready to field such a request, thus resulting in a hang situation.
5348b8
5348b8
This fix modifies the cert checks for ca and ocsp to ONLY do a validity test for each cert.
5348b8
5348b8
The code has created an optional parameter than can force our of this behaviour if the admin absolutely wants to:
5348b8
5348b8
selftests.plugin.SystemCertsVerification.FullCAandOCSPVerify= true
5348b8
5348b8
IF, the admin wants the test to behave as it did before. This may be the case where we know ocsp is not configured for the ca or ocsp itself.
5348b8
5348b8
The value, is false by default and is false if the line is not present.
5348b8
5348b8
The simple validity test is all that gets done at this point but could be modified to do more in the future.
5348b8
We already have a validity test for just the CA singing and OCSP signing certs. I felt it was cleaner to just leave those in place unchanged, safely leaving the original wiring in place.
5348b8
5348b8
(cherry picked from commit 3eab287365d83a167fff7ec1287bd70647e93757)
5348b8
---
5348b8
 base/ca/shared/profiles/ca/caCMCECUserCert.cfg     |  2 +-
5348b8
 .../selftests/common/SystemCertsVerification.java  | 17 +++++++-
5348b8
 .../src/com/netscape/cmscore/apps/CMSEngine.java   |  2 +-
5348b8
 .../src/com/netscape/cmscore/cert/CertUtils.java   | 50 ++++++++++++++++++++--
5348b8
 base/server/tomcat7/conf/server.xml                |  9 +++-
5348b8
 base/server/tomcat8/conf/server.xml                |  9 +++-
5348b8
 6 files changed, 78 insertions(+), 11 deletions(-)
5348b8
5348b8
diff --git a/base/ca/shared/profiles/ca/caCMCECUserCert.cfg b/base/ca/shared/profiles/ca/caCMCECUserCert.cfg
5348b8
index 226c05c..c45da2e 100644
5348b8
--- a/base/ca/shared/profiles/ca/caCMCECUserCert.cfg
5348b8
+++ b/base/ca/shared/profiles/ca/caCMCECUserCert.cfg
5348b8
@@ -1,5 +1,5 @@
5348b8
 desc=This certificate profile is for enrolling user certificates with ECC keys by using the CMC certificate request with CMC Signature authentication.
5348b8
-visible=true
5348b8
+visible=false
5348b8
 enable=true
5348b8
 enableBy=admin
5348b8
 auth.instance_id=CMCAuth
5348b8
diff --git a/base/server/cms/src/com/netscape/cms/selftests/common/SystemCertsVerification.java b/base/server/cms/src/com/netscape/cms/selftests/common/SystemCertsVerification.java
5348b8
index cc52f83..335a940 100644
5348b8
--- a/base/server/cms/src/com/netscape/cms/selftests/common/SystemCertsVerification.java
5348b8
+++ b/base/server/cms/src/com/netscape/cms/selftests/common/SystemCertsVerification.java
5348b8
@@ -36,6 +36,7 @@ import com.netscape.certsrv.selftests.EMissingSelfTestException;
5348b8
 import com.netscape.certsrv.selftests.ESelfTestException;
5348b8
 import com.netscape.certsrv.selftests.ISelfTestSubsystem;
5348b8
 import com.netscape.cms.selftests.ASelfTest;
5348b8
+import com.netscape.cmscore.cert.CertUtils;
5348b8
 
5348b8
 //////////////////////
5348b8
 // class definition //
5348b8
@@ -60,7 +61,9 @@ public class SystemCertsVerification
5348b8
 
5348b8
     // parameter information
5348b8
     public static final String PROP_SUB_ID = "SubId";
5348b8
+    public static final String PROP_FULL_CA_OCSP_VERIFY = "FullCAandOCSPVerify";
5348b8
     private String mSubId = null;
5348b8
+    private boolean mFullCAandOCSPVerify = false;
5348b8
 
5348b8
     /////////////////////
5348b8
     // default methods //
5348b8
@@ -122,6 +125,13 @@ public class SystemCertsVerification
5348b8
 
5348b8
         // retrieve optional parameter(s)
5348b8
 
5348b8
+        try {
5348b8
+            mFullCAandOCSPVerify = mConfig.getBoolean(PROP_FULL_CA_OCSP_VERIFY, false);
5348b8
+        } catch (EBaseException e) {
5348b8
+            //Since this is fully optional, keep going.
5348b8
+            mFullCAandOCSPVerify = false;
5348b8
+        }
5348b8
+
5348b8
         return;
5348b8
     }
5348b8
 
5348b8
@@ -190,7 +200,12 @@ public class SystemCertsVerification
5348b8
     public void runSelfTest(ILogEventListener logger) throws Exception {
5348b8
 
5348b8
         try {
5348b8
-            CMS.verifySystemCerts();
5348b8
+            if (("ca".equalsIgnoreCase(mSubId) || "ocsp".equalsIgnoreCase(mSubId)) && !mFullCAandOCSPVerify) {
5348b8
+                //Perform validity only
5348b8
+                CertUtils.verifySystemCerts(true);
5348b8
+            } else {
5348b8
+                CertUtils.verifySystemCerts(false);
5348b8
+            }
5348b8
 
5348b8
             String logMessage = CMS.getLogMessage(
5348b8
                     "SELFTESTS_COMMON_SYSTEM_CERTS_VERIFICATION_SUCCESS",
5348b8
diff --git a/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java b/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java
5348b8
index 2c953cc..f1a3b78 100644
5348b8
--- a/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java
5348b8
+++ b/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java
5348b8
@@ -1711,7 +1711,7 @@ public class CMSEngine implements ICMSEngine {
5348b8
     }
5348b8
 
5348b8
     public void verifySystemCerts() throws Exception {
5348b8
-        CertUtils.verifySystemCerts();
5348b8
+        CertUtils.verifySystemCerts(false);
5348b8
     }
5348b8
 
5348b8
     public void verifySystemCertByTag(String tag) throws Exception {
5348b8
diff --git a/base/server/cmscore/src/com/netscape/cmscore/cert/CertUtils.java b/base/server/cmscore/src/com/netscape/cmscore/cert/CertUtils.java
5348b8
index 3334b43..6669632 100644
5348b8
--- a/base/server/cmscore/src/com/netscape/cmscore/cert/CertUtils.java
5348b8
+++ b/base/server/cmscore/src/com/netscape/cmscore/cert/CertUtils.java
5348b8
@@ -817,6 +817,30 @@ public class CertUtils {
5348b8
         return tmp.toString();
5348b8
     }
5348b8
 
5348b8
+    public static void verifySystemCertValidityByNickname(String nickname) throws Exception {
5348b8
+
5348b8
+        String method = "Certutils.verifySystemCertValidityByNickname: ";
5348b8
+
5348b8
+        CMS.debug(method + "(" + nickname + ")");
5348b8
+        try {
5348b8
+            CryptoManager cm = CryptoManager.getInstance();
5348b8
+            org.mozilla.jss.crypto.X509Certificate cert = cm.findCertByNickname(nickname);
5348b8
+
5348b8
+            X509CertImpl impl = new X509CertImpl(cert.getEncoded());
5348b8
+
5348b8
+            boolean valid = isValidCert(impl);
5348b8
+
5348b8
+            if (!valid) {
5348b8
+                throw new Exception(method + " failed: nickname: " + nickname);
5348b8
+            }
5348b8
+        } catch (Exception e) {
5348b8
+            CMS.debug(method + " failed : " + e);
5348b8
+            throw new Exception(method + " faliled: nickname: "+ nickname + "cause: " + e);
5348b8
+        }
5348b8
+
5348b8
+        CMS.debug(method + "success");
5348b8
+    }
5348b8
+
5348b8
     /*
5348b8
      * verify a certificate by its nickname
5348b8
      * @throws Exception if something is wrong
5348b8
@@ -891,10 +915,18 @@ public class CertUtils {
5348b8
     }
5348b8
 
5348b8
     /*
5348b8
-     * verify a certificate by its tag name
5348b8
+     * verify a certificate by its tag name, do a full verification
5348b8
      * @throws Exception if something is wrong
5348b8
      */
5348b8
     public static void verifySystemCertByTag(String tag) throws Exception {
5348b8
+        verifySystemCertByTag(tag,false);
5348b8
+    }
5348b8
+    /*
5348b8
+     * verify a certificate by its tag name
5348b8
+     * @throws Exception if something is wrong
5348b8
+     * perform optional validity check only
5348b8
+     */
5348b8
+    public static void verifySystemCertByTag(String tag,boolean checkValidityOnly) throws Exception {
5348b8
 
5348b8
         CMS.debug("CertUtils: verifySystemCertByTag(" + tag + ")");
5348b8
 
5348b8
@@ -934,7 +966,11 @@ public class CertUtils {
5348b8
                 // throw new Exception("Missing certificate usage for " + tag + " certificate"); ?
5348b8
             }
5348b8
 
5348b8
-            verifySystemCertByNickname(nickname, certusage);
5348b8
+            if(!checkValidityOnly) {
5348b8
+                verifySystemCertByNickname(nickname, certusage);
5348b8
+            } else {
5348b8
+                verifySystemCertValidityByNickname(nickname);
5348b8
+            }
5348b8
 
5348b8
             auditMessage = CMS.getLogMessage(
5348b8
                     AuditEvent.CIMC_CERT_VERIFICATION,
5348b8
@@ -999,8 +1035,9 @@ public class CertUtils {
5348b8
      * goes through all system certs and check to see if they are good
5348b8
      * and audit the result
5348b8
      * @throws Exception if something is wrong
5348b8
+     * optionally only check certs validity.
5348b8
      */
5348b8
-    public static void verifySystemCerts() throws Exception {
5348b8
+    public static void verifySystemCerts(boolean checkValidityOnly) throws Exception {
5348b8
 
5348b8
         String auditMessage = null;
5348b8
         IConfigStore config = CMS.getConfigStore();
5348b8
@@ -1051,7 +1088,12 @@ public class CertUtils {
5348b8
                 String tag = tokenizer.nextToken();
5348b8
                 tag = tag.trim();
5348b8
                 CMS.debug("CertUtils: verifySystemCerts() cert tag=" + tag);
5348b8
-                verifySystemCertByTag(tag);
5348b8
+
5348b8
+                if (!checkValidityOnly) {
5348b8
+                    verifySystemCertByTag(tag);
5348b8
+                } else {
5348b8
+                    verifySystemCertByTag(tag, true);
5348b8
+                }
5348b8
             }
5348b8
 
5348b8
         } catch (Exception e) {
5348b8
diff --git a/base/server/tomcat7/conf/server.xml b/base/server/tomcat7/conf/server.xml
5348b8
index dae513d..02eb8eb 100644
5348b8
--- a/base/server/tomcat7/conf/server.xml
5348b8
+++ b/base/server/tomcat7/conf/server.xml
5348b8
@@ -173,6 +173,11 @@ Tomcat Port         = [TOMCAT_SERVER_PORT] (for shutdown)
5348b8
         In case of an ocsp signing certificate, one must import the cert
5348b8
         into the subsystem's nss db and set trust. e.g.:
5348b8
           certutil -d . -A -n "ocspSigningCert cert-pki-ca" -t "C,," -a -i ocspCert.b64
5348b8
+
5348b8
+        If both ocspResponderURL and ocspResponderCertNickname are both unset
5348b8
+        all OCSP checks will be made using the URL encoded within the AIA extension
5348b8
+        of each cert being verified.
5348b8
+
5348b8
         ocspCacheSize - sets max cache entries
5348b8
         ocspMinCacheEntryDuration - sets minimum seconds to next fetch attempt
5348b8
         ocspMaxCacheEntryDuration - sets maximum seconds to next fetch attempt
5348b8
@@ -192,8 +197,8 @@ Tomcat Port         = [TOMCAT_SERVER_PORT] (for shutdown)
5348b8
            ocspResponderURL="http://[PKI_HOSTNAME]:[PKI_UNSECURE_PORT]/ca/ocsp"
5348b8
            ocspResponderCertNickname="ocspSigningCert cert-pki-ca"
5348b8
            ocspCacheSize="1000"
5348b8
-           ocspMinCacheEntryDuration="60"
5348b8
-           ocspMaxCacheEntryDuration="120"
5348b8
+           ocspMinCacheEntryDuration="7200"
5348b8
+           ocspMaxCacheEntryDuration="14400"
5348b8
            ocspTimeout="10"
5348b8
            strictCiphers="true"
5348b8
            clientAuth="[PKI_AGENT_CLIENTAUTH]"
5348b8
diff --git a/base/server/tomcat8/conf/server.xml b/base/server/tomcat8/conf/server.xml
5348b8
index d08e3b1..c83ab58 100644
5348b8
--- a/base/server/tomcat8/conf/server.xml
5348b8
+++ b/base/server/tomcat8/conf/server.xml
5348b8
@@ -193,6 +193,11 @@ Tomcat Port         = [TOMCAT_SERVER_PORT] (for shutdown)
5348b8
         In case of an ocsp signing certificate, one must import the cert
5348b8
         into the subsystem's nss db and set trust. e.g.:
5348b8
           certutil -d . -A -n "ocspSigningCert cert-pki-ca" -t "C,," -a -i ocspCert.b64
5348b8
+
5348b8
+        If both ocspResponderURL and ocspResponderCertNickname are both unset
5348b8
+        all OCSP checks will be made using the URL encoded within the AIA extension
5348b8
+        of each cert being verified.
5348b8
+
5348b8
         ocspCacheSize - sets max cache entries
5348b8
         ocspMinCacheEntryDuration - sets minimum seconds to next fetch attempt
5348b8
         ocspMaxCacheEntryDuration - sets maximum seconds to next fetch attempt
5348b8
@@ -218,8 +223,8 @@ Tomcat Port         = [TOMCAT_SERVER_PORT] (for shutdown)
5348b8
            ocspResponderURL="http://[PKI_HOSTNAME]:[PKI_UNSECURE_PORT]/ca/ocsp"
5348b8
            ocspResponderCertNickname="ocspSigningCert cert-pki-ca"
5348b8
            ocspCacheSize="1000"
5348b8
-           ocspMinCacheEntryDuration="60"
5348b8
-           ocspMaxCacheEntryDuration="120"
5348b8
+           ocspMinCacheEntryDuration="7200"
5348b8
+           ocspMaxCacheEntryDuration="14400"
5348b8
            ocspTimeout="10"
5348b8
            strictCiphers="true"
5348b8
            clientAuth="[PKI_AGENT_CLIENTAUTH]"
5348b8
-- 
5348b8
1.8.3.1
5348b8