How can I implement a secure WebSocket (wss://) server in Python?

后端 未结 5 2055
情深已故
情深已故 2021-01-31 20:00

I want to serve a real-time stream that has to be securely encrypted due to sensitive data.

I\'ve successfully got normal WebSockets streaming using both gevent and guni

5条回答
  •  长情又很酷
    2021-01-31 20:54

    Take a look at the standalone websockets server of the pywebsocket project supported by Google.

    Note that this Python module uses CGIHTTPServer so you need to tweak it to make it secure. I had a similar requirement for a project I was involved in some months ago, so I forked the standalone.py module and removed the dependencies with CGI stuff but I haven't tested secure connections very much.

    Maybe you can import OpenSSL.SSL and set up a WebSocketServer as it is in my script. It should use a WebSocketRequestHandler with the proper configuration of use_tls, private_key and certificate in order to implement TLS (Transport Layer Security).

    Read the source code. I think you can extend it to meet your needs.

提交回复
热议问题