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
Since the last drive down to zero finalizations (ensuring no platform-induced ones) a few have slipped back in. This caused unnecessary distraction while
investigating a different problem.
This also leaves the "print a stack trace during finalization" code in place for DEBUG builds, behind an environment variable check (cached at type load).
Commit migrated from https://github.com/dotnet/corefx/commit/5012dfe0813bf9f3eaf7a6460671e07ea048fd52
This PR adds support for passing in the computed TLS channel binding
token (cbt) into the gssapi during NTLM authentication. This included
removing the code that threw the PlatformNotSupported exception.
No new tests were added to this PR since it requires machine changes
to test. However, I manually tested various combinations of NTLM
authentication including when the server requires (or NOT) the cbt
to be used. Currently only Windows Servers uses this functionality
as part of the "Extended Protection for Authentication" feature.
CurlHandler does not support using the cbt during NTLM authentication.
This is a problem with libcurl itself.
As part of this PR I removed a redundant assert and refactored the
SecChannelBindings structure into src/Common.
Fixesdotnet/corefx#34879
Commit migrated from https://github.com/dotnet/corefx/commit/6575de65608c95717b2a032b689adae32378778f
* Basic support for GoAway frames.
* Review feedback.
* Remove go-away frame handling, add testing to ensure that the loopback server closes the connection instead.
* Remove comma.
* Change error code to reflect the actual failure mode.
* Correct swapped error codes.
Commit migrated from https://github.com/dotnet/corefx/commit/47f6404357832466585f06d5c9ee07ed2f7a27a4
This PR addresses 3 issues in GSSAPI error handling:
* Fixes an uninitialized variable when calling gss_display_status().
This was causing the major statuscode error message to always return
'An invalid status code was supplied'.
* If the minor statuscode is 0 (GSS_S_COMPLETE), we shouldn't be calling
for the minor statuscode error message text. That is why we were always getting
'Unknown error' for that text.
* Added more text (help text) to certain errors returned from GSSAPI
such as when the NTLM plugin is not installed.
No new tests were added to this PR since it requires machine changes
to test. However, I manually tested various combinations of errors
including when 'gss-ntlmssp' is installed or not.
In terms of dotnet/corefx#34877, the exception message goes from:
>GSSAPI operation failed with error - An invalid status code was supplied (Unknown error).
to
>GSSAPI operation failed with error - An unsupported mechanism was requested. NTLM authentication requires the GSSAPI plugin 'gss-ntlmssp'.
Fixesdotnet/corefx#34877
Commit migrated from https://github.com/dotnet/corefx/commit/eec001d96a68376c0e504eb7635c8edec196f90f
In a bunch of places we're creating a Span only to then cast it (generally implicitly) to a ReadOnlySpan. While the JIT is generally able to do the RightThing(tm), we can avoid the unnecessary IL and pressure on the JIT by just creating a ReadOnlySpan to begin with.
Commit migrated from https://github.com/dotnet/corefx/commit/ab925533fade636748f5d932546e1ce2fe33c1dd
* Fixed XML documentation tags for CoreFx.Private.TestUtilities
* Fixed XML documentation tags for System.Diagnostics.Process
* Fixed XML documentation tags for System.ComponentModel.Composition
* Fixed XML documentation tags for System.ComponentModel.Primitives
* Fixed XML documentation tags for System.ComponentModel.TypeConverter
* Fixed XML documentation tags for System.Data.Common
* Fixed XML documentation tags for System.Data.SqlClient
* Fixed XML documentation tags for System.Diagnostics.PerformanceCounter
* Fixed XML documentation tags for System.Diagnostics.StackTrace
* Fixed XML documentation for System.Diagnostics.TraceSource
* Fixed XML documentation for System.IO.Compression.ZipFile
* Fixed XML documentation for System.IO.Compression
* Fixed XMl documentation reference according to review notes
* Fixed XML documentation tags for System.IO.MemoryMappedFiles
* Fixed XML documentation tags for System.IO.Pipes
* Fixed XML documentation tag for OSX interop in System.Diagnostics.Process
* Fixed XML documentation tags for CoreFx.Private.TestUtilities for Unix
* Fixed XML documentation tags for System.Linq.Expressions
* Fixed XML documentation for System.Linq.Parallel
* Fixed XML documentationt ags for System.Linq
* Fixed XML documentation tags for System.Management
* Fixed XMl documentation tags for System.Net.Http (left CS1573)
* Fixed XMl documentation tags for System.Net.Mail
* Fixed XML documentation tags for System.Net.NameResolution
* Fixed XML documentation tags for System.Net.Primitives - added T prefix for Socket as Primitives do not reference System.Net.Sockets
* Fixed XML documentation tags for System.Net.Sockets
* Fixed XML documentation tags for Unix interop files
* Fixed XML documentation tags for System.Net.Http (Unix)
* Fixed XML documentation tags for PlatformDetection.Unix.cs according to review notes
* Fixed XML documentation tags for OSX interop
* Ignore CS1574 for System.Linq as there is no ConcatIterator{TSource}.ToList for uap.
* Fixed XML documentation tags for FreeBSD interop
* Fixed XML documentation tags for System.Net.WebSockets
* Fixed XMLm documentation tags for System.Transactions.Local
* Fixed XML documentation for System.Security.Principal.Windows
* Fixed XML documentation for System.Drawing.Common
* Fixed XML documentation for System.Net.NetworkInformation
* Fixed XML documentation tags for System.Private.XML (left CS1589)
* Fixed XML documentation tags for System.Security.Cryptography
* Fixed XML documentation for System.Runtime.WindowsRuntime
* Fixed XML documentation tags for System.Security.Cryptography.Xml
* Fixed XML documentation tags for System.Security.Cryptography.Primitives
CS3016 was added by mistake as part of dotnet/corefx#32934 so I removed it.
* Fixed XML documentation tags for System.Linq: added M to ToList method as it is not accessible by uap builds.
* Fixed XML documentation tags for System.IO.FileSystem
* Fixed XML documentation tags for System.Security.Cryptography.*
* Fixed XML documentation for System.IO.Ports
* Fixed XML documentation tags for System.Private.Reflection.Metadata.Ecma335
* Fixed XML documentation tags for System.Windows.Extensions
* Fixed XMl documentation tags for System.Console
* Fixed XML documentation for System.IO.FileSystem.DriveInfo
* Fixed XML documentation tags for System.Runtime.Extensions
* Fixed XML documentation tags for System.Drawing.Primitives.
Left CS1589 as there is no 'doc\KnownColor.uex' file.
* Fixed XMl documentation for System.Runtime.WindowsRuntime.
Had to add M prefix to 'Windows.Foundation.IAsyncAction' as Windows.Foundation is not accessible at compilation time.
* Fixed XML documentation tags for System.Private.Xml
* Fixed XML documentation tags for System.Private.Reflection.Metadata.Ecma335
Had to add a prefixes to: 'T:System.Collections.Immutable' and 'M:Enumerable.ToArray{TSource}' as they are not available for uap at compilation time.
* Fixed XML documentation tags for System.Net.WebSockets.WebSocketProtocol
* Fixed XML documentation tags for System.Net.WebSockets.WebSocketProtocol
* XML documentation tags fixes: changes after review.
Commit migrated from https://github.com/dotnet/corefx/commit/f7539b726c4bc2385b7f49e5751c1cff2f2c7368