diff options
author | Alan Antonuk <alan.antonuk@gmail.com> | 2017-09-13 23:23:57 -0700 |
---|---|---|
committer | Alan Antonuk <alan.antonuk@gmail.com> | 2018-01-09 23:56:34 -0800 |
commit | 4910ec0954f69f2747ad6bd2ba31c512f36ad151 (patch) | |
tree | d78e0a300ecd15efb539ea62f8a72c038ed6c39c | |
parent | 8ab25ab6772857336f1e11ae64dacd091ce371c2 (diff) | |
download | rabbitmq-c-ossl-v110.tar.gz |
Lib: Support OpenSSL v1.1.0 in amqp_openssl_bioossl-v110
-rw-r--r-- | librabbitmq/amqp_openssl.c | 12 | ||||
-rw-r--r-- | librabbitmq/amqp_openssl_bio.c | 55 | ||||
-rw-r--r-- | librabbitmq/amqp_openssl_bio.h | 4 |
3 files changed, 62 insertions, 9 deletions
diff --git a/librabbitmq/amqp_openssl.c b/librabbitmq/amqp_openssl.c index 234a698..7cc01f8 100644 --- a/librabbitmq/amqp_openssl.c +++ b/librabbitmq/amqp_openssl.c @@ -57,6 +57,7 @@ static pthread_mutex_t *amqp_openssl_lockarray = NULL; static pthread_mutex_t openssl_init_mutex = PTHREAD_MUTEX_INITIALIZER; static amqp_boolean_t do_initialize_openssl = 1; static amqp_boolean_t openssl_initialized = 0; +static amqp_boolean_t openssl_bio_initialized = 0; static int openssl_connections = 0; #define CHECK_SUCCESS(condition) \ @@ -614,6 +615,14 @@ static int initialize_ssl_and_increment_connections() { openssl_initialized = 1; } + if (!openssl_bio_initialized) { + status = amqp_openssl_bio_init(); + if (status) { + goto exit; + } + openssl_bio_initialized = 1; + } + openssl_connections += 1; status = AMQP_STATUS_OK; exit: @@ -641,6 +650,9 @@ int amqp_uninitialize_ssl_library(void) { goto out; } + amqp_openssl_bio_destroy(); + openssl_bio_initialized = 0; + ERR_remove_state(0); FIPS_mode_set(0); diff --git a/librabbitmq/amqp_openssl_bio.c b/librabbitmq/amqp_openssl_bio.c index b0f4aad..91a46bb 100644 --- a/librabbitmq/amqp_openssl_bio.c +++ b/librabbitmq/amqp_openssl_bio.c @@ -43,7 +43,12 @@ static int amqp_ssl_bio_initialized = 0; #ifdef AMQP_USE_AMQP_BIO -static BIO_METHOD amqp_bio_method; + +#if (OPENSSL_VERSION_NUMBER > 0x10100000L) +#define AMQP_OPENSSL_V110 +#endif + +static BIO_METHOD *amqp_bio_method; static int amqp_openssl_bio_should_retry(int res) { if (res == -1) { @@ -120,7 +125,7 @@ static int amqp_openssl_bio_read(BIO *b, char *out, int outl) { return res; } -#if (OPENSSL_VERSION_NUMBER < 0x10100000L) +#ifndef AMQP_OPENSSL_V110 static int BIO_meth_set_write(BIO_METHOD *biom, int (*wfn)(BIO *, const char *, int)) { biom->bwrite = wfn; @@ -131,24 +136,58 @@ static int BIO_meth_set_read(BIO_METHOD *biom, int (*rfn)(BIO *, char *, int)) { biom->bread = rfn; return 0; } -#endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */ +#endif /* AQP_OPENSSL_V110 */ #endif /* AMQP_USE_AMQP_BIO */ -void amqp_openssl_bio_init(void) { +int amqp_openssl_bio_init(void) { assert(!amqp_ssl_bio_initialized); #ifdef AMQP_USE_AMQP_BIO - memcpy(&amqp_bio_method, BIO_s_socket(), sizeof(amqp_bio_method)); - BIO_meth_set_write(&amqp_bio_method, amqp_openssl_bio_write); - BIO_meth_set_read(&amqp_bio_method, amqp_openssl_bio_read); +#ifdef AMQP_OPENSSL_V110 + if (!(amqp_bio_method = BIO_meth_new(BIO_TYPE_SOCKET, "amqp_bio_method"))) { + return AMQP_STATUS_NO_MEMORY; + } + + BIO_METHOD *meth = BIO_s_socket(); + BIO_meth_set_create(amqp_bio_method, BIO_meth_get_create(meth)); + BIO_meth_set_destroy(amqp_bio_method, BIO_meth_get_destroy(meth)); + BIO_meth_set_ctrl(amqp_bio_method, BIO_meth_get_ctrl(meth)); + BIO_meth_set_callback_ctrl(amqp_bio_method, BIO_meth_get_callback_ctrl(meth)); + BIO_meth_set_read(amqp_bio_method, BIO_meth_get_read(meth)); + BIO_meth_set_write(amqp_bio_method, BIO_meth_get_write(meth)); + BIO_meth_set_gets(amqp_bio_method, BIO_meth_get_gets(meth)); + BIO_meth_set_puts(amqp_bio_method, BIO_meth_get_puts(meth)); +#else + if (!(amqp_bio_method = OPENSSL_malloc(sizeof(BIO_METHOD)))) { + return AMQP_STATUS_NO_MEMORY; + } + + memcpy(amqp_bio_method, BIO_s_socket(), sizeof(BIO_METHOD)); +#endif + BIO_meth_set_write(amqp_bio_method, amqp_openssl_bio_write); + BIO_meth_set_read(amqp_bio_method, amqp_openssl_bio_read); #endif amqp_ssl_bio_initialized = 1; + return AMQP_STATUS_OK; +} + +void amqp_openssl_bio_destroy(void) { + assert(amqp_ssl_bio_initialized); +#ifdef AMQP_USE_AMQP_BIO +#ifdef AMQP_OPENSSL_V110 + BIO_meth_free(amqp_bio_method); +#else + OPENSSL_free(amqp_bio_method); +#endif + amqp_bio_method = NULL; +#endif + amqp_ssl_bio_initialized = 0; } BIO_METHOD *amqp_openssl_bio(void) { assert(amqp_ssl_bio_initialized); #ifdef AMQP_USE_AMQP_BIO - return &amqp_bio_method; + return amqp_bio_method; #else return BIO_s_socket(); #endif diff --git a/librabbitmq/amqp_openssl_bio.h b/librabbitmq/amqp_openssl_bio.h index 68be2de..9c99c78 100644 --- a/librabbitmq/amqp_openssl_bio.h +++ b/librabbitmq/amqp_openssl_bio.h @@ -25,7 +25,9 @@ #include <openssl/bio.h> -void amqp_openssl_bio_init(void); +int amqp_openssl_bio_init(void); + +void amqp_openssl_bio_destroy(void); BIO_METHOD* amqp_openssl_bio(void); |