Fix SocketsHttpHandler proxy auth for 'Negotiate' scheme (dotnet/corefx#39933)
authorDavid Shulman <david.shulman@microsoft.com>
Thu, 1 Aug 2019 20:54:45 +0000 (13:54 -0700)
committerGitHub <noreply@github.com>
Thu, 1 Aug 2019 20:54:45 +0000 (13:54 -0700)
commitfd89065fb655f22462f1f74669d3ee557a366dcc
treef43891df50f353697d28fe89fbb813ef75a91b6f
parentacd8190eab1f6f114fbb5b0de0b8c13c48fa265d
Fix SocketsHttpHandler proxy auth for 'Negotiate' scheme (dotnet/corefx#39933)

Issue dotnet/corefx#39887 reported that proxy authentication with 'Negotiate' scheme broke between
.NET Core 3.0 Preview 6 and Preview 7. The base64 blob was no longer using SPNEGO protocol
but instead was always using NTLM. While 'Negotiate' scheme can use either SPNEGO or NTLM,
it should always use SPNEGO if possible. And many enterprises have a setting which requires
it and rejects NTLM protocol.

This issue was caused by PR dotnet/corefx#38465 which fixed some other SPN issues with Kerberos
authentication. That PR regressed the SPN calculation for the proxy authentication by
using the wrong host name in the SPN. A mismatch of the SPN will cause NTLM to be used
instead of SPNEGO.

The fix is to check if proxy authentication is being used instead of server authentication.
If so, it ignores any 'Host' header and always will use the uri, which in this case is the
uri of the proxy server.

This was tested manually. It is impossible right now to test Kerberos and proxy scenarios in
CI because they require machine configuration to register SPNs in a Windows Active Directory
environment.

This PR will be ported for release/3.0 for ASK mode consideration since it affects a mainline
enterprise scenario.

Fixes dotnet/corefx#39887

Commit migrated from https://github.com/dotnet/corefx/commit/85f30cc03470691f0096d4c89ba787727aa55790
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/AuthenticationHelper.NtAuth.cs
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Authentication.cs