Skip to content

Commit 7f864ff

Browse files
committed
bpo-31453: Allow to change TLS protocols on Debian
Undo Debian Unstable's patching for SSL_CTX. Allow all protocols with SSL_CTX_set_min_proto_version() again so they can be enabled and disabled with SSL_CTX_set_options(). The set_min_proto_version is not supported by Python, set_options is available as SSLContext.options. Signed-off-by: Christian Heimes <[email protected]>
1 parent 9abee72 commit 7f864ff

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Undo Debian Unstable's patching for SSL_CTX. Allow all protocols with
2+
SSL_CTX_set_min_proto_version() again so they can be enabled and disabled
3+
with SSL_CTX_set_options(). The set_min_proto_version is not supported by
4+
Python, set_options is available as SSLContext.options.

Modules/_ssl.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,6 +2746,34 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
27462746
return NULL;
27472747
}
27482748

2749+
#ifdef SSL_CTX_set_min_proto_version
2750+
/* Workaround for Debian's OpenSSL patch
2751+
*
2752+
* Debian disables SSL 3.0, TLS 1.0, and TLS 1.1 by default. Python
2753+
* does not expose the new OpenSSL 1.1 API that is required to
2754+
* re-enable the old protocols. Documentation also promises that
2755+
* PROTOCOL_TLS has TLS 1.0 and 1.1 enabled and SSLv3 can be enabled
2756+
* by changing SSLContext.options.
2757+
*/
2758+
if ((proto_version == PY_SSL_VERSION_TLS) ||
2759+
(proto_version == PY_SSL_VERSION_TLS_CLIENT) ||
2760+
(proto_version == PY_SSL_VERSION_TLS_SERVER)) {
2761+
#if !defined(OPENSSL_NO_SSL3)
2762+
result = SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION);
2763+
#elif !defined(OPENSSL_NO_TLS1)
2764+
result = SSL_CTX_set_min_proto_version(ctx, TLS1_VERSION);
2765+
#elif !defined(OPENSSL_NO_TLS1_1)
2766+
result = SSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION);
2767+
#else
2768+
result = 1;
2769+
#endif
2770+
if (result == 0) {
2771+
_setSSLError(NULL, 0, __FILE__, __LINE__);
2772+
return NULL;
2773+
}
2774+
}
2775+
#endif /* SSL_CTX_set_min_proto_version */
2776+
27492777
assert(type != NULL && type->tp_alloc != NULL);
27502778
self = (PySSLContext *) type->tp_alloc(type, 0);
27512779
if (self == NULL) {

0 commit comments

Comments
 (0)