WebSocket4Net
WebSocket4Net copied to clipboard
TLS Example
I am trying to connect to a websocket server using TLS and I am receiving a exception "The authentication or decryption has failed."
The URI I am passing is :
"wss://ortc-developers2-uswest2-s0001.realtime.co:443/broadcast/926/WNWJYJUQ/websocket"
My constructor looks like
_websocket = new WebSocket(uri, SslProtocols.Tls12.ToString(), WebSocketVersion.Rfc6455);
(I am pretty sure this is wrong, but I do not see any docs)
Just only keep the first parameter in the constructor. The other two are not necessary. Make sure the certificate of your server side is setup correct.
Using MonoDroid
There is no constructor with only a single parameter.
Internally are we using an Android Websocket implementation or are we using a Mono / .Net implementation. I ask because If we are using mono, It is a known issue that TLS is nonfunctional.
The second parameter is not for transfer level security protocol like SSL/TLS. Instead, it's for application level sub protocol.
There is a constructor with only one required parameter, other parameters are optional: https://github.com/kerryjiang/WebSocket4Net/blob/master/WebSocket4Net/WebSocket.Net.cs
Do you mean there is a know issue about MonoDroid TLS, so you want to use TLS12?

CS0121 The call is ambiguous between the following methods or properties: 'WebSocket.WebSocket(string, string, List<KeyValuePair<string, string>>, List<KeyValuePair<string, string>>, string, string, WebSocketVersion)' and 'WebSocket.WebSocket(string, string, List<KeyValuePair<string, string>>, List<KeyValuePair<string, string>>, string, string, WebSocketVersion, EndPoint)'
I am using the version on Nuget, should I be using another version ?
Known Issue
https://github.com/rdavisau/sockets-for-pcl/issues/35
@kerryjiang Hi. Any news on when Websocket4Net will be capable of accommodating TLS 1.1 and up? My client code connects to various 3rd party websocket servers and some of them no longer support TLS 1.0 due to POODLE vulnerability...
@DragonFly81 Hello, there is already a constructor allowing the SslProtocols parameter in the latest WebSocket4Net.
@kerryjiang Thanks for the reply. Please forgive me if I'm misunderstanding something, but I don't see a "SslProtocols"-parameter in any of the constructors. Are you referring to the "WebSocketVersion"-parameter? If so, I've tried all the options in the enumerator (including "Rfc6455") but its seems the highest TLS that gets used in the handshake is version 1.0, resulting in an "The client and server cannot communicate, because they do not possess a common algorithm"-error. Could you possibly give an example of the constructor using TLS 1.2 (RFC5246) or even TLS 1.1 (RFC4346) exclusively? Thanks for your time.
The version on nuget 0.14.1.0 was published before the parameter was introduced. There is such a constructor on github.
@kerryjiang Any ideas on when a new version will be published to NuGet? not having the TLS options in the 0.14.1 released version is causing us some grief when connecting to a crossbars.io server which enables TLS1.2 only. Current workaround is to build manually and use the resulting DLLs, but as we also use an upstream project WampSharp this also means a rebuild of that solution as well, obviously not ideal.
@jmortlock Could you try the latest beta version? https://www.nuget.org/packages/WebSocket4Net/0.15.0-beta2
You can setup SslProtocols through the new property "Securiity".
The Security property seems to be readonly.
Elad
Yes, but the properties of Security are not.
has anyone got this working?
Yes, using https://www.nuget.org/packages/WebSocket4Net/0.15.0-beta6 I can specify the SSL protocols like this:
var socket = new WebSocket(url, sslProtocols: SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls);
@kerryjiang perhaps it is time to mark 0.15.0-beta6 as the stable version? It appears relatively popular based on downloads, and is nearly 6 months old now.