Answer the question
In order to leave comments, you need to log in
How to set up WSS in Python?
Wem hello.
To create a WebSokcet server, I used . such a library
Recently, the question arose about how to encrypt the connection to the web socket
on the library website in the WSS section.
WSS is to WS what HTTPS is to HTTP: the connection is encrypted using Transport Layer Security (TLS), often referred to as Secure Sockets Layer (SSL). WSS requires TLS certificates like HTTPS.
Here's how to adapt the server example to provide secure connections. See the documentation for the SSL module to configure the context securely.
That is, in fact, I can use the same certificates as for encrypting an HTTP connection.
The domain name registrar presented me with such keys
certificate_ca.crt Root certificate
certificate.csr CSR request
certificate.crt Certificate
I can't figure out how to connect them
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ssl_context.load_cert_chain("/chain.crt")
start_server = websockets.serve(counter, "localhost", 6666, ssl=ssl_context)
ssl_context.load_cert_chain("chain.crt")
ssl.SSLError: [SSL] PEM lib (_ssl.c:4012)
Answer the question
In order to leave comments, you need to log in
Figured out pem can be created from a certificate and a private key. Everything works great.
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question