GRPC .Net Core 服务器和 C++ 客户端:Https 连接失败,“客户端/服务器之间没有通用的应用程序协议”

时间:2021-03-03 21:11:20

标签: asp.net-core ssl grpc sslhandshakeexception

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

服务器以“netcoreapp3.1”为目标,依赖“Grpc.AspNetCore”版本2.28.0。服务器代码本身基本上是复制from the official grpc repo's examplesStartup.csProgram.cs 本身并不太有趣,可能不是问题,所以我只是将它们上传到 a gist(但请注意对 UseHttps 的调用)。一切都建立起来了,一个玩具 .NET 核心 GRPC 客户端(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++ 客户端是从 WSL 1 (Ubuntu 18.04) 编译/运行的,而服务器是在 Windows Server 2019 数据中心上运行的。

注意 2:此处的讨论seems 相关,但最终不会产生任何有用的东西。

1 个答案:

答案 0 :(得分:0)

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

相关问题