我有一个使用LibCurl的C应用程序(LibCurl是一个建立到web服务器的超文本传输协议连接的C应用程序接口)。使用LibCurl时,我需要从需要客户端证书的HTTPS服务器下载文件。
到目前为止,我们的技术解决方案运行良好。
我的问题是,我们需要使用的客户端证书驻留在DoD CAC卡上。我需要能够从DOD CAC卡(从我的C应用程序中)中提取客户端证书,并将其写入文件或仅引用CAC上的文件。然后,这个写入或引用的文件将被指定为我的HTTPS连接中的客户端证书。
我不知道如何查找或引用DoD CAC卡上的客户端证书。任何帮助都是非常感谢的。谢谢。
发布于 2011-10-25 00:53:45
当activeClient将CAC卡证书发布到windows时,它应该将证书导出到存储区。您可能需要自动将证书从本地证书存储导出到.pfx或.p7b格式的文件。也许是.cer,我不知道这是否可能。它需要受到pwd的保护。
我认为如果没有中间中间层(如证书存储),您无法直接从CAC卡完成此操作。
发布于 2015-07-24 00:26:59
这是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中使用这些库,但为了以防万一,我把它们贴上了。
https://stackoverflow.com/questions/7878952
复制相似问题