我尝试使用gRPC执行服务器身份验证,但我不确定如何继续。 我目前的设置是我在一台机器上运行服务器,在另一台机器上运行客户机(两台Windows机器)。 出于测试目的,我使用windows makecert.exe生成了证书颁发机构和私有证书(来自此证书颁发机构)。 这会生成.cer文件。
SslServerCredentials的文档没有任何.cer文件的规定。在这种情况下,我的KeyCertificatePair是什么?文档目前尚不清楚。 http://www.grpc.io/grpc/csharp/html/T_Grpc_Core_SslServerCredentials.htm
另外,我只希望服务器自我验证,我是否需要在客户端gRPC上调用任何特殊规定?
答案 0 :(得分:1)
首先,您应该将此配置添加到您的appsettings.json
},
"AllowedHosts": "*",
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http2"
},
"EndPoints": {
"Https": {
"Url": "https://*:5002",
"Certificate": {
"Path": "c:\\test.pfx",
"Password": "password1234"
}
}
}
},
"token": "DO6&gkOK5%$fRD#eRt$",
}
该证书可以通过多种方式生成。 IIS或powershell命令。这段代码在驱动器c中:仅用于测试。
然后您应该在Program.main上获得这样的令牌值:
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
// Duplicate here any configuration sources you use.
configurationBuilder.AddJsonFile("AppSettings.json");
IConfiguration configuration = configurationBuilder.Build();
string token = configuration["token"];
有人说这个令牌不应该放在配置文件中,但是现在我不知道该把它放在哪里。您还应该对此进行调查。告诉我你是否不介意:)
答案 1 :(得分:0)
您需要私钥和证书文件。您可以看到gRPC测试代码如何执行here。