【发布时间】:2020-11-13 14:48:59
【问题描述】:
- 这就是我在本地机器上使用它的方式。我使用此 pfx 证书从外部 API 获取数据。
services.AddHttpClient("test", c =>{}).ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler
{
ClientCertificateOptions = ClientCertificateOption.Manual,
SslProtocols = SslProtocols.Tls12
}
handler.ClientCertificates.Add(newX509Certificate2("pathtopfxcert", "pathtokey"));
return handler;
}
- 但是这段代码在 RHEL Container 中运行时会抛出如下错误
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HM47J1331JFT", Request id "0HM47J1331JFT:00000001": An unhandled exception was thrown by the application.
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
at System.Net.Security.SslStream.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)
- 如何解决这个问题?我应该更改代码吗?
【问题讨论】:
-
调试代码时(无容器)是否有效?
-
它适用于我的本地,如步骤 1 中所述。
标签: c# docker .net-core rhel7 pfx