runtime: Bug Report: Authentication Validation Error (GenericFailure) in .NET8

Description

When executing the provided code snippet in a .NET 8 project, an HttpRequestException is thrown with the message Authentication validation failed with error - GenericFailure. This issue occurs when attempting to send an HTTP request using HttpClient with Kerberos authentication and utilizing default credentials.

Reproduction Steps

  1. Create a new .NET 8 project.
  2. Add the following code to the Program.cs file:
using System.Net;
class Program
{
    static async Task Main(string[] args)
    {

        var handler = new HttpClientHandler
        {
            UseDefaultCredentials = true,
        };

        using (var client = new HttpClient(handler))
        {
            try
            {
                HttpResponseMessage response = await client.GetAsync("...");
                response.EnsureSuccessStatusCode();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}
  1. Run the project.

Expected behavior

The HTTP request is successfully sent, and the response is processed without any exceptions.

Actual behavior

System.Net.Http.HttpRequestException: Authentication validation failed with error - GenericFailure.
   at System.Net.Http.AuthenticationHelper.SendWithNtAuthAsync(HttpRequestMessage request, Uri authUri, Boolean async, ICredentials credentials, Boolean isProxyAuth, HttpConnection connection, HttpConnectionPool connectionPool, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, Boolean async, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Program.Main(String[] args) in C:\...\Program.cs:line 16

Regression?

In .NET 6 this issue does not occur.

Known Workarounds

  • Changing the HTTP version to HTTP/1.0 by setting client.DefaultRequestVersion = HttpVersion.Version10.
  • Using .NET 6 where this issue does not occur.

Configuration

  • .NET SDK Version: .NET8

  • Operating System: Win10

  • Server: Using gokrb5 Kerberos library

Other information

The problem may be related to the following code added in .NET 8: https://github.com/dotnet/runtime/blob/eb765b71a4a93e4157cd7e1eaf33995ffc80285c/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/AuthenticationHelper.NtAuth.cs#L208

Additionally, in the gokrb5 library, there is a constant used for the WWW-Authenticate header set to the client upon successful authentication with HTTP code 200 . Could this be related to the issue?

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (11 by maintainers)

Most upvoted comments

Thanks, this is helpful. It means the client is opportunistically sending the Kerberos token with OID 1.2.840.113554.1.2.2.

That does match the OID in the server’s response:

[1] @0+20 (constructed): (1 elem)
  SEQUENCE @2+18 (constructed): (2 elem)
    [0] @4+3 (constructed): (1 elem)
      ENUMERATED @6+1: 0
    [1] @9+11 (constructed): (1 elem)
      OBJECT_IDENTIFIER @11+9: 1.2.840.113554.1.2.2

I’ll need to dive into the (newer) SPNEGO specification to see what are the requirements for MIC (Message Integrity Check). At least the basic construction of the requests and responses look okay.

@filipnavara

ContentInfo [?] Application_0 @0+6024 (constructed): (2 elem)
  contentType ContentType OBJECT_IDENTIFIER @4+6: 1.3.6.1.5.5.2
  content [0] @12+6012 (constructed): (1 elem)
    ANY SEQUENCE @16+6008 (constructed): (2 elem)
      [0] @20+48 (constructed): (1 elem)
        SEQUENCE @22+46 (constructed): (4 elem)
          OBJECT_IDENTIFIER @24+9: 1.2.840.48018.1.2.2
          OBJECT_IDENTIFIER @35+9: 1.2.840.113554.1.2.2
          OBJECT_IDENTIFIER @46+10: 1.3.6.1.4.1.311.2.2.30
          OBJECT_IDENTIFIER @58+10: 1.3.6.1.4.1.311.2.2.10
      [2] @70+5954 (constructed): (1 elem)
        OCTET_STRING @74+5950 (encapsulates): (5950 byte)|XXXXXXXX
          Application_0 @78+5946 (constructed): (3 elem)
            OBJECT_IDENTIFIER @82+9: 1.2.840.113554.1.2.2
            BOOLEAN @93+0: true
            Application_14 @95+5929 (constructed): (1 elem)
              SEQUENCE @99+5925 (constructed): (5 elem)
                [0] @103+3 (constructed): (1 elem)
                  INTEGER @105+1: 5
                [1] @108+3 (constructed): (1 elem)
                  INTEGER @110+1: 14
                [2] @113+7 (constructed): (1 elem)
                  BIT_STRING @115+5: (32 bit)|00100000000000000000000000000000
                [3] @122+5482 (constructed): (1 elem)
                  Application_1 @126+5478 (constructed): (1 elem)
                    SEQUENCE @130+5474 (constructed): (4 elem)
                      [0] @134+3 (constructed): (1 elem)
                        INTEGER @136+1: 5
                      [1] @139+8 (constructed): (1 elem)
                        GeneralString @141+6: AVP.RU
                      [2] @149+37 (constructed): (1 elem)
                        SEQUENCE @151+35 (constructed): (2 elem)
                          [0] @153+3 (constructed): (1 elem)
                            INTEGER @155+1: 2
                          [1] @158+28 (constructed): (1 elem)
                            SEQUENCE @160+26 (constructed): (2 elem)
                              GeneralString @162+4: HTTP
                              GeneralString @168+18: sandbox.sbx.avp.ru
                      [3] @188+5416 (constructed): (1 elem)
                        SEQUENCE @192+5412 (constructed): (3 elem)
                          [0] @196+3 (constructed): (1 elem)
                            INTEGER @198+1: 23
                          [1] @201+3 (constructed): (1 elem)
                            INTEGER @203+1: 4
                          [2] @206+5398 (constructed): (1 elem)
                            OCTET_STRING @210+5394: (5394 byte)|XXXXXXXX
                [4] @5608+416 (constructed): (1 elem)
                  SEQUENCE @5612+412 (constructed): (2 elem)
                    [0] @5616+3 (constructed): (1 elem)
                      INTEGER @5618+1: 23
                    [2] @5621+403 (constructed): (1 elem)
                      OCTET_STRING @5625+399: (399 byte)|XXXXXXXX

@filipnavara I have added the logs (in the comment above), please let me know if any additional logs are needed.