Bug 56922 - TLS Failure while connecting to secure websocket
Summary: TLS Failure while connecting to secure websocket
Status: RESOLVED NORESPONSE
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Security ()
Version: 5.0 (2017-02)
Hardware: PC All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-05-28 20:43 UTC by aggieben@gmail.com
Modified: 2018-03-13 11:07 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description aggieben@gmail.com 2017-05-28 20:43:47 UTC
I'm playing around with some simple code to read data from a realtime socket hosted by the GDAX bitcoin exchange, and when run with mono it fails to connect for what seems to be some problem related to TLS compatibility.


Here's the code:
https://gist.github.com/aggieben/693751844eeccfca52950206bd033d06

Just replace the socket address in that gist with "wss://ws-feed.gdax.com" to do exactly what I'm doing.

Here is the --trace=N:nothing output on Windows 10:

C:\Users\ben\proj\bt\simple-gdax-bot [master +1 ~1 -0 !]
λ mono --trace=N:nothing .\build\BitThicket.Gdax.SimpleBot.exe
[0000000000003170:] EXCEPTION handling: System.ArgumentException: 'CP1252' is not a supported encoding name.
Parameter name: name
[15:19:45 INF] Simple GDAX Bot Started
[00000000000012E4:] EXCEPTION handling: System.Security.Cryptography.CryptographicException: Store Root doesn't exists.
[00000000000012E4:] EXCEPTION handling: System.Security.Cryptography.CryptographicException: Store CA doesn't exists.
[00000000000012E4:] EXCEPTION handling: System.Security.Cryptography.CryptographicException: Store CA doesn't exists.
[15:19:46 INF] Connected to socket.
[15:19:46 VRB] waiting for message
[00000000000012E4:] EXCEPTION handling: Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
[0000000000000CAC:] EXCEPTION handling: Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
[0000000000000CAC:] EXCEPTION handling: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
[0000000000003170:] EXCEPTION handling: System.AggregateException: One or more errors occurred.

After building it again, I can only get the following output:
C:\Users\ben\proj\bt\simple-gdax-bot [master +1 ~1 -0 !]
λ mono --trace=N:nothing .\build\BitThicket.Gdax.SimpleBot.exe
[000000000000181C:] EXCEPTION handling: System.ArgumentException: 'CP1252' is not a supported encoding name.
Parameter name: name
[15:39:05 INF] Simple GDAX Bot Started
[00000000000010A8:] EXCEPTION handling: System.Security.Cryptography.CryptographicException: Store Root doesn't exists.
[00000000000010A8:] EXCEPTION handling: System.Security.Cryptography.CryptographicException: Store CA doesn't exists.
[00000000000010A8:] EXCEPTION handling: System.Security.Cryptography.CryptographicException: Store CA doesn't exists.
[15:39:07 INF] Connected to socket.
[15:39:07 VRB] waiting for message
[15:39:07 DBG] result: { CloseStatus: null, CloseStatusDescription: null, Count: 51, EndOfMessage: true, MessageType: Text }
[15:39:07 DBG] received message:

In Linux (using Ubuntu on WSL), the output is a little different:

ben@Kenobi:/mnt/d/Users/ben/proj/bt/simple-gdax-bot$ mono --trace=N:nothing build/BitThicket.Gdax.SimpleBot.exe
[15:36:20 INF] Simple GDAX Bot Started
[0x7f3893ff0700:] EXCEPTION handling: System.ArgumentException: Value does not fall within the expected range.
[0x7f3893ff0700:] EXCEPTION handling: System.Net.WebException: Error: ConnectFailure (Value does not fall within the expected range.)
[0x7f3893ff0700:] EXCEPTION handling: System.Net.WebException: Error: ConnectFailure (Value does not fall within the expected range.)
[0x7f3893ff0700:] EXCEPTION handling: System.Net.WebSockets.WebSocketException: Generic WebSocket exception
[0x7f38a4a90740:] EXCEPTION handling: System.AggregateException: One or more errors occurred.

Unhandled Exception:
System.AggregateException: One or more errors occurred. ---> System.Net.WebSockets.WebSocketException: Generic WebSocket exception ---> System.Net.WebException: Error: ConnectFailure (Value does not fall within the expected range.) ---> System.ArgumentException: Value does not fall within the expected range.
  at System.Net.Sockets.Socket.SetSocketOption (System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, System.Int32 optionValue) [0x00023] in <2b0d86369d72459baed0cee98a8e578a>:0
  at System.Net.Sockets.Socket.set_DontFragment (System.Boolean value) [0x00009] in <2b0d86369d72459baed0cee98a8e578a>:0
  at System.Net.Sockets.Socket.SocketDefaults () [0x00009] in <2b0d86369d72459baed0cee98a8e578a>:0
  at System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) [0x00095] in <2b0d86369d72459baed0cee98a8e578a>:0
  at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x000bb] in <2b0d86369d72459baed0cee98a8e578a>:0
   --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00058] in <2b0d86369d72459baed0cee98a8e578a>:0
  at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in <a07d6bf484a54da2861691df910339b1>:0

MacOS (current) produces an output similar to Windows.
Comment 1 aggieben@gmail.com 2017-05-29 00:44:51 UTC
Here's the MacOS output:

✔ ~/proj/bt/bot2 [:184fbfa|✚ 1] 
19:41 $ mono --trace=N:nothing build/BitThicket.Gdax.SimpleBot.exe
[19:41:54 INF] Simple GDAX Bot Started
[19:41:55 INF] Connected to socket.
[19:41:55 VRB] waiting for message
[0xb0a4c000:] EXCEPTION handling: Mono.Security.Interface.TlsException: Unknown Secure Transport error `PeerProtocolVersion'.
[0xb0a4c000:] EXCEPTION handling: Mono.Security.Interface.TlsException: Unknown Secure Transport error `PeerProtocolVersion'.
[0xb0a4c000:] EXCEPTION handling: Mono.Security.Interface.TlsException: Unknown Secure Transport error `PeerProtocolVersion'.
[0xb0a4c000:] EXCEPTION handling: System.IO.IOException: read failed
[0xb0a4c000:] EXCEPTION handling: System.Net.Sockets.SocketException: The socket has been shut down
[0xb0a4c000:] EXCEPTION handling: System.IO.IOException: Unable to write data to the transport connection: The socket has been shut down.
[0xb0a4c000:] EXCEPTION handling: System.IO.IOException: Unable to write data to the transport connection: The socket has been shut down.
[0xb0a4c000:] EXCEPTION handling: System.IO.IOException: Unable to write data to the transport connection: The socket has been shut down.
[0xb0a4c000:] EXCEPTION handling: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
[0xa70c91c0:] EXCEPTION handling: System.AggregateException: One or more errors occurred.

Unhandled Exception:
System.AggregateException: One or more errors occurred. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
  at System.Net.WebConnection.Read (System.Net.HttpWebRequest request, System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x0002b] in <f040dd46aca1406687d2fd7ae8251c9c>:0 
  at System.Net.WebSockets.ClientWebSocket+<>c__DisplayClass35_0.<ReceiveAsync>b__0 () [0x0016b] in <f040dd46aca1406687d2fd7ae8251c9c>:0 
  at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <b697cffb61b74023aa9c587e6c49beb3>:0 
  at System.Threading.Tasks.Task.Execute () [0x00010] in <b697cffb61b74023aa9c587e6c49beb3>:0 
   --- End of inner exception stack trace ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <b697cffb61b74023aa9c587e6c49beb3>:0 
  at Microsoft.FSharp.Control.AsyncBuilderImpl.commit[a] (Microsoft.FSharp.Control.AsyncBuilderImpl+AsyncImplResult`1[T] res) [0x0002d] in <5893d081904cf4daa745038381d09358>:0 
  at Microsoft.FSharp.Control.CancellationTokenOps.RunSynchronouslyInCurrentThread[a] (System.Threading.CancellationToken token, Microsoft.FSharp.Control.FSharpAsync`1[T] computation) [0x00029] in <5893d081904cf4daa745038381d09358>:0 
  at Microsoft.FSharp.Control.CancellationTokenOps.RunSynchronously[a] (System.Threading.CancellationToken token, Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Core.FSharpOption`1[T] timeout) [0x00014] in <5893d081904cf4daa745038381d09358>:0 
  at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T] (Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Core.FSharpOption`1[T] timeout, Microsoft.FSharp.Core.FSharpOption`1[T] cancellationToken) [0x00071] in <5893d081904cf4daa745038381d09358>:0 
  at BitThicket.Gdax.SimpleBot.Main+loop@24T[a].Invoke (Microsoft.FSharp.Core.Unit unitVar0) [0x00038] in <592b6e4531daab4da7450383456e2b59>:0 
  at BitThicket.Gdax.SimpleBot.Main.main (System.String[] argv) [0x000b4] in <592b6e4531daab4da7450383456e2b59>:0 
---> (Inner Exception #0) System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
  at System.Net.WebConnection.Read (System.Net.HttpWebRequest request, System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x0002b] in <f040dd46aca1406687d2fd7ae8251c9c>:0 
  at System.Net.WebSockets.ClientWebSocket+<>c__DisplayClass35_0.<ReceiveAsync>b__0 () [0x0016b] in <f040dd46aca1406687d2fd7ae8251c9c>:0 
  at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <b697cffb61b74023aa9c587e6c49beb3>:0 
  at System.Threading.Tasks.Task.Execute () [0x00010] in <b697cffb61b74023aa9c587e6c49beb3>:0 <---
Comment 2 Marek Safar 2017-09-13 13:51:59 UTC
I cannot reproduce it with mono 5.4 I get following output (probably due to missing credentials)

Connected to socket.
waiting for message.  Socket state: Open
result: System.Net.WebSockets.WebSocketReceiveResult
received message:
{"type":"error","message":"Failed to subscribe","reason":"No channels provided"}
waiting for message.  Socket state: Open
Comment 3 Marek Safar 2018-03-13 11:07:05 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and reopen the bug report.

Thank you!