从DoD CAC卡获取客户端证书

时间:2011-10-24 16:44:55

标签: https client-certificates cac

我有一个使用LibCurl的C应用程序(LibCurl是一个与Web服务器建立HTTP连接的C API)。使用LibCurl我需要从需要客户端证书的HTTPS服务器下载文件。

到目前为止,我们的技术解决方案效果很好。

我的问题是我们需要使用的客户端证书驻留在DoD CAC卡上。我需要能够从DOD CAC卡(从我的C应用程序中)提取客户端证书,并将其写入文件或仅引用CAC上的文件。然后,此写入或引用的文件将在我的HTTPS连接中指定为我的客户端证书。

我不知道如何从DoD CAC卡中找到或引用客户端证书。很感谢任何形式的帮助。感谢。

2 个答案:

答案 0 :(得分:3)

当activeClient将CAC卡证书发布到Windows时,它应该将证书导出到商店。您可能需要自动将证书从本地证书库导出到.pfx或.p7b格式的文件。也许是.cer,我不知道这是否可能。它需要受到保护。

我认为如果没有中间中间层(如证书存储区),您可以直接从CAC卡中执行此操作。

答案 1 :(得分: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中使用这些库,但万一我可以发布它们。