websockets-rs / rust-websocket

A WebSocket (RFC6455) library written in Rust
http://websockets-rs.github.io/rust-websocket/
MIT License
1.55k stars 223 forks source link

TlsHandshakeFailure #275

Open lynn2910 opened 1 year ago

lynn2910 commented 1 year ago

Hello, i have an error when connecting to a secure websocket (url: wss://gateway.discord.gg)

Error:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Other(TlsHandshakeFailure)', src/workers/ws.rs:45:14

I declare the client with

        let client = ClientBuilder::new(&*url)
            .unwrap()
            .connect(None)
            .unwrap();

It seems like connecting to a wss throw this error. Perhaps, when i try using "ws://echo.websocket.org", i get:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Other(StatusCodeError(Ok))', src/workers/ws.rs:47:14

(trace:)

2023-05-20T12:40:45.599 [DEBUG] Connecting to ws://echo.websocket.org
2023-05-20T12:40:45.778 [TRACE] Headers.set( "Host", Host { hostname: "echo.websocket.org", port: None } )
2023-05-20T12:40:45.778 [TRACE] Headers.set( "Connection", Connection([ConnectionHeader(UniCase("Upgrade"))]) )
2023-05-20T12:40:45.778 [TRACE] Headers.set( "Upgrade", Upgrade([Protocol { name: WebSocket, version: None }]) )
2023-05-20T12:40:45.778 [TRACE] Headers.set( "Sec-WebSocket-Version", 13 )
2023-05-20T12:40:45.778 [TRACE] Headers.set( "Sec-WebSocket-Key", WebSocketKey(6v8eRHPaNOtWbexb1RRQtg==) )
2023-05-20T12:40:45.778 [TRACE] get_buf []
2023-05-20T12:40:45.778 [TRACE] read_into_buf buf[0..4096]
2023-05-20T12:40:45.911 [TRACE] get_buf [u8; 4096][0..354]
2023-05-20T12:40:45.911 [TRACE] try_parse([72, 84, 84, 80, 47, 49, 46, 49, 32, 50, 48, 48, 32, 79, 75, 13, 10, 120, 45, 97, 109, 122, 45, 105, 100, 45, 50, 58, 32, 115, 77, 68, 100, 77, 79, 57, 117, 56, 76, 118, 112, 121, 77, 99, 76, 67, 84, 83, 76, 56, 74, 105, 77, 50, 86, 77, 54, 88, 121, 84, 55, 83, 47, 97, 87, 56, 71, 89, 82, 118, 54, 103, 68, 67, 109, 76, 80, 114, 69, 78, 113, 70, 120, 56, 70, 80, 57, 54, 73, 43, 105, 110, 109, 66, 120, 104, 112, 54, 56, 119, 98, 77, 85, 99, 61, 13, 10, 120, 45, 97, 109, 122, 45, 114, 101, 113, 117, 101, 115, 116, 45, 105, 100, 58, 32, 52, 55, 81, 86, 68, 80, 71, 87, 56, 71, 86, 72, 75, 53, 88, 69, 13, 10, 68, 97, 116, 101, 58, 32, 83, 97, 116, 44, 32, 50, 48, 32, 77, 97, 121, 32, 50, 48, 50, 51, 32, 49, 50, 58, 52, 48, 58, 52, 54, 32, 71, 77, 84, 13, 10, 76, 97, 115, 116, 45, 77, 111, 100, 105, 102, 105, 101, 100, 58, 32, 84, 104, 117, 44, 32, 50, 54, 32, 65, 117, 103, 32, 50, 48, 50, 49, 32, 48, 51, 58, 51, 53, 58, 52, 50, 32, 71, 77, 84, 13, 10, 69, 84, 97, 103, 58, 32, 34, 54, 100, 53, 97, 50, 56, 102, 52, 99, 53, 101, 50, 57, 55, 101, 57, 53, 97, 50, 57, 57, 56, 56, 56, 56, 52, 99, 57, 101, 56, 57, 54, 34, 13, 10, 67, 111, 110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 116, 101, 120, 116, 47, 104, 116, 109, 108, 13, 10, 83, 101, 114, 118, 101, 114, 58, 32, 65, 109, 97, 122, 111, 110, 83, 51, 13, 10, 67, 111, 110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 52, 52, 49, 51, 13, 10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 99, 108, 111, 115, 101, 13, 10, 13, 10])
2023-05-20T12:40:45.911 [TRACE] Response.try_parse([Header; 100], [u8; 354])
2023-05-20T12:40:45.912 [TRACE] Response.try_parse Complete(354)
2023-05-20T12:40:45.912 [TRACE] raw header: "x-amz-id-2"=[115, 77, 68, 100, 77, 79, 57, 117, 56, 76, 118, 112, 121, 77, 99, 76, 67, 84, 83, 76, 56, 74, 105, 77, 50, 86, 77, 54, 88, 121, 84, 55, 83, 47, 97, 87, 56, 71, 89, 82, 118, 54, 103, 68, 67, 109, 76, 80, 114, 69, 78, 113, 70, 120, 56, 70, 80, 57, 54, 73, 43, 105, 110, 109, 66, 120, 104, 112, 54, 56, 119, 98, 77, 85, 99, 61]
2023-05-20T12:40:45.912 [TRACE] raw header: "x-amz-request-id"=[52, 55, 81, 86, 68, 80, 71, 87, 56, 71, 86, 72, 75, 53, 88, 69]
2023-05-20T12:40:45.912 [TRACE] raw header: "Date"=[83, 97, 116, 44, 32, 50, 48, 32, 77, 97, 121, 32, 50, 48, 50, 51, 32, 49, 50, 58, 52, 48, 58, 52, 54, 32, 71, 77, 84]
2023-05-20T12:40:45.912 [TRACE] raw header: "Last-Modified"=[84, 104, 117, 44, 32, 50, 54, 32, 65, 117, 103, 32, 50, 48, 50, 49, 32, 48, 51, 58, 51, 53, 58, 52, 50, 32, 71, 77, 84]
2023-05-20T12:40:45.912 [TRACE] raw header: "ETag"=[34, 54, 100, 53, 97, 50, 56, 102, 52, 99, 53, 101, 50, 57, 55, 101, 57, 53, 97, 50, 57, 57, 56, 56, 56, 56, 52, 99, 57, 101, 56, 57, 54, 34]
2023-05-20T12:40:45.912 [TRACE] raw header: "Content-Type"=[116, 101, 120, 116, 47, 104, 116, 109, 108]
2023-05-20T12:40:45.912 [TRACE] raw header: "Server"=[65, 109, 97, 122, 111, 110, 83, 51]
2023-05-20T12:40:45.912 [TRACE] raw header: "Content-Length"=[52, 52, 49, 51]
2023-05-20T12:40:45.912 [TRACE] raw header: "Connection"=[99, 108, 111, 115, 101]
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Other(StatusCodeError(Ok))', src/workers/ws.rs:47:14

But the websocket doesn't initialize itself when connecting to a wss

vi commented 1 year ago

ws://echo.websocket.org

No longer works. You can use ws://ws.vi-server.org/mirror instead.


What is the reason of using websocket instead of recommended alternative tungstenite?

lynn2910 commented 1 year ago

ws://echo.websocket.org

No longer works. You can use ws://ws.vi-server.org/mirror instead.

This address works properly, but how can I connect to wss since I have the handshake failure ?

lynn2910 commented 1 year ago

What is the reason of using websocket instead of recommended alternative tungstenite?

Because, I use this in the crate mlua, but the Tokio runtime can't be used a athis context. That's why I need a websocket client that is not async

vi commented 1 year ago

Tokio runtime can't be used a athis context

I don't remember tungstenite (unlike tokio-tungstenite or async-tungstenite) to be dependent on Tokio.


Does tungstenite::client_tls match your needs?