Blame SOURCES/libreswan-3.25-EKU-1639404.patch

5b9a3d
diff --git a/lib/libswan/Makefile b/lib/libswan/Makefile
5b9a3d
index 510148ad1..0f5c26228 100644
5b9a3d
--- a/lib/libswan/Makefile
5b9a3d
+++ b/lib/libswan/Makefile
5b9a3d
@@ -200,10 +200,6 @@ CFLAGS+=-I${LIBRESWANSRCDIR}/include ${PORTINCLUDE}
5b9a3d
 CFLAGS+=$(USERLAND_CFLAGS)
5b9a3d
 CFLAGS+=${CROSSFLAGS}
5b9a3d
 
5b9a3d
-ifeq ($(NSS_REQ_AVA_COPY),true)
5b9a3d
-CFLAGS+=-DNSS_REQ_AVA_COPY
5b9a3d
-endif
5b9a3d
-
5b9a3d
 OBJS += $(abs_builddir)/version.o
5b9a3d
 
5b9a3d
 include $(top_srcdir)/mk/library.mk
5b9a3d
diff --git a/mk/config.mk b/mk/config.mk
5b9a3d
index 3f2bd55c1..fcdabd1fb 100644
5b9a3d
--- a/mk/config.mk
5b9a3d
+++ b/mk/config.mk
5b9a3d
@@ -242,6 +242,17 @@ NSPR_LDFLAGS ?= -lnspr4
5b9a3d
 # Use nss copy for CERT_CompareAVA
5b9a3d
 # See https://bugzilla.mozilla.org/show_bug.cgi?id=1336487
5b9a3d
 NSS_REQ_AVA_COPY?=true
5b9a3d
+ifeq ($(NSS_REQ_AVA_COPY),true)
5b9a3d
+NSSFLAGS+=-DNSS_REQ_AVA_COPY
5b9a3d
+endif
5b9a3d
+
5b9a3d
+# Use nss IPsec profile for X509 validation. This is less restrictive
5b9a3d
+# ok EKU's. This is not yet in upstream nss.
5b9a3d
+# See https://bugzilla.mozilla.org/show_bug.cgi?id=1252891
5b9a3d
+NSS_HAS_IPSEC_PROFILE?=false
5b9a3d
+ifeq ($(NSS_HAS_IPSEC_PROFILE),true)
5b9a3d
+NSSFLAGS+=-DNSS_IPSEC_PROFILE
5b9a3d
+endif
5b9a3d
 
5b9a3d
 # Use a local copy of xfrm.h. This can be needed on older systems
5b9a3d
 # that do not ship linux/xfrm.h, or when the shipped version is too
5b9a3d
diff --git a/programs/pluto/nss_cert_verify.c b/programs/pluto/nss_cert_verify.c
5b9a3d
index 95c637f53..7d458ac2a 100644
5b9a3d
--- a/programs/pluto/nss_cert_verify.c
5b9a3d
+++ b/programs/pluto/nss_cert_verify.c
5b9a3d
@@ -299,6 +299,28 @@ static int vfy_chain_pkix(CERTCertificate **chain, int chain_len,
5b9a3d
 	cvout[1].value.pointer.chain = NULL;
5b9a3d
 	cvout[2].type = cert_po_end;
5b9a3d
 
5b9a3d
+	int fin;
5b9a3d
+
5b9a3d
+#ifdef NSS_IPSEC_PROFILE
5b9a3d
+	SECStatus rv = CERT_PKIXVerifyCert(end_cert, certificateUsageIPsec,
5b9a3d
+						cvin, cvout, NULL);
5b9a3d
+	if (rv != SECSuccess || cur_log->count > 0) {
5b9a3d
+		if (cur_log->count > 0 && cur_log->head != NULL) {
5b9a3d
+			fin = nss_err_to_revfail(cur_log->head);
5b9a3d
+		} else {
5b9a3d
+			/*
5b9a3d
+			 * An rv != SECSuccess without CERTVerifyLog
5b9a3d
+			 * results should not * happen, but catch it anyway
5b9a3d
+			 */
5b9a3d
+			loglog(RC_LOG_SERIOUS, "X509: unspecified NSS verification failure");
5b9a3d
+			fin = VERIFY_RET_FAIL;
5b9a3d
+		}
5b9a3d
+	} else {
5b9a3d
+		DBG(DBG_X509, DBG_log("certificate is valid"));
5b9a3d
+		*end_out = end_cert;
5b9a3d
+		fin = VERIFY_RET_OK;
5b9a3d
+	}
5b9a3d
+#else
5b9a3d
 	/* kludge alert!!
5b9a3d
 	 * verification may be performed twice: once with the
5b9a3d
 	 * 'client' usage and once with 'server', which is an NSS
5b9a3d
@@ -307,12 +329,10 @@ static int vfy_chain_pkix(CERTCertificate **chain, int chain_len,
5b9a3d
 	 * KU/EKU combinations
5b9a3d
 	 */
5b9a3d
 
5b9a3d
-	int fin;
5b9a3d
 	SECCertificateUsage usage;
5b9a3d
 
5b9a3d
 	for (usage = certificateUsageSSLClient; ; usage = certificateUsageSSLServer) {
5b9a3d
 		SECStatus rv = CERT_PKIXVerifyCert(end_cert, usage, cvin, cvout, NULL);
5b9a3d
-
5b9a3d
 		if (rv != SECSuccess || cur_log->count > 0) {
5b9a3d
 			if (cur_log->count > 0 && cur_log->head != NULL) {
5b9a3d
 				if (usage == certificateUsageSSLClient &&
5b9a3d
@@ -346,6 +366,7 @@ static int vfy_chain_pkix(CERTCertificate **chain, int chain_len,
5b9a3d
 		}
5b9a3d
 		break;
5b9a3d
 	}
5b9a3d
+#endif
5b9a3d
 	pexpect(fin != 0);
5b9a3d
 
5b9a3d
 	CERT_DestroyCertList(trustcl);
5b9a3d
diff --git a/programs/pluto/plutomain.c b/programs/pluto/plutomain.c
5b9a3d
index 50582822d..007d73f45 100644
5b9a3d
--- a/programs/pluto/plutomain.c
5b9a3d
+++ b/programs/pluto/plutomain.c
5b9a3d
@@ -180,6 +180,12 @@ static const char compile_time_interop_options[] = ""
5b9a3d
 	" BROKEN_POPEN"
5b9a3d
 #endif
5b9a3d
 	" NSS"
5b9a3d
+#ifdef NSS_REQ_AVA_COPY
5b9a3d
+	" (AVA copy)"
5b9a3d
+#endif
5b9a3d
+#ifdef NSS_IPSEC_PROFILE
5b9a3d
+	" (IPsec profile)"
5b9a3d
+#endif
5b9a3d
 #ifdef USE_DNSSEC
5b9a3d
 	" DNSSEC"
5b9a3d
 #endif