I'm learning how to write a multi-threaded DTLS server using OpenSSL. I've been looking through documentation, and it looks like OpenSSL should work with multiple threads if i set CRYPTO_set_id_callback
and CRYPTO_set_locking_callback
. I'm using OpenSSL 1.1.1c, and when I look in crypto.h
, I find this:
/*
* The old locking functions have been removed completely without compatibility
* macros. This is because the old functions either could not properly report
* errors, or the returned error values were not clearly documented.
* Replacing the locking functions with no-ops would cause race condition
* issues in the affected applications. It is far better for them to fail at
* compile time.
* On the other hand, the locking callbacks are no longer used. Consequently,
* the callback management functions can be safely replaced with no-op macros.
*/
# define CRYPTO_num_locks() (1)
# define CRYPTO_set_locking_callback(func)
# define CRYPTO_get_locking_callback() (NULL)
# define CRYPTO_set_add_lock_callback(func)
# define CRYPTO_get_add_lock_callback() (NULL)
So, I looks like this method is outdated. What should I do instead to ensure that my OpenSSL code is thread safe?
--
After researching some more, I've found this: Tutorial on Using OpenSSL with pthreads. I've also found https://www.openssl.org/docs/man1.0.2/man3/CRYPTO_THREADID_set_callback.html.
However, CRYPTO_THREADID_set_callback()
is also a no-op! It looks like I could do nothing but compile OpenSSL with the right flags.