|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jaipaul Cheernam <jaipaul.cheernam@est.tech> |
| 3 | +Date: Thu, 27 Aug 2026 11:00:00 +0000 |
| 4 | +Subject: [PATCH] Fix build with OpenSSL 4.0 |
| 5 | + |
| 6 | +OpenSSL 4.0 removes SSLv3_method(), per-version TLS method functions, |
| 7 | +ERR_remove_state(), ASN1_STRING_data(), and returns const pointers |
| 8 | +from X509 accessor functions. |
| 9 | + |
| 10 | +C++ (TSSLSocket.cpp): |
| 11 | +- Guard SSLv3 and TLS version methods with version check |
| 12 | +- Replace ASN1_STRING_data with ASN1_STRING_get0_data |
| 13 | +- Add const qualifiers for X509_NAME, X509_NAME_ENTRY, ASN1_STRING |
| 14 | + |
| 15 | +C (thrift_ssl_socket.c): |
| 16 | +- Remove ERR_remove_state() calls (no-op since OpenSSL 1.1) |
| 17 | +- Guard SSLv3 and TLS version methods with version check |
| 18 | + |
| 19 | +Upstream-Status: Submitted [https://github.com/apache/thrift/pull/3752] |
| 20 | + |
| 21 | +Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech> |
| 22 | +--- |
| 23 | +diff --git a/lib/cpp/src/thrift/transport/TSSLSocket.cpp b/lib/cpp/src/thrift/transport/TSSLSocket.cpp |
| 24 | +--- a/lib/cpp/src/thrift/transport/TSSLSocket.cpp 2026-08-27 11:26:40.242005669 +0000 |
| 25 | ++++ b/lib/cpp/src/thrift/transport/TSSLSocket.cpp 2026-08-27 11:26:40.263005736 +0000 |
| 26 | +@@ -182,16 +182,18 @@ |
| 27 | + SSLContext::SSLContext(const SSLProtocol& protocol) { |
| 28 | + if (protocol == SSLTLS) { |
| 29 | + ctx_ = SSL_CTX_new(SSLv23_method()); |
| 30 | +-#ifndef OPENSSL_NO_SSL3 |
| 31 | ++#if !defined(OPENSSL_NO_SSL3) && OPENSSL_VERSION_NUMBER < 0x40000000L |
| 32 | + } else if (protocol == SSLv3) { |
| 33 | + ctx_ = SSL_CTX_new(SSLv3_method()); |
| 34 | + #endif |
| 35 | ++#if OPENSSL_VERSION_NUMBER < 0x40000000L |
| 36 | + } else if (protocol == TLSv1_0) { |
| 37 | + ctx_ = SSL_CTX_new(TLSv1_method()); |
| 38 | + } else if (protocol == TLSv1_1) { |
| 39 | + ctx_ = SSL_CTX_new(TLSv1_1_method()); |
| 40 | + } else if (protocol == TLSv1_2) { |
| 41 | + ctx_ = SSL_CTX_new(TLSv1_2_method()); |
| 42 | ++#endif |
| 43 | + } else { |
| 44 | + /// UNKNOWN PROTOCOL! |
| 45 | + throw TSSLException("SSL_CTX_new: Unknown protocol"); |
| 46 | +@@ -770,7 +772,7 @@ |
| 47 | + if (name == nullptr) { |
| 48 | + continue; |
| 49 | + } |
| 50 | +- char* data = (char*)ASN1_STRING_data(name->d.ia5); |
| 51 | ++ const char* data = (const char*)ASN1_STRING_get0_data(name->d.ia5); |
| 52 | + int length = ASN1_STRING_length(name->d.ia5); |
| 53 | + switch (name->type) { |
| 54 | + case GEN_DNS: |
| 55 | +@@ -796,19 +798,19 @@ |
| 56 | + } |
| 57 | + |
| 58 | + // extract commonName |
| 59 | +- X509_NAME* name = X509_get_subject_name(cert); |
| 60 | ++ const X509_NAME* name = X509_get_subject_name(cert); |
| 61 | + if (name != nullptr) { |
| 62 | +- X509_NAME_ENTRY* entry; |
| 63 | ++ const X509_NAME_ENTRY* entry; |
| 64 | + unsigned char* utf8; |
| 65 | + int last = -1; |
| 66 | + while (decision == AccessManager::SKIP) { |
| 67 | +- last = X509_NAME_get_index_by_NID(name, NID_commonName, last); |
| 68 | ++ last = X509_NAME_get_index_by_NID((X509_NAME *)name, NID_commonName, last); |
| 69 | + if (last == -1) |
| 70 | + break; |
| 71 | + entry = X509_NAME_get_entry(name, last); |
| 72 | + if (entry == nullptr) |
| 73 | + continue; |
| 74 | +- ASN1_STRING* common = X509_NAME_ENTRY_get_data(entry); |
| 75 | ++ const ASN1_STRING* common = X509_NAME_ENTRY_get_data(entry); |
| 76 | + int size = ASN1_STRING_to_UTF8(&utf8, common); |
| 77 | + if (host.empty()) { |
| 78 | + host = (server() ? getPeerHost() : getHost()); |
| 79 | +diff --git a/lib/c_glib/src/thrift/c_glib/transport/thrift_ssl_socket.c b/lib/c_glib/src/thrift/c_glib/transport/thrift_ssl_socket.c |
| 80 | +--- a/lib/c_glib/src/thrift/c_glib/transport/thrift_ssl_socket.c 2026-08-27 11:26:40.245005679 +0000 |
| 81 | ++++ b/lib/c_glib/src/thrift/c_glib/transport/thrift_ssl_socket.c 2026-08-27 11:26:52.923045957 +0000 |
| 82 | +@@ -285,7 +285,6 @@ |
| 83 | + SSL_shutdown(ssl_socket->ssl); |
| 84 | + SSL_free(ssl_socket->ssl); |
| 85 | + ssl_socket->ssl = NULL; |
| 86 | +- ERR_remove_state(0); |
| 87 | + } |
| 88 | + return thrift_socket_close(transport, error); |
| 89 | + } |
| 90 | +@@ -710,7 +709,6 @@ |
| 91 | + ERR_free_strings(); |
| 92 | + EVP_cleanup(); |
| 93 | + CRYPTO_cleanup_all_ex_data(); |
| 94 | +- ERR_remove_state(0); |
| 95 | + } |
| 96 | + |
| 97 | + |
| 98 | +@@ -835,6 +833,7 @@ |
| 99 | + case SSLTLS: |
| 100 | + context = SSL_CTX_new(SSLv23_method()); |
| 101 | + break; |
| 102 | ++#if OPENSSL_VERSION_NUMBER < 0x40000000L |
| 103 | + #ifndef OPENSSL_NO_SSL3 |
| 104 | + case SSLv3: |
| 105 | + context = SSL_CTX_new(SSLv3_method()); |
| 106 | +@@ -849,6 +848,7 @@ |
| 107 | + case TLSv1_2: |
| 108 | + context = SSL_CTX_new(TLSv1_2_method()); |
| 109 | + break; |
| 110 | ++#endif /* OPENSSL_VERSION_NUMBER < 0x40000000L */ |
| 111 | + default: |
| 112 | + g_set_error (error, THRIFT_TRANSPORT_ERROR, |
| 113 | + THRIFT_SSL_SOCKET_ERROR_CIPHER_NOT_AVAILABLE, |
0 commit comments