Bug 42420 - ClientWebSocket class doesn't seem to receive data correctly over SSL when running on Xamarin/iOS
Summary: ClientWebSocket class doesn't seem to receive data correctly over SSL when ru...
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries (show other bugs)
Version: XI 9.6 (iOS 9.3)
Hardware: Other Other
: Normal major
Target Milestone: Future Cycle (TBD)
Assignee: Manuel de la Peña [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-07-08 09:36 UTC by jon.close
Modified: 2018-03-23 14:46 UTC (History)
11 users (show)

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


Attachments
Sample (16.14 KB, application/x-zip-compressed)
2016-07-14 20:48 UTC, Cody Beyer (MSFT)
Details


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 for Bug 42420 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description jon.close 2016-07-08 09:36:03 UTC
To reproduce:


var ws = new ClientWebSocket();

//  Non SSL - works
await ws.ConnectAsync(new Uri("ws://echo.websocket.org"), CancellationToken.None);

//  SSL - doesn't work
//await ws.ConnectAsync(new Uri("wss://echo.websocket.org"), CancellationToken.None);

var messageBytes = Encoding.UTF8.GetBytes("Hello world!");

var sendArraySegment = new ArraySegment<byte>(messageBytes);


await ws.SendAsync(sendArraySegment, WebSocketMessageType.Text, true, CancellationToken.None);

var receiveBuffer = new byte[1024];
var receiveArraySegment = new ArraySegment<byte>(receiveBuffer);

var result = await ws.ReceiveAsync(receiveArraySegment, CancellationToken.None);

//  receiveMessage should equal the send message "Hello world!"
//  When not using SSL this works
//  When using SSL then this string is blank.  In this case, "result" above still indicates that 
//  12 bytes was received but the data doesn't appear in the buffer
var receiveMessage = Encoding.UTF8.GetString(receiveBuffer, 0, result.Count);


Running the above code on Windows from a standard console application works for both SSL and non-SSL
Comment 1 Cody Beyer (MSFT) 2016-07-14 20:48:12 UTC
Created attachment 16671 [details]
Sample
Comment 2 Sebastien Pouliot 2016-07-19 13:50:35 UTC
@Manuel please check if this happens only with MonoTLS and/or AppleTLS (on C7SR1 branch).

Also confirm if the was working on the latest C6 release (i.e. regression or not).
Comment 3 Manuel de la Peña [MSFT] 2016-07-19 17:17:56 UTC
I've ran the sample application with different runtimes:

9.6.2.4 (Stable- mtouch 9.6.2.4 (cycle6-xi: d8bedd0)) - 
    Apple TLS - The bug exists.
    Mono TLS - The bug exists.
9.8.2.16 (mtouch 9.8.2.16 (cycle7-sr1: db3d76f)) - 
    Apple TLS - Application works
    Mono TLS -  Bug exists.

Therefore this is not a regressions AFAIK and the code works with the Apple TLS implementation and NOT with the Mono one.
Comment 4 Manuel de la Peña [MSFT] 2016-07-19 17:18:12 UTC
I've ran the sample application with different runtimes:

9.6.2.4 (Stable- mtouch 9.6.2.4 (cycle6-xi: d8bedd0)) - 
    Apple TLS - The bug exists.
    Mono TLS - The bug exists.
9.8.2.16 (mtouch 9.8.2.16 (cycle7-sr1: db3d76f)) - 
    Apple TLS - Application works
    Mono TLS -  Bug exists.

Therefore this is not a regressions AFAIK and the code works with the Apple TLS implementation and NOT with the Mono one.
Comment 5 Sebastien Pouliot 2016-07-19 17:28:01 UTC
Thanks! 

Note: C6 / 9.6.x did not have AppleTLS, that's likely just the IDE that shows the option.

The fact it works on AppleTLS makes it sounds like the host server requires TLS 1.1+ which Mono TLS does not support (only SSL3 and TLS 1.0) and Ssl Labs [1] agrees with my assessment.

TLS 1.2	Yes
TLS 1.1	Yes
TLS 1.0	No
SSL 3	No
SSL 2	No

Please use AppleTLS as we have no plan to further update MonoTLS.

[1] https://www.ssllabs.com/ssltest/analyze.html?d=echo.websocket.org
Comment 6 Cosmin 2017-07-09 13:15:32 UTC
I am running into similar issues. I have downloaded the sample app attached by jon and the issue still reproduces.

I am new to Xamarin, I'm am coming from a native iOS / Android. I am using Visual Studio for Mac 7.0.1.24 and I am not sure how I can toggle between different runtimes (so that I can point to 9.8.2.16 with Apple TLS (where as mentioned above the code should work)
Comment 7 Cosmin 2017-07-09 13:23:15 UTC
Also the issue reproduces on Android as well.
Comment 8 Cosmin 2017-07-09 14:18:26 UTC
I'm using Xamarin.iOS.framework Version 10.10.0.36 and MonoAndroid v7.1
Comment 9 Cosmin 2017-07-09 14:23:59 UTC
And the actual received message is "\0\0\0\0\0\0\0\0\0\0\0\0"
Comment 10 Manuel de la Peña [MSFT] 2017-07-10 08:40:51 UTC
@Cosmin could you provide the full information of you enviroment?
Comment 11 Cosmin 2017-07-10 10:13:31 UTC
Hi Manuel,

I'm using the following:

macOS Sierra 10.12.4 (16E195)
Visual Studio for Mac 7.0.1.24
Xamarin.iOS 10.10.0.36
MonoAndroid v7.1
iOS Simulator 10.3
Android Emulator API Level 23

On iOS I have HttpClient implementation set to NSUrlSession and there's not SSL/TLS option in Project Options -> Build -> iOS Build

On Android I have HttpClient implementation set to AndroidClientHandler and SSL/TLS implementation set to Native TLS 1.2+ in Project Options -> Build -> Android Build

As mentioned above, I'm quite new to Xamarin development so if there's other info about my environment that you need me to provide please let me know.
Comment 12 Sebastien Pouliot 2017-07-10 13:34:25 UTC
The HttpClient options should have no impact on the sockets.

@Manuel please re-confirm comment #4 with the latest stable, if it fails go back on each stable to see when it regressed so we can identify which mono version was bundled. Thanks!
Comment 13 Cosmin 2017-07-10 13:54:59 UTC
This is a dump of my environment (found how to fetch this from this ticket - https://bugzilla.xamarin.com/show_bug.cgi?id=57106)

Visual Studio Community 2017 for Mac
Version 7.0.1 (build 24)
Installation UUID: 1ede8c5d-9d75-419f-82a5-a4e553d2c07f
Runtime:
	Mono 5.0.1.1 (2017-02/5077205) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 500010001

NuGet
Version: 4.0.0.2323

.NET Core
Runtime: Not installed
SDK: Not installed
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.0.1/lib/mono/msbuild/15.0/bin/Sdks

Xamarin.Profiler
Version: 1.5.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Apple Developer Tools
Xcode 8.3.2 (12175)
Build 8E2002

Xamarin.Mac
Version: 3.4.0.36 (Visual Studio Community)

Xamarin.Android
Version: 7.3.1.2 (Visual Studio Community)
Android SDK: /Users/cosminstirbu/Documents/sdk
	Supported Android versions:
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
		7.0    (API level 24)
		7.1    (API level 25)

SDK Tools Version: 26.0.2
SDK Platform Tools Version: 25.0.6
SDK Build Tools Version: 26.0.0

Java SDK: /usr
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Xamarin.iOS
Version: 10.10.0.36 (Visual Studio Community)
Hash: d2270eec
Branch: d15-2
Build date: 2017-05-22 16:30:53-0400

Xamarin Inspector
Version: 1.2.2
Hash: b71b035
Branch: d15-1
Build date: Fri, 21 Apr 2017 17:57:12 GMT

Build Information
Release ID: 700010024
Git revision: 7ab1ca2ced6f584e56b7a0d4d321d00775cd95c9
Build date: 2017-05-19 05:44:51-04
Xamarin addins: 08d17158f3365beee5e60f67999e607cce4b3f93
Build lane: monodevelop-lion-d15-2

Operating System
Mac OS X 10.12.4
Darwin 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
Comment 14 Cosmin 2017-08-01 09:58:25 UTC
Hello.

Are there any updates on this ticket?

Thank you.
Comment 15 Manuel de la Peña [MSFT] 2017-09-11 15:25:46 UTC
Hello, sorry for the delay, I'll retake this issue and will get back to you asap.