jirihybek / unity-websocket-webgl

Hybrid WebSocket implementation for Unity 3D with support of native and browser client.
Other
248 stars 61 forks source link

Can't handshake with WSS #6

Open CodeSpartan opened 5 years ago

CodeSpartan commented 5 years ago

Error log:

WS closed with code: TlsHandshakeFailure
UnityEngine.Debug:Log(Object)
<>c:<Start>b__1_2(WebSocketCloseCode) (at Assets/Scripts/WebSocketDemo.cs:40)
HybridWebSocket.WebSocket:<.ctor>b__13_3(Object, CloseEventArgs) (at Assets/Plugins/WebSocket.cs:495)
WebSocketSharp.Ext:Emit(EventHandler`1, Object, CloseEventArgs) (at E:/Repos/WebsocketsSharp/websocket-sharp/Ext.cs:1269)

In sta/websocket-sharp, this is fixed by adding this line: ws.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12;

Is it possible to fix this in this library? I could add this line myself in the constructor, I'm just not sure what's the correct way to treat it.

salmansaleem32 commented 5 years ago

Hi, any update on this issue ?

Swaelo commented 5 years ago

Hi, any update on this issue ?

The fix is in CodeSpartans comment, owner of the repo is inactive so pull request hasnt been accepted

salmansaleem32 commented 5 years ago

Hi @Swaelo That error has been resolved. Now browser is giving me this error. WebSocket connection to "domain" failed: Error in connection establishment: net::ERR_CERT_AUTHORITY_INVALID

Any suggestions ?

KudryX2 commented 3 years ago

The solution CodeSpartan found worked for me too.

@salmansaleem32 you need to create the server with a certificate, you can do it with openssl. In my case im using typescript with node

const Fs = require('fs');
const Https = require('https');
const WebSocketServer = require('ws').Server;

const httpsServer = Https.createServer({
  cert: Fs.readFileSync('cert/cert.pem'),
  key: Fs.readFileSync('cert/key.pem'),
  passphrase : 'certPassword'
});

const wss = new WebSocketServer({server: httpsServer});