Skip to content

Commit e78bf04

Browse files
committed
Feature: Added a function for creating an SSL context without initializing OpenSSL
1 parent 188d004 commit e78bf04

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

include/cassandra.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,6 +3247,37 @@ cass_aggregate_meta_field_by_name_n(const CassAggregateMeta* aggregate_meta,
32473247
CASS_EXPORT CassSsl*
32483248
cass_ssl_new();
32493249

3250+
/**
3251+
* Creates a new SSL context <b>without</b> initializing the underlying library
3252+
* implementation. The integrating application is responsible for
3253+
* initializing the underlying SSL implementation. The driver uses the SSL
3254+
* implmentation from several threads concurrently so it's important that it's
3255+
* properly setup for multithreaded use e.g. lock callbacks for OpenSSL.
3256+
*
3257+
* <b>Important:</b> The SSL library must be initialized before calling this
3258+
* function.
3259+
*
3260+
* When using OpenSSL the following components need to be initialized:
3261+
*
3262+
* SSL_library_init();
3263+
* SSL_load_error_strings();
3264+
* OpenSSL_add_all_algorithms();
3265+
*
3266+
* The following thread-safety callbacks also need to be set:
3267+
*
3268+
* CRYPTO_set_locking_callback(...);
3269+
* CRYPTO_set_id_callback(...);
3270+
*
3271+
* @public @memberof CassSsl
3272+
*
3273+
* @return Returns a SSL context that must be freed.
3274+
*
3275+
* @see cass_ssl_new()
3276+
* @see cass_ssl_free()
3277+
*/
3278+
CASS_EXPORT CassSsl*
3279+
cass_ssl_new_no_library_init();
3280+
32503281
/**
32513282
* Frees a SSL context instance.
32523283
*

src/ssl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
extern "C" {
2525

2626
CassSsl* cass_ssl_new() {
27+
cass::SslContextFactory::init();
28+
return cass_ssl_new_no_library_init();
29+
}
30+
31+
CassSsl* cass_ssl_new_no_library_init() {
2732
cass::SslContext* ssl_context = cass::SslContextFactory::create();
2833
ssl_context->inc_ref();
2934
return CassSsl::to(ssl_context);
@@ -82,7 +87,6 @@ static uv_once_t ssl_init_guard = UV_ONCE_INIT;
8287

8388
template<class T>
8489
SslContext* SslContextFactoryBase<T>::create() {
85-
init();
8690
return T::create();
8791
}
8892

0 commit comments

Comments
 (0)