Skip to content

Commit

Permalink
BoringSSL support (#814)
Browse files Browse the repository at this point in the history
Improved support for either OpenSSL or BoringSSL

Co-authored-by: John Harrison <johnh@quintar.ai>
  • Loading branch information
johnhe4 and John Harrison authored Mar 13, 2024
1 parent cde3436 commit 5ec806e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,14 @@ endif()
option(ENABLE_SSL_SUPPORT "Enable SSL support" ON)

if (ENABLE_SSL_SUPPORT)
# Manually check OpenSSL version because BoringSSL doesn't support version checking via find_package
set(RMQ_OPENSSL_MIN_VERSION 1.1.1)
find_package(OpenSSL "${RMQ_OPENSSL_MIN_VERSION}" REQUIRED)
find_package(OpenSSL REQUIRED)
if(OPENSSL_VERSION) # Will be empty for BoringSSL
if(OPENSSL_VERSION VERSION_LESS RMQ_OPENSSL_MIN_VERSION)
MESSAGE(FATAL_ERROR "Found OpenSSL version ${OPENSSL_VERSION} but ${RMQ_OPENSSL_MIN_VERSION} or later is required")
endif()
endif()

cmake_push_check_state()
set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down
7 changes: 6 additions & 1 deletion cmake/rabbitmq-c-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ set(RMQ_USES_OPENSSL @ENABLE_SSL_SUPPORT@)
include(CMakeFindDependencyMacro)

if (RMQ_USES_OPENSSL)
find_dependency(OpenSSL @RMQ_OPENSSL_MIN_VERSION@ REQUIRED)
find_dependency(OpenSSL REQUIRED)
if(OPENSSL_VERSION)
if(OPENSSL_VERSION VERSION_LESS RMQ_OPENSSL_MIN_VERSION)
MESSAGE(FATAL_ERROR "Found OpenSSL version @OPENSSL_VERSION@ but @RMQ_OPENSSL_MIN_VERSION@ or later is required")
endif()
endif()
endif ()

include(${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake)
Expand Down
11 changes: 10 additions & 1 deletion librabbitmq/amqp_openssl_bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ int amqp_openssl_bio_init(void) {
if (!(amqp_bio_method = BIO_meth_new(BIO_TYPE_SOCKET, "amqp_bio_method"))) {
return AMQP_STATUS_NO_MEMORY;
}

#ifdef OPENSSL_IS_BORINGSSL
BIO_meth_set_create(amqp_bio_method, BIO_s_socket()->create);
BIO_meth_set_destroy(amqp_bio_method, BIO_s_socket()->destroy);
BIO_meth_set_ctrl(amqp_bio_method, BIO_s_socket()->ctrl);
BIO_meth_set_read(amqp_bio_method, BIO_s_socket()->bread);
BIO_meth_set_write(amqp_bio_method, BIO_s_socket()->bwrite);
BIO_meth_set_gets(amqp_bio_method, BIO_s_socket()->bgets);
BIO_meth_set_puts(amqp_bio_method, BIO_s_socket()->bputs);
#else
BIO_meth_set_create(amqp_bio_method, BIO_meth_get_create(BIO_s_socket()));
BIO_meth_set_destroy(amqp_bio_method, BIO_meth_get_destroy(BIO_s_socket()));
BIO_meth_set_ctrl(amqp_bio_method, BIO_meth_get_ctrl(BIO_s_socket()));
Expand All @@ -118,6 +126,7 @@ int amqp_openssl_bio_init(void) {
BIO_meth_set_write(amqp_bio_method, BIO_meth_get_write(BIO_s_socket()));
BIO_meth_set_gets(amqp_bio_method, BIO_meth_get_gets(BIO_s_socket()));
BIO_meth_set_puts(amqp_bio_method, BIO_meth_get_puts(BIO_s_socket()));
#endif

BIO_meth_set_write(amqp_bio_method, amqp_openssl_bio_write);
BIO_meth_set_read(amqp_bio_method, amqp_openssl_bio_read);
Expand Down

0 comments on commit 5ec806e

Please sign in to comment.