Blame SOURCES/mysql-openssl3.patch

4522a4
Make MySQL compile with openssl 3.x without FIPS properly implemented
4522a4
4522a4
This change takes some pieces from MariaDB, including compat_ssl.h and
4522a4
changes in my_md5.cc.
4522a4
4522a4
MySQL utilizes FIPS_mode() and FIPS_mode_set() functions that are not
4522a4
available in OpenSSL 3.x any more. This patch only mocks the call of
4522a4
those functions, returning 0 every time, which effectively makes usage
4522a4
of those functions non working. For making the MySQL build with
4522a4
OpenSSL 3.x this seems to be enough though.
4522a4
4522a4
Resolves: #1952951
4522a4
4522a4
diff -rup mysql-8.0.22-orig/cmake/ssl.cmake mysql-8.0.22/cmake/ssl.cmake
4522a4
--- mysql-8.0.22-orig/cmake/ssl.cmake	2021-05-19 21:36:33.161996422 +0200
4522a4
+++ mysql-8.0.22/cmake/ssl.cmake	2021-05-19 23:06:54.211877057 +0200
4522a4
@@ -227,8 +227,7 @@ MACRO (MYSQL_CHECK_SSL)
4522a4
     ENDIF()
4522a4
     IF(OPENSSL_INCLUDE_DIR AND
4522a4
        OPENSSL_LIBRARY   AND
4522a4
-       CRYPTO_LIBRARY      AND
4522a4
-       OPENSSL_MAJOR_VERSION STREQUAL "1"
4522a4
+       CRYPTO_LIBRARY
4522a4
       )
4522a4
       SET(OPENSSL_FOUND TRUE)
4522a4
       FIND_PROGRAM(OPENSSL_EXECUTABLE openssl
4522a4
diff -rup mysql-8.0.22-orig/include/ssl_compat.h mysql-8.0.22/include/ssl_compat.h
4522a4
--- mysql-8.0.22-orig/include/ssl_compat.h	2021-05-19 23:19:36.152956356 +0200
4522a4
+++ mysql-8.0.22/include/ssl_compat.h	2021-05-19 23:06:55.048885933 +0200
4522a4
@@ -0,0 +1,105 @@
4522a4
+/*
4522a4
+ Copyright (c) 2016, 2021, MariaDB Corporation.
4522a4
+
4522a4
+ This program is free software; you can redistribute it and/or modify
4522a4
+ it under the terms of the GNU General Public License as published by
4522a4
+ the Free Software Foundation; version 2 of the License.
4522a4
+
4522a4
+ This program is distributed in the hope that it will be useful,
4522a4
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
4522a4
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4522a4
+ GNU General Public License for more details.
4522a4
+
4522a4
+ You should have received a copy of the GNU General Public License
4522a4
+ along with this program; if not, write to the Free Software
4522a4
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
4522a4
+
4522a4
+#include <openssl/opensslv.h>
4522a4
+
4522a4
+/* OpenSSL version specific definitions */
4522a4
+#if defined(OPENSSL_VERSION_NUMBER)
4522a4
+
4522a4
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
4522a4
+#define HAVE_OPENSSL11 1
4522a4
+#define SSL_LIBRARY OpenSSL_version(OPENSSL_VERSION)
4522a4
+#define ERR_remove_state(X) ERR_clear_error()
4522a4
+#define EVP_CIPHER_CTX_SIZE 176
4522a4
+#define EVP_MD_CTX_SIZE 48
4522a4
+#undef EVP_MD_CTX_init
4522a4
+#define EVP_MD_CTX_init(X) do { memset((X), 0, EVP_MD_CTX_SIZE); EVP_MD_CTX_reset(X); } while(0)
4522a4
+#undef EVP_CIPHER_CTX_init
4522a4
+#define EVP_CIPHER_CTX_init(X) do { memset((X), 0, EVP_CIPHER_CTX_SIZE); EVP_CIPHER_CTX_reset(X); } while(0)
4522a4
+
4522a4
+/*
4522a4
+  Macros below are deprecated. OpenSSL 1.1 may define them or not,
4522a4
+  depending on how it was built.
4522a4
+*/
4522a4
+#undef ERR_free_strings
4522a4
+#define ERR_free_strings()
4522a4
+#undef EVP_cleanup
4522a4
+#define EVP_cleanup()
4522a4
+#undef CRYPTO_cleanup_all_ex_data
4522a4
+#define CRYPTO_cleanup_all_ex_data()
4522a4
+#undef SSL_load_error_strings
4522a4
+#define SSL_load_error_strings()
4522a4
+
4522a4
+#else
4522a4
+#define HAVE_OPENSSL10 1
4522a4
+#ifdef HAVE_WOLFSSL
4522a4
+#define SSL_LIBRARY "WolfSSL " WOLFSSL_VERSION
4522a4
+#else
4522a4
+#define SSL_LIBRARY SSLeay_version(SSLEAY_VERSION)
4522a4
+#endif
4522a4
+
4522a4
+#ifdef HAVE_WOLFSSL
4522a4
+#undef ERR_remove_state
4522a4
+#define ERR_remove_state(x) do {} while(0)
4522a4
+#elif defined (HAVE_ERR_remove_thread_state)
4522a4
+#define ERR_remove_state(X) ERR_remove_thread_state(NULL)
4522a4
+#endif /* HAVE_ERR_remove_thread_state */
4522a4
+
4522a4
+#endif /* HAVE_OPENSSL11 */
4522a4
+#endif
4522a4
+
4522a4
+#ifdef HAVE_WOLFSSL
4522a4
+#define EVP_MD_CTX_SIZE                 sizeof(wc_Md5)
4522a4
+#endif
4522a4
+
4522a4
+#ifndef HAVE_OPENSSL11
4522a4
+#ifndef ASN1_STRING_get0_data
4522a4
+#define ASN1_STRING_get0_data(X)        ASN1_STRING_data(X)
4522a4
+#endif
4522a4
+#ifndef EVP_MD_CTX_SIZE
4522a4
+#define EVP_MD_CTX_SIZE                 sizeof(EVP_MD_CTX)
4522a4
+#endif
4522a4
+
4522a4
+#define DH_set0_pqg(D,P,Q,G)            ((D)->p= (P), (D)->g= (G))
4522a4
+#define EVP_CIPHER_CTX_buf_noconst(ctx) ((ctx)->buf)
4522a4
+#define EVP_CIPHER_CTX_encrypting(ctx)  ((ctx)->encrypt)
4522a4
+#define EVP_CIPHER_CTX_SIZE             sizeof(EVP_CIPHER_CTX)
4522a4
+
4522a4
+#ifndef HAVE_WOLFSSL
4522a4
+#define OPENSSL_init_ssl(X,Y)           SSL_library_init()
4522a4
+#define EVP_MD_CTX_reset(X) EVP_MD_CTX_cleanup(X)
4522a4
+#define EVP_CIPHER_CTX_reset(X) EVP_CIPHER_CTX_cleanup(X)
4522a4
+#define X509_get0_notBefore(X) X509_get_notBefore(X)
4522a4
+#define X509_get0_notAfter(X) X509_get_notAfter(X)
4522a4
+#endif
4522a4
+#endif
4522a4
+
4522a4
+#ifndef TLS1_3_VERSION
4522a4
+//#define SSL_CTX_set_ciphersuites(X,Y) 0
4522a4
+#endif
4522a4
+
4522a4
+#ifdef	__cplusplus
4522a4
+extern "C" {
4522a4
+#endif /* __cplusplus */
4522a4
+
4522a4
+int check_openssl_compatibility();
4522a4
+
4522a4
+#define FIPS_mode_set(X) 0
4522a4
+#define FIPS_mode() 0
4522a4
+
4522a4
+#ifdef	__cplusplus
4522a4
+}
4522a4
+#endif
4522a4
diff -rup mysql-8.0.22-orig/mysys/my_md5.cc mysql-8.0.22/mysys/my_md5.cc
4522a4
--- mysql-8.0.22-orig/mysys/my_md5.cc	2021-05-19 21:36:31.738980913 +0200
4522a4
+++ mysql-8.0.22/mysys/my_md5.cc	2021-05-19 23:13:41.380194493 +0200
4522a4
@@ -34,13 +34,12 @@
4522a4
 
4522a4
 #include <openssl/crypto.h>
4522a4
 #include <openssl/md5.h>
4522a4
+#include <openssl/evp.h>
4522a4
+#include <ssl_compat.h>
4522a4
 
4522a4
 static void my_md5_hash(unsigned char *digest, unsigned const char *buf,
4522a4
                         int len) {
4522a4
-  MD5_CTX ctx;
4522a4
-  MD5_Init(&ctx;;
4522a4
-  MD5_Update(&ctx, buf, len);
4522a4
-  MD5_Final(digest, &ctx;;
4522a4
+  MD5(buf, len, digest);
4522a4
 }
4522a4
 
4522a4
 /**
4522a4
diff -rup mysql-8.0.22-orig/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_ssl_transport.cc mysql-8.0.22/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_ssl_transport.cc
4522a4
--- mysql-8.0.22-orig/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_ssl_transport.cc	2021-05-19 21:36:14.531793376 +0200
4522a4
+++ mysql-8.0.22/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_ssl_transport.cc	2021-05-19 23:06:55.049885943 +0200
4522a4
@@ -25,6 +25,7 @@
4522a4
 #include <assert.h>
4522a4
 #include <stdlib.h>
4522a4
 
4522a4
+#include <openssl/crypto.h>
4522a4
 #include <openssl/dh.h>
4522a4
 #include <openssl/opensslv.h>
4522a4
 #include <openssl/x509v3.h>
4522a4
@@ -35,6 +36,7 @@
4522a4
 #endif
4522a4
 
4522a4
 #include "openssl/engine.h"
4522a4
+#include <ssl_compat.h>
4522a4
 
4522a4
 #include "xcom/task_debug.h"
4522a4
 #include "xcom/x_platform.h"
4522a4
diff -rup mysql-8.0.22-orig/plugin/x/client/xconnection_impl.cc mysql-8.0.22/plugin/x/client/xconnection_impl.cc
4522a4
--- mysql-8.0.22-orig/plugin/x/client/xconnection_impl.cc	2021-05-19 21:36:14.388791818 +0200
4522a4
+++ mysql-8.0.22/plugin/x/client/xconnection_impl.cc	2021-05-19 23:06:55.049885943 +0200
4522a4
@@ -31,6 +31,7 @@
4522a4
 #ifdef HAVE_NETINET_IN_H
4522a4
 #include <netinet/in.h>
4522a4
 #endif  // HAVE_NETINET_IN_H
4522a4
+#include <openssl/crypto.h>
4522a4
 #include <openssl/x509v3.h>
4522a4
 #include <cassert>
4522a4
 #include <chrono>  // NOLINT(build/c++11)
4522a4
@@ -38,6 +39,7 @@
4522a4
 #include <limits>
4522a4
 #include <sstream>
4522a4
 #include <string>
4522a4
+#include <ssl_compat.h>
4522a4
 
4522a4
 #include "errmsg.h"       // NOLINT(build/include_subdir)
4522a4
 #include "my_config.h"    // NOLINT(build/include_subdir)
4522a4
diff -rup mysql-8.0.22-orig/vio/viosslfactories.cc mysql-8.0.22/vio/viosslfactories.cc
4522a4
--- mysql-8.0.22-orig/vio/viosslfactories.cc	2021-05-19 21:36:33.310998046 +0200
4522a4
+++ mysql-8.0.22/vio/viosslfactories.cc	2021-05-19 23:06:55.049885943 +0200
4522a4
@@ -39,7 +39,9 @@
4522a4
 #include "mysys_err.h"
4522a4
 #include "vio/vio_priv.h"
4522a4
 
4522a4
+#include <openssl/crypto.h>
4522a4
 #include <openssl/dh.h>
4522a4
+#include <ssl_compat.h>
4522a4
 
4522a4
 #if OPENSSL_VERSION_NUMBER < 0x10002000L
4522a4
 #include <openssl/ec.h>