Skip to content

Commit 8bdaffc

Browse files
committed
Merge pull request #920 from docker/ssl_version_simpler
Remove obsolete SSL version computation
2 parents 9d8663c + b808cc4 commit 8bdaffc

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

docker/ssladapter/ssladapter.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55
from distutils.version import StrictVersion
66
from requests.adapters import HTTPAdapter
7-
import ssl
87

98
try:
109
import requests.packages.urllib3 as urllib3
@@ -14,20 +13,10 @@
1413
PoolManager = urllib3.poolmanager.PoolManager
1514

1615

17-
def get_max_tls_protocol():
18-
protocols = ('PROTOCOL_TLSv1_2',
19-
'PROTOCOL_TLSv1_1',
20-
'PROTOCOL_TLSv1')
21-
for proto in protocols:
22-
if hasattr(ssl, proto):
23-
return getattr(ssl, proto)
24-
25-
2616
class SSLAdapter(HTTPAdapter):
2717
'''An HTTPS Transport Adapter that uses an arbitrary SSL version.'''
2818
def __init__(self, ssl_version=None, assert_hostname=None,
2919
assert_fingerprint=None, **kwargs):
30-
ssl_version = ssl_version or get_max_tls_protocol()
3120
self.ssl_version = ssl_version
3221
self.assert_hostname = assert_hostname
3322
self.assert_fingerprint = assert_fingerprint
@@ -41,7 +30,7 @@ def init_poolmanager(self, connections, maxsize, block=False):
4130
'assert_hostname': self.assert_hostname,
4231
'assert_fingerprint': self.assert_fingerprint,
4332
}
44-
if self.can_override_ssl_version():
33+
if self.ssl_version and self.can_override_ssl_version():
4534
kwargs['ssl_version'] = self.ssl_version
4635

4736
self.poolmanager = PoolManager(**kwargs)

docker/tls.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ def __init__(self, client_cert=None, ca_cert=None, verify=None,
1919
# here, but also disable any public/default CA pool verification by
2020
# leaving tls_verify=False
2121

22-
# urllib3 sets a default ssl_version if ssl_version is None,
23-
# but that default is the vulnerable PROTOCOL_SSLv23 selection,
24-
# so we override the default with the maximum supported in the running
25-
# Python interpeter up to TLS 1.2. (see: http://tinyurl.com/kxga8hb)
26-
ssl_version = ssl_version or ssladapter.get_max_tls_protocol()
2722
self.ssl_version = ssl_version
2823
self.assert_hostname = assert_hostname
2924
self.assert_fingerprint = assert_fingerprint

tests/unit/utils_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@
1212
import pytest
1313
import six
1414

15+
try:
16+
from ssl import OP_NO_SSLv3, OP_NO_SSLv2, OP_NO_TLSv1
17+
except ImportError:
18+
OP_NO_SSLv2 = 0x1000000
19+
OP_NO_SSLv3 = 0x2000000
20+
OP_NO_TLSv1 = 0x4000000
21+
1522
from docker.client import Client
1623
from docker.constants import DEFAULT_DOCKER_API_VERSION
1724
from docker.errors import DockerException, InvalidVersion
25+
from docker.ssladapter import ssladapter
1826
from docker.utils import (
1927
parse_repository_tag, parse_host, convert_filters, kwargs_from_env,
2028
create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file,
@@ -927,3 +935,12 @@ def test_tar_with_directory_symlinks(self):
927935
self.assertEqual(
928936
sorted(tar_data.getnames()), ['bar', 'bar/foo', 'foo']
929937
)
938+
939+
940+
class SSLAdapterTest(base.BaseTestCase):
941+
def test_only_uses_tls(self):
942+
ssl_context = ssladapter.urllib3.util.ssl_.create_urllib3_context()
943+
944+
assert ssl_context.options & OP_NO_SSLv3
945+
assert ssl_context.options & OP_NO_SSLv2
946+
assert not ssl_context.options & OP_NO_TLSv1

0 commit comments

Comments
 (0)