9

How to set WSS (Secure WebSockets) on Tornado?

In their docstring, they say the following:

WebSocketHandler.get_websocket_scheme can be used to select the appropriate url scheme (ws:// or wss://) in cases where HTTPRequest.protocol is not set correctly.

So, how can I use get_websocket_scheme and/or HTTPRequest.protocol to get the WSS to work on Tornado.

securecurve
  • 5,589
  • 5
  • 45
  • 80

1 Answers1

13

I got it :))

Just add this to your application:

   http_server = tornado.httpserver.HTTPServer(application,ssl_options={
    "certfile": "cert.cer",
    "keyfile":  "key.key",
})

This will solve the problem. Just very similar to regular HTTPS. I also appreciate any other way to make it work.

securecurve
  • 5,589
  • 5
  • 45
  • 80
  • i am not sure if it's a certificate issue. but when i am trying to connect ssl over secure websocket and https. it's working in html & java script environment. but when i created a client in python script. it showing me certificate verification failed. I posted a question over stackoverflow as well https://stackoverflow.com/questions/46852066/how-to-create-python-secure-websocket-client-request. could you please advise? it's bit urgent. – Ravi Anand Oct 23 '17 at 11:12
  • I posted a comment there .. let me know if resolves your problem. – securecurve Oct 23 '17 at 12:19