Ubuntu 上 dotnet Core 中的客户端证书
本文关键字:客户端 证书 Core dotnet Ubuntu | 更新日期: 2023-09-27 17:56:17
all - 我编写了一个在Windows上完美运行的dotnet核心API集。在 Ubuntu 14.04 上,除了向使用客户端证书进行身份验证的供应商发出一个 SOAP 请求外,一切正常。
请求始终超时。Netstat 跟踪显示,在 443 上,只有 1 个字节的数据发送到远程服务。100 秒内未发生通信,然后应用引发超时异常。
我尝试使用 openssl 导出 PEM 和 CRT 文件,除了现在配置代码的方式(pfx 带密码)之外,还引用了这些文件。我还将 PFX 的证书部分加载到 ca-certs 中。
代码如下:
var binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var baseAddress = new Uri(mySettings.ClientUrl);
factory = new ChannelFactory<SingleSignOnSoap>(binding, new EndpointAddress(baseAddress));
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{
//windows file location
factory.Credentials.ClientCertificate.Certificate = new X509Certificate2(mySettings.PrivateKeyWindowsPath, mySettings.PfxPass);
}
else
{
//linux file location
factory.Credentials.ClientCertificate.Certificate = new X509Certificate2(mySettings.ClientPrivateKeyUnixPath, mySettings.PfxPass);
}
serviceProxy = factory.CreateChannel();
RequestTicketRequest request = new RequestTicketRequest();
RequestTicketRequestBody requestBody = new RequestTicketRequestBody(xmlRequest);
request.Body = requestBody;
RequestTicketResponse response = serviceProxy.RequestTicket(request);
return response.Body.RequestTicketResult;
Wireshark 和 Tshark 显示身份验证实际上工作正常。发生超时是因为服务工厂正在等待接收响应,但网络已向远程服务器发送连接重置标志([RST、ACK])。我已经能够在多个 linux 发行版上重现,所以我在 github 上的 dotnet 核心 WCF 团队队列中添加了一个问题。