|
4 | 4 | import os |
5 | 5 | import ssl |
6 | 6 | import tempfile |
7 | | -import warnings |
8 | 7 |
|
9 | 8 | import dask |
10 | 9 | from dask.widgets import get_template |
11 | 10 |
|
12 | 11 | __all__ = ("Security",) |
13 | 12 |
|
14 | 13 |
|
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 | | - |
56 | 14 | class Security: |
57 | 15 | """Security configuration for a Dask cluster. |
58 | 16 |
|
@@ -112,11 +70,8 @@ class Security: |
112 | 70 |
|
113 | 71 | def __init__(self, require_encryption=None, **kwargs): |
114 | 72 | 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 | + |
120 | 75 | extra = set(kwargs).difference(self.__slots__) |
121 | 76 | if extra: |
122 | 77 | raise TypeError("Unknown parameters: %r" % sorted(extra)) |
@@ -299,9 +254,11 @@ def _get_tls_context(self, tls, purpose): |
299 | 254 |
|
300 | 255 | # the _set_tls_version_field method enforces that |
301 | 256 | # 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 |
303 | 260 | 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 |
305 | 262 |
|
306 | 263 | cert_in_memory = "\n" in cert |
307 | 264 | key_in_memory = key is not None and "\n" in key |
|
0 commit comments