0

In my application, I am trying to have a python tornado server communicate with a javascript html page through websockets. I was able to get the connection to work using an un-encrypted ws connection but when I tried to implement the solution on this post:

How to use secure websocket (wss) in Tornado

I get the error:

WARNING:tornado.general:SSL Error on 10 ('::1', 57020, 0, 0): [SSL: SSLV3_ALERT_CERTIFICATE_UNKNOWN] sslv3 alert certificate unknown (_ssl.c:727)

I'm using a self signed certificate and trying to get this working on localhost before I put this onto the real server. I also made sure to change the client code to use wss instead of ws when connecting.

How do I modify my javascript code in the webpage environment so that I can connect to the server even though it is using self signed certificates?

James
  • 1
  • 3

1 Answers1

0

Yes, the fact that your certificates are self-signed is the problem. You can pass validate_cert=False to websocket_connect like this:

ws_req = HTTPRequest("wss://127.0.0.1:8080/ws", validate_cert=False)
ws = await websocket_connect(ws_req)

(full example here)

Ben Darnell
  • 21,844
  • 3
  • 29
  • 50
  • It might seem obvious but it is worth noting that certificate validation should not be skipped when running in production. In other words, you probably want to make sure that `validate_cert` can be controlled easily in dev vs. prod environments. – MrName Jan 23 '20 at 18:33
  • This works for a python client to connect but I do not know how to translate this to javascript on my html page. I tried following the solution here: [link](https://stackoverflow.com/questions/10888610/ignore-invalid-self-signed-ssl-certificate-in-node-js-with-https-request) But since I am not running the code in Node I cannot implement their solution. – James Jan 24 '20 at 14:18
  • I suggest adding some javascript tags to your question, then, to attract the attention of people familiar with javascript. Maybe reword the question to emphasize that you need to do this in the browser environment (which is the important part; the fact that the server is tornado is not really a relevant detail) – Ben Darnell Jan 24 '20 at 17:28