Skip to content

Commit 500286d

Browse files
dpernyshin-
authored andcommitted
Change default TLS version
Detects if python has an up-to-date version of OpenSSL that supports TLSv1.2. If it does, choose that as the default TLS version, instead of TLSv1. The Docker Engine and the majority of other Docker API servers should suppot TLSv1.2, and if they do not, the user can manually set a different (lower) version. Signed-off-by: Drew Erny <[email protected]>
1 parent 766d890 commit 500286d

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

docker/tls.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,40 @@ def __init__(self, client_cert=None, ca_cert=None, verify=None,
3737
self.assert_hostname = assert_hostname
3838
self.assert_fingerprint = assert_fingerprint
3939

40-
# TLS v1.0 seems to be the safest default; SSLv23 fails in mysterious
41-
# ways: https://github.com/docker/docker-py/issues/963
42-
43-
self.ssl_version = ssl_version or ssl.PROTOCOL_TLSv1
44-
45-
# "tls" and "tls_verify" must have both or neither cert/key files
46-
# In either case, Alert the user when both are expected, but any are
40+
# TODO(dperny): according to the python docs, PROTOCOL_TLSvWhatever is
41+
# depcreated, and it's recommended to use OPT_NO_TLSvWhatever instead
42+
# to exclude versions. But I think that might require a bigger
43+
# architectural change, so I've opted not to pursue it at this time
44+
45+
# If the user provides an SSL version, we should use their preference
46+
if ssl_version:
47+
self.ssl_version = ssl_version
48+
else:
49+
# If the user provides no ssl version, we should default to
50+
# TLSv1_2. This option is the most secure, and will work for the
51+
# majority of users with reasonably up-to-date software. However,
52+
# before doing so, detect openssl version to ensure we can support
53+
# it.
54+
55+
# ssl.OPENSSL_VERSION_INFO returns a tuple of 5 integers
56+
# representing version info. We want any OpenSSL version greater
57+
# than 1.0.1. Python compares tuples lexigraphically, which means
58+
# this comparison will work.
59+
if ssl.OPENSSL_VERSION_INFO > (1, 0, 1, 0, 0):
60+
# If this version is high enough to support TLSv1_2, then we
61+
# should use it.
62+
self.ssl_version = ssl.PROTOCOL_TLSv1_2
63+
else:
64+
# If we can't, use a differnent default. Before the commit
65+
# introducing this version detection, the comment read:
66+
# >>> TLS v1.0 seems to be the safest default; SSLv23 fails in
67+
# >>> mysterious ways:
68+
# >>> https://github.com/docker/docker-py/issues/963
69+
# Which is why we choose PROTOCOL_TLSv1
70+
self.ssl_version = ssl.PROTOCOL_TLSv1
71+
72+
# "tls" and "tls_verify" must have both or neither cert/key files In
73+
# either case, Alert the user when both are expected, but any are
4774
# missing.
4875

4976
if client_cert:

0 commit comments

Comments
 (0)