Blame SOURCES/0024-curl-7.61.1-openssl-partial-chain.patch

c3d52c
From 673adb0a7a21ca3a877ee03dc9e197d5be15a9d3 Mon Sep 17 00:00:00 2001
c3d52c
From: Daniel Stenberg <daniel@haxx.se>
c3d52c
Date: Mon, 2 Dec 2019 10:45:55 +0100
c3d52c
Subject: [PATCH 1/3] openssl: set X509_V_FLAG_PARTIAL_CHAIN
c3d52c
c3d52c
Have intermediate certificates in the trust store be treated as
c3d52c
trust-anchors, in the same way as self-signed root CA certificates
c3d52c
are. This allows users to verify servers using the intermediate cert
c3d52c
only, instead of needing the whole chain.
c3d52c
c3d52c
Other TLS backends already accept partial chains.
c3d52c
c3d52c
Reported-by: Jeffrey Walton
c3d52c
Bug: https://curl.haxx.se/mail/lib-2019-11/0094.html
c3d52c
c3d52c
Upstream-commit: 94f1f771586913addf5c68f9219e176036c50115
c3d52c
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c3d52c
---
c3d52c
 lib/vtls/openssl.c | 26 +++++++++++++++++---------
c3d52c
 1 file changed, 17 insertions(+), 9 deletions(-)
c3d52c
c3d52c
diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
c3d52c
index d8bcc4f..8e791b9 100644
c3d52c
--- a/lib/vtls/openssl.c
c3d52c
+++ b/lib/vtls/openssl.c
c3d52c
@@ -2551,19 +2551,27 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
c3d52c
     infof(data, "  CRLfile: %s\n", ssl_crlfile);
c3d52c
   }
c3d52c
 
c3d52c
-  /* Try building a chain using issuers in the trusted store first to avoid
c3d52c
-  problems with server-sent legacy intermediates.
c3d52c
-  Newer versions of OpenSSL do alternate chain checking by default which
c3d52c
-  gives us the same fix without as much of a performance hit (slight), so we
c3d52c
-  prefer that if available.
c3d52c
-  https://rt.openssl.org/Ticket/Display.html?id=3621&user=guest&pass=guest
c3d52c
-  */
c3d52c
-#if defined(X509_V_FLAG_TRUSTED_FIRST) && !defined(X509_V_FLAG_NO_ALT_CHAINS)
c3d52c
   if(verifypeer) {
c3d52c
+    /* Try building a chain using issuers in the trusted store first to avoid
c3d52c
+       problems with server-sent legacy intermediates.  Newer versions of
c3d52c
+       OpenSSL do alternate chain checking by default which gives us the same
c3d52c
+       fix without as much of a performance hit (slight), so we prefer that if
c3d52c
+       available.
c3d52c
+       https://rt.openssl.org/Ticket/Display.html?id=3621&user=guest&pass=guest
c3d52c
+    */
c3d52c
+#if defined(X509_V_FLAG_TRUSTED_FIRST) && !defined(X509_V_FLAG_NO_ALT_CHAINS)
c3d52c
     X509_STORE_set_flags(SSL_CTX_get_cert_store(BACKEND->ctx),
c3d52c
                          X509_V_FLAG_TRUSTED_FIRST);
c3d52c
-  }
c3d52c
 #endif
c3d52c
+#ifdef X509_V_FLAG_PARTIAL_CHAIN
c3d52c
+    /* Have intermediate certificates in the trust store be treated as
c3d52c
+       trust-anchors, in the same way as self-signed root CA certificates
c3d52c
+       are. This allows users to verify servers using the intermediate cert
c3d52c
+       only, instead of needing the whole chain. */
c3d52c
+    X509_STORE_set_flags(SSL_CTX_get_cert_store(BACKEND->ctx),
c3d52c
+                         X509_V_FLAG_PARTIAL_CHAIN);
c3d52c
+#endif
c3d52c
+  }
c3d52c
 
c3d52c
   /* SSL always tries to verify the peer, this only says whether it should
c3d52c
    * fail to connect if the verification fails, or if it should continue
c3d52c
-- 
c3d52c
2.26.2
c3d52c
c3d52c
c3d52c
From b2e6e39b60e1722aecf250ff79a69867df5d3aa8 Mon Sep 17 00:00:00 2001
c3d52c
From: Daniel Stenberg <daniel@haxx.se>
c3d52c
Date: Mon, 2 Dec 2019 10:55:33 +0100
c3d52c
Subject: [PATCH 2/3] openssl: CURLSSLOPT_NO_PARTIALCHAIN can disable partial
c3d52c
 cert chains
c3d52c
c3d52c
Closes #4655
c3d52c
c3d52c
Upstream-commit: 564d88a8bd190a21b362d6da535fccf74d33394d
c3d52c
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c3d52c
---
c3d52c
 docs/libcurl/opts/CURLOPT_SSL_OPTIONS.3 | 40 +++++++++++++------------
c3d52c
 docs/libcurl/symbols-in-versions        |  1 +
c3d52c
 include/curl/curl.h                     |  4 +++
c3d52c
 lib/setopt.c                            |  1 +
c3d52c
 lib/urldata.h                           |  1 +
c3d52c
 lib/vtls/openssl.c                      | 14 +++++----
c3d52c
 6 files changed, 36 insertions(+), 25 deletions(-)
c3d52c
c3d52c
diff --git a/docs/libcurl/opts/CURLOPT_SSL_OPTIONS.3 b/docs/libcurl/opts/CURLOPT_SSL_OPTIONS.3
c3d52c
index d781434..6286a64 100644
c3d52c
--- a/docs/libcurl/opts/CURLOPT_SSL_OPTIONS.3
c3d52c
+++ b/docs/libcurl/opts/CURLOPT_SSL_OPTIONS.3
c3d52c
@@ -29,25 +29,27 @@ CURLOPT_SSL_OPTIONS \- set SSL behavior options
c3d52c
 
c3d52c
 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSL_OPTIONS, long bitmask);
c3d52c
 .SH DESCRIPTION
c3d52c
-Pass a long with a bitmask to tell libcurl about specific SSL behaviors.
c3d52c
-
c3d52c
-\fICURLSSLOPT_ALLOW_BEAST\fP tells libcurl to not attempt to use any
c3d52c
-workarounds for a security flaw in the SSL3 and TLS1.0 protocols.  If this
c3d52c
-option isn't used or this bit is set to 0, the SSL layer libcurl uses may use a
c3d52c
-work-around for this flaw although it might cause interoperability problems
c3d52c
-with some (older) SSL implementations. WARNING: avoiding this work-around
c3d52c
-lessens the security, and by setting this option to 1 you ask for exactly that.
c3d52c
-This option is only supported for DarwinSSL, NSS and OpenSSL.
c3d52c
-
c3d52c
-Added in 7.44.0:
c3d52c
-
c3d52c
-\fICURLSSLOPT_NO_REVOKE\fP tells libcurl to disable certificate revocation
c3d52c
-checks for those SSL backends where such behavior is present. \fBCurrently this
c3d52c
-option is only supported for WinSSL (the native Windows SSL library), with an
c3d52c
-exception in the case of Windows' Untrusted Publishers blacklist which it seems
c3d52c
-can't be bypassed.\fP This option may have broader support to accommodate other
c3d52c
-SSL backends in the future.
c3d52c
-https://curl.haxx.se/docs/ssl-compared.html
c3d52c
+Pass a long with a bitmask to tell libcurl about specific SSL
c3d52c
+behaviors. Available bits:
c3d52c
+.IP CURLSSLOPT_ALLOW_BEAST
c3d52c
+Tells libcurl to not attempt to use any workarounds for a security flaw in the
c3d52c
+SSL3 and TLS1.0 protocols.  If this option isn't used or this bit is set to 0,
c3d52c
+the SSL layer libcurl uses may use a work-around for this flaw although it
c3d52c
+might cause interoperability problems with some (older) SSL
c3d52c
+implementations. WARNING: avoiding this work-around lessens the security, and
c3d52c
+by setting this option to 1 you ask for exactly that.  This option is only
c3d52c
+supported for DarwinSSL, NSS and OpenSSL.
c3d52c
+.IP CURLSSLOPT_NO_REVOKE
c3d52c
+Tells libcurl to disable certificate revocation checks for those SSL backends
c3d52c
+where such behavior is present. This option is only supported for Schannel
c3d52c
+(the native Windows SSL library), with an exception in the case of Windows'
c3d52c
+Untrusted Publishers blacklist which it seems can't be bypassed. (Added in
c3d52c
+7.44.0)
c3d52c
+.IP CURLSSLOPT_NO_PARTIALCHAIN
c3d52c
+Tells libcurl to not accept "partial" certificate chains, which it otherwise
c3d52c
+does by default. This option is only supported for OpenSSL and will fail the
c3d52c
+certificate verification if the chain ends with an intermediate certificate
c3d52c
+and not with a root cert. (Added in 7.68.0)
c3d52c
 .SH DEFAULT
c3d52c
 0
c3d52c
 .SH PROTOCOLS
c3d52c
diff --git a/docs/libcurl/symbols-in-versions b/docs/libcurl/symbols-in-versions
c3d52c
index 3b3861f..54923d0 100644
c3d52c
--- a/docs/libcurl/symbols-in-versions
c3d52c
+++ b/docs/libcurl/symbols-in-versions
c3d52c
@@ -713,6 +713,7 @@ CURLSSLBACKEND_QSOSSL           7.34.0        -           7.38.1
c3d52c
 CURLSSLBACKEND_SCHANNEL         7.34.0
c3d52c
 CURLSSLBACKEND_WOLFSSL          7.49.0
c3d52c
 CURLSSLOPT_ALLOW_BEAST          7.25.0
c3d52c
+CURLSSLOPT_NO_PARTIALCHAIN      7.68.0
c3d52c
 CURLSSLOPT_NO_REVOKE            7.44.0
c3d52c
 CURLSSLSET_NO_BACKENDS          7.56.0
c3d52c
 CURLSSLSET_OK                   7.56.0
c3d52c
diff --git a/include/curl/curl.h b/include/curl/curl.h
c3d52c
index 8f473e2..75f9384 100644
c3d52c
--- a/include/curl/curl.h
c3d52c
+++ b/include/curl/curl.h
c3d52c
@@ -795,6 +795,10 @@ typedef enum {
c3d52c
    SSL backends where such behavior is present. */
c3d52c
 #define CURLSSLOPT_NO_REVOKE (1<<1)
c3d52c
 
c3d52c
+/* - NO_PARTIALCHAIN tells libcurl to *NOT* accept a partial certificate chain
c3d52c
+   if possible. The OpenSSL backend has this ability. */
c3d52c
+#define CURLSSLOPT_NO_PARTIALCHAIN (1<<2)
c3d52c
+
c3d52c
 /* The default connection attempt delay in milliseconds for happy eyeballs.
c3d52c
    CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS.3 and happy-eyeballs-timeout-ms.d document
c3d52c
    this value, keep them in sync. */
c3d52c
diff --git a/lib/setopt.c b/lib/setopt.c
c3d52c
index 5c5f4b3..4f04962 100644
c3d52c
--- a/lib/setopt.c
c3d52c
+++ b/lib/setopt.c
c3d52c
@@ -2046,6 +2046,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option,
c3d52c
     arg = va_arg(param, long);
c3d52c
     data->set.ssl.enable_beast = arg&CURLSSLOPT_ALLOW_BEAST?TRUE:FALSE;
c3d52c
     data->set.ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
c3d52c
+    data->set.ssl.no_partialchain = !!(arg & CURLSSLOPT_NO_PARTIALCHAIN);
c3d52c
     break;
c3d52c
 
c3d52c
   case CURLOPT_PROXY_SSL_OPTIONS:
c3d52c
diff --git a/lib/urldata.h b/lib/urldata.h
c3d52c
index 4b70cc5..c70290a 100644
c3d52c
--- a/lib/urldata.h
c3d52c
+++ b/lib/urldata.h
c3d52c
@@ -235,6 +235,7 @@ struct ssl_config_data {
c3d52c
   bool enable_beast; /* especially allow this flaw for interoperability's
c3d52c
                         sake*/
c3d52c
   bool no_revoke;    /* disable SSL certificate revocation checks */
c3d52c
+  bool no_partialchain;  /* don't accept partial certificate chains */
c3d52c
   long certverifyresult; /* result from the certificate verification */
c3d52c
   char *CRLfile;   /* CRL to check certificate revocation */
c3d52c
   char *issuercert;/* optional issuer certificate filename */
c3d52c
diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
c3d52c
index 8e791b9..87f6c4c 100644
c3d52c
--- a/lib/vtls/openssl.c
c3d52c
+++ b/lib/vtls/openssl.c
c3d52c
@@ -2564,12 +2564,14 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
c3d52c
                          X509_V_FLAG_TRUSTED_FIRST);
c3d52c
 #endif
c3d52c
 #ifdef X509_V_FLAG_PARTIAL_CHAIN
c3d52c
-    /* Have intermediate certificates in the trust store be treated as
c3d52c
-       trust-anchors, in the same way as self-signed root CA certificates
c3d52c
-       are. This allows users to verify servers using the intermediate cert
c3d52c
-       only, instead of needing the whole chain. */
c3d52c
-    X509_STORE_set_flags(SSL_CTX_get_cert_store(BACKEND->ctx),
c3d52c
-                         X509_V_FLAG_PARTIAL_CHAIN);
c3d52c
+    if(!SSL_SET_OPTION(no_partialchain)) {
c3d52c
+      /* Have intermediate certificates in the trust store be treated as
c3d52c
+         trust-anchors, in the same way as self-signed root CA certificates
c3d52c
+         are. This allows users to verify servers using the intermediate cert
c3d52c
+         only, instead of needing the whole chain. */
c3d52c
+      X509_STORE_set_flags(SSL_CTX_get_cert_store(BACKEND->ctx),
c3d52c
+                           X509_V_FLAG_PARTIAL_CHAIN);
c3d52c
+    }
c3d52c
 #endif
c3d52c
   }
c3d52c
 
c3d52c
-- 
c3d52c
2.26.2
c3d52c
c3d52c
c3d52c
From d149ba12f302e5275b408d82ffb349eac16b9226 Mon Sep 17 00:00:00 2001
c3d52c
From: Daniel Stenberg <daniel@haxx.se>
c3d52c
Date: Mon, 11 May 2020 23:00:31 +0200
c3d52c
Subject: [PATCH 3/3] OpenSSL: have CURLOPT_CRLFILE imply
c3d52c
 CURLSSLOPT_NO_PARTIALCHAIN
c3d52c
c3d52c
... to avoid an OpenSSL bug that otherwise makes the CRL check to fail.
c3d52c
c3d52c
Reported-by: Michael Kaufmann
c3d52c
Fixes #5374
c3d52c
Closes #5376
c3d52c
c3d52c
Upstream-commit: 81a54b12c631e8126e3eb484c74040b991e78f0c
c3d52c
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c3d52c
---
c3d52c
 docs/libcurl/opts/CURLOPT_CRLFILE.3 | 13 ++++++++-----
c3d52c
 lib/vtls/openssl.c                  |  8 ++++++--
c3d52c
 2 files changed, 14 insertions(+), 7 deletions(-)
c3d52c
c3d52c
diff --git a/docs/libcurl/opts/CURLOPT_CRLFILE.3 b/docs/libcurl/opts/CURLOPT_CRLFILE.3
c3d52c
index 080caa7..f111585 100644
c3d52c
--- a/docs/libcurl/opts/CURLOPT_CRLFILE.3
c3d52c
+++ b/docs/libcurl/opts/CURLOPT_CRLFILE.3
c3d52c
@@ -5,7 +5,7 @@
c3d52c
 .\" *                            | (__| |_| |  _ <| |___
c3d52c
 .\" *                             \___|\___/|_| \_\_____|
c3d52c
 .\" *
c3d52c
-.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
c3d52c
+.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
c3d52c
 .\" *
c3d52c
 .\" * This software is licensed as described in the file COPYING, which
c3d52c
 .\" * you should have received as part of this distribution. The terms
c3d52c
@@ -34,10 +34,13 @@ concatenation of CRL (in PEM format) to use in the certificate validation that
c3d52c
 occurs during the SSL exchange.
c3d52c
 
c3d52c
 When curl is built to use NSS or GnuTLS, there is no way to influence the use
c3d52c
-of CRL passed to help in the verification process. When libcurl is built with
c3d52c
-OpenSSL support, X509_V_FLAG_CRL_CHECK and X509_V_FLAG_CRL_CHECK_ALL are both
c3d52c
-set, requiring CRL check against all the elements of the certificate chain if
c3d52c
-a CRL file is passed.
c3d52c
+of CRL passed to help in the verification process.
c3d52c
+
c3d52c
+When libcurl is built with OpenSSL support, X509_V_FLAG_CRL_CHECK and
c3d52c
+X509_V_FLAG_CRL_CHECK_ALL are both set, requiring CRL check against all the
c3d52c
+elements of the certificate chain if a CRL file is passed. Also note that
c3d52c
+\fICURLOPT_CRLFILE(3)\fP will imply \fBCURLSSLOPT_NO_PARTIALCHAIN\fP (see
c3d52c
+\fICURLOPT_SSL_OPTIONS(3)\fP) since curl 7.71.0 due to an OpenSSL bug.
c3d52c
 
c3d52c
 This option makes sense only when used in combination with the
c3d52c
 \fICURLOPT_SSL_VERIFYPEER(3)\fP option.
c3d52c
diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
c3d52c
index 87f6c4c..9476773 100644
c3d52c
--- a/lib/vtls/openssl.c
c3d52c
+++ b/lib/vtls/openssl.c
c3d52c
@@ -2564,11 +2564,15 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
c3d52c
                          X509_V_FLAG_TRUSTED_FIRST);
c3d52c
 #endif
c3d52c
 #ifdef X509_V_FLAG_PARTIAL_CHAIN
c3d52c
-    if(!SSL_SET_OPTION(no_partialchain)) {
c3d52c
+    if(!SSL_SET_OPTION(no_partialchain) && !ssl_crlfile) {
c3d52c
       /* Have intermediate certificates in the trust store be treated as
c3d52c
          trust-anchors, in the same way as self-signed root CA certificates
c3d52c
          are. This allows users to verify servers using the intermediate cert
c3d52c
-         only, instead of needing the whole chain. */
c3d52c
+         only, instead of needing the whole chain.
c3d52c
+
c3d52c
+         Due to OpenSSL bug https://github.com/openssl/openssl/issues/5081 we
c3d52c
+         cannot do partial chains with CRL check.
c3d52c
+      */
c3d52c
       X509_STORE_set_flags(SSL_CTX_get_cert_store(BACKEND->ctx),
c3d52c
                            X509_V_FLAG_PARTIAL_CHAIN);
c3d52c
     }
c3d52c
-- 
c3d52c
2.26.2
c3d52c