我正在尝试在 Google Cloud Platform 中设置我的网络应用程序并使用 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 new razor -o HelloWorldAspNetCore
- cd HelloWorldAspNetCore/
- dotnet 开发证书 https
- 点网运行
- 将 Web 预览设置为端口 5001 并尝试打开。错误将显示在终端窗口中
完全相同的代码在 Windows PC 上运行良好。我还将 Windows 代码编译到 Windows 上的 linux docker 容器中并执行了 docker。如果代码在 docker 中执行,则会出现此问题,因此它似乎与运行 .net 代码的操作系统有关。我尝试使用 Wireshark 分析来自 Docker 映像的 TLS 数据包,但数据在前几个数据包之后被加密,并且没有出现任何错误。任何帮助,将不胜感激。