Skip to content

Commit e7acd6a

Browse files
authored
gh-159387: Fix TLS 1.0–1.2 availability detection with OpenSSL 4.0 (GH-159388)
Fix TLS 1.0–1.2 availability detection with OpenSSL 4.0 OpenSSL 4.0 removed the version-specific methods but still supports TLS 1.0–1.2 through TLS_method(). Stop reporting these versions as unavailable, and expose legacy PROTOCOL_TLSv1* constants only when their corresponding methods exist.
1 parent 6b58f9a commit e7acd6a

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎Lib/test/test_ssl.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4567,6 +4567,8 @@ def test_protocol_tlsv1_1(self):
45674567
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False)
45684568

45694569
@requires_tls_version('TLSv1_2')
4570+
@unittest.skipUnless(hasattr(ssl, 'PROTOCOL_TLSv1_2'),
4571+
'needs ssl.PROTOCOL_TLSv1_2')
45704572
def test_protocol_tlsv1_2(self):
45714573
"""Connecting to a TLSv1.2 server with various client options.
45724574
Testing against older TLS versions."""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :mod:`ssl` reporting TLS 1.0, 1.1, and 1.2 as unavailable when built
2+
with OpenSSL 4.0, despite support for these protocol versions.

‎Modules/_ssl.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,9 @@ static void _PySSLFixErrno(void) {
148148
#endif
149149

150150
#if (OPENSSL_VERSION_NUMBER >= 0x40000000L)
151+
/* OpenSSL 4.0 removed SSLv3 and the version-specific methods,
152+
* but TLS 1.0, 1.1 and 1.2 are still available via TLS_method(). */
151153
# define OPENSSL_NO_SSL3
152-
# define OPENSSL_NO_TLS1
153-
# define OPENSSL_NO_TLS1_1
154-
# define OPENSSL_NO_TLS1_2
155154
# define OPENSSL_NO_SSL3_METHOD
156155
# define OPENSSL_NO_TLS1_METHOD
157156
# define OPENSSL_NO_TLS1_1_METHOD
@@ -7526,13 +7525,13 @@ sslmodule_init_constants(PyObject *m)
75267525
ADD_INT_CONST("PROTOCOL_TLS", PY_SSL_VERSION_TLS);
75277526
ADD_INT_CONST("PROTOCOL_TLS_CLIENT", PY_SSL_VERSION_TLS_CLIENT);
75287527
ADD_INT_CONST("PROTOCOL_TLS_SERVER", PY_SSL_VERSION_TLS_SERVER);
7529-
#ifndef OPENSSL_NO_TLS1
7528+
#if !defined(OPENSSL_NO_TLS1) && !defined(OPENSSL_NO_TLS1_METHOD)
75307529
ADD_INT_CONST("PROTOCOL_TLSv1", PY_SSL_VERSION_TLS1);
75317530
#endif
7532-
#ifndef OPENSSL_NO_TLS1_1
7531+
#if !defined(OPENSSL_NO_TLS1_1) && !defined(OPENSSL_NO_TLS1_1_METHOD)
75337532
ADD_INT_CONST("PROTOCOL_TLSv1_1", PY_SSL_VERSION_TLS1_1);
75347533
#endif
7535-
#ifndef OPENSSL_NO_TLS1_2
7534+
#if !defined(OPENSSL_NO_TLS1_2) && !defined(OPENSSL_NO_TLS1_2_METHOD)
75367535
ADD_INT_CONST("PROTOCOL_TLSv1_2", PY_SSL_VERSION_TLS1_2);
75377536
#endif
75387537

0 commit comments

Comments
 (0)