Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NET Core 2.1 on Google Cloud Platform Failed to authenticate HTTPS connection TLS handshake failure with unexpected packet format

I am trying to set my web application up in Google Cloud Platform and use https. When the browser tries to connect over the https port Kestrel reports the following:

Hosting environment: Development
Content root path: /home/cvanem2/abc/HelloWorldAspNetCore
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
dbug: HttpsConnectionAdapter[1]
      Failed to authenticate HTTPS connection.
System.IO.IOException: The handshake failed due to an unexpected packet format.
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
--- End of stack trace from previous location where exception was thrown ---
   at System.Net.Security.SslState.ThrowIfExceptional()
   at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
   at System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)
   at System.Net.Security.SslStream.<>c.<AuthenticateAsServerAsync>b__51_1(IAsyncResult iar)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionAdapter.InnerOnConnectionAsync(ConnectionAdapterContext context)ext)

I am having this issue on my production code, but it can also be easily produced with the provided sample code. Here are the instructions on how to reproduce the issue if you have a google cloud platform project setup:

  1. Open the GCP terminal window
  2. sudo apt-get -y install dotnet-sdk-2.1
  3. dotnet new razor -o HelloWorldAspNetCore
  4. cd HelloWorldAspNetCore/
  5. dotnet dev-certs https
  6. dotnet run
  7. Set Web Preview to Port 5001 and try and open. The error will be shown in the terminal window

The same exact code runs fine on a Windows PC. I have also compiled the Windows code into a linux docker container on Windows and executed the docker. The issue occurs if the code is executed in the docker, so it appears to be related to the OS running the .net code. I tried to analyze the TLS packets from the Docker image with Wireshark but the data is encrypted after the first few packets and nothing appeared erroneous. Any help would be appreciated.

like image 852
Chris Avatar asked Mar 26 '26 06:03

Chris


1 Answers

You can change the launchSettings.json, modify the http before the https

"WebApplication2": {
  "commandName": "Project",
  "launchBrowser": true,
  "launchUrl": "api/values",
  "environmentVariables": {      
    "ASPNETCORE_ENVIRONMENT": "Development"
  },
  **"applicationUrl": "http://localhost:5000;https://localhost:5001"**
}
like image 168
Crashsol Avatar answered Mar 29 '26 09:03

Crashsol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!