Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSSL 1.1.0 compatibility #2000

Merged
merged 1 commit into from
Oct 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/rdkafka_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,15 @@ static char *rd_kafka_ssl_error (rd_kafka_t *rk, rd_kafka_broker_t *rkb,
return errstr;
}


#if OPENSSL_VERSION_NUMBER < 0x10100000L
static RD_UNUSED void
rd_kafka_transport_ssl_lock_cb (int mode, int i, const char *file, int line) {
if (mode & CRYPTO_LOCK)
mtx_lock(&rd_kafka_ssl_locks[i]);
else
mtx_unlock(&rd_kafka_ssl_locks[i]);
}
#endif

static RD_UNUSED unsigned long rd_kafka_transport_ssl_threadid_cb (void) {
#ifdef _MSC_VER
Expand All @@ -466,16 +467,26 @@ static RD_UNUSED unsigned long rd_kafka_transport_ssl_threadid_cb (void) {
#endif
}

#ifdef HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK
static void rd_kafka_transport_libcrypto_THREADID_callback(CRYPTO_THREADID *id)
{
unsigned long thread_id = rd_kafka_transport_ssl_threadid_cb();

CRYPTO_THREADID_set_numeric(id, thread_id);
}
#endif

/**
* Global OpenSSL cleanup.
*/
void rd_kafka_transport_ssl_term (void) {
int i;

#if OPENSSL_VERSION_NUMBER < 0x10100000L
CRYPTO_set_id_callback(NULL);
CRYPTO_set_locking_callback(NULL);
CRYPTO_cleanup_all_ex_data();
#endif

for (i = 0 ; i < rd_kafka_ssl_locks_cnt ; i++)
mtx_destroy(&rd_kafka_ssl_locks[i]);
Expand All @@ -489,6 +500,7 @@ void rd_kafka_transport_ssl_term (void) {
* Global OpenSSL init.
*/
void rd_kafka_transport_ssl_init (void) {
#if OPENSSL_VERSION_NUMBER < 0x10100000L
int i;

rd_kafka_ssl_locks_cnt = CRYPTO_num_locks();
Expand All @@ -497,12 +509,18 @@ void rd_kafka_transport_ssl_init (void) {
for (i = 0 ; i < rd_kafka_ssl_locks_cnt ; i++)
mtx_init(&rd_kafka_ssl_locks[i], mtx_plain);

CRYPTO_set_id_callback(rd_kafka_transport_ssl_threadid_cb);
#ifdef HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK
CRYPTO_THREADID_set_callback(rd_kafka_transport_libcrypto_THREADID_callback);
#else
CRYPTO_set_id_callback(rd_kafka_transport_ssl_threadid_cb);
#endif

CRYPTO_set_locking_callback(rd_kafka_transport_ssl_lock_cb);

SSL_load_error_strings();
SSL_library_init();
OpenSSL_add_all_algorithms();
#endif
}


Expand Down