【发布时间】:2021-11-15 23:56:01
【问题描述】:
我正在尝试使用 OpenSSL(或者实际上使用 Python,但似乎 Python 在证书处理方面很烂)验证 PE 文件的证书/签名。
我已经从 PE 文件中提取了 DER PKCS7 证书,如下所述:http://blog.didierstevens.com/2008/01/11/the-case-of-the-missing-digital-signatures-tab/
我已经创建了一个没有校验和和签名数据的 PE 文件的修改版本,如下所述:http://www.mail-archive.com/cryptography@c2.net/msg04202.html
修改后文件的sha1sum与证书中的sha1sum一致。
我尝试使用 openssl 验证未签名、修改的 PE 文件:openssl smime -verify -in signature.der -content modified_executable.exe -inform DER -binary 但我只得到 p>
验证失败 140415508248232:错误:21075075:PKCS7 例程:PKCS7_verify:证书验证错误:pk7_smime.c:342:验证错误:不支持的证书用途
如果我在命令中添加-noverify,我就会得到
验证失败 140595583981224:错误:21071065:PKCS7 例程:PKCS7_signatureVerify:摘要失败:pk7_doit.c:1097: 140595583981224:错误:21075069:PKCS7 例程:PKCS7_verify:签名失败:pk7_smime.c:410:
我错过了什么?
【问题讨论】:
-
需要使用 openssl CLI 执行此操作,因为系统是用 python 编写的,我无法从那里轻松调用 openssl C API 函数。
-
什么样的签名?它是 Authenticode 签名吗?如果是这样,请参阅 Verifying Authenticode signed executables and DLLs using OpenSSL API 和 Verify Authenticode signature as being from our company for automatic updater。另请参阅 Microsoft 的 Windows Authenticode Portable Executable Signature Format。
-
我已经大幅更新了我的答案。如果它适合你,请投票。
-
似乎 Python 在证书处理方面很糟糕 - M2Crypto 对证书处理有相当好的支持,并提供 PKCS#7 验证功能。自提交 03eb29d10 以来,您甚至可以设置自定义验证回调以忽略“不支持的证书用途”错误。
标签: python openssl certificate signature authenticode