Skip to content

Updated WebSocketHandler ssl to work with Python 3.12+ #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions websocket_server/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,13 @@ def __init__(self, socket, addr, server):
self._send_lock = threading.Lock()
if server.key and server.cert:
try:
socket = ssl.wrap_socket(socket, server_side=True, certfile=server.cert, keyfile=server.key)
except: # Not sure which exception it throws if the key/cert isn't found
logger.warning("SSL not available (are the paths {} and {} correct for the key and cert?)".format(server.key, server.cert))
ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_context.load_cert_chain(certfile=server.cert, keyfile=server.key)
socket = ssl_context.wrap_socket(socket, server_side=True)
except FileNotFoundError:
logger.warning("SSL key or certificate file not found. Please check the paths for the key and cert.")
except ssl.SSLError as e:
logger.warning(f"SSL error occurred: {e}")
StreamRequestHandler.__init__(self, socket, addr, server)

def setup(self):
Expand Down