Skip to content

Commit edd5418

Browse files
authored
[2.7] bpo-33127: Compatibility patch for LibreSSL 2.7.0 (GH-6210) (GH-6215)
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]>. (cherry picked from commit 4ca0739) Co-authored-by: Christian Heimes <[email protected]>
1 parent 0694b6a commit edd5418

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ struct py_ssl_library_code {
102102

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

107113
/* Openssl comes with TLSv1.1 and TLSv1.2 between 1.0.0h and 1.0.1
@@ -149,16 +155,18 @@ struct py_ssl_library_code {
149155
#define INVALID_SOCKET (-1)
150156
#endif
151157

152-
#ifdef OPENSSL_VERSION_1_1
153-
/* OpenSSL 1.1.0+ */
154-
#ifndef OPENSSL_NO_SSL2
155-
#define OPENSSL_NO_SSL2
156-
#endif
157-
#else /* OpenSSL < 1.1.0 */
158-
#if defined(WITH_THREAD)
158+
/* OpenSSL 1.0.2 and LibreSSL needs extra code for locking */
159+
#if !defined(OPENSSL_VERSION_1_1) && defined(WITH_THREAD)
159160
#define HAVE_OPENSSL_CRYPTO_LOCK
160161
#endif
161162

163+
#if defined(OPENSSL_VERSION_1_1) && !defined(OPENSSL_NO_SSL2)
164+
#define OPENSSL_NO_SSL2
165+
#endif
166+
167+
#ifndef PY_OPENSSL_1_1_API
168+
/* OpenSSL 1.1 API shims for OpenSSL < 1.1.0 and LibreSSL < 2.7.0 */
169+
162170
#define TLS_method SSLv23_method
163171

164172
static int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne)
@@ -201,7 +209,7 @@ static X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *store)
201209
{
202210
return store->param;
203211
}
204-
#endif /* OpenSSL < 1.1.0 or LibreSSL */
212+
#endif /* OpenSSL < 1.1.0 or LibreSSL < 2.7.0 */
205213

206214

207215
enum py_ssl_error {

Tools/ssl/multissltests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@
5858
]
5959

6060
LIBRESSL_RECENT_VERSIONS = [
61-
"2.5.3",
6261
"2.5.5",
62+
"2.6.4",
63+
"2.7.1",
6364
]
6465

6566
# store files in ../multissl

0 commit comments

Comments
 (0)