Skip to content

Commit bd78d1a

Browse files
tiranaexvir
authored andcommitted
bpo-33127: Compatibility patch for LibreSSL 2.7.0 (pythonGH-6210)
LibreSSL 2.7 introduced OpenSSL 1.1.0 API. The ssl module now detects LibreSSL 2.7 and only provides API shims for OpenSSL < 1.1.0 and LibreSSL < 2.7. Documentation updates and fixes for failing tests will be provided in another patch set. Signed-off-by: Christian Heimes <[email protected]>
1 parent 1a2b52b commit bd78d1a

File tree

3 files changed

+459
-4
lines changed

3 files changed

+459
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The ssl module now compiles with LibreSSL 2.7.1.

Modules/_ssl.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ struct py_ssl_library_code {
101101

102102
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
103103
# define OPENSSL_VERSION_1_1 1
104+
# define PY_OPENSSL_1_1_API 1
105+
#endif
106+
107+
/* LibreSSL 2.7.0 provides necessary OpenSSL 1.1.0 APIs */
108+
#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x2070000fL
109+
# define PY_OPENSSL_1_1_API 1
104110
#endif
105111

106112
/* Openssl comes with TLSv1.1 and TLSv1.2 between 1.0.0h and 1.0.1
@@ -129,16 +135,22 @@ struct py_ssl_library_code {
129135
#define INVALID_SOCKET (-1)
130136
#endif
131137

132-
#ifdef OPENSSL_VERSION_1_1
133-
/* OpenSSL 1.1.0+ */
134-
#ifndef OPENSSL_NO_SSL2
138+
/* OpenSSL 1.0.2 and LibreSSL needs extra code for locking */
139+
#ifndef OPENSSL_VERSION_1_1
140+
#define HAVE_OPENSSL_CRYPTO_LOCK
141+
#endif
142+
143+
#if defined(OPENSSL_VERSION_1_1) && !defined(OPENSSL_NO_SSL2)
135144
#define OPENSSL_NO_SSL2
136145
#endif
137146
#else /* OpenSSL < 1.1.0 */
138147
#if defined(WITH_THREAD)
139148
#define HAVE_OPENSSL_CRYPTO_LOCK
140149
#endif
141150

151+
#ifndef PY_OPENSSL_1_1_API
152+
/* OpenSSL 1.1 API shims for OpenSSL < 1.1.0 and LibreSSL < 2.7.0 */
153+
142154
#define TLS_method SSLv23_method
143155

144156
static int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne)
@@ -187,7 +199,7 @@ static X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *store)
187199
{
188200
return store->param;
189201
}
190-
#endif /* OpenSSL < 1.1.0 or LibreSSL */
202+
#endif /* OpenSSL < 1.1.0 or LibreSSL < 2.7.0 */
191203

192204

193205
enum py_ssl_error {

0 commit comments

Comments
 (0)