PKCS#7 签名代码 图像提取

发布于 2024-09-01 01:46:12 字数 419 浏览 13 评论 0原文

我想使用 C/CPP 从 PKCS#7 签名代码映像中提取签名者信息。我想了解 openssl API。 我能够使用充气城堡 (CMSSignedData) 进行提取

请让我知道 openssl API,我可以在 C/CPP 中使用它来提取每个签名者和签名者信息并验证签名者。

是否有像 X509_LOOKUP_buffer() 而不是 X509_LOOKUP_file() 的 API ???

预先感谢opensid

I wanted to extract the Signer Informations from PKCS#7 Signed Code Image using C/CPP. I wanted to know the openssl API's. I am Able to extract Using bouncy castle (CMSSignedData).

Please let me know the openssl API's which I can use in C/CPP to extract the each signers and signer informations and verify the Signers.

is there any API like X509_LOOKUP_buffer() instead of X509_LOOKUP_file() ???

Thanks in advance opensid

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚你心 2024-09-08 01:46:12

我有类似的问题。我必须从 PKCS#7 签名中提取签名时间属性。我在互联网上找不到最终的解决方案,但我可以从不同的地方找到一些零碎的东西,然后想到了这个。也许有更好/更好/更安全的方法,这是我第一次这样做,但它似乎有效。

在一个函数中,我在 const void *p_pkcs7Sig 指向的缓冲区中有 p_pkcs7SigSize 字节的 PKCS#7 签名。这样我就有了签名时间。我已经删除了错误处理,不要使用这段冗长的代码!

BIO                         *v_in          = NULL;
PKCS7                       *v_p7          = NULL;
STACK_OF(PKCS7_SIGNER_INFO) *v_signerInfos = NULL;
PKCS7_SIGNER_INFO           *v_signerInfo  = NULL;
ASN1_TYPE                   *v_asn1SigningTime  = NULL;

/* make BIO for input buffer */
v_in = BIO_new_mem_buf( (void*)(uintptr_t) p_pkcs7Sig, p_pkcs7SigSize );

/* make a PKCS7 object of it */
v_p7 = d2i_PKCS7_bio( v_in, NULL);

/* get all signer infos */
v_signerInfos = PKCS7_get_signer_info( v_p7 );

/* if you need all signer infos then loop through all, 
 * count you get by k_PKCS7_SIGNER_INFO_num(v_signerInfos) 
 */

/* get the first signer info */
v_signerInfo = sk_PKCS7_SIGNER_INFO_value(v_signerInfos,0);

/* get signing time */
v_asn1SigningTime = PKCS7_get_signed_attribute( v_signerInfo, NID_pkcs9_signingTime );

/* You should got a v_asn1SigningTime->type == V_ASN1_UTCTIME, 
 * if yes then the actual value is in the string buffer at
 * v_asn1SigningTime->value.utctime->data 
 */

if ( v_in )
{
   BIO_free_all( v_in );
   v_in = NULL;
}

I had a similar problem. I had to extract signingTime attribute from a PKCS#7 signature. I couldn't find the ultimate solution on the Internet but I could pick up bits and parts from various places and came up to this. Maybe there is a nicer/better/safer way, it's the first time I amd doing this but it seems to work.

In a function I have p_pkcs7SigSize bytes of PKCS#7 signature in a buffer pointing by const void *p_pkcs7Sig. I got signing time by this. I've removed the error handling, do not use this code verbose!

BIO                         *v_in          = NULL;
PKCS7                       *v_p7          = NULL;
STACK_OF(PKCS7_SIGNER_INFO) *v_signerInfos = NULL;
PKCS7_SIGNER_INFO           *v_signerInfo  = NULL;
ASN1_TYPE                   *v_asn1SigningTime  = NULL;

/* make BIO for input buffer */
v_in = BIO_new_mem_buf( (void*)(uintptr_t) p_pkcs7Sig, p_pkcs7SigSize );

/* make a PKCS7 object of it */
v_p7 = d2i_PKCS7_bio( v_in, NULL);

/* get all signer infos */
v_signerInfos = PKCS7_get_signer_info( v_p7 );

/* if you need all signer infos then loop through all, 
 * count you get by k_PKCS7_SIGNER_INFO_num(v_signerInfos) 
 */

/* get the first signer info */
v_signerInfo = sk_PKCS7_SIGNER_INFO_value(v_signerInfos,0);

/* get signing time */
v_asn1SigningTime = PKCS7_get_signed_attribute( v_signerInfo, NID_pkcs9_signingTime );

/* You should got a v_asn1SigningTime->type == V_ASN1_UTCTIME, 
 * if yes then the actual value is in the string buffer at
 * v_asn1SigningTime->value.utctime->data 
 */

if ( v_in )
{
   BIO_free_all( v_in );
   v_in = NULL;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文