Skip to content

Commit 29e962e

Browse files
author
Jaipaul Cheernam
committed
THRIFT-6170: Fix TSSLSocket build with OpenSSL 4.0
OpenSSL 4.0 removes SSLv3_method() and per-version TLS method functions (TLSv1_method, TLSv1_1_method, TLSv1_2_method), the deprecated ASN1_STRING_data() function, and returns const pointers from X509_get_subject_name(), X509_NAME_get_entry(), and X509_NAME_ENTRY_get_data(). - Guard SSLv3_method and TLS version methods with version check - Replace ASN1_STRING_data with ASN1_STRING_get0_data - Add const qualifiers for X509_NAME, X509_NAME_ENTRY, ASN1_STRING This is backward-compatible with OpenSSL >= 1.1.0 since all replacement APIs exist since that version. Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
1 parent 28d59c3 commit 29e962e

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

lib/c_glib/src/thrift/c_glib/transport/thrift_ssl_socket.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ thrift_ssl_socket_close (ThriftTransport *transport, GError **error)
285285
SSL_shutdown(ssl_socket->ssl);
286286
SSL_free(ssl_socket->ssl);
287287
ssl_socket->ssl = NULL;
288-
ERR_remove_state(0);
289288
}
290289
return thrift_socket_close(transport, error);
291290
}
@@ -710,7 +709,6 @@ void thrift_ssl_socket_finalize_openssl(void)
710709
ERR_free_strings();
711710
EVP_cleanup();
712711
CRYPTO_cleanup_all_ex_data();
713-
ERR_remove_state(0);
714712
}
715713

716714

@@ -835,9 +833,15 @@ thrift_ssl_socket_context_initialize(ThriftSSLSocketProtocol ssl_protocol, GErro
835833
case SSLTLS:
836834
context = SSL_CTX_new(SSLv23_method());
837835
break;
836+
#if OPENSSL_VERSION_NUMBER < 0x40000000L
838837
#ifndef OPENSSL_NO_SSL3
839838
case SSLv3:
839+
/* SSLv3_method removed in OpenSSL 4.0 */
840+
#if OPENSSL_VERSION_NUMBER < 0x40000000L
840841
context = SSL_CTX_new(SSLv3_method());
842+
#else
843+
context = NULL;
844+
#endif
841845
break;
842846
#endif
843847
case TLSv1_0:
@@ -849,6 +853,7 @@ thrift_ssl_socket_context_initialize(ThriftSSLSocketProtocol ssl_protocol, GErro
849853
case TLSv1_2:
850854
context = SSL_CTX_new(TLSv1_2_method());
851855
break;
856+
#endif /* OPENSSL_VERSION_NUMBER < 0x40000000L */
852857
default:
853858
g_set_error (error, THRIFT_TRANSPORT_ERROR,
854859
THRIFT_SSL_SOCKET_ERROR_CIPHER_NOT_AVAILABLE,

lib/cpp/src/thrift/transport/TSSLSocket.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,18 @@ static char uppercase(char c);
182182
SSLContext::SSLContext(const SSLProtocol& protocol) {
183183
if (protocol == SSLTLS) {
184184
ctx_ = SSL_CTX_new(SSLv23_method());
185-
#ifndef OPENSSL_NO_SSL3
185+
#if !defined(OPENSSL_NO_SSL3) && OPENSSL_VERSION_NUMBER < 0x40000000L
186186
} else if (protocol == SSLv3) {
187187
ctx_ = SSL_CTX_new(SSLv3_method());
188188
#endif
189+
#if OPENSSL_VERSION_NUMBER < 0x40000000L
189190
} else if (protocol == TLSv1_0) {
190191
ctx_ = SSL_CTX_new(TLSv1_method());
191192
} else if (protocol == TLSv1_1) {
192193
ctx_ = SSL_CTX_new(TLSv1_1_method());
193194
} else if (protocol == TLSv1_2) {
194195
ctx_ = SSL_CTX_new(TLSv1_2_method());
196+
#endif
195197
} else {
196198
/// UNKNOWN PROTOCOL!
197199
throw TSSLException("SSL_CTX_new: Unknown protocol");
@@ -770,7 +772,7 @@ void TSSLSocket::authorize() {
770772
if (name == nullptr) {
771773
continue;
772774
}
773-
char* data = (char*)ASN1_STRING_data(name->d.ia5);
775+
const char* data = (const char*)ASN1_STRING_get0_data(name->d.ia5);
774776
int length = ASN1_STRING_length(name->d.ia5);
775777
switch (name->type) {
776778
case GEN_DNS:
@@ -796,19 +798,19 @@ void TSSLSocket::authorize() {
796798
}
797799

798800
// extract commonName
799-
X509_NAME* name = X509_get_subject_name(cert);
801+
const X509_NAME* name = X509_get_subject_name(cert);
800802
if (name != nullptr) {
801-
X509_NAME_ENTRY* entry;
803+
const X509_NAME_ENTRY* entry;
802804
unsigned char* utf8;
803805
int last = -1;
804806
while (decision == AccessManager::SKIP) {
805-
last = X509_NAME_get_index_by_NID(name, NID_commonName, last);
807+
last = X509_NAME_get_index_by_NID((X509_NAME *)name, NID_commonName, last);
806808
if (last == -1)
807809
break;
808810
entry = X509_NAME_get_entry(name, last);
809811
if (entry == nullptr)
810812
continue;
811-
ASN1_STRING* common = X509_NAME_ENTRY_get_data(entry);
813+
const ASN1_STRING* common = X509_NAME_ENTRY_get_data(entry);
812814
int size = ASN1_STRING_to_UTF8(&utf8, common);
813815
if (host.empty()) {
814816
host = (server() ? getPeerHost() : getHost());

0 commit comments

Comments
 (0)