c# - grpc客户端的证书认证问题
问题描述
我创建了一个带有 gRPC 客户端(控制台应用程序)和一个 gRPC 服务器应用程序的演示解决方案。(在 .NET Core 3 上为其提供的模板)
我正在尝试测试两者之间的证书身份验证,但由于某种原因它失败并出现以下错误:
AuthenticationException: The remote certificate is invalid according to the validation procedure."
我Program.cs
的服务器
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureKestrel(o =>
{
o.ConfigureHttpsDefaults(o =>
{
o.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
o.ServerCertificate = <MyCertificateWithPrivateKey>;
});
});
在客户端应用程序中,我在 HttpHandler 中传递了相同的证书,该证书被传递到我创建的通道,即
GrpcChannel.ForAddress("https://localhost:5001", new GrpcChannelOptions
{
HttpHandler = handler
});
我的服务器的启动类:
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
services.AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme)
.AddCertificate();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthentication();
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<GreeterService>();
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
});
});
}
}
感谢您能给我的任何帮助。
解决方案
推荐阅读
- angular - 如何设置每个 ion-popover 的大小
- javascript - 为什么我的 React 中的模块构建失败?
- ios - 如何在呈现后隐藏视图的阴影?
- sql - Amazon Redshift :- 对查询执行过滤器
- javascript - 根据子值删除父 JSON 元素
- flutter - 我如何在颤振中以base64格式显示pdf
- c++ - 访问来自不同函数但相同类的数组元素
- android - 我在回收站视图中隐藏了一些图像视图,但是当我向下滚动所有图像视图时隐藏
- apache-spark - 无法减少 Pyspark 中的任务数量
- r - 如何使用 Shinyusing 模块在 modalDialog 中为高级设置显示反应式 UI