Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ssladapter.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """ Resolves OpenSSL issues in some servers:
  2. https://lukasa.co.uk/2013/01/Choosing_SSL_Version_In_Requests/
  3. https://github.com/kennethreitz/requests/pull/799
  4. """
  5. from packaging.version import Version
  6. from requests.adapters import HTTPAdapter
  7. from docker.transport.basehttpadapter import BaseHTTPAdapter
  8. import urllib3
  9. PoolManager = urllib3.poolmanager.PoolManager
  10. class SSLHTTPAdapter(BaseHTTPAdapter):
  11. '''An HTTPS Transport Adapter that uses an arbitrary SSL version.'''
  12. __attrs__ = HTTPAdapter.__attrs__ + ['assert_fingerprint',
  13. 'assert_hostname',
  14. 'ssl_version']
  15. def __init__(self, ssl_version=None, assert_hostname=None,
  16. assert_fingerprint=None, **kwargs):
  17. self.ssl_version = ssl_version
  18. self.assert_hostname = assert_hostname
  19. self.assert_fingerprint = assert_fingerprint
  20. super().__init__(**kwargs)
  21. def init_poolmanager(self, connections, maxsize, block=False):
  22. kwargs = {
  23. 'num_pools': connections,
  24. 'maxsize': maxsize,
  25. 'block': block,
  26. 'assert_hostname': self.assert_hostname,
  27. 'assert_fingerprint': self.assert_fingerprint,
  28. }
  29. if self.ssl_version and self.can_override_ssl_version():
  30. kwargs['ssl_version'] = self.ssl_version
  31. self.poolmanager = PoolManager(**kwargs)
  32. def get_connection(self, *args, **kwargs):
  33. """
  34. Ensure assert_hostname is set correctly on our pool
  35. We already take care of a normal poolmanager via init_poolmanager
  36. But we still need to take care of when there is a proxy poolmanager
  37. """
  38. conn = super().get_connection(*args, **kwargs)
  39. if conn.assert_hostname != self.assert_hostname:
  40. conn.assert_hostname = self.assert_hostname
  41. return conn
  42. def can_override_ssl_version(self):
  43. urllib_ver = urllib3.__version__.split('-')[0]
  44. if urllib_ver is None:
  45. return False
  46. if urllib_ver == 'dev':
  47. return True
  48. return Version(urllib_ver) > Version('1.5')