Pithikos / python-websocket-server

A simple fully working websocket-server in Python with no external dependencies
MIT License
1.14k stars 381 forks source link

Support wss #48

Closed arjunmenon closed 6 years ago

arjunmenon commented 6 years ago

Hey I understand this lib at the moment doesn't support SSL but if we have to add the secure websocket, what can we do?

Pithikos commented 6 years ago

This is duplicate of this: https://github.com/Pithikos/python-websocket-server/issues/35

I haven't dug much into it but I assume the main change would be replacing the HttpServer with an HttpsServer (if that exists).

vmandke commented 5 years ago
class WebsocketServerSSL(WebsocketServer):
    def __init__(self, port, host='127.0.0.1', loglevel=logging.INFO):
        WebsocketServer.__init__(self, port, host, loglevel)
        self.context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        self.context.load_cert_chain(cert_, privkey_)
        self.socket = self.context.wrap_socket(self.socket, server_side=True)

This works for me without any modifications to the lib

HaukHuang commented 5 years ago
class WebsocketServerSSL(WebsocketServer):
    def __init__(self, port, host='127.0.0.1', loglevel=logging.INFO):
        WebsocketServer.__init__(self, port, host, loglevel)
        self.context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        self.context.load_cert_chain(cert_, privkey_)
        self.socket = self.context.wrap_socket(self.socket, server_side=True)

This works for me without any modifications to the lib

Does that mean you have achieved it?