【问题标题】:Get a client certificate off of a DoD CAC Card从 DoD CAC 卡中获取客户端证书
【发布时间】:2015-07-24 01:05:58
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: https client-certificates cac


    【解决方案1】:

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

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

    【讨论】:

    • 所以你是说插入CAC卡时,客户端证书会自动复制到证书存储区?我最终需要 .pem 格式的证书(如果可能的话)。
    • Windows 凭据管理器怎么样?
    【解决方案2】:

    这是 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 中使用这些库,但以防万一您可以发布它们。

    【讨论】:

      猜你喜欢
      • 2011-04-25
      • 2014-03-02
      • 1970-01-01
      • 2011-05-26
      • 2021-08-02
      • 1970-01-01
      • 2019-05-12
      • 2015-01-23
      • 2012-04-25
      相关资源
      最近更新 更多