There's no guarantee that WebSocket.ReceiveAsync will return a complete message; in the extreme, a message can contain long.MaxValue bytes but the API only allows you to retrieve ~int.MaxValue at a time, but even way below that, it's common for ReceiveAsync to return the data it has available rather than gathering up all of the data from the message. However, several of the ConnectTest tests were depending on the full-message behavior. This commit fixes that.
Commit migrated from https://github.com/dotnet/corefx/commit/ffaf5375c00622b285997bc9626c042b9d64195c
* Moving PlatformDetection to Corefx.Private.TestUtilities assembly
The purpose of this change is to clean up all test projects instead of including the PlatformDetection code inside every test project, we’ll have it in the Corefx.Private.TestUtilities.
I have refactored the PlatformDetection to split the different implementation of Windows and Linux. If we need to do more refactoring there we can do it later as needed.
* Fix Linux BB
* Update the xunit package reference
* Fix wrong condition on one of the tests
* Update the ConditionalFact/Theory to use Type as a parameter
Commit migrated from https://github.com/dotnet/corefx/commit/878e2fcf5a9f1068015e5fada9231088663e3490
Re-enabling ClientWebSocket's CloseTest and CancelTest runs for UWP.
All of these tests pass after a minor behavioral fix, where the "cancel pending ReceiveAsync" scenario was resulting in a different exception type compared to .NET Framework and non-UWP .NET Core. The following CancelTest test cases caught the bad behavior that I'm fixing as part of this PR:
ReceiveAsync_CancelThenReceive_ThrowsOperationCanceledException
ReceiveAsync_ReceiveThenCancel_ThrowsOperationCanceledException
ReceiveAsync_AfterCancellationDoReceiveAsync_ThrowsWebSocketException
Contributes to dotnet/corefx#20132
Commit migrated from https://github.com/dotnet/corefx/commit/218348948f536a89f71a61f279d50353f587eb0d
* Implement client certificates for HttpClient on UAP
Added code for HttpClientHandler.ClientCertificates on UAP.
Moved code duplicated in several places into a common helper class, CertificateHelper.
Then I discovered a bug introduced into GetEligibleCertificates (from PR dotnet/corefx#21908) that
doesn't properly filter by EKU or KeyUsage if there is only one cert (this was failing
the WinHttpHandler Unit tests). So, I removed that optimization.
Used the new Azure test endpoint for client certificates. I did not use the loopback
server because there is a problem using it with HttpClient in UAP. There is a crash
in the SslStream.AuthenticateAsServer that I was not able to diagnose yet. It will
require a lot of time debugging and I wanted to get this HttpClientHandler feature
done now. Tracking that investigation with dotnet/corefx#22021.
Fixesdotnet/corefx#21628
Contributes to dotnet/corefx#14542
* Address PR feedback
* Moved method to Windows-only Common file
* Fixed some line spacing
Other potential refactoring/optimizations will be looked into in dotnet/corefx#22045
Commit migrated from https://github.com/dotnet/corefx/commit/472b8d8ec212c2afb107dea305b4624c4989a79f
With these changes, the UWP implementation of ClientWebSocket.ReceiveAsync hands partial WebSocket message data back to the app as soon as it arrives. This eliminates the behavioral difference between .NET Core and UWP tracked by issue dotnet/corefx#21102.
This fix leverages WinRT APIs that are only present since Windows 10 Insider Preview Build 16215, so API presence checks are in place. The pre-fix behavior takes effect when running on older Windows builds.
Fixesdotnet/corefx#21102
Commit migrated from https://github.com/dotnet/corefx/commit/09d029cbe1734ffb4f2ee5f259acfd69ea172158
With these changes, the UWP implementation of ClientWebSocket.ConnectAsync takes the ClientCertificates member of the app-provided ClientWebSocketOptions into account. The first client cert that can be successfully converted into a WinRT client cert (if any) is configured on the underlying WinRT MessageWebSocket instance, leading to the cert being used for mutual TLS authentication when establishing connections with WSS endpoints.
This fix leverages WinRT APIs that are only present since Windows 10 Insider Preview Build 16215, so API presence checks are in place.
Fixesdotnet/corefx#21393
Commit migrated from https://github.com/dotnet/corefx/commit/0c478304177f038af958959f1d106522b77bce26
The UWP implementation of ClientWebSocket uses WinRT MessageWebSocket APIs internally. If a connection-related or message-processing failure occurs, WinRT raises a MessageReceived event that throws an exception containing the failure's details when GetDataReader() is called. Unfortunately, ClientWebSocket isn't handling those exceptions inside its MessageReceived event handler, so they end up bringing down the entire process.
These changes add basic handling of GetDataReader() exceptions. They also contain a new functional test that pins the current behavior of all ClientWebSocket implementations around the "connection is prematurely closed" scenario. Without the proposed product code changes, this new test case reproduces the crash tracked by dotnet/corefx#17317.
Fixesdotnet/corefx#17317
Commit migrated from https://github.com/dotnet/corefx/commit/5573a9e3d4151642e8e2ff477eba2f2eda954fb4
To help diagnose pernicious exceptions, this debug-build-only change augments exceptions created using CreateExceptionUsingError to include the calling thread's stack trace, so that when these exceptions are then moved to other threads and propagated there, we can better correlate where they came from.
Commit migrated from https://github.com/dotnet/corefx/commit/2c368e81d9d07f0d40edf36047e5b93e44db200b
Now instead of Use*Key a project can instead define the assembly key
in the project (genreally the common dir.pops for a project) using
the AssemblyKey property. The accepted values are Open, ECMA, MSFT,
Test.
This change allows for a repo to set the default key they want to use
for projects. In corefx we have switched the default to use the Open
key instead of the old BuildTools default of MSFT key.
As part of this update we are explicitly setting the AssemblyKey in
all the library projects (although it is really only necessary for
projects that aren't the default).
Also with this change we are updating all the new libraries that have
not yet shipped stable (compared to our 1.1 release) and making them
use the Open key. Which means that for prerelease dependencies there
might be some binary breaking changes to consume.
The following libraries ahven't shipped so there key is being
changed from MSFT to Open:
Microsoft.XmlSerializer.Generator
System.CodeDom
System.Configuration.ConfigurationManager
System.Data.Odbc
System.DirectoryServices
System.DirectoryServices.AccountManagement
System.DirectoryServices.Protocols
System.IO.Ports
System.Json
System.Memory
System.Net.HttpListener
System.Net.Mail
System.Net.ServicePoint
System.Net.WebClient
System.Net.WebProxy
System.Private.Xml
System.Private.Xml.Linq
System.Security.Cryptography.Xml
System.Security.Permissions
System.Transactions.Local
System.Web.HttpUtility
Commit migrated from https://github.com/dotnet/corefx/commit/ac09a797d09502ebab61f7167bb856846602e1e6
The managed websockets handler was using this custom NetworkStream-derived stream as an optimization to use SocketAsyncEventArgs for async reads/writes. Now that this optimization is built directly into NetworkStream, the custom type is no longer needed.
Commit migrated from https://github.com/dotnet/corefx/commit/430d7bdde46e7915a39d7a93383f1abc3466a809
The web socket protocol uses a 4-byte mask sent from client to server and xor'd with the payload data. In the managed web socket implementation, that mask is currently applied byte-by-byte. This commit changes it to be done using SIMD.
Micro-benchmarks on the ApplyMask function itself show a regression for payload lengths under 4 bytes, but above that it's a clear win:
```
1: 0.44x
3: 0.64x
4: 1.15x
7: 1.16x
31: 1.73x
32: 6.06x
63: 3.37x
64: 10.40x
1024: 20.36x
```
This doesn't have a measurable affect on small payloads in the overall context of sending/receiving data, but the larger the payload, the more it applies. Locally I measured upwards of a 10% improvement for payloads several-K in size.
Commit migrated from https://github.com/dotnet/corefx/commit/c73b5ebc1eb92ae5b674fbfc3e871bfc61d2b4aa