Commit f599b34e authored by Jason's avatar Jason

Merge pull request #2 from Eugeny/cpython2.7.9

Work around missing sslwrap in Python 2.7.9 (fixes #477) #481
parents ac1b6095 edd26a72
...@@ -62,6 +62,8 @@ class SSLSocket(socket): ...@@ -62,6 +62,8 @@ class SSLSocket(socket):
ssl_version=PROTOCOL_SSLv23, ca_certs=None, ssl_version=PROTOCOL_SSLv23, ca_certs=None,
do_handshake_on_connect=True, do_handshake_on_connect=True,
suppress_ragged_eofs=True, suppress_ragged_eofs=True,
server_hostname=None,
_context=None,
ciphers=None): ciphers=None):
socket.__init__(self, _sock=sock) socket.__init__(self, _sock=sock)
...@@ -80,6 +82,7 @@ class SSLSocket(socket): ...@@ -80,6 +82,7 @@ class SSLSocket(socket):
self._sslobj = None self._sslobj = None
else: else:
# yes, create the SSL object # yes, create the SSL object
if hasattr(_ssl, 'sslwrap'):
if ciphers is None: if ciphers is None:
self._sslobj = _ssl.sslwrap(self._sock, server_side, self._sslobj = _ssl.sslwrap(self._sock, server_side,
keyfile, certfile, keyfile, certfile,
...@@ -89,6 +92,20 @@ class SSLSocket(socket): ...@@ -89,6 +92,20 @@ class SSLSocket(socket):
keyfile, certfile, keyfile, certfile,
cert_reqs, ssl_version, ca_certs, cert_reqs, ssl_version, ca_certs,
ciphers) ciphers)
else:
if _context:
self.context = _context
else:
self.context = __ssl__.SSLContext(ssl_version)
self.context.verify_mode = cert_reqs
if ca_certs:
self.context.load_verify_locations(ca_certs)
if certfile:
self.context.load_cert_chain(certfile, keyfile)
if ciphers:
self.context.set_ciphers(ciphers)
self._sslobj = self.context._wrap_socket(self._sock, server_side=server_side, ssl_sock=self, server_hostname=server_hostname)
if do_handshake_on_connect: if do_handshake_on_connect:
self.do_handshake() self.do_handshake()
self.keyfile = keyfile self.keyfile = keyfile
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment