From de227075540da487137d3e541220a45098bfb972 Mon Sep 17 00:00:00 2001 From: Michael Penick Date: Wed, 5 Oct 2016 08:25:22 -0700 Subject: [PATCH] Feature: Added a function for creating an SSL context without initializing OpenSSL --- include/cassandra.h | 31 +++++++++++++++++++++++++++++++ src/ssl.cpp | 6 +++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/cassandra.h b/include/cassandra.h index 753e3eda0..d8982dae4 100644 --- a/include/cassandra.h +++ b/include/cassandra.h @@ -3247,6 +3247,37 @@ cass_aggregate_meta_field_by_name_n(const CassAggregateMeta* aggregate_meta, CASS_EXPORT CassSsl* cass_ssl_new(); +/** + * Creates a new SSL context without initializing the underlying library + * implementation. The integrating application is responsible for + * initializing the underlying SSL implementation. The driver uses the SSL + * implmentation from several threads concurrently so it's important that it's + * properly setup for multithreaded use e.g. lock callbacks for OpenSSL. + * + * Important: The SSL library must be initialized before calling this + * function. + * + * When using OpenSSL the following components need to be initialized: + * + * SSL_library_init(); + * SSL_load_error_strings(); + * OpenSSL_add_all_algorithms(); + * + * The following thread-safety callbacks also need to be set: + * + * CRYPTO_set_locking_callback(...); + * CRYPTO_set_id_callback(...); + * + * @public @memberof CassSsl + * + * @return Returns a SSL context that must be freed. + * + * @see cass_ssl_new() + * @see cass_ssl_free() + */ +CASS_EXPORT CassSsl* +cass_ssl_new_no_lib_init(); + /** * Frees a SSL context instance. * diff --git a/src/ssl.cpp b/src/ssl.cpp index 2d5b91347..d414b08ef 100644 --- a/src/ssl.cpp +++ b/src/ssl.cpp @@ -24,6 +24,11 @@ extern "C" { CassSsl* cass_ssl_new() { + cass::SslContextFactory::init(); + return cass_ssl_new_no_lib_init(); +} + +CassSsl* cass_ssl_new_no_lib_init() { cass::SslContext* ssl_context = cass::SslContextFactory::create(); ssl_context->inc_ref(); return CassSsl::to(ssl_context); @@ -82,7 +87,6 @@ static uv_once_t ssl_init_guard = UV_ONCE_INIT; template SslContext* SslContextFactoryBase::create() { - init(); return T::create(); }