Blame SOURCES/Fix-k5tls-module-for-OpenSSL-3.patch

cb4cef
From 51938a8b731740299fe47d132b8840edba4141bc Mon Sep 17 00:00:00 2001
cb4cef
From: Robbie Harwood <rharwood@redhat.com>
cb4cef
Date: Sat, 29 May 2021 12:05:49 -0400
cb4cef
Subject: [PATCH] Fix k5tls module for OpenSSL 3
cb4cef
cb4cef
Starting in OpenSSL 3, connection termination without a close_notify
cb4cef
alert causes SSL_read() to return SSL_ERROR_SSL instead of
cb4cef
SSL_ERROR_SYSCALL.  OpenSSL 3 also provides a new option
cb4cef
SSL_OP_IGNORE_UNEXPECTED_EOF which allows an application to explicitly
cb4cef
ignore possible truncation attacks and receive SSL_ERROR_ZERO_RETURN
cb4cef
instead.
cb4cef
cb4cef
Remove the call to SSL_CTX_get_options() since SSL_CTX_set_options()
cb4cef
doesn't clear existing options.
cb4cef
cb4cef
[ghudson@mit.edu: edited commit message and comment]
cb4cef
cb4cef
(cherry picked from commit aa9b4a2a64046afd2fab7cb49c346295874a5fb6)
cb4cef
(cherry picked from commit 201e38845e9f70234bcaa9ba7c25b28e38169b0a)
cb4cef
---
cb4cef
 src/plugins/tls/k5tls/openssl.c | 17 ++++++++++++++---
cb4cef
 1 file changed, 14 insertions(+), 3 deletions(-)
cb4cef
cb4cef
diff --git a/src/plugins/tls/k5tls/openssl.c b/src/plugins/tls/k5tls/openssl.c
cb4cef
index 76a43b3cd..99fda7ffc 100644
cb4cef
--- a/src/plugins/tls/k5tls/openssl.c
cb4cef
+++ b/src/plugins/tls/k5tls/openssl.c
cb4cef
@@ -433,7 +433,7 @@ setup(krb5_context context, SOCKET fd, const char *servername,
cb4cef
       char **anchors, k5_tls_handle *handle_out)
cb4cef
 {
cb4cef
     int e;
cb4cef
-    long options;
cb4cef
+    long options = SSL_OP_NO_SSLv2;
cb4cef
     SSL_CTX *ctx = NULL;
cb4cef
     SSL *ssl = NULL;
cb4cef
     k5_tls_handle handle = NULL;
cb4cef
@@ -448,8 +448,19 @@ setup(krb5_context context, SOCKET fd, const char *servername,
cb4cef
     ctx = SSL_CTX_new(SSLv23_client_method());
cb4cef
     if (ctx == NULL)
cb4cef
         goto error;
cb4cef
-    options = SSL_CTX_get_options(ctx);
cb4cef
-    SSL_CTX_set_options(ctx, options | SSL_OP_NO_SSLv2);
cb4cef
+
cb4cef
+#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
cb4cef
+    /*
cb4cef
+     * For OpenSSL 3 and later, mark close_notify alerts as optional.  We don't
cb4cef
+     * need to worry about truncation attacks because the protocols this module
cb4cef
+     * is used with (Kerberos and change-password) receive a single
cb4cef
+     * length-delimited message from the server.  For prior versions of OpenSSL
cb4cef
+     * we check for SSL_ERROR_SYSCALL when reading instead (this error changes
cb4cef
+     * to SSL_ERROR_SSL in OpenSSL 3).
cb4cef
+     */
cb4cef
+    options |= SSL_OP_IGNORE_UNEXPECTED_EOF;
cb4cef
+#endif
cb4cef
+    SSL_CTX_set_options(ctx, options);
cb4cef
 
cb4cef
     SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, verify_callback);
cb4cef
     X509_STORE_set_flags(SSL_CTX_get_cert_store(ctx), 0);