This PR changes the Azure test endpoint for HTTP/1.1 and WebSocket tests to use
Azure App Service instead of the classic Azure Cloud Service endpoint. This now
matches the HTTP/2.0 endpoint architecture.
We are deprecating the use of Azure Cloud Service endpoints because they are hard
to deploy and maintain. Azure App Service, on the other hand, provides a lot of benefits
including built in production/staging slots, TLS certificate handling and easier
integration with Azure DevOps deployment models.
There are a few downsides to Azure App Service which are known feature limitations.
Since it uses ARR (reverse proxy), it causes websocket connections to be proxied.
This results in some behavior changes for some edge condition tests we have. For example,
when a websocket handshake fails (due to subprotocol mismatch for example), the client
side doesn't see a TCP disconnect. Instead, due to the reverse proxy, we end up getting
an HTTP status code (like 500). Either way, it is a websocket handshake failure. So, I've
updated a few tests to be less brittle for that. I also opened another issue dotnet/corefx#36016 to
track moving a few websocket tests to the loopback websocket server which doesn't yet
have full capability.
I also converted an HTTP statusline test to use the loopback server.
Commit migrated from https://github.com/dotnet/corefx/commit/689e58ec123d8c730d48d1c35c8f7ecbba6c22cf
* Clean up lots of string.Format usage
This PR does a few things:
- Adds new SR.Format overloads, in particular to support accepting an IFormatProvider as the first argument.
- Fixes a bunch of calls to string.Format that should have been using SR.Format. This not only helps in AOT builds where we want to be able to more cleanly remove resource strings, it enables easier auditing of the remaining string.Format uses to determine whether there are more appropriate implementations.
- Replaces some string.Format uses, in particular in asserts, with easier to read and maintain string interpolation
- Replaces some string.Format uses with string concatenation where it's simple and cheaper
- Fixes a bunch of SR.Format(SR.Something) calls where the SR.Format part is extraneous and should just be removed.
- Replaces a bunch of Debug.Assert(false, ...) calls with Debug.Fail(...). This isn't directly related to string.Format, but I started this cleanup as part of cleaning up asserts that were using string.Format, and then ended up accidentally merging the chain into the same commit, and decided it was simple enough that I should just leave it rather than trying to separate it out again.
* Address PR feedback
* Fix breaks due to lower netstandard builds
Commit migrated from https://github.com/dotnet/corefx/commit/a6f76f4f620cbe74821c6445af3f13e048361658
* Auto-generate the reference assemblies
* Add back type forwards.
* Revert "Add back type forwards."
This reverts commit dotnet/corefx@3acf74aabb.
* Add back TypeForwardedTo in .Forward.cs files
* Add new type forward files to the csproj files
* Add back if-defs and move TestUtilities comment from ref to source
* Remove duplicate definitions, delete unnecessary manual files,
* Fix build breaks
* Add back missing AsyncMethodBuilderAttr to S.Runtime ref
* Fix typo between XmlDocument and XPath.XDocument
* Add type forward fild missed from previous commit
* Fix ECDiffieHellmanCngPublicKey internal ctor for netfx 4.6.1
* Remove "this type was moved to comments" from the type forwards.
* Add back the Xml and Debugger* attributes to Xml.ReaderWriter
* Add back struct layout attributes
* Add back attributes missing (highlighted from api compat)
* Add missing toolbox item attribute in s.data.common.
* Add missing struct layout attributes and remove unnecessary additions
* Add back InterfaceTypeAttribute
Commit migrated from https://github.com/dotnet/corefx/commit/16689aa0a933517dc45465fc6edb6223222414a6
* Remove Task{CompletionSource} allocations from Http2Stream
This change makes the Http2Stream instance itself awaitable via ValueTask, such that we don't need to allocate any additional TaskCompletionSource or Task objects for such internal await'ing, regardless of how many times the Http2Connection or Http2ReadStream needs to wait for headers or response data to arrive.
* Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/aacff5212204ee54e3b3e0172fcf364c3fe253e3
This change moves a lot of the chain building work from managed code into the native shim, largely to cut down on the number of P/Invokes required to set up the chain builder.
Once a chain has been built to a point where only one issuer will be considered, if revocation was requested and a CRL is not available, attempt an OCSP request if the certificate indicates the CA has an OCSP endpoint.
Based on CA/Browser Forum's requirements this expects CRL for all intermediates and only attempts OCSP for the end-entity certificate.
"Conforming" OCSP requests are opportunistically cached on the basis that local filesystem re-reads are more reliable (and faster) than doing a live request to the CA.
Commit migrated from https://github.com/dotnet/corefx/commit/0fbbb68a3f7be82d26e4b2dff5c25c192e3a2023
* Simplify ConnectHelper.ConnectAsync to just return Stream
SocketsHttpHandler's ConnectHelper.ConnectAsync currently returns a tuple of (Socket, Stream). We can instead just have it return the Stream and allow the call site to fish out the Socket from the Stream if it can. This is slightly more efficient memory-wise, in that the state machine involved will be smaller, but it also allows for a potential extensibility point that's simpler (abstracting out the ConnectAsync as a callback) and potentially allows us to in the future get a Socket in more cases, e.g. any connection helper handing back a NetworkStream.
Unfortunately, NetworkStream.Socket is protected rather than public. Until such time that there's a public property for this, there are two options here:
1. Use reflection to create a delegate we can then use to get at the property; "Socket" is part of the exposed surface area, so the only dependency here is on documented surface area.
2. Create a custom NetworkStream-derived type that exposes the protected as a public.
I started with (2), which works fine for our own internal needs currently, but shifted to (1), as it's more flexible.
* Don't use reflection
Commit migrated from https://github.com/dotnet/corefx/commit/d9cdbc3cca0f75e5d7692f9ae03978dd0ed9b2e9
This PR adds support to our Linux gssapi layer so that we properly handle the Negotiate
protocol (SPNEGO) being able to to fall back from Kerberos to NTLM.
Windows Negotiate SSPI implements the SPNEGO protocol. However, it has built-in error
handling for dealing with quick fallback from Kerberos to NTLM in error cases such as where
the client is not on a domain/Kerberos realm, the client is using a local credential, the
client is talking to a non-domain server, etc.
However, the Linux implementation of SPNEGO doesn't handle those error cases very well.
So, I added the proper retry logic when generating the initial context token. Now, we will
be able to fall back from SPNEGO-wrapped Kerberos to SPNEGO-wrapped NTLM protocol blobs.
A similar bug exists in libcurl which is why Curl and CurlHandler are unable to connect to
Negotiate servers when not part of the Kerberos realm. I am considering proposing my fixes
to the libcurl repo as well.
I added more tests to support this PR and did manual testing. I added some additional
EventSource tracing as well.
Contributes to dotnet/corefx#34878
Commit migrated from https://github.com/dotnet/corefx/commit/1fd3ba126538c2fed76d2279db26dc7ba5ceed41
We don't need the accuracy of UtcNow nor the absolute time when getting a time stamp in order to determine whether a connection should be retired; rather, we only need an approximate difference in time. This means the resolution of TickCount is fine, and the worst that happens if a connection happens to be alive for more than its ~49 day period is we may allow the connection to then live even longer than we otherwise would. In exchange, we get a much cheaper mechanism (~20x on Windows) mechanism for computing the connection age.
Commit migrated from https://github.com/dotnet/corefx/commit/dca39727b02ceb4413d0fde11467965099ab4a2f
Http2Connection keeps these buffers for a really long time; we don't want it to starve the pool. It also leads to lifetime issues, as the buffers need to be (but currently aren't) released back to the pool, yet work can end up accessing the ArrayBuffer after the connection is logically disposed.
Commit migrated from https://github.com/dotnet/corefx/commit/847f64fa812362e75dfcbd0bdcf41541921d607c
I added this test to help get familiar with the new GenericLoopbackServer
test pattern as well as use the new SkipTestException() ability.
The test is not an end-to-end test. It simply validates that the client is able
to begin the multi-leg Windows auth handshake and send the initial Authorization
header.
In addition, once https://github.com/dotnet/core-eng/issues/5135 is completed,
the 'IsNtlmInstalled' condition will always be true for the CI machines. Thus,
we will get better test coverage for Windows auth scenarios.
Contributes to dotnet/corefx#34878
Commit migrated from https://github.com/dotnet/corefx/commit/48bcedf786f264aa15adcb55b161ecc0cb2b2172
A set of HttpClient tests related to ClientCertificates were always failing on my machine:
System.Net.Http.Functional.Tests.SocketsHttpHandler_HttpClientHandler_ClientCertificates_Test
* method="Manual_SendClientCertificateWithClientAuthEKUToRemoteServer_OK"
* method="Manual_SendClientCertificateWithNoEKUToRemoteServer_OK"
* method="Manual_SendClientCertificateWithServerAuthEKUToRemoteServer_Forbidden"
These tests would generate an exception:
>System.Net.Http.HttpRequestException: An error occurred while sending the request. --->
System.IO.IOException: The remote party requested renegotiation when AllowRenegotiation was set to false.
Similar to the tests failing and fixed in PR dotnet/corefx#35225, the CI machines don't have the test
root certificate installed. So, the tests weren't running in CI and the failures weren't noticed.
The root cause of the test failures is due to using SocketsHttpHandler. It is always setting
`SslStream.AllowRenegotiation` to false when first attempting to connect via HTTP/2. This is fine
if the connection is truely HTTP/2 since HTTP/2 doesn't support TLS renegotiation. However, if the
remote endpoint doesn't support HTTP/2 and thus connects with HTTP/1.1, then the SslStream should
not have AllowRenegotiation set to false. Client certificate scenarios frequently have the server
ask for the client certificate later in the connection process. So, TLS renegotiation is used. Opened
new issue dotnet/corefx#35239 to fix this in SocketsHttpHandler (or SslStream).
As part of fixing these tests, I refactored them into a single Theory test. But I had to workaround
complications due to using RemoteInvoke. I added a new RemoteInvoke overload to handling passing
an additional parameter.
Commit migrated from https://github.com/dotnet/corefx/commit/0c2ccd172157e0ebf1957e1bbcd5f07786ad6e3d
This PR works toward the goal of our Enterprise Scenarios. I added logic in the Unix
PAL gssapi layer to detect whether the NTLM plugin is installed. This is useful both
in the product code (to return better exception messages) and the test code (to
skip NTLM tests if needed).
Refactored some of the Common System.Net.Configuration logic for tests. Added new
environment variable logic to separate between domain-joined and standalone server
environments.
Add new tests to validate NTLM end-to-end connectivity. Opened some new issues
discovered along with way regarding HTTP/2 and Windows authentication.
To run these new tests simply set the 3 environment variables to point to the
standalone windows server environment. For example, on Linux:
```
export COREFX_WINDOWSSERVER_HTTPHOST=somewindowsmachine.contoso.com
export COREFX_NET_SERVER_USERNAME=someusername
export COREFX_NET_SERVER_PASSWORD=somepassword
```
I have already deployed a standalone Windows server for these tests but
we're not ready yet to have the tests always run in CI.
Contributes to dotnet/corefx#34878
Commit migrated from https://github.com/dotnet/corefx/commit/fe6f55b496489dbd02cdd207c0b1f9112b560763
* Remove a lot of allocation from SslStream's handshake
This makes a sizeable dent in the allocation incurred as part of SslStream's handshake (AuthenticateAsClient/Server{Async}), though mainly on Windows; many of these changes also impact Unix, but on Unix there's also substantially more allocation, so the relevant percentage impact is less.
Main changes:
- X509Certificate2.RawData. This was being accessed by SslStream in order to store the byte[] away in case the RemoteCertificate property was accessed, in which case it would use it to instantiate an X509Certificate2. That, however, was resulting in lots of sizeable byte[]s being allocated. We can instead just instantiate an X509Certificate2 from the original, and while that entails a few additional small allocations, it's a sizeable reduction, and we'd eventually need the cert anyway if the property is accessed.
- X509ChainPolicy. Every time Reset was called, it would allocate several new collections, but they often weren't used. Made them lazy.
- X509 object finalization. A bunch of X509-related objects were being left for finalization. Those are now aggressively disposed.
- ChainPal.GetChainStatusInformation: every call was P/Invoke'ing to get a string error message for a handful of prechosen error codes... we can just get the strings once upfront and avoid allocating them each time.
- OidCollections. A bunch of these are created but not actually populated, and each time one is created it was allocating a new List. Changed to just have it be built around an array.
- SecPkgContext classes. These have been converted to blittable structs, avoiding the associated allocations and marshaling costs, e.g. SecPkgContext_ApplicationProtocol would end up allocating a byte[] along with the instance itself.
- PtrToStructure. When QueryContextAttributes was being called, in many cases PtrToStructure was being used. This has been cleaned up, to avoid the marshaling and just use spans / casting.
- SecurityBuffer[] arrays. Lots of code was written in terms of SecurityBuffer[], which meant lots of operations allocating these. However, they were never larger than three items. We now just stack allocate spans for them.
- Overloads taking both SecurityBuffer and SecurityBuffer[]. I believe because of the arrays, there were some cases where methods would take both a SecurityBuffer argument and a SecurityBuffer[] argument, with one and only one non-null. Now that we're just passing around allocation-free spans, this has been cleaned up.
- GCHandles and GCHandle[]. Multiple methods were allocating arrays of GCHandles, and then one GCHandle.Alloc (not a managed allocation, but also not free) per SecurityBuffer. Now that we're known to be limited to at most three, we just used fixed (even if we don't actually have three), avoiding the need for the arrays and for the GCHandle.Alloc, which is more expensive than fixed.
- SecBuffer[] arrays. Several places were allocating a SecBuffer[]; we can just stackalloc a struct. These are all limited by the number of SecurityBuffers passed around, which is inherently small (<= 3 in the current code).
- SecureChannel.EnsurePrivateKey. It was always forcing a certificate's Thumbpring into existence, even though it was rarely needed.
- SecureChannel.AcquireClientCredentials. It was always forcing a List into existence, even if it wasn't needed.
- SslAuthenticationOptions. This internal type had several fields for delegates that were never used. Removed.
- Span.ToArray. In several places utilize span to create an array from a pointer/length rather than allocating the array and Marshal.Copy'ing. This is mostly for readability.
- Also cleaned up a few things, like using ?.Dispose across System.Net.Security.
- Protocol version strings. On Unix we were getting the protocol version constant string from the native string, allocating a managed string for it, and then comparing it against the set of known constant strings. We don't need to do that.
There's still more that can be done. On Windows, the two big remaining sources of allocation are for byte[]s created for data to send/receive in the handshake, and that will hopefully be addressed by work to combine SslStream/SslStreamInternal/SslState and to rewrite them to use async/await, and the allocation of the actual SecurityBuffers, which should be fairly straightforward to convert to structs (albeit with some care, as they're mutated as they're passed around). On Unix, there's a ton more allocation, in particular as part of X509Chain building, and that should be investigated separately as part of an effort to improve performance there.
* Move SecurityBuffer to be Windows-only and make it a struct
* Rename several files
* Fix netstandard build of SqlClient
Commit migrated from https://github.com/dotnet/corefx/commit/3c30357d51b96339021b4ee52f38445c31248bb2