[英]gRPC C# Server authentication
我正在嘗試使用 gRPC 執行服務器身份驗證,但是我不確定如何繼續。 我目前的設置是我在一台機器上運行一個服務器,在另一台機器上運行一個客戶端(兩台 Windows 機器)。 出於測試目的,我使用 windows makecert.exe 生成了證書頒發機構和私有證書(來自該證書頒發機構)。 這將生成 .cer 文件。
SslServerCredentials 的文檔對 .cer 文件沒有任何規定。 在這種情況下,我的 KeyCertificatePair 是什么? 文檔對此不清楚。 http://www.grpc.io/grpc/csharp/html/T_Grpc_Core_SslServerCredentials.htm
另外,我只希望服務器對自身進行身份驗證,是否需要對客戶端 gRPC 調用進行任何特殊規定?
您將需要私鑰和證書文件。 您可以在此處查看 gRPC 測試代碼是如何執行的。
首先,您應該將此配置添加到您的 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"];
有人說這個令牌不應該出現在配置文件中,但現在我不知道還能把它放在哪里。 你也應該調查一下。 如果你不介意,請告訴我:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.