从DoD CAC卡中获取客户端证书

3
我有一个C应用程序,使用LibCurl(LibCurl是一个C API,可与Web服务器建立HTTP连接)。使用LibCurl,我需要从需要客户端证书的HTTPS服务器下载文件。
到目前为止,我们的技术解决方案非常好。
我的问题是,我们需要使用的客户端证书驻留在DoD CAC卡上。我需要能够从DoD CAC卡中获取客户端证书(从我的C应用程序内部),并将其写入文件或仅引用CAC上的文件。然后,在我的HTTPS连接中,这个编写或引用的文件将被指定为我的客户端证书。
我不知道如何找到或引用DoD CAC卡上的客户端证书。非常感谢任何帮助。谢谢。
2个回答

3
当activeClient将CAC卡证书发布到Windows时,它应该将证书导出到存储中。您可能需要自动将证书从本地证书存储导出到文件(如.pfx或.p7b格式)。也许是.cer,我不知道是否可能。它需要受到密码保护。
我认为您无法直接从CAC卡中完成此操作,除非使用中间层(如证书存储)。

所以您的意思是插入CAC卡后,客户端证书会自动复制到证书存储中?最终我需要以.pem格式获取该证书(如果可能的话)。 - kmehta
Windows凭据管理器怎么样? - bahrep

0

这是 C# 的方法,它可能对 C 有所帮助,但我对 C 代码不太熟悉。

using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
private static X509Certificate GetClientCert()
{
  X509Store store = null;
  try
   {
    store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
    store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);

    var certs = store.Certificates.Find(X509FindType.FindBySubjectName, "Integration Client Certificate", true);
    if (certs.Count == 1)
    {
       var cert = certs[0];
       return cert;
    }
   }
   finally
   {
    if (store != null)
    store.Close();
   }

 return null;
}

获取并导出证书的代码如下:

//This will bring up the selection prompt to select your cert


X509Certificate c = GetClientCert();


//The password should be the pin converted to a secure string variable.
//note the code above will not prompt for a pin if you want this you will have to build the prompt yourself.  It will only select the certificate.

c.Export(X509ContentType.Cert, securestring password);

导出方法有多种类型可供导出,我不确定其中是否有一种是您提到的格式。这是您需要尝试的事情。我甚至不确定您是否能在 C 中使用这些库,但以防万一我发布了它们。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接