Skip to content

Commit

Permalink
tls_mgm: use the new threadid interface for ssl 1.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Jan 8, 2020
1 parent be93525 commit 3d508e7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
34 changes: 29 additions & 5 deletions modules/tls_mgm/tls.h
Expand Up @@ -67,6 +67,13 @@ static int ssl_versions[TLS_USE_TLSv1_2 + 1];
static SSL_METHOD *ssl_methods[TLS_USE_TLSv1_2 + 1];
#endif

#if OPENSSL_VERSION_NUMBER >= 0x10000000L && defined __OS_linux
#include <sys/types.h>
#if (__GLIBC__ < 2) || (__GLIBC_MINOR__ < 30)
#include <sys/syscall.h>
#endif
#endif

#define VERIFY_DEPTH_S 3


Expand Down Expand Up @@ -120,17 +127,34 @@ static void os_free(void *ptr)



inline static unsigned long tls_get_id(void)
{
#if defined __OS_linux
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 30)
return gettid();
#else
return syscall(SYS_gettid);
#endif
#else /* __OS_linux */
return my_pid(); /* TODO: fix on non linux systems, where we have to
1. include a thread id alongside with the PID
2. alocate a new structure that indicates PID + thread id */
#endif /* __OS_linux */
}

#if OPENSSL_VERSION_NUMBER >= 0x10000000L
void tls_get_thread_id(CRYPTO_THREADID *tid)
{
CRYPTO_THREADID_set_numeric(tid, tls_get_id());
}
#endif /* OPENSSL_VERSION_NUMBER */

/* these locks can not be used in 1.1.0, because the interface has changed */
#if OPENSSL_VERSION_NUMBER < 0x10100000L
struct CRYPTO_dynlock_value {
gen_lock_t lock;
};

static unsigned long tls_get_id(void)
{
return my_pid();
}

static struct CRYPTO_dynlock_value* tls_dyn_lock_create(const char* file,
int line)
{
Expand Down
8 changes: 8 additions & 0 deletions modules/tls_mgm/tls_mgm.c
Expand Up @@ -34,6 +34,10 @@
*
*/

#ifdef __OS_linux
#define _GNU_SOURCE /* we need this for gettid() */
#endif

#include <openssl/ui.h>
#include <openssl/ssl.h>
#include <openssl/opensslv.h>
Expand Down Expand Up @@ -1489,7 +1493,11 @@ static int tls_init_multithread(void)
CRYPTO_set_locking_callback(tls_static_locks_ops);
}

#if OPENSSL_VERSION_NUMBER < 0x10000000L
CRYPTO_set_id_callback(tls_get_id);
#else /* between 1.0.0 and 1.1.0 */
CRYPTO_THREADID_set_callback(tls_get_thread_id);
#endif /* OPENSSL_VERSION_NUMBER */

/* dynamic locks support*/
CRYPTO_set_dynlock_create_callback(tls_dyn_lock_create);
Expand Down

0 comments on commit 3d508e7

Please sign in to comment.