Skip to content

Commit 56f8783

Browse files
aexvirlarryhastings
authored andcommitted
[3.5] bpo-33127: Compatibility patch for LibreSSL 2.7.0 (GH-6210) (#10994)
* 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 7cd08cf commit 56f8783

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
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: 17 additions & 8 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,18 @@ 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
135-
#define OPENSSL_NO_SSL2
136-
#endif
137-
#else /* OpenSSL < 1.1.0 */
138-
#if defined(WITH_THREAD)
138+
/* OpenSSL 1.0.2 and LibreSSL needs extra code for locking */
139+
#ifndef OPENSSL_VERSION_1_1
139140
#define HAVE_OPENSSL_CRYPTO_LOCK
140141
#endif
141142

143+
#if defined(OPENSSL_VERSION_1_1) && !defined(OPENSSL_NO_SSL2)
144+
#define OPENSSL_NO_SSL2
145+
#endif
146+
147+
#ifndef PY_OPENSSL_1_1_API
148+
/* OpenSSL 1.1 API shims for OpenSSL < 1.1.0 and LibreSSL < 2.7.0 */
149+
142150
#define TLS_method SSLv23_method
143151

144152
static int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne)
@@ -187,7 +195,8 @@ static X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *store)
187195
{
188196
return store->param;
189197
}
190-
#endif /* OpenSSL < 1.1.0 or LibreSSL */
198+
199+
#endif /* OpenSSL < 1.1.0 or LibreSSL < 2.7.0 */
191200

192201

193202
enum py_ssl_error {

0 commit comments

Comments
 (0)