Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Windows API解码PKCS#7签名?_Windows_Pkcs#7_Authenticode - Fatal编程技术网

通过Windows API解码PKCS#7签名?

通过Windows API解码PKCS#7签名?,windows,pkcs#7,authenticode,Windows,Pkcs#7,Authenticode,我希望解析并显示从Window PE二进制文件的安全目录中提取的Authenticode PKCS#7签名的内容 我可以使用OpenSSL在命令行上通过“OpenSSL pkcs7-text-in extracted_signature.pks-notify DER-print_certs”来完成这项工作,但是我需要通过C/C++和Windows API来完成。我不能使用OpenSSL库本身 使用CryptDecodeObjectExAPI,我可以开始解码提取的签名: CRYPT_CONTENT

我希望解析并显示从Window PE二进制文件的安全目录中提取的Authenticode PKCS#7签名的内容

我可以使用OpenSSL在命令行上通过“
OpenSSL pkcs7-text-in extracted_signature.pks-notify DER-print_certs
”来完成这项工作,但是我需要通过C/C++和Windows API来完成。我不能使用OpenSSL库本身

使用
CryptDecodeObjectEx
API,我可以开始解码提取的签名:

CRYPT_CONTENT_INFO * content_info;
DWORD len;

CryptDecodeObjectEx(
    X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
    PKCS_CONTENT_INFO,
    pointer_to_extracted_signature,
    length_of_extracted_signature,
    CRYPT_DECODE_ALLOC_FLAG,
    NULL,
    &content_info,
    &len
);
上述调用成功完成,
content\u info->pszObjId
的OID为“1.2.840.113549.1.7.2”(szod\u RSA\u signedData),但我无法找到继续解码所需的结构。列出了CryptDecodeObjectEx的可用OID


任何人都可以建议如何通过Windows API解码Authenticode PKCS#7签名吗?

我发现解码Authenticode PKCS#7签名的正确方法是使用
CryptQueryObject
CERT\u QUERY\u对象BLOB
CERT\u QUERY\u内容\u标志设置PKCS7\u签名。下面为可能需要执行此操作的任何人编写代码snippit

CERT_BLOB cert_blob;
HCERTSTORE cert_store = NULL;
HCRYPTMSG cert_msg    = NULL;

cert_blob.pbData = pointer_to_extracted_signature;
cert_blob.cbData = length_of_extracted_signature;

CryptQueryObject(
    CERT_QUERY_OBJECT_BLOB,
    &cert_blob,
    CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED,
    CERT_QUERY_FORMAT_FLAG_BINARY,
    0,
    NULL,
    NULL,
    NULL,
    &cert_store,
    &cert_msg,
    NULL
);

PCCERT_CONTEXT next_cert = NULL;

while( (next_cert = CertEnumCertificatesInStore( cert_store, next_cert ) ) != NULL )
{
    // process next_cert...
}