Можете ли вы помочь мне с сертификацией ssl для сервера gRPC?
Вот как я это делаю с C # Core Console application :
const int Port = 50051;
const string host = "127.0.0.1";
var cacert = File.ReadAllText(@"Certs/ca.crt");
var servercert = File.ReadAllText(@"Certs/server.crt");
var serverkey = File.ReadAllText(@"Certs/server.key");
var keypair = new KeyCertificatePair(servercert, serverkey);
var sslCredentials = new SslServerCredentials(new List<KeyCertificatePair>() { keypair }, cacert, false);
var server = new Server()
{
// setup host, port and server credentials
Ports = { new ServerPort(host, Port, sslCredentials) },
// register the service we built earlier
Services = { Messages.BindService(new MessagesImpl()) }
};
server.Start();
Я не знаю, как предоставить SslServerCredentials в ASP.NET core gRPC Server ?
Сервер cRPG запускается путем добавления в файл Stattup.cs в разделе Настройка:
public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
}
// 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.UseEndpoints(endpoints =>
{
// 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
endpoints.MapGrpcService<ServiceBaaseClass>();
});
}