【发布时间】:2020-04-07 20:00:53
【问题描述】:
我的 gRPC 客户端/服务器代码使用 ChannelCredentials.Insecure 在我的本地机器上愉快地工作,但需要切换到安全模式。我不需要任何证书检查,只需要加密流量。 我一直找不到可以相互通信的客户端服务器的任何配置。 运行 c# 核心服务器 (gRPC 2.27.0) 和 c# .net 框架客户端 (gRPC 2.28.1)。
服务器说它在 http 和 https 上发布如下:
[20:12:58 DBG] Using development certificate: CN=localhost (Thumbprint: 3EDA2E5BD559D75C9DCF058E0A6994EED859CD34)
[20:12:58 INF] Now listening on: https://localhost:5001
[20:12:58 INF] Now listening on: http://localhost:5000
与客户合作:
ChannelBase channel = new Channel("localhost:5000", ChannelCredentials.Insecure);
var client = new MyApp.MyAppClient(channel);
var response = client.Test(request)
如果我如下将客户端切换到 SslCredentials
ChannelBase channel = new Channel("localhost:5001", new SslCredentials());
var client = new MyApp.MyAppClient(channel);
var response = client.Test(request)
我收到以下错误。
服务器错误
[19:32:53 DBG] Failed to authenticate HTTPS connection.
System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslStream.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
客户端错误
Grpc.Core.RpcException: 'Status(StatusCode=Unavailable, Detail="failed to connect to all addresses")'
我也尝试添加(服务器),但错误没有变化。
services.AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme)
.AddCertificate(options =>
{
options.RevocationMode = X509RevocationMode.NoCheck;
options.ValidateCertificateUse = false;
options.AllowedCertificateTypes = CertificateTypes.SelfSigned;
});
关于我需要做什么来让他们说话的任何建议。
【问题讨论】:
-
我找到了一种显示所有客户端 grpc 调试语句(GRPC_TRACE 和 GRPC_VERBOSITY)的方法 - 但只记录了放弃。需要为服务器找到类似的。