Fix Negotiate/SPNEGO Kerberos to NTLM fallback on Linux (dotnet/corefx#35383)
authorDavid Shulman <david.shulman@microsoft.com>
Tue, 19 Feb 2019 17:14:44 +0000 (09:14 -0800)
committerGitHub <noreply@github.com>
Tue, 19 Feb 2019 17:14:44 +0000 (09:14 -0800)
commit6167d604af9513e6bc35a5b3af73fd5c338531e6
treef26272006395c164cbca59a4b6d515987f1eb990
parenta66eb9941fba7fe720360b15e99855994df4df53
Fix Negotiate/SPNEGO Kerberos to NTLM fallback on Linux (dotnet/corefx#35383)

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
src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.cs
src/libraries/Common/src/Microsoft/Win32/SafeHandles/GssSafeHandles.cs
src/libraries/Common/src/System/Net/Security/NegotiateStreamPal.Unix.cs
src/libraries/Common/src/System/Net/Security/Unix/SafeDeleteNegoContext.cs
src/libraries/Native/Unix/System.Net.Security.Native/pal_gssapi.c
src/libraries/Native/Unix/System.Net.Security.Native/pal_gssapi.h
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Authentication.cs