runtime: Got Win32Exception when I send an HTTPS request

Description

I get Win32Exception error (0x80090326) when I send HTTPS requests.

Reproduction Steps

Two lines of code are enough to reproduce

var client = new HttpClient();
var response = await client.GetAsync("https://google.com/");

Expected behavior

It is expected that I will receive the contents of the page google.com in response

Actual behavior

Actually I get the error below

Unhandled exception. System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.IO.IOException: The read operation failed, see inner exception.
 ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
 ---> System.ComponentModel.Win32Exception (0x80090326): The message received was unexpected or badly formatted.
   --- End of inner exception stack trace ---
   at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken)
   at System.Net.Security.SslStream.ReplyOnReAuthenticationAsync[TIOAdapter](Byte[] buffer, CancellationToken cancellationToken)
   at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](Memory`1 buffer, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](Memory`1 buffer, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
   at System.Net.Http.HttpConnection.InitialFillAsync(Boolean async)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, 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)

Regression?

This applies equally to httpclient, WebClient, HttpWebRequest. This applies equally to all versions .NET Core, from 2.1 to 8.0. This also applies to .NET Framework 4.8.1. This is reproduced in both Windows 22h2 and Debian 12 located on my local network. This is not fixed with a VPN.

This is not reproducible in the browser (using JS) and is not reproducible using Python

Known Workarounds

No response

Configuration

I use .NET 8.0, but its applies to all other .NETs. I use Windows 10 22h2, but its also applies to Debian 12. I use x64 architecture

Other information

No response

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 27 (15 by maintainers)

Most upvoted comments

I fixed it! https://stackoverflow.com/questions/56072561/how-to-enable-tls-1-3-in-windows-10/59210166#59210166

But on the contrary, it was necessary to turn off "Enabled"=dword:00000000

Thank you!

My mistake. Here is the correct HTTPS TLS 1.2 capture

https://1dndn.ru/files/google2.zip

TLS 1.2 working properly

Console output:

{
  Date: Tue, 12 Sep 2023 18:51:19 GMT
  Cache-Control: private, max-age=0
  Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-PXYTjK8bUpFZNr1HY7oh-Q' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
  P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
  Server: gws
  X-XSS-Protection: 0
  X-Frame-Options: SAMEORIGIN
  Set-Cookie: 1P_JAR=2023-09-12-18; expires=Thu, 12-Oct-2023 18:51:19 GMT; path=/; domain=.google.com; Secure
  Set-Cookie: AEC=Ad49MVGcqmFQNKGGh7SuSXQExTkZhPe_CPd78hTLTj1ihAU_gNsnL8bS; expires=Sun, 10-Mar-2024 18:51:19 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax
  Set-Cookie: NID=511=Jk360R_Ls5zOBpzT1G5vf9nxzBrKJTBLmqG4iuKQcZefNty-WW5fu2N31xGF2beYCJ6DohvDKaXjTIOq-ugG6I3MSE3wgGI5GRMmiuC3voCsETuFtEoC5J7vrZvbMSiidCDZ1YH2CtNEoNN5yUq28hMCyGZp5nm2uq-sLhBgQVA; expires=Wed, 13-Mar-2024 18:51:19 GMT; path=/; domain=.google.com;
HttpOnly
  Alt-Svc: h3=":443"; ma=2592000
  Alt-Svc: h3-29=":443"; ma=2592000
  Accept-Ranges: none
  Vary: Accept-Encoding
  Transfer-Encoding: chunked
  Expires: -1
  Content-Type: text/html; charset=ISO-8859-1
}

CODE-OF-CONDUCT.md