Skip to content

Commit e47ad0a

Browse files
Marcel Heckoclaude
andcommitted
Fix deprecated OpenSSL calls in diameter_client tcp_comm
- Replace TLSv1_client_method() with TLS_client_method() for OpenSSL 1.1+ - Replace SSL_library_init()/SSL_load_error_strings() with OPENSSL_init_ssl() - Add version-conditional const qualifier on SSL_METHOD pointer - Fix undefined variable ctx -> conn_st->ctx in SSL_CTX_set_verify_depth All changes use #if OPENSSL_VERSION_NUMBER guards to maintain backward compatibility with OpenSSL 1.0.2 (RHEL 7). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2474909 commit e47ad0a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

apps/diameter_client/lib_dbase/tcp_comm.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ int check_cert(SSL * ssl, char* host) {
128128

129129
int tcp_init_tcp() {
130130
#ifdef WITH_OPENSSL
131+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
132+
OPENSSL_init_ssl(0, NULL);
133+
#else
131134
SSL_library_init();
132135
SSL_load_error_strings();
136+
#endif
133137
bio_err = BIO_new(BIO_s_null());
134138
BIO_set_callback(bio_err, tcp_ssl_dbg_cb);
135139
#endif
@@ -144,7 +148,11 @@ dia_tcp_conn* tcp_create_connection(const char* host, int port,
144148
struct sockaddr_in serv_addr;
145149
struct hostent *server;
146150
#ifdef WITH_OPENSSL
151+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
152+
const SSL_METHOD* meth;
153+
#else
147154
SSL_METHOD* meth;
155+
#endif
148156
#endif
149157

150158
sockfd = socket(PF_INET, SOCK_STREAM, 0);
@@ -192,11 +200,15 @@ dia_tcp_conn* tcp_create_connection(const char* host, int port,
192200
return conn_st;
193201
}
194202

195-
meth=(SSL_METHOD *)TLSv1_client_method();
203+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
204+
meth = TLS_client_method();
205+
#else
206+
meth = (SSL_METHOD *)TLSv1_client_method();
207+
#endif
196208
conn_st->ctx = SSL_CTX_new(meth);
197209

198210
if (!conn_st->ctx) {
199-
ERROR("SSL: creating TLSv1_client_method context\n");
211+
ERROR("SSL: creating SSL context\n");
200212
tcp_close_connection(conn_st);
201213
return 0;
202214
}
@@ -246,7 +258,7 @@ dia_tcp_conn* tcp_create_connection(const char* host, int port,
246258
}
247259

248260
#if (OPENSSL_VERSION_NUMBER < 0x00905100L)
249-
SSL_CTX_set_verify_depth(ctx,1);
261+
SSL_CTX_set_verify_depth(conn_st->ctx, 1);
250262
#endif
251263

252264
conn_st->ssl=SSL_new(conn_st->ctx);

0 commit comments

Comments
 (0)