Can not established Websocket secure connection on Firefox

后端 未结 6 1593
傲寒
傲寒 2020-12-06 11:03

I am stucked with Firefox. I could not make Websocket work on it. I use Tornado Websocket and I initialized it by code below:

app = Application([(r\'/mypath/         


        
相关标签:
6条回答
  • 2020-12-06 11:35

    I've solved this problem adding a certificate exception in Firefox's advanced preferences.

    0 讨论(0)
  • 2020-12-06 11:36

    Try to open this url https://websocket.localhost/mypath/ws in firefox and accept certificate first.

    0 讨论(0)
  • 2020-12-06 11:48

    If it's a self-signed certificate, browsers won't show the dialog to accept the certificate if it's only used in a websocket. You must first visit a normal page on the same server to see and accept the certificate warning, and then you can create the secure websocket.

    0 讨论(0)
  • 2020-12-06 11:50

    I solved my problem via ProxyPass. I created a non-secure Websocket server with Tornado and run it on a specific port such as 3232:

    app = Application([(r'/ws/', WSHandler)])
    ws_server = HTTPServer(app)
    ws_server.listen("3232")
    

    Then I've written a proxypass in my Apache conf and use mod_proxy_wstunnel:

    ProxyPass /ws/ ws://127.0.0.1:3232/ws/
    ProxyPassReverse /ws/ ws://127.0.0.1:3232/ws/
    

    And I create Websocket client on frontend like this:

    var WS = new WebSocket("wss://websocket.localhost:81/ws/")
    

    In this case I can create a connection on a secure connection with https and my port is 81 and my proxypass redirect any Websocket request to locally listened port 3232. It is not a exact solution mostly like a workaround. But it works fine for me.

    0 讨论(0)
  • 2020-12-06 11:53

    If it's a self-signed certificate, browsers won't show the dialog to accept the certificate if it's only used in a websocket.
    You must first visit the requested url to see and accept the certificate warning, and then you can create the secure websocket.

    For example if your websocket url is:
    wss://localhost:44300/OpenWebSocket
    then visit:
    https://localhost:44300/OpenWebSocket
    and accept the certificate warning

    0 讨论(0)
  • 2020-12-06 11:57

    I was pulling my hair out over this one for a while. I was getting all kinds of cryptic error messages depending on different web browsers, that all made it sound like it was something about certificate exceptions. I had already made exceptions in Firefox and Chrome,

    It turned out I had a typo in my sub-protocol string in my Javascript!

    Correcting the sub-protocol string made everything better. More information on WebSockets and using sub-protocol(s): https://developer.mozilla.org/en-US/docs/Web/API/WebSocket

    0 讨论(0)
提交回复
热议问题