Skip to content

Commit e08a219

Browse files
committed
Clean up deprecations in security
1 parent d9c0010 commit e08a219

1 file changed

Lines changed: 6 additions & 49 deletions

File tree

distributed/security.py

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,13 @@
44
import os
55
import ssl
66
import tempfile
7-
import warnings
87

98
import dask
109
from dask.widgets import get_template
1110

1211
__all__ = ("Security",)
1312

1413

15-
if ssl.OPENSSL_VERSION_INFO >= (1, 1, 0, 7):
16-
# The OP_NO_SSL* and OP_NO_TLS* become deprecated in favor of
17-
# 'SSLContext.minimum_version' from Python 3.7 onwards, however
18-
# this attribute is not available unless the ssl module is compiled
19-
# with OpenSSL 1.1.0g or newer.
20-
# https://docs.python.org/3.10/library/ssl.html#ssl.SSLContext.minimum_version
21-
# https://docs.python.org/3.7/library/ssl.html#ssl.SSLContext.minimum_version
22-
23-
# these _set_minimum_version and _set_maximum_version depend on the validation
24-
# already performed in `Security._set_tls_version_field`,
25-
# and that they only apply to freshly created ssl.SSLContext instances in
26-
# _get_tls_context
27-
def _set_minimum_version(ctx: ssl.SSLContext, version: ssl.TLSVersion) -> None:
28-
ctx.minimum_version = version
29-
30-
def _set_maximum_version(ctx: ssl.SSLContext, version: ssl.TLSVersion) -> None:
31-
ctx.maximum_version = version
32-
33-
else:
34-
35-
def _set_minimum_version(ctx: ssl.SSLContext, version: ssl.TLSVersion) -> None:
36-
# if the ctx.maximum_version attribute is unsupported then we can infer
37-
# that TLS 1.3 is not supported.
38-
# _set_tls_version_field enforces that version is TLSVersion.TLSv1_2,
39-
# or TLSVersion.TLSv1_3
40-
if version is not ssl.TLSVersion.TLSv1_2:
41-
raise ValueError(f"Unsupported TLS/SSL version: {version!r}")
42-
ctx.options |= (
43-
ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1
44-
)
45-
46-
def _set_maximum_version(ctx: ssl.SSLContext, version: ssl.TLSVersion) -> None:
47-
# if the ctx.maximum_version attribute is unsupported then we can infer
48-
# that TLSv1_3 is not supported.
49-
# _set_tls_version_field enforces that version is TLSVersion.TLSv1_2,
50-
# TLSVersion.TLSv1_3, or None
51-
# _get_tls_context enforces that version is not None
52-
if version is not ssl.TLSVersion.TLSv1_2:
53-
raise ValueError(f"Unsupported TLS/SSL version: {version!r}")
54-
55-
5614
class Security:
5715
"""Security configuration for a Dask cluster.
5816
@@ -112,11 +70,8 @@ class Security:
11270

11371
def __init__(self, require_encryption=None, **kwargs):
11472
if ssl.OPENSSL_VERSION_INFO < (1, 1, 1):
115-
warnings.warn(
116-
f"support for {ssl.OPENSSL_VERSION} is deprecated,"
117-
" and will be removed in a future release",
118-
DeprecationWarning,
119-
)
73+
raise ImportError("Dask TLS support requires OpenSSL 1.1.1 or newer")
74+
12075
extra = set(kwargs).difference(self.__slots__)
12176
if extra:
12277
raise TypeError("Unknown parameters: %r" % sorted(extra))
@@ -299,9 +254,11 @@ def _get_tls_context(self, tls, purpose):
299254

300255
# the _set_tls_version_field method enforces that
301256
# self.tls_min_version is TLSv1_2, or TLSv1_3
302-
_set_minimum_version(ctx, self.tls_min_version)
257+
# This depends on the validation already performed in
258+
# `Security._set_tls_version_field`.
259+
ctx.minimum_version = self.tls_min_version
303260
if self.tls_max_version is not None:
304-
_set_maximum_version(ctx, self.tls_max_version)
261+
ctx.maximum_version = self.tls_max_version
305262

306263
cert_in_memory = "\n" in cert
307264
key_in_memory = key is not None and "\n" in key

0 commit comments

Comments
 (0)