websocket-sharp: An error has occurred during a TLS handshake. (wss)

Server: Node + ws (npm) Client: Unity3D (4.6) + websocket-sharp

Usually the connection is good. But sometimes (5-10%) you receive this message. (An error has occurred during a TLS handshake. ) When receive this message, handshake is hanged for 3 minutes.

I found the code. WebSocket.cs private void setClientStream() { ... sslStream.AuthenticateAsClient(...) <== hang ... }

It Is Secured WebSocket has this chronic problem? (.net’s bug??.. unity3d’s old framework) (https://www.google.co.jp/webhp?sourceid=chrome-instant&ion=1&espv=2&es_th=1&ie=UTF-8#q=AuthenticateAsClient+hang)

Or, the server’s the problem?

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 2
  • Comments: 15

Most upvoted comments

Workaround to TLS handshake issue:

private enum SslProtocolsHack
{
    Tls = 192,
    Tls11 = 768,
    Tls12 = 3072
}
ws.OnClose += (sender, e) =>
{
    var sslProtocolHack = (System.Security.Authentication.SslProtocols)(SslProtocolsHack.Tls12 | SslProtocolsHack.Tls11 | SslProtocolsHack.Tls);
    //TlsHandshakeFailure
    if (e.Code == 1015 && ws.SslConfiguration.EnabledSslProtocols != sslProtocolHack)
    {
        ws.SslConfiguration.EnabledSslProtocols = sslProtocolHack;
        ws.Connect();
    }
};

Workaround to TLS handshake issue:

private enum SslProtocolsHack
{
    Tls = 192,
    Tls11 = 768,
    Tls12 = 3072
}
ws.OnClose += (sender, e) =>
{
    var sslProtocolHack = (System.Security.Authentication.SslProtocols)(SslProtocolsHack.Tls12 | SslProtocolsHack.Tls11 | SslProtocolsHack.Tls);
    //TlsHandshakeFailure
    if (e.Code == 1015 && ws.SslConfiguration.EnabledSslProtocols != sslProtocolHack)
    {
        ws.SslConfiguration.EnabledSslProtocols = sslProtocolHack;
        ws.Connect();
    }
};

Had the same issue today and your workaround is still working. Is this fixed in the library itself by now? And how do I get the WebSocketServer working in wss mode?