【问题标题】:GRPC .Net Core server & C++ client: Https connection fails, "No common application protocol between client/server"GRPC .Net Core 服务器和 C++ 客户端:Https 连接失败,“客户端/服务器之间没有通用应用程序协议”
【发布时间】:2021-06-02 12:10:21
【问题描述】:

我正在尝试让 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 Datacenter 上运行的。

注意 2:这里的讨论 seems 相关,但最终并没有带来任何有用的东西。

【问题讨论】:

标签: asp.net-core ssl grpc sslhandshakeexception


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2019-07-20
    • 2016-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 2016-07-21
    • 2012-06-28
    相关资源
    最近更新 更多