Websocket handshake Sec-WebSocket-Accept header value is incorrect

前端 未结 1 1277
情深已故
情深已故 2021-01-03 10:52

I\'m writing a c++ websocket server, dev tools on chrome says sec-websocket-accept header value is incorrect. I\'ve tested for days and it all seems fine. The client closes

相关标签:
1条回答
  • 2021-01-03 11:39

    Chrome says that 'Sec-WebSocket-Accept' is incorrect. Trying to compute it manually, I have to agree with Chrome.

    My test:

    1. concat "LKF8lHGznbKGIgO1UzAOhg==" and "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" => "LKF8lHGznbKGIgO1UzAOhg==258EAFA5-E914-47DA-95CA-C5AB0DC85B11", that's key.
    2. compute SHA1 160 bits hex: bf15 14e3 7108 0ee4 7782 c709 a767 cc72 423d e5c4
    3. From your log, your encoding to base64 is: 5T5MvxP1iz40vLpi3kQs/ifDaCo=
    4. Decoding it to hex: e53e 4cbf 13f5 8b3e 34bc ba62 de44 2cfe 27c3 682a

    The bold values should be equal. Feel free to correct me if I'm wrong somewhere.

    Possible problems:

    • Is sha_str null-terminated ? i.e. strlen((char*)sha_str) == 20 ?

    • signed/unsigned char mixup ?

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