Skip to content

Commit 9ffee99

Browse files
authored
Fix ssl.wrap_socket() is deprecated (#283)
self signed certificate; no need to verify signed commit final commit
1 parent b5a477e commit 9ffee99

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ws4py/client/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ def __init__(self, url, protocols=None, extensions=None,
8181
self.exclude_headers = exclude_headers or []
8282
self.exclude_headers = [x.lower() for x in self.exclude_headers]
8383

84-
if self.scheme == "wss":
85-
# Prevent check_hostname requires server_hostname (ref #187)
86-
if "cert_reqs" not in self.ssl_options:
87-
self.ssl_options["cert_reqs"] = ssl.CERT_NONE
88-
8984
self._parse_url()
9085

9186
if self.unix_socket_path:
@@ -211,7 +206,15 @@ def connect(self):
211206
"""
212207
if self.scheme == "wss":
213208
# default port is now 443; upgrade self.sender to send ssl
214-
self.sock = ssl.wrap_socket(self.sock, **self.ssl_options)
209+
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
210+
if self.ssl_options.get('certfile', None):
211+
context.load_cert_chain(self.ssl_options.get('certfile'), self.ssl_options.get('keyfile'))
212+
# Prevent check_hostname requires server_hostname (ref #187)
213+
if "cert_reqs" not in self.ssl_options:
214+
context.check_hostname = False
215+
context.verify_mode = ssl.CERT_NONE
216+
217+
self.sock = context.wrap_socket(self.sock)
215218
self._is_secure = True
216219

217220
self.sock.connect(self.bind_addr)

0 commit comments

Comments
 (0)