尝试使用 . 从 PE 文件中提取证书时cryptography
,失败并显示ValueError: Unable to load certificate
. 我能够使用命令行从同一个 PE 文件中正确提取subprocess
证书openssl
。我想了解使用cryptography
.
我正在使用 Python 3.7.1、密码学 2.4.2 和 pefile 2018.8.8
import pefile
from cryptography import x509
from cryptography.hazmat.backends import default_backend
pe = pefile.PE(fname)
pe.parse_data_directories(directories=[pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_SECURITY']])
sigoff = 0
siglen = 0
for s in pe.__structures__:
if s.name == 'IMAGE_DIRECTORY_ENTRY_SECURITY':
sigoff = s.VirtualAddress
siglen = s.Size
pe.close()
with open(fname, 'rb') as fh:
fh.seek(sigoff)
thesig = fh.read(siglen)
cert = x509.load_der_x509_certificate(thesig[8:], default_backend())
这失败了ValueError: Unable to load certificate