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

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