Skip to content

Commit c087a26

Browse files
authored
bpo-40515: Require OPENSSL_THREADS (GH-19953)
The ``ssl`` and ``hashlib`` modules now actively check that OpenSSL is build with thread support. Python 3.7.0 made thread support mandatory and no longer works safely with a no-thread builds. Signed-off-by: Christian Heimes <[email protected]>
1 parent 62d618c commit c087a26

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The :mod:`ssl` and :mod:`hashlib` modules now actively check that OpenSSL is
2+
build with thread support. Python 3.7.0 made thread support mandatory and no
3+
longer works safely with a no-thread builds.

Modules/_hashopenssl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727

2828
#include <openssl/crypto.h> // FIPS_mode()
2929

30+
#ifndef OPENSSL_THREADS
31+
# error "OPENSSL_THREADS is not defined, Python requires thread-safe OpenSSL"
32+
#endif
33+
3034
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
3135
/* OpenSSL < 1.1.0 */
3236
#define EVP_MD_CTX_new EVP_MD_CTX_create

Modules/_ssl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ static PySocketModule_APIObject PySocketModule;
7373
# endif
7474
#endif
7575

76+
#ifndef OPENSSL_THREADS
77+
# error "OPENSSL_THREADS is not defined, Python requires thread-safe OpenSSL"
78+
#endif
79+
7680
/* SSL error object */
7781
static PyObject *PySSLErrorObject;
7882
static PyObject *PySSLCertVerificationErrorObject;
@@ -6005,7 +6009,7 @@ PyInit__ssl(void)
60056009
if (!_setup_ssl_threads()) {
60066010
return NULL;
60076011
}
6008-
#elif OPENSSL_VERSION_1_1 && defined(OPENSSL_THREADS)
6012+
#elif OPENSSL_VERSION_1_1
60096013
/* OpenSSL 1.1.0 builtin thread support is enabled */
60106014
_ssl_locks_count++;
60116015
#endif

0 commit comments

Comments
 (0)