我有一个 C# RestFull 客户端试图连接到一个 Go 服务器。一旦到达 TLS 握手阶段,它就会失败,因为客户端没有提供证书。
在执行请求之前,我已验证客户端证书与 RestClient 对象相关联。
// Initializing the client
RestClient client = new RestClient(Config.SERVER_DOMAIN);
// Adding client certificate (exported from a smart card with no private key attributes)
client.ClientCertificates = Global.cpf.getCertCollection();
// defining our request then executing it
var request = new RestRequest("users", Method.GET);
var response = await client.ExecuteTaskAsync(request);
仅当从私有(private)组件所在的 .PFX 文件中读取证书时,它才有效。但是当我切换到智能卡证书时(它没有私钥属性,因为智能卡不希望你拥有它们)服务器没有收到来自客户端的任何证书。
我知道 TLS 在握手阶段需要一个私钥,但客户端 obj 没有看到任何与给定证书关联的私钥,因此不认为该证书是用于 TLS 建立的有效证书。
我知道私钥不能从智能卡导出,我知道必须有一种方法告诉 RestClient 对象为了通过握手阶段,你应该与智能卡通信,但是,我放弃了!
有人能指出我正确的方向吗?
最佳答案
对于大多数智能卡,应该有微型驱动程序或独立的 CSP(加密服务提供程序)可用。这些组件充当驱动程序,将卡与 Windows 加密子系统集成在一起。它们通常由设备供应商提供,一旦它们设置正确,您应该能够从 Windows 证书存储中引用正确的私钥获取证书。
尝试使用以下方法:
private static X509Certificate2 GetCertificate()
{
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
try
{
// Note: X509Certificate2UI requires reference to System.Security
X509Certificate2Collection certs = X509Certificate2UI.SelectFromCollection(store.Certificates, null, null, X509SelectionFlag.SingleSelection);
if (certs != null && certs.Count > 0)
return certs[0];
}
finally
{
store.Close();
}
return null;
}
关于c# - 来自 ... tls : client didn't provide a certificate 的 TLS 握手错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52847522/