我正试图在谷歌云平台中设置我的web应用程序并使用https。当浏览器尝试通过https端口连接时,Kestrel报告如下:
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)
我的生产代码有这个问题,但使用提供的示例代码也可以很容易地生成它。如果你有一个谷歌云平台项目设置,以下是如何重现问题的说明:
- 打开GCP终端窗口
- sudo apt-get-y安装dotnet-sdk-2.1
- dotnet新剃须刀-o HelloWorldAspNetCore
- cd HelloWorldAspNetCore/
- dotnet开发证书https
- dotnet运行
- 将"Web预览"设置为"端口5001",然后尝试打开。错误将显示在终端窗口中
同样的代码在Windows PC上运行良好。我还将Windows代码编译到Windows上的linux docker容器中,并执行了docker。如果代码在docker中执行,则会出现此问题,因此它似乎与运行.net代码的操作系统有关。我试图用Wireshark分析Docker映像中的TLS数据包,但在最初的几个数据包之后,数据被加密了,没有任何错误。如有任何帮助,我们将不胜感激。
您可以更改launchSettings.json,在https 之前修改http
"WebApplication2": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
**"applicationUrl": "http://localhost:5000;https://localhost:5001"**
}