Skip to content

Commit f5befbb

Browse files
authored
[3.6] bpo-33127: Compatibility patch for LibreSSL 2.7.0 (GH-6210) (GH-6214)
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 <christian@python.org>. (cherry picked from commit 4ca0739) Co-authored-by: Christian Heimes <christian@python.org>
1 parent 643a781 commit f5befbb

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

Lib/test/test_ssl.py

+1
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,7 @@ def test_get_ca_certs_capath(self):
16871687
self.assertEqual(len(ctx.get_ca_certs()), 1)
16881688

16891689
@needs_sni
1690+
@unittest.skipUnless(hasattr(ssl, "PROTOCOL_TLSv1_2"), "needs TLS 1.2")
16901691
def test_context_setget(self):
16911692
# Check that the context of a connected socket can be replaced.
16921693
ctx1 = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
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

+16-8
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ struct py_ssl_library_code {
106106

107107
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
108108
# define OPENSSL_VERSION_1_1 1
109+
# define PY_OPENSSL_1_1_API 1
110+
#endif
111+
112+
/* LibreSSL 2.7.0 provides necessary OpenSSL 1.1.0 APIs */
113+
#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x2070000fL
114+
# define PY_OPENSSL_1_1_API 1
109115
#endif
110116

111117
/* Openssl comes with TLSv1.1 and TLSv1.2 between 1.0.0h and 1.0.1
@@ -152,16 +158,18 @@ struct py_ssl_library_code {
152158
#define INVALID_SOCKET (-1)
153159
#endif
154160

155-
#ifdef OPENSSL_VERSION_1_1
156-
/* OpenSSL 1.1.0+ */
157-
#ifndef OPENSSL_NO_SSL2
158-
#define OPENSSL_NO_SSL2
159-
#endif
160-
#else /* OpenSSL < 1.1.0 */
161-
#if defined(WITH_THREAD)
161+
/* OpenSSL 1.0.2 and LibreSSL needs extra code for locking */
162+
#if !defined(OPENSSL_VERSION_1_1) && defined(WITH_THREAD)
162163
#define HAVE_OPENSSL_CRYPTO_LOCK
163164
#endif
164165

166+
#if defined(OPENSSL_VERSION_1_1) && !defined(OPENSSL_NO_SSL2)
167+
#define OPENSSL_NO_SSL2
168+
#endif
169+
170+
#ifndef PY_OPENSSL_1_1_API
171+
/* OpenSSL 1.1 API shims for OpenSSL < 1.1.0 and LibreSSL < 2.7.0 */
172+
165173
#define TLS_method SSLv23_method
166174
#define TLS_client_method SSLv23_client_method
167175
#define TLS_server_method SSLv23_server_method
@@ -227,7 +235,7 @@ SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s)
227235
return s->tlsext_tick_lifetime_hint;
228236
}
229237

230-
#endif /* OpenSSL < 1.1.0 or LibreSSL */
238+
#endif /* OpenSSL < 1.1.0 or LibreSSL < 2.7.0 */
231239

232240

233241
enum py_ssl_error {

Tools/ssl/multissltests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@
5757
]
5858

5959
LIBRESSL_RECENT_VERSIONS = [
60-
"2.5.3",
6160
"2.5.5",
61+
"2.6.4",
62+
"2.7.1",
6263
]
6364

6465
# store files in ../multissl

0 commit comments

Comments
 (0)