If an SSL operation fails, we call SSL_get_error to determine how to proceed.
SSL_get_error's logic is, essentially
libcrypto_error ?? WANT_READ ?? WANT_WRITE ?? WANT_X509 ?? panic
This means that if a previous call into libcrypto on the same thread had left
something in the error queue when the operation goes into the WANT_READ state (etc)
SSL_get_error will report that the request must have failed due to something in
libcrypto.
There are two different fixes being done here:
1) PKCS12_parse is a known contributor to this problem, clear out the queue on a
successful exit.
2) Before any SSL stream operation (handshake, read, write, shutdown) clear the
queue, in case there are other functions which are leaving dangling errors.
With those mitigations in place, the intermittent errors seen during SslStream
usage should hopefully be a thing of the past.
Commit migrated from https://github.com/dotnet/corefx/commit/80a53ed415ece115d15bcf519e81e600362fd3dc
When a server offers multiple auth schemes, WinHttpHandler is supposed
to select the more secure scheme regardless of the order of the
authentication headers. So, despite a server offering Basic and
Negotitate (in that order), Negotiate would be selected.
When using default credentials, however, it was not calling
WinHttpSetCredentials(null, null). This resulted in the first scheme
offered by the server (Basic) to be attempted. But there were no
credentials set and so a 401 resulted.
Fix WinHttpHandler so that it will always call WinHttpSetCredentials
even with default credentials. This ensures that the selected auth
scheme (in this case Negotiate) is used correctly.
Revised test configuration instructions. An IHttpModule is used for the
test server endpoint to ensure that IIS will put 'Basic' first in the
response headers.
Commit migrated from https://github.com/dotnet/corefx/commit/9c6821d9d39ebe67b03f6e491489ffbb44844612
- Add "debian.8-x64". This is the correct rid for Debian, after this
lands, I will need to update CI before we can remove "debian.8.2-x64"
- Add a generic "linux-x64" rid which we can use in cases where we want
to build for a distro where we don't yet have a set of runtime
packages. This will let us restore the managed assets (since they are
specific to "unix" or "linux" and then folks can do a native build to
get the shims and runtime and copy them over (this is a more
reasonable approach than our current strategy of just using
ubuntu.14.04-x64)
- Sort runtime sections
Commit migrated from https://github.com/dotnet/corefx/commit/6fa4bc1d215d17ff484aa3f541c5e3181f6918de
It turns out that setting the WinHTTP 'Connect' timeout does nothing. We discovered this because we still got ERROR_WINHTTP_TIMEOUT errors after about 20 seconds even after setting the 'Connect' timeout to INFINITE. We discussed this with the WinHTTP team and they told us that this timeout is essentially deprecated due to performance enhancements in the TCP stack.
For the technically curious, here is the explanation. Underneath the 'Connect' timeout is really a set of TCP timeouts related to setting up the socket via the 3-leg SYN/ACK exchange. The TCP timeout is about retransmits with backoff and how many is tried by the winsock stack. The default of these initial packet exchanges is 21 seconds with 2 retransmits (3 overall SYNs) and initial RTO of 3 (3 + 6 + 12). So that explained the timeouts we saw during periods of high network congestion.
There is no API exposed in WinHTTP to control those low-level TCP timeouts. And thus it doesn't make any sense to have a 'ConnectTimeout' on the WinHttpHandler class.
Commit migrated from https://github.com/dotnet/corefx/commit/ee0b3a76c8c57ef80d1d53a16deb5b0bc6b46793
I'd added this when bringing properties from WinHttpHandler to CurlHandler in bulk, with the expectation that we might expose them. Since we're not planning on exposing this particular property from HttpClientHandler (turns out it's not very useful in practice), I'm removing it.
Commit migrated from https://github.com/dotnet/corefx/commit/953bbe0006ce7f29c87b798eb10d072df06d6f99
Building on the current use of environment variables for passing in test settings, added a common test helper class to allow the http and websocket tests to access alternate test servers. This will help with load balancing and network latency issues which are causing occasional timeouts in CI tests. This will also allow developers to run their own version of the Azure test endpoints. Consolidated the current environment variables used and standardized on a naming format.
Fixesdotnet/corefx#2383.
Commit migrated from https://github.com/dotnet/corefx/commit/3603ed2578220f0ecb2f101324e04acb80fa3196
On Unix when an HttpClientHandler is disposed, we cancel all outstanding operations associated with that handler. It turns out this isn't the desired behavior (aka the behavior of WinHttpHandler), which is that we should cancel all outstanding operations that haven't yet published its HttpResponseMessage, but for requests where the HttpResponseMessage has been published, it should remain valid.
This commit tweaks the behavior accordingly and adds a test for it.
Commit migrated from https://github.com/dotnet/corefx/commit/f949d92b3ee26168277f56fbd2c6686505ea0b4a
One of the HttpClient client tests hangs on a machine with a single core.
xunit by default uses a SynchronizationContext that has N threads to do
work, where N defaults to Environment.ProcessorCount. Thus on a single
core machine, there's only one thread available to run tests, and if that
thread blocks waiting for an async operation that'll schedule work back to
that context, it'll deadlock.
Commit migrated from https://github.com/dotnet/corefx/commit/916798757c122b81e61666c4f0af0c446d378824
* Improve WinHttpHandler logic regarding default credentials
In some cases, WinHttpHandler was not sending default credentials that were specified inside a custom ICredentials object. In other cases, default credentials would be sent even though CredentialCache.DefaultCredentials was not specified. The code was incorrectly comparing the proxy and server credential (ICredential interface) values against the DefaultCredentials object. Instead, the ICredentials.GetCredential() method should be called to compute the final NetworkCredential object. This takes into account the given uri and auth scheme.
This PR fixes the logic by delay the setting in WinHTTP for releasing default credentials. This ensures that default crdentials are released when requested.
Fixesdotnet/corefx#8176.
* Address PR feedback
Reword comments for clarity.
Add TODO issue.
Sending default creds to proxy only needs MEDIUM security policy.
Commit migrated from https://github.com/dotnet/corefx/commit/90b8ff36c8c9f9cfb1a2cf1302ff7a98ac7801ed
libcurl v7.37 added support for parsing IPv6 uris with scope/zone IDs, but some of the Unix systems we target have an older libcurl. Rather than just saying "use a newer libcurl", we can use libcurl's CURLOPT_ADDRESS_SCOPE to explicitly set the link-local scope ID when it's set, and allow such Uris to be used on older libcurls.
Commit migrated from https://github.com/dotnet/corefx/commit/0c9948a86d36963d92f7e53c8df18c150675c9b5
We currently make a lot of calls off-box in our unit tests. By adding SSL support to the loopback server, we should be able to convert many more tests to avoid needing to actually hit the network. This adds such basic support, and converts a few tests to use it.
Also, since I was moving the certificate configuration code to a central location, I fixed an issue related to cleanup.
Commit migrated from https://github.com/dotnet/corefx/commit/b90795e1d5d7e8d8c68b9ca23d53b1ba0e392f46
* Fix bug in Cookie where Value can == null
* Add a regression test for the bug
* Fix compilation errors
* Fix the netcore50 version of Cookie as well
* Update CookieTest.cs
* Add comment about the test failing on desktop
Commit migrated from https://github.com/dotnet/corefx/commit/9872c2aa881e8651486a6e3ae90fb2f59038baf6
These tests require the client and server to be on a Windows Active Directory domain. These tests are Windows specific. Currently this cannot be done in the CI system. So, these tests are only enabled when an environment variable is set which points to the test server.
There is a separate todo item dotnet/corefx#4989 to provide more automated scripts for setting up the test server. For now, there is a readme file with some details.
These tests will help support fixes for dotnet/corefx#8176 and related bugs.
Commit migrated from https://github.com/dotnet/corefx/commit/4739da8c8d4965fdaf2fc45ae915297208672d15