f6e752
# HG changeset patch
f6e752
# User Robert Relyea <rrelyea@redhat.com>
f6e752
# Date 1541713180 28800
f6e752
#      Thu Nov 08 13:39:40 2018 -0800
f6e752
# Node ID 0c8334a3b23372556ebedbdfe513417eb9ee55a0
f6e752
# Parent  070bebf39672054410437b0cf931e00a8920a1ff
f6e752
try: -b do -p all -u all -t all
f6e752
f6e752
diff --git a/cmd/certutil/certutil.c b/cmd/certutil/certutil.c
f6e752
--- a/cmd/certutil/certutil.c
f6e752
+++ b/cmd/certutil/certutil.c
f6e752
@@ -736,16 +736,19 @@ ValidateCert(CERTCertDBHandle *handle, c
f6e752
             usage = certificateUsageVerifyCA;
f6e752
             break;
f6e752
         case 'C':
f6e752
             usage = certificateUsageSSLClient;
f6e752
             break;
f6e752
         case 'V':
f6e752
             usage = certificateUsageSSLServer;
f6e752
             break;
f6e752
+        case 'I':
f6e752
+            usage = certificateUsageIPsec;
f6e752
+            break;
f6e752
         case 'S':
f6e752
             usage = certificateUsageEmailSigner;
f6e752
             break;
f6e752
         case 'R':
f6e752
             usage = certificateUsageEmailRecipient;
f6e752
             break;
f6e752
         case 'J':
f6e752
             usage = certificateUsageObjectSigner;
f6e752
@@ -1701,16 +1704,17 @@ luV(enum usage_level ul, const char *com
f6e752
         "   -n cert-name");
f6e752
     FPS "%-20s validity time (\"YYMMDDHHMMSS[+HHMM|-HHMM|Z]\")\n",
f6e752
         "   -b time");
f6e752
     FPS "%-20s Check certificate signature \n",
f6e752
         "   -e ");
f6e752
     FPS "%-20s Specify certificate usage:\n", "   -u certusage");
f6e752
     FPS "%-25s C \t SSL Client\n", "");
f6e752
     FPS "%-25s V \t SSL Server\n", "");
f6e752
+    FPS "%-25s I \t IPsec\n", "");
f6e752
     FPS "%-25s L \t SSL CA\n", "");
f6e752
     FPS "%-25s A \t Any CA\n", "");
f6e752
     FPS "%-25s Y \t Verify CA\n", "");
f6e752
     FPS "%-25s S \t Email signer\n", "");
f6e752
     FPS "%-25s R \t Email Recipient\n", "");
f6e752
     FPS "%-25s O \t OCSP status responder\n", "");
f6e752
     FPS "%-25s J \t Object signer\n", "");
f6e752
     FPS "%-20s Cert database directory (default is ~/.netscape)\n",
f6e752
diff --git a/cmd/dbck/dbrecover.c b/cmd/dbck/dbrecover.c
f6e752
--- a/cmd/dbck/dbrecover.c
f6e752
+++ b/cmd/dbck/dbrecover.c
f6e752
@@ -283,17 +283,18 @@ addCertToDB(certDBEntryCert *certEntry, 
f6e752
     userCert = (SEC_GET_TRUST_FLAGS(trust, trustSSL) & CERTDB_USER) ||
f6e752
                (SEC_GET_TRUST_FLAGS(trust, trustEmail) & CERTDB_USER) ||
f6e752
                (SEC_GET_TRUST_FLAGS(trust, trustObjectSigning) & CERTDB_USER);
f6e752
     if (userCert)
f6e752
         goto createcert;
f6e752
 
f6e752
     /*  If user chooses so, ignore expired certificates.  */
f6e752
     allowOverride = (PRBool)((oldCert->keyUsage == certUsageSSLServer) ||
f6e752
-                             (oldCert->keyUsage == certUsageSSLServerWithStepUp));
f6e752
+                             (oldCert->keyUsage == certUsageSSLServerWithStepUp) ||
f6e752
+                             (oldCert->keyUsage == certUsageIPsec));
f6e752
     validity = CERT_CheckCertValidTimes(oldCert, PR_Now(), allowOverride);
f6e752
     /*  If cert expired and user wants to delete it, ignore it. */
f6e752
     if ((validity != secCertTimeValid) &&
f6e752
         userSaysDeleteCert(&oldCert, 1, dbInvalidCert, info, 0)) {
f6e752
         info->dbErrors[dbInvalidCert]++;
f6e752
         if (info->verbose) {
f6e752
             PR_fprintf(info->out, "Deleting expired certificate:\n");
f6e752
             dumpCertificate(oldCert, -1, info->out);
f6e752
diff --git a/cmd/ocspclnt/ocspclnt.c b/cmd/ocspclnt/ocspclnt.c
f6e752
--- a/cmd/ocspclnt/ocspclnt.c
f6e752
+++ b/cmd/ocspclnt/ocspclnt.c
f6e752
@@ -129,16 +129,18 @@ long_usage(char *progname)
f6e752
     PR_fprintf(pr_stderr,
f6e752
                "  %-13s Type of certificate usage for verification:\n",
f6e752
                "-u usage");
f6e752
     PR_fprintf(pr_stderr,
f6e752
                "%-17s c   SSL Client\n", "");
f6e752
     PR_fprintf(pr_stderr,
f6e752
                "%-17s s   SSL Server\n", "");
f6e752
     PR_fprintf(pr_stderr,
f6e752
+               "%-17s I   IPsec\n", "");
f6e752
+    PR_fprintf(pr_stderr,
f6e752
                "%-17s e   Email Recipient\n", "");
f6e752
     PR_fprintf(pr_stderr,
f6e752
                "%-17s E   Email Signer\n", "");
f6e752
     PR_fprintf(pr_stderr,
f6e752
                "%-17s S   Object Signer\n", "");
f6e752
     PR_fprintf(pr_stderr,
f6e752
                "%-17s C   CA\n", "");
f6e752
     PR_fprintf(pr_stderr,
f6e752
@@ -903,16 +905,19 @@ cert_usage_from_char(const char *cert_us
f6e752
 
f6e752
     switch (*cert_usage_str) {
f6e752
         case 'c':
f6e752
             *cert_usage = certUsageSSLClient;
f6e752
             break;
f6e752
         case 's':
f6e752
             *cert_usage = certUsageSSLServer;
f6e752
             break;
f6e752
+        case 'I':
f6e752
+            *cert_usage = certUsageIPsec;
f6e752
+            break;
f6e752
         case 'e':
f6e752
             *cert_usage = certUsageEmailRecipient;
f6e752
             break;
f6e752
         case 'E':
f6e752
             *cert_usage = certUsageEmailSigner;
f6e752
             break;
f6e752
         case 'S':
f6e752
             *cert_usage = certUsageObjectSigner;
f6e752
diff --git a/cmd/p7verify/p7verify.c b/cmd/p7verify/p7verify.c
f6e752
--- a/cmd/p7verify/p7verify.c
f6e752
+++ b/cmd/p7verify/p7verify.c
f6e752
@@ -112,16 +112,17 @@ Usage(char *progName)
f6e752
     fprintf(stderr, "%-25s  4 - certUsageEmailSigner\n", " ");
f6e752
     fprintf(stderr, "%-25s  5 - certUsageEmailRecipient\n", " ");
f6e752
     fprintf(stderr, "%-25s  6 - certUsageObjectSigner\n", " ");
f6e752
     fprintf(stderr, "%-25s  7 - certUsageUserCertImport\n", " ");
f6e752
     fprintf(stderr, "%-25s  8 - certUsageVerifyCA\n", " ");
f6e752
     fprintf(stderr, "%-25s  9 - certUsageProtectedObjectSigner\n", " ");
f6e752
     fprintf(stderr, "%-25s 10 - certUsageStatusResponder\n", " ");
f6e752
     fprintf(stderr, "%-25s 11 - certUsageAnyCA\n", " ");
f6e752
+    fprintf(stderr, "%-25s 12 - certUsageIPsec\n", " ");
f6e752
 
f6e752
     exit(-1);
f6e752
 }
f6e752
 
f6e752
 static int
f6e752
 HashDecodeAndVerify(FILE *out, FILE *content, PRFileDesc *signature,
f6e752
                     SECCertUsage usage, char *progName)
f6e752
 {
f6e752
diff --git a/cmd/smimetools/cmsutil.c b/cmd/smimetools/cmsutil.c
f6e752
--- a/cmd/smimetools/cmsutil.c
f6e752
+++ b/cmd/smimetools/cmsutil.c
f6e752
@@ -110,16 +110,17 @@ Usage(void)
f6e752
     fprintf(stderr, "%-25s  4 - certUsageEmailSigner\n", " ");
f6e752
     fprintf(stderr, "%-25s  5 - certUsageEmailRecipient\n", " ");
f6e752
     fprintf(stderr, "%-25s  6 - certUsageObjectSigner\n", " ");
f6e752
     fprintf(stderr, "%-25s  7 - certUsageUserCertImport\n", " ");
f6e752
     fprintf(stderr, "%-25s  8 - certUsageVerifyCA\n", " ");
f6e752
     fprintf(stderr, "%-25s  9 - certUsageProtectedObjectSigner\n", " ");
f6e752
     fprintf(stderr, "%-25s 10 - certUsageStatusResponder\n", " ");
f6e752
     fprintf(stderr, "%-25s 11 - certUsageAnyCA\n", " ");
f6e752
+    fprintf(stderr, "%-25s 12 - certUsageIPsec\n", " ");
f6e752
 
f6e752
     exit(-1);
f6e752
 }
f6e752
 
f6e752
 struct optionsStr {
f6e752
     char *pwfile;
f6e752
     char *password;
f6e752
     SECCertUsage certUsage;
f6e752
diff --git a/cmd/vfychain/vfychain.c b/cmd/vfychain/vfychain.c
f6e752
--- a/cmd/vfychain/vfychain.c
f6e752
+++ b/cmd/vfychain/vfychain.c
f6e752
@@ -59,17 +59,18 @@ Usage(const char *progName)
f6e752
             "\t-o oid\t\t Set policy OID for cert validation(Format OID.1.2.3)\n"
f6e752
             "\t-p \t\t Use PKIX Library to validate certificate by calling:\n"
f6e752
             "\t\t\t   * CERT_VerifyCertificate if specified once,\n"
f6e752
             "\t\t\t   * CERT_PKIXVerifyCert if specified twice and more.\n"
f6e752
             "\t-r\t\t Following certfile is raw binary DER (default)\n"
f6e752
             "\t-t\t\t Following cert is explicitly trusted (overrides db trust).\n"
f6e752
             "\t-u usage \t 0=SSL client, 1=SSL server, 2=SSL StepUp, 3=SSL CA,\n"
f6e752
             "\t\t\t 4=Email signer, 5=Email recipient, 6=Object signer,\n"
f6e752
-            "\t\t\t 9=ProtectedObjectSigner, 10=OCSP responder, 11=Any CA\n"
f6e752
+            "\t\t\t 9=ProtectedObjectSigner, 10=OCSP responder, 11=Any CA,\n"
f6e752
+            "\t\t\t 12=IPsec\n"
f6e752
             "\t-T\t\t Trust both explicit trust anchors (-t) and the database.\n"
f6e752
             "\t\t\t (Default is to only trust certificates marked -t, if there are any,\n"
f6e752
             "\t\t\t or to trust the database if there are certificates marked -t.)\n"
f6e752
             "\t-v\t\t Verbose mode. Prints root cert subject(double the\n"
f6e752
             "\t\t\t argument for whole root cert info)\n"
f6e752
             "\t-w password\t Database password.\n"
f6e752
             "\t-W pwfile\t Password file.\n\n"
f6e752
             "\tRevocation options for PKIX API(invoked with -pp options) is a\n"
f6e752
diff --git a/lib/certdb/certdb.c b/lib/certdb/certdb.c
f6e752
--- a/lib/certdb/certdb.c
f6e752
+++ b/lib/certdb/certdb.c
f6e752
@@ -441,16 +441,84 @@ cert_GetCertType(CERTCertificate *cert)
f6e752
     nsCertType = cert_ComputeCertType(cert);
f6e752
 
f6e752
     /* Assert that it is safe to cast &cert->nsCertType to "PRInt32 *" */
f6e752
     PORT_Assert(sizeof(cert->nsCertType) == sizeof(PRInt32));
f6e752
     PR_ATOMIC_SET((PRInt32 *)&cert->nsCertType, nsCertType);
f6e752
     return SECSuccess;
f6e752
 }
f6e752
 
f6e752
+PRBool
f6e752
+cert_EKUAllowsIPsecIKE(CERTCertificate *cert, PRBool *isCritical)
f6e752
+{
f6e752
+    SECStatus rv;
f6e752
+    SECItem encodedExtKeyUsage;
f6e752
+    CERTOidSequence *extKeyUsage = NULL;
f6e752
+    PRBool result = PR_FALSE;
f6e752
+
f6e752
+    rv = CERT_GetExtenCriticality(cert->extensions,
f6e752
+                                  SEC_OID_X509_EXT_KEY_USAGE,
f6e752
+                                  isCritical);
f6e752
+    if (rv != SECSuccess) {
f6e752
+        *isCritical = PR_FALSE;
f6e752
+    }
f6e752
+
f6e752
+    encodedExtKeyUsage.data = NULL;
f6e752
+    rv = CERT_FindCertExtension(cert, SEC_OID_X509_EXT_KEY_USAGE,
f6e752
+                                &encodedExtKeyUsage);
f6e752
+    if (rv != SECSuccess) {
f6e752
+        /* EKU not present, allowed. */
f6e752
+        result = PR_TRUE;
f6e752
+        goto done;
f6e752
+    }
f6e752
+
f6e752
+    extKeyUsage = CERT_DecodeOidSequence(&encodedExtKeyUsage);
f6e752
+    if (!extKeyUsage) {
f6e752
+        /* failure */
f6e752
+        goto done;
f6e752
+    }
f6e752
+
f6e752
+    if (findOIDinOIDSeqByTagNum(extKeyUsage,
f6e752
+                                SEC_OID_X509_ANY_EXT_KEY_USAGE) ==
f6e752
+        SECSuccess) {
f6e752
+        result = PR_TRUE;
f6e752
+        goto done;
f6e752
+    }
f6e752
+
f6e752
+    if (findOIDinOIDSeqByTagNum(extKeyUsage,
f6e752
+                                SEC_OID_EXT_KEY_USAGE_IPSEC_IKE) ==
f6e752
+        SECSuccess) {
f6e752
+        result = PR_TRUE;
f6e752
+        goto done;
f6e752
+    }
f6e752
+
f6e752
+    if (findOIDinOIDSeqByTagNum(extKeyUsage,
f6e752
+                                SEC_OID_IPSEC_IKE_END) ==
f6e752
+        SECSuccess) {
f6e752
+        result = PR_TRUE;
f6e752
+        goto done;
f6e752
+    }
f6e752
+
f6e752
+    if (findOIDinOIDSeqByTagNum(extKeyUsage,
f6e752
+                                SEC_OID_IPSEC_IKE_INTERMEDIATE) ==
f6e752
+        SECSuccess) {
f6e752
+        result = PR_TRUE;
f6e752
+        goto done;
f6e752
+    }
f6e752
+
f6e752
+done:
f6e752
+    if (encodedExtKeyUsage.data != NULL) {
f6e752
+        PORT_Free(encodedExtKeyUsage.data);
f6e752
+    }
f6e752
+    if (extKeyUsage != NULL) {
f6e752
+        CERT_DestroyOidSequence(extKeyUsage);
f6e752
+    }
f6e752
+    return result;
f6e752
+}
f6e752
+
f6e752
 PRUint32
f6e752
 cert_ComputeCertType(CERTCertificate *cert)
f6e752
 {
f6e752
     SECStatus rv;
f6e752
     SECItem tmpitem;
f6e752
     SECItem encodedExtKeyUsage;
f6e752
     CERTOidSequence *extKeyUsage = NULL;
f6e752
     PRBool basicConstraintPresent = PR_FALSE;
f6e752
@@ -1078,16 +1146,20 @@ CERT_KeyUsageAndTypeForCertUsage(SECCert
f6e752
             case certUsageSSLClient:
f6e752
                 requiredKeyUsage = KU_KEY_CERT_SIGN;
f6e752
                 requiredCertType = NS_CERT_TYPE_SSL_CA;
f6e752
                 break;
f6e752
             case certUsageSSLServer:
f6e752
                 requiredKeyUsage = KU_KEY_CERT_SIGN;
f6e752
                 requiredCertType = NS_CERT_TYPE_SSL_CA;
f6e752
                 break;
f6e752
+            case certUsageIPsec:
f6e752
+                requiredKeyUsage = KU_KEY_CERT_SIGN;
f6e752
+                requiredCertType = NS_CERT_TYPE_SSL_CA;
f6e752
+                break;
f6e752
             case certUsageSSLCA:
f6e752
                 requiredKeyUsage = KU_KEY_CERT_SIGN;
f6e752
                 requiredCertType = NS_CERT_TYPE_SSL_CA;
f6e752
                 break;
f6e752
             case certUsageEmailSigner:
f6e752
                 requiredKeyUsage = KU_KEY_CERT_SIGN;
f6e752
                 requiredCertType = NS_CERT_TYPE_EMAIL_CA;
f6e752
                 break;
f6e752
@@ -1120,16 +1192,21 @@ CERT_KeyUsageAndTypeForCertUsage(SECCert
f6e752
                  */
f6e752
                 requiredKeyUsage = KU_DIGITAL_SIGNATURE;
f6e752
                 requiredCertType = NS_CERT_TYPE_SSL_CLIENT;
f6e752
                 break;
f6e752
             case certUsageSSLServer:
f6e752
                 requiredKeyUsage = KU_KEY_AGREEMENT_OR_ENCIPHERMENT;
f6e752
                 requiredCertType = NS_CERT_TYPE_SSL_SERVER;
f6e752
                 break;
f6e752
+            case certUsageIPsec:
f6e752
+                /* RFC 4945 Section 5.1.3.2 */
f6e752
+                requiredKeyUsage = KU_DIGITAL_SIGNATURE_OR_NON_REPUDIATION;
f6e752
+                requiredCertType = 0;
f6e752
+                break;
f6e752
             case certUsageSSLServerWithStepUp:
f6e752
                 requiredKeyUsage =
f6e752
                     KU_KEY_AGREEMENT_OR_ENCIPHERMENT | KU_NS_GOVT_APPROVED;
f6e752
                 requiredCertType = NS_CERT_TYPE_SSL_SERVER;
f6e752
                 break;
f6e752
             case certUsageSSLCA:
f6e752
                 requiredKeyUsage = KU_KEY_CERT_SIGN;
f6e752
                 requiredCertType = NS_CERT_TYPE_SSL_CA;
f6e752
diff --git a/lib/certdb/certi.h b/lib/certdb/certi.h
f6e752
--- a/lib/certdb/certi.h
f6e752
+++ b/lib/certdb/certi.h
f6e752
@@ -289,16 +289,19 @@ SECStatus cert_DestroyLocks(void);
f6e752
 extern SECStatus cert_GetCertType(CERTCertificate* cert);
f6e752
 
f6e752
 /*
f6e752
  * compute and return the value of nsCertType for cert, but do not
f6e752
  * update the CERTCertificate.
f6e752
  */
f6e752
 extern PRUint32 cert_ComputeCertType(CERTCertificate* cert);
f6e752
 
f6e752
+extern PRBool cert_EKUAllowsIPsecIKE(CERTCertificate* cert,
f6e752
+                                     PRBool* isCritical);
f6e752
+
f6e752
 void cert_AddToVerifyLog(CERTVerifyLog* log, CERTCertificate* cert,
f6e752
                          long errorCode, unsigned int depth, void* arg);
f6e752
 
f6e752
 /* Insert a DER CRL into the CRL cache, and take ownership of it.
f6e752
  *
f6e752
  * cert_CacheCRLByGeneralName takes ownership of the memory in crl argument
f6e752
  * completely.  crl must be freeable by SECITEM_FreeItem. It will be freed
f6e752
  * immediately if it is rejected from the CRL cache, or later during cache
f6e752
diff --git a/lib/certdb/certt.h b/lib/certdb/certt.h
f6e752
--- a/lib/certdb/certt.h
f6e752
+++ b/lib/certdb/certt.h
f6e752
@@ -442,17 +442,18 @@ typedef enum SECCertUsageEnum {
f6e752
     certUsageSSLCA = 3,
f6e752
     certUsageEmailSigner = 4,
f6e752
     certUsageEmailRecipient = 5,
f6e752
     certUsageObjectSigner = 6,
f6e752
     certUsageUserCertImport = 7,
f6e752
     certUsageVerifyCA = 8,
f6e752
     certUsageProtectedObjectSigner = 9,
f6e752
     certUsageStatusResponder = 10,
f6e752
-    certUsageAnyCA = 11
f6e752
+    certUsageAnyCA = 11,
f6e752
+    certUsageIPsec = 12
f6e752
 } SECCertUsage;
f6e752
 
f6e752
 typedef PRInt64 SECCertificateUsage;
f6e752
 
f6e752
 #define certificateUsageCheckAllUsages (0x0000)
f6e752
 #define certificateUsageSSLClient (0x0001)
f6e752
 #define certificateUsageSSLServer (0x0002)
f6e752
 #define certificateUsageSSLServerWithStepUp (0x0004)
f6e752
@@ -460,18 +461,19 @@ typedef PRInt64 SECCertificateUsage;
f6e752
 #define certificateUsageEmailSigner (0x0010)
f6e752
 #define certificateUsageEmailRecipient (0x0020)
f6e752
 #define certificateUsageObjectSigner (0x0040)
f6e752
 #define certificateUsageUserCertImport (0x0080)
f6e752
 #define certificateUsageVerifyCA (0x0100)
f6e752
 #define certificateUsageProtectedObjectSigner (0x0200)
f6e752
 #define certificateUsageStatusResponder (0x0400)
f6e752
 #define certificateUsageAnyCA (0x0800)
f6e752
+#define certificateUsageIPsec (0x1000)
f6e752
 
f6e752
-#define certificateUsageHighest certificateUsageAnyCA
f6e752
+#define certificateUsageHighest certificateUsageIPsec
f6e752
 
f6e752
 /*
f6e752
  * Does the cert belong to the user, a peer, or a CA.
f6e752
  */
f6e752
 typedef enum CERTCertOwnerEnum {
f6e752
     certOwnerUser = 0,
f6e752
     certOwnerPeer = 1,
f6e752
     certOwnerCA = 2
f6e752
diff --git a/lib/certhigh/certvfy.c b/lib/certhigh/certvfy.c
f6e752
--- a/lib/certhigh/certvfy.c
f6e752
+++ b/lib/certhigh/certvfy.c
f6e752
@@ -284,16 +284,20 @@ CERT_TrustFlagsForCACertUsage(SECCertUsa
f6e752
             requiredFlags = CERTDB_TRUSTED_CLIENT_CA;
f6e752
             trustType = trustSSL;
f6e752
             break;
f6e752
         case certUsageSSLServer:
f6e752
         case certUsageSSLCA:
f6e752
             requiredFlags = CERTDB_TRUSTED_CA;
f6e752
             trustType = trustSSL;
f6e752
             break;
f6e752
+        case certUsageIPsec:
f6e752
+            requiredFlags = CERTDB_TRUSTED_CA;
f6e752
+            trustType = trustSSL;
f6e752
+            break;
f6e752
         case certUsageSSLServerWithStepUp:
f6e752
             requiredFlags = CERTDB_TRUSTED_CA | CERTDB_GOVT_APPROVED_CA;
f6e752
             trustType = trustSSL;
f6e752
             break;
f6e752
         case certUsageEmailSigner:
f6e752
         case certUsageEmailRecipient:
f6e752
             requiredFlags = CERTDB_TRUSTED_CA;
f6e752
             trustType = trustEmail;
f6e752
@@ -574,16 +578,17 @@ cert_VerifyCertChainOld(CERTCertDBHandle
f6e752
         EXIT_IF_NOT_LOGGING(log);
f6e752
         requiredCAKeyUsage = 0;
f6e752
         caCertType = 0;
f6e752
     }
f6e752
 
f6e752
     switch (certUsage) {
f6e752
         case certUsageSSLClient:
f6e752
         case certUsageSSLServer:
f6e752
+        case certUsageIPsec:
f6e752
         case certUsageSSLCA:
f6e752
         case certUsageSSLServerWithStepUp:
f6e752
         case certUsageEmailSigner:
f6e752
         case certUsageEmailRecipient:
f6e752
         case certUsageObjectSigner:
f6e752
         case certUsageVerifyCA:
f6e752
         case certUsageAnyCA:
f6e752
         case certUsageStatusResponder:
f6e752
@@ -640,17 +645,18 @@ cert_VerifyCertChainOld(CERTCertDBHandle
f6e752
          * certifcates (except leaf (EE) certs, root CAs, and self-issued
f6e752
          * intermediate CAs) to be verified against the name constraints
f6e752
          * extension of the issuer certificate.
f6e752
          */
f6e752
         if (subjectCertIsSelfIssued == PR_FALSE) {
f6e752
             CERTGeneralName *subjectNameList;
f6e752
             int subjectNameListLen;
f6e752
             int i;
f6e752
-            PRBool getSubjectCN = (!count && certUsage == certUsageSSLServer);
f6e752
+            PRBool getSubjectCN = (!count &&
f6e752
+                                   (certUsage == certUsageSSLServer || certUsage == certUsageIPsec));
f6e752
             subjectNameList =
f6e752
                 CERT_GetConstrainedCertificateNames(subjectCert, arena,
f6e752
                                                     getSubjectCN);
f6e752
             if (!subjectNameList)
f6e752
                 goto loser;
f6e752
             subjectNameListLen = CERT_GetNamesLength(subjectNameList);
f6e752
             if (!subjectNameListLen)
f6e752
                 goto loser;
f6e752
@@ -981,16 +987,17 @@ CERT_VerifyCACertForUsage(CERTCertDBHand
f6e752
         EXIT_IF_NOT_LOGGING(log);
f6e752
         requiredCAKeyUsage = 0;
f6e752
         caCertType = 0;
f6e752
     }
f6e752
 
f6e752
     switch (certUsage) {
f6e752
         case certUsageSSLClient:
f6e752
         case certUsageSSLServer:
f6e752
+        case certUsageIPsec:
f6e752
         case certUsageSSLCA:
f6e752
         case certUsageSSLServerWithStepUp:
f6e752
         case certUsageEmailSigner:
f6e752
         case certUsageEmailRecipient:
f6e752
         case certUsageObjectSigner:
f6e752
         case certUsageVerifyCA:
f6e752
         case certUsageStatusResponder:
f6e752
             if (CERT_TrustFlagsForCACertUsage(certUsage, &requiredFlags,
f6e752
@@ -1166,16 +1173,17 @@ cert_CheckLeafTrust(CERTCertificate *cer
f6e752
     *failedFlags = 0;
f6e752
     *trusted = PR_FALSE;
f6e752
 
f6e752
     /* check trust flags to see if this cert is directly trusted */
f6e752
     if (CERT_GetCertTrust(cert, &trust) == SECSuccess) {
f6e752
         switch (certUsage) {
f6e752
             case certUsageSSLClient:
f6e752
             case certUsageSSLServer:
f6e752
+            case certUsageIPsec:
f6e752
                 flags = trust.sslFlags;
f6e752
 
f6e752
                 /* is the cert directly trusted or not trusted ? */
f6e752
                 if (flags & CERTDB_TERMINAL_RECORD) { /* the trust record is
f6e752
                             * authoritative */
f6e752
                     if (flags & CERTDB_TRUSTED) {     /* trust this cert */
f6e752
                         *trusted = PR_TRUE;
f6e752
                         return SECSuccess;
f6e752
@@ -1342,45 +1350,48 @@ CERT_VerifyCertificate(CERTCertDBHandle 
f6e752
         /* we don't have a place to return status for all usages,
f6e752
            so we can skip checks for usages that aren't required */
f6e752
         checkAllUsages = PR_FALSE;
f6e752
     }
f6e752
     valid = SECSuccess; /* start off assuming cert is valid */
f6e752
 
f6e752
     /* make sure that the cert is valid at time t */
f6e752
     allowOverride = (PRBool)((requiredUsages & certificateUsageSSLServer) ||
f6e752
-                             (requiredUsages & certificateUsageSSLServerWithStepUp));
f6e752
+                             (requiredUsages & certificateUsageSSLServerWithStepUp) ||
f6e752
+                             (requiredUsages & certificateUsageIPsec));
f6e752
     validity = CERT_CheckCertValidTimes(cert, t, allowOverride);
f6e752
     if (validity != secCertTimeValid) {
f6e752
         valid = SECFailure;
f6e752
         LOG_ERROR_OR_EXIT(log, cert, 0, validity);
f6e752
     }
f6e752
 
f6e752
     /* check key usage and netscape cert type */
f6e752
     cert_GetCertType(cert);
f6e752
     certType = cert->nsCertType;
f6e752
 
f6e752
     for (i = 1; i <= certificateUsageHighest &&
f6e752
                 (SECSuccess == valid || returnedUsages || log);) {
f6e752
+        PRBool typeAndEKUAllowed = PR_TRUE;
f6e752
         PRBool requiredUsage = (i & requiredUsages) ? PR_TRUE : PR_FALSE;
f6e752
         if (PR_FALSE == requiredUsage && PR_FALSE == checkAllUsages) {
f6e752
             NEXT_USAGE();
f6e752
         }
f6e752
         if (returnedUsages) {
f6e752
             *returnedUsages |= i; /* start off assuming this usage is valid */
f6e752
         }
f6e752
         switch (certUsage) {
f6e752
             case certUsageSSLClient:
f6e752
             case certUsageSSLServer:
f6e752
             case certUsageSSLServerWithStepUp:
f6e752
             case certUsageSSLCA:
f6e752
             case certUsageEmailSigner:
f6e752
             case certUsageEmailRecipient:
f6e752
             case certUsageObjectSigner:
f6e752
             case certUsageStatusResponder:
f6e752
+            case certUsageIPsec:
f6e752
                 rv = CERT_KeyUsageAndTypeForCertUsage(certUsage, PR_FALSE,
f6e752
                                                       &requiredKeyUsage,
f6e752
                                                       &requiredCertType);
f6e752
                 if (rv != SECSuccess) {
f6e752
                     PORT_Assert(0);
f6e752
                     /* EXIT_IF_NOT_LOGGING(log); XXX ??? */
f6e752
                     requiredKeyUsage = 0;
f6e752
                     requiredCertType = 0;
f6e752
@@ -1403,17 +1414,29 @@ CERT_VerifyCertificate(CERTCertDBHandle 
f6e752
         }
f6e752
         if (CERT_CheckKeyUsage(cert, requiredKeyUsage) != SECSuccess) {
f6e752
             if (PR_TRUE == requiredUsage) {
f6e752
                 PORT_SetError(SEC_ERROR_INADEQUATE_KEY_USAGE);
f6e752
             }
f6e752
             LOG_ERROR(log, cert, 0, requiredKeyUsage);
f6e752
             INVALID_USAGE();
f6e752
         }
f6e752
-        if (!(certType & requiredCertType)) {
f6e752
+        if (certUsage != certUsageIPsec) {
f6e752
+            if (!(certType & requiredCertType)) {
f6e752
+                typeAndEKUAllowed = PR_FALSE;
f6e752
+            }
f6e752
+        } else {
f6e752
+            PRBool isCritical;
f6e752
+            PRBool allowed = cert_EKUAllowsIPsecIKE(cert, &isCritical);
f6e752
+            /* If the extension isn't critical, we allow any EKU value. */
f6e752
+            if (isCritical && !allowed) {
f6e752
+                typeAndEKUAllowed = PR_FALSE;
f6e752
+            }
f6e752
+        }
f6e752
+        if (!typeAndEKUAllowed) {
f6e752
             if (PR_TRUE == requiredUsage) {
f6e752
                 PORT_SetError(SEC_ERROR_INADEQUATE_CERT_TYPE);
f6e752
             }
f6e752
             LOG_ERROR(log, cert, 0, requiredCertType);
f6e752
             INVALID_USAGE();
f6e752
         }
f6e752
 
f6e752
         rv = cert_CheckLeafTrust(cert, certUsage, &flags, &trusted);
f6e752
@@ -1503,29 +1526,31 @@ cert_VerifyCertWithFlags(CERTCertDBHandl
f6e752
     if (rv != SECSuccess) {
f6e752
         PORT_SetError(SEC_ERROR_REVOKED_CERTIFICATE);
f6e752
         LOG_ERROR_OR_EXIT(log, cert, 0, 0);
f6e752
     }
f6e752
 #endif
f6e752
 
f6e752
     /* make sure that the cert is valid at time t */
f6e752
     allowOverride = (PRBool)((certUsage == certUsageSSLServer) ||
f6e752
-                             (certUsage == certUsageSSLServerWithStepUp));
f6e752
+                             (certUsage == certUsageSSLServerWithStepUp) ||
f6e752
+                             (certUsage == certUsageIPsec));
f6e752
     validity = CERT_CheckCertValidTimes(cert, t, allowOverride);
f6e752
     if (validity != secCertTimeValid) {
f6e752
         LOG_ERROR_OR_EXIT(log, cert, 0, validity);
f6e752
     }
f6e752
 
f6e752
     /* check key usage and netscape cert type */
f6e752
     cert_GetCertType(cert);
f6e752
     certType = cert->nsCertType;
f6e752
     switch (certUsage) {
f6e752
         case certUsageSSLClient:
f6e752
         case certUsageSSLServer:
f6e752
         case certUsageSSLServerWithStepUp:
f6e752
+        case certUsageIPsec:
f6e752
         case certUsageSSLCA:
f6e752
         case certUsageEmailSigner:
f6e752
         case certUsageEmailRecipient:
f6e752
         case certUsageObjectSigner:
f6e752
         case certUsageStatusResponder:
f6e752
             rv = CERT_KeyUsageAndTypeForCertUsage(certUsage, PR_FALSE,
f6e752
                                                   &requiredKeyUsage,
f6e752
                                                   &requiredCertType);
f6e752
@@ -1628,16 +1653,17 @@ CERT_VerifyCertNow(CERTCertDBHandle *han
f6e752
 }
f6e752
 
f6e752
 /* [ FROM pcertdb.c ] */
f6e752
 /*
f6e752
  * Supported usage values and types:
f6e752
  *  certUsageSSLClient
f6e752
  *  certUsageSSLServer
f6e752
  *  certUsageSSLServerWithStepUp
f6e752
+ *  certUsageIPsec
f6e752
  *  certUsageEmailSigner
f6e752
  *  certUsageEmailRecipient
f6e752
  *  certUsageObjectSigner
f6e752
  */
f6e752
 
f6e752
 CERTCertificate *
f6e752
 CERT_FindMatchingCert(CERTCertDBHandle *handle, SECItem *derName,
f6e752
                       CERTCertOwner owner, SECCertUsage usage,
f6e752
diff --git a/lib/libpkix/pkix_pl_nss/pki/pkix_pl_cert.c b/lib/libpkix/pkix_pl_nss/pki/pkix_pl_cert.c
f6e752
--- a/lib/libpkix/pkix_pl_nss/pki/pkix_pl_cert.c
f6e752
+++ b/lib/libpkix/pkix_pl_nss/pki/pkix_pl_cert.c
f6e752
@@ -2909,17 +2909,18 @@ PKIX_PL_Cert_CheckValidity(
f6e752
                         PKIX_DATEGETPRTIMEFAILED);
f6e752
         } else {
f6e752
                 timeToCheck = PR_Now();
f6e752
         }
f6e752
 
f6e752
         requiredUsages = ((PKIX_PL_NssContext*)plContext)->certificateUsage;
f6e752
         allowOverride =
f6e752
             (PRBool)((requiredUsages & certificateUsageSSLServer) ||
f6e752
-                     (requiredUsages & certificateUsageSSLServerWithStepUp));
f6e752
+                     (requiredUsages & certificateUsageSSLServerWithStepUp) ||
f6e752
+                     (requiredUsages & certificateUsageIPsec));
f6e752
         val = CERT_CheckCertValidTimes(cert->nssCert, timeToCheck, allowOverride);
f6e752
         if (val != secCertTimeValid){
f6e752
                 PKIX_ERROR(PKIX_CERTCHECKCERTVALIDTIMESFAILED);
f6e752
         }
f6e752
 
f6e752
 cleanup:
f6e752
         PKIX_RETURN(CERT);
f6e752
 }
f6e752
@@ -2996,18 +2997,27 @@ PKIX_PL_Cert_VerifyCertAndKeyType(
f6e752
         /* use this key usage and cert type for certUsageAnyCA and
f6e752
          * certUsageVerifyCA. */
f6e752
 	requiredKeyUsage = KU_KEY_CERT_SIGN;
f6e752
 	requiredCertType = NS_CERT_TYPE_CA;
f6e752
     }
f6e752
     if (CERT_CheckKeyUsage(cert->nssCert, requiredKeyUsage) != SECSuccess) {
f6e752
         PKIX_ERROR(PKIX_CERTCHECKKEYUSAGEFAILED);
f6e752
     }
f6e752
-    if (!(certType & requiredCertType)) {
f6e752
-        PKIX_ERROR(PKIX_CERTCHECKCERTTYPEFAILED);
f6e752
+    if (certUsage != certUsageIPsec) {
f6e752
+        if (!(certType & requiredCertType)) {
f6e752
+            PKIX_ERROR(PKIX_CERTCHECKCERTTYPEFAILED);
f6e752
+        }
f6e752
+    } else {
f6e752
+        PRBool isCritical;
f6e752
+        PRBool allowed = cert_EKUAllowsIPsecIKE(cert->nssCert, &isCritical);
f6e752
+        /* If the extension isn't critical, we allow any EKU value. */
f6e752
+        if (isCritical && !allowed) {
f6e752
+            PKIX_ERROR(PKIX_CERTCHECKCERTTYPEFAILED);
f6e752
+        }
f6e752
     }
f6e752
 cleanup:
f6e752
     PKIX_DECREF(basicConstraints);
f6e752
     PKIX_RETURN(CERT);
f6e752
 }
f6e752
 
f6e752
 /*
f6e752
  * FUNCTION: PKIX_PL_Cert_VerifyKeyUsage (see comments in pkix_pl_pki.h)
f6e752
diff --git a/tests/chains/chains.sh b/tests/chains/chains.sh
f6e752
--- a/tests/chains/chains.sh
f6e752
+++ b/tests/chains/chains.sh
f6e752
@@ -347,16 +347,22 @@ create_cert_req()
f6e752
     OPTIONS=
f6e752
 
f6e752
     if [ "${TYPE}" != "EE" ]; then
f6e752
         CA_FLAG="-2"
f6e752
         EXT_DATA="y
f6e752
 -1
f6e752
 y
f6e752
 "
f6e752
+    else
f6e752
+        CA_FLAG="-2"
f6e752
+        EXT_DATA="n
f6e752
+-1
f6e752
+y
f6e752
+"
f6e752
     fi
f6e752
 
f6e752
     process_crldp
f6e752
 
f6e752
     echo "${EXT_DATA}" > ${CU_DATA}
f6e752
 
f6e752
     TESTNAME="Creating ${TYPE} certifiate request ${REQ}"
f6e752
     echo "${SCRIPTNAME}: ${TESTNAME}"
f6e752
@@ -1253,16 +1259,22 @@ process_scenario()
f6e752
 
f6e752
     while read AIA_FILE
f6e752
     do
f6e752
 	rm ${AIA_FILE} 2> /dev/null
f6e752
     done < ${AIA_FILES}
f6e752
     rm ${AIA_FILES}
f6e752
 }
f6e752
 
f6e752
+# process ipsec.cfg separately
f6e752
+chains_ipsec()
f6e752
+{
f6e752
+    process_scenario "ipsec.cfg"
f6e752
+}
f6e752
+
f6e752
 # process ocspd.cfg separately
f6e752
 chains_ocspd()
f6e752
 {
f6e752
     process_scenario "ocspd.cfg"
f6e752
 }
f6e752
 
f6e752
 # process ocsp.cfg separately
f6e752
 chains_method()
f6e752
@@ -1274,29 +1286,31 @@ chains_method()
f6e752
 # local shell function to process all testing scenarios
f6e752
 ########################################################################
f6e752
 chains_main()
f6e752
 {
f6e752
     while read LINE 
f6e752
     do
f6e752
         [ `echo ${LINE} | cut -b 1` != "#" ] || continue
f6e752
 
f6e752
+	[ ${LINE} != 'ipsec.cfg' ] || continue
f6e752
 	[ ${LINE} != 'ocspd.cfg' ] || continue
f6e752
 	[ ${LINE} != 'method.cfg' ] || continue
f6e752
 
f6e752
 	process_scenario ${LINE}
f6e752
     done < "${CHAINS_SCENARIOS}"
f6e752
 }
f6e752
 
f6e752
 ################################ main ##################################
f6e752
 
f6e752
 chains_init
f6e752
 VERIFY_CLASSIC_ENGINE_TOO=
f6e752
 chains_ocspd
f6e752
 VERIFY_CLASSIC_ENGINE_TOO=1
f6e752
+chains_ipsec
f6e752
 chains_run_httpserv get
f6e752
 chains_method
f6e752
 chains_stop_httpserv
f6e752
 chains_run_httpserv post
f6e752
 chains_method
f6e752
 chains_stop_httpserv
f6e752
 VERIFY_CLASSIC_ENGINE_TOO=
f6e752
 chains_run_httpserv random
f6e752
diff --git a/tests/chains/scenarios/ipsec.cfg b/tests/chains/scenarios/ipsec.cfg
f6e752
new file mode 100644
f6e752
--- /dev/null
f6e752
+++ b/tests/chains/scenarios/ipsec.cfg
f6e752
@@ -0,0 +1,61 @@
f6e752
+# This Source Code Form is subject to the terms of the Mozilla Public
f6e752
+# License, v. 2.0. If a copy of the MPL was not distributed with this
f6e752
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
f6e752
+
f6e752
+scenario IPsec
f6e752
+
f6e752
+entity Root
f6e752
+  type Root
f6e752
+
f6e752
+entity CA1
f6e752
+  type Intermediate
f6e752
+  issuer Root 
f6e752
+
f6e752
+entity NoKU
f6e752
+  type EE
f6e752
+  issuer CA1
f6e752
+
f6e752
+entity DigSig
f6e752
+  type EE
f6e752
+  issuer CA1
f6e752
+    ku digitalSignature
f6e752
+
f6e752
+entity NonRep
f6e752
+  type EE
f6e752
+  issuer CA1
f6e752
+    ku nonRepudiation
f6e752
+
f6e752
+entity DigSigNonRepAndExtra
f6e752
+  type EE
f6e752
+  issuer CA1
f6e752
+    ku digitalSignature,nonRepudiation,keyEncipherment,dataEncipherment,keyAgreement
f6e752
+
f6e752
+entity NoMatch
f6e752
+  type EE
f6e752
+  issuer CA1
f6e752
+    ku keyEncipherment,dataEncipherment,keyAgreement
f6e752
+
f6e752
+db All
f6e752
+
f6e752
+import Root::C,,
f6e752
+import CA1:Root:
f6e752
+
f6e752
+verify NoKU:CA1
f6e752
+  usage 12
f6e752
+  result pass
f6e752
+
f6e752
+verify DigSig:CA1
f6e752
+  usage 12
f6e752
+  result pass
f6e752
+
f6e752
+verify NonRep:CA1
f6e752
+  usage 12
f6e752
+  result pass
f6e752
+
f6e752
+verify DigSigNonRepAndExtra:CA1
f6e752
+  usage 12
f6e752
+  result pass
f6e752
+
f6e752
+verify NoMatch:CA1
f6e752
+  usage 12
f6e752
+  result fail
f6e752
diff --git a/tests/chains/scenarios/scenarios b/tests/chains/scenarios/scenarios
f6e752
--- a/tests/chains/scenarios/scenarios
f6e752
+++ b/tests/chains/scenarios/scenarios
f6e752
@@ -17,8 +17,9 @@ bridgewithhalfaia.cfg
f6e752
 bridgewithpolicyextensionandmapping.cfg
f6e752
 realcerts.cfg
f6e752
 dsa.cfg
f6e752
 revoc.cfg
f6e752
 ocsp.cfg
f6e752
 crldp.cfg
f6e752
 trustanchors.cfg
f6e752
 nameconstraints.cfg
f6e752
+ipsec.cfg