From b14760f0724926327a35dcb5e8592266632101cf Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Wed, 20 Jul 2016 17:47:49 -0400 Subject: Support OpenSSL 1.1 Closes https://github.com/urweb/urweb/issues/35. --- src/c/openssl.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/c/openssl.c b/src/c/openssl.c index 15c4de5e..5982b831 100644 --- a/src/c/openssl.c +++ b/src/c/openssl.c @@ -1,6 +1,5 @@ #include "config.h" -#include #include #include #include @@ -8,17 +7,13 @@ #include #include #include -#include -#include +#include #include #include #define PASSSIZE 4 -// OpenSSL locks array. See threads(3SSL). -static pthread_mutex_t *openssl_locks; - int uw_hash_blocksize = 32; static int password[PASSSIZE]; @@ -33,6 +28,17 @@ static void random_password() { } } +#if OPENSSL_VERSION_NUMBER < 0x10100000L +// We're using OpenSSL <1.1, so we need to specify threading callbacks. See +// threads(3SSL). + +#include +#include + +#include + +static pthread_mutex_t *openssl_locks; + // OpenSSL callbacks #ifdef PTHREAD_T_IS_POINTER static void thread_id(CRYPTO_THREADID *const result) { @@ -60,7 +66,7 @@ static void lock_or_unlock(const int mode, const int type, const char *file, } } -void uw_init_crypto() { +static void init_openssl() { int i; // Set up OpenSSL. assert(openssl_locks == NULL); @@ -74,6 +80,18 @@ void uw_init_crypto() { } CRYPTO_THREADID_set_callback(thread_id); CRYPTO_set_locking_callback(lock_or_unlock); +} + +#else +// We're using OpenSSL >=1.1, which is thread-safe by default. We don't need to +// do anything here. + +static void init_openssl() {} + +#endif // OPENSSL_VERSION_NUMBER < 0x10100000L + +void uw_init_crypto() { + init_openssl(); // Prepare signatures. if (uw_sig_file) { int fd; -- cgit v1.2.3