WebSocket4Net icon indicating copy to clipboard operation
WebSocket4Net copied to clipboard

TLS Example

Open NVentimiglia opened this issue 10 years ago • 14 comments

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)

NVentimiglia avatar Oct 01 '15 20:10 NVentimiglia

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.

kerryjiang avatar Oct 02 '15 00:10 kerryjiang

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.

NVentimiglia avatar Oct 02 '15 01:10 NVentimiglia

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?

kerryjiang avatar Oct 02 '15 02:10 kerryjiang

badmethod

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

NVentimiglia avatar Oct 02 '15 02:10 NVentimiglia

@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 avatar Jan 01 '16 18:01 DragonFly81

@DragonFly81 Hello, there is already a constructor allowing the SslProtocols parameter in the latest WebSocket4Net.

kerryjiang avatar Jan 04 '16 01:01 kerryjiang

@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.

DragonFly81 avatar Jan 04 '16 05:01 DragonFly81

The version on nuget 0.14.1.0 was published before the parameter was introduced. There is such a constructor on github.

vraikov avatar May 19 '16 13:05 vraikov

@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 avatar Jul 05 '16 01:07 jmortlock

@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".

kerryjiang avatar Aug 23 '16 16:08 kerryjiang

The Security property seems to be readonly.

Elad

darkl avatar Aug 24 '16 09:08 darkl

Yes, but the properties of Security are not.

kerryjiang avatar Aug 24 '16 17:08 kerryjiang

has anyone got this working?

Raj123456788 avatar Oct 14 '16 22:10 Raj123456788

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.

plinehan avatar Feb 22 '17 01:02 plinehan