Skip to content

Commit 4ca0739

Browse files
authored
bpo-33127: Compatibility patch for LibreSSL 2.7.0 (GH-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 e42ae91 commit 4ca0739

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ static void _PySSLFixErrno(void) {
136136

137137
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
138138
# define OPENSSL_VERSION_1_1 1
139+
# define PY_OPENSSL_1_1_API 1
140+
#endif
141+
142+
/* LibreSSL 2.7.0 provides necessary OpenSSL 1.1.0 APIs */
143+
#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x2070000fL
144+
# define PY_OPENSSL_1_1_API 1
139145
#endif
140146

141147
/* Openssl comes with TLSv1.1 and TLSv1.2 between 1.0.0h and 1.0.1
@@ -182,13 +188,17 @@ static void _PySSLFixErrno(void) {
182188
#define INVALID_SOCKET (-1)
183189
#endif
184190

185-
#ifdef OPENSSL_VERSION_1_1
186-
/* OpenSSL 1.1.0+ */
187-
#ifndef OPENSSL_NO_SSL2
191+
/* OpenSSL 1.0.2 and LibreSSL needs extra code for locking */
192+
#ifndef OPENSSL_VERSION_1_1
193+
#define HAVE_OPENSSL_CRYPTO_LOCK
194+
#endif
195+
196+
#if defined(OPENSSL_VERSION_1_1) && !defined(OPENSSL_NO_SSL2)
188197
#define OPENSSL_NO_SSL2
189198
#endif
190-
#else /* OpenSSL < 1.1.0 */
191-
#define HAVE_OPENSSL_CRYPTO_LOCK
199+
200+
#ifndef PY_OPENSSL_1_1_API
201+
/* OpenSSL 1.1 API shims for OpenSSL < 1.1.0 and LibreSSL < 2.7.0 */
192202

193203
#define TLS_method SSLv23_method
194204
#define TLS_client_method SSLv23_client_method
@@ -250,7 +260,7 @@ SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s)
250260
return s->tlsext_tick_lifetime_hint;
251261
}
252262

253-
#endif /* OpenSSL < 1.1.0 or LibreSSL */
263+
#endif /* OpenSSL < 1.1.0 or LibreSSL < 2.7.0 */
254264

255265
/* Default cipher suites */
256266
#ifndef PY_SSL_DEFAULT_CIPHERS

Tools/ssl/multissltests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
]
5555

5656
LIBRESSL_RECENT_VERSIONS = [
57-
# "2.6.5",
57+
"2.7.1",
5858
]
5959

6060
# store files in ../multissl

0 commit comments

Comments
 (0)