GRPC .Net Core 服务器和 C++ 客户端:Https 连接失败,"No common application protocol between client/server"

GRPC .Net Core server & C++ client: Https connection fails, "No common application protocol between client/server"

我正在尝试让 GRPC 服务器(用 .NET 核心编写)和客户端(用 C++ 编写)通过 SSL/TLS-secured 通道进行通信。

服务器针对“netcoreapp3.1”,依赖“Grpc.AspNetCore”版本2.28.0。服务器代码本身基本上是复制的 from the official grpc repo's examples. The Startup.cs and Program.cs are not too interesting on their own & probably aren't the problems, so I just uploaded them to a gist (do note the call to UseHttps though). Everything builds, and a toy .NET core GRPC client (sources for that here) 通过 HTTPS 连接就好了

不幸的是,我需要使用 C++ 客户端来建立连接。理论上,过程很简单:获取与传递给 UseHttps 调用的证书对应的 .pfx 文件,用它创建 server.crt via openssl,并用它创建安全通道对于像这样的 C++ 客户端:

grpc::SslCredentialsOptions sslOpts{};
sslOpts.pem_root_certs = file_to_string(path_to_server_crt);
auto creds = grpc::SslCredentials(sslOpts);
auto channel = grpc::CreateChannel("localhost:50052", creds);

我已经成功地将客户端与 C++ grpc 服务器一起使用,所以这方面也没有挥之不去的错误。但是,当我将它指向我的 .NET 核心服务器时,事情就崩溃了。客户端信息并不有趣,只是一个 GRPC 错误 14。当服务器设置为在 Trace 记录内容时,会弹出一些内容

dbug: Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer[2] 
  Connection id "0HM6UG4PBICBP" accepted.
dbug: Microsoft.AspNetCore.Server.Kestrel[1]
      Connection id "0HM6UG4PBICBP" started.
dbug: Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware[1]
      Failed to authenticate HTTPS connection.
System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> System.ComponentModel.Win32Exception (0x80090367): No common application protocol exists between the client and the server. Application protocol negotiation failed.
--- End of inner exception stack trace ---
// Some detailed stack trace, pretty sure it's garbage
dbug: Microsoft.AspNetCore.Server.Kestrel[2]
    Connection id "0HM6UG4PBICBP" stopped.
dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7]
    Connection id "0HM6UG4PBICBP" sending FIN because: "The Socket transport's send loop completed gracefully

No common application protocol exists between the client and the server,这当然很有趣:服务器必须拒绝 C++ 客户端尝试使用的任何协议(TLS 1.2,来自某些谷歌搜索?)。我怎样才能让他们通过通用协议相互交谈?

注意 1:我应该提到 C++ 客户端是 compiled/run 来自 WSL 1 (Ubuntu 18.04) 而服务器是 运行 Windows 服务器 2019 数据中心。

注2:这里的讨论seems相关,但最终没有任何用处。

我后来提交了另一个问题,其中包含更多详细信息和“答案”。你可以看看