Improve initialization of openssl
authorsubodh <subodh@fb.com>
Sun, 16 Nov 2014 01:17:53 +0000 (17:17 -0800)
committerDave Watson <davejwatson@fb.com>
Wed, 19 Nov 2014 20:52:41 +0000 (12:52 -0800)
commitdf3064cff7f28210540614e64dfa0126c3cf78c3
tree2640fbcfd00b852627b59ba1f0b5831d67271ef5
parent832ecb9f330fa34eb47d0b6858aa48c04097d128
Improve initialization of openssl

Summary:
SSLContext takes it upon itself to
perform initialization of openssl along with
cleaning it up.

However in applications where there are multiple
libraries using openssl, cleanup is not really
desirable. Thus the application should own init
and cleanup of openssl, rather than SSLContext.

This is bad because openssl's init apis are not thread
safe.

This diff modifies SSLContext with 3 changes to
make this possible in the context of apps:

1. Add macro SSLCONTEXT_NO_REFCOUNT, for apps to be
able to disable refcounting
2. Move all steps of init into initializeOpenSSL.
As a result, apps can choose when to call
SSLContext::intitializeOpenSSL and if it has
been called before, openssl will not be reinitialized.
3. Move randomize as a static method to make it a part
of the initialization process.

Test Plan: Unit tests.

Reviewed By: ranjeeth@fb.com

Subscribers: ranjeeth, folly-diffs@, ssl-diffs@, njormrod, seanc, trunkagent, dihde

FB internal diff: D1686397

Signature: t1:1686397:1416270565:de805794d65af1c164ed334ff7ba93fe60b2b78a
folly/io/async/SSLContext.cpp
folly/io/async/SSLContext.h