首页 > 解决方案 > 带有 localhost 自签名证书的 Grpc.core TLS 握手

问题描述

我有一个 gRPC 服务在我的本地机器上运行,它需要通过 TLS 的请求。

当我使用 Grpc.Net.Client 库时,以下工作:

var channelGrpcNetClient = GrpcChannel.ForAddress("https://localhost:5003");
var clientGrpcNetClient = new ProvisionClient(channelGrpcNetClient);
await clientGrpcNetClient.CreateAsync(createRequest);

但是,当我尝试在 Grpc.Core 中做类似的事情时,它不再起作用了

var channelGrpcCore = new Channel("https://127:0:0:1", 5003, new SslCredentials());
var clientGrpcCore= new ProvisionClient(channelGrpcCore );
await clientGrpcCore.CreateAsync(createRequest);

这是我得到的例外:

Grpc.Core.RpcException: 'Status(StatusCode="Unavailable", Detail="无法连接到所有地址", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1622691838.697000000","description" :"未能选择子频道","file":"......\src\core\ext\filters\client_channel\client_channel.cc","file_line":5420,"referenced_errors":[{"created" :"@1622691838.697000000","description":"连接所有地址失败","file":"......\src\core\ext\filters\client_channel\lb_policy\pick_first\pick_first.cc", "file_line":398,"grpc_status":14}]}")'

Grpc.Core 库是否不允许使用 localhost 自签名证书的 TLS 连接?似乎 Grpc.Core 使用 BoringSSL,它与 Grpc.Net.Client 使用的库不同。我想知道这个问题是否有解决方法,允许在本地运行客户端和服务器,并且只使用自签名证书。

标签: sslgrpcgrpc-c#

解决方案


推荐阅读