【问题标题】:TLS handshake error from ... tls: client didn't provide a certificate来自 ... tls 的 TLS 握手错误:客户端未提供证书
【发布时间】:2018-10-17 04:55:11
【问题描述】:

我有一个 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);

仅当证书是从私有组件所在的 .PFX 文件中读取时才有效。但是当我切换到智能卡证书(它没有私钥属性,因为智能卡不希望你拥有它们)时,服务器没有收到来自客户端的任何证书。

我知道 TLS 在握手阶段需要一个私钥,但客户端 obj 没有看到任何与给定证书关联的私钥,因此无法将该证书识别为 TLS 建立的有效证书。

我知道私钥不能从智能卡中导出,并且我知道必须有一种方法告诉 RestClient 对象,为了通过握手阶段,您应该与智能卡进行通信,但是,我放弃了!

有人能指出正确的方向吗?

【问题讨论】:

  • client.ClientCertificates 的类型是什么?
  • X509Certificate2 的集合(在我的例子中只有一个),没有私钥。

标签: c# authentication ssl smartcard pkcs#11


【解决方案1】:

对于大多数智能卡,应该有微型驱动程序或独立的 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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 2019-08-18
    • 2016-06-15
    • 1970-01-01
    • 2020-10-11
    • 2020-02-14
    相关资源
    最近更新 更多