我正在尝试将一个签名与python中pdf文件的证书进行比较。我发现这个很好的包裹叫做“可爱”。
我以验证pdf签名的例子为例,我有如下所示:
pdf_file_path = "/workspaces/test.pdf"
data = open(pdf_file_path, 'rb').read()
certificates = (
open("/workspaces/certificates/pki.pem", 'rt').read(),
open("/workspaces/certificates/pki-chain.pem", 'rt').read()
)
(hashok, signatureok, certok) = pdf.verify(data, certificates)
print('signature ok?', signatureok)
print('hash ok?', hashok)
print('cert ok?', certok)
这应该是很直接的。我读了pdf,我打开证书,然后我'pdf.verify‘,以确保一切都井然有序。
pdf.verify,有一次调用如下:signed_data = cms.ContentInfo.load(bcontents)['content'].native
,它使ans1crypto反复引发错误File "/home/vscode/.local/lib/python3.9/site-packages/asn1crypto/core.py", line 4060, in native raise e
,直到它到达
ValueError: Unknown element - context class, constructed method, tag 0
while parsing asn1crypto.core.Sequence
while parsing asn1crypto.cms.SetOfAny
while parsing asn1crypto.cms.CMSAttribute
while parsing asn1crypto.cms.CMSAttributes
while parsing asn1crypto.cms.SignerInfo
这里会出什么问题?
发布于 2022-07-03 11:19:36
而不是像这样对签名者数据信息进行寻址:
signature = signed_data['signer_infos'][0].native['signature']
应该这样处理:
signature = signed_data['signer_infos'][0]['signature'].native
这已经被这里解决了。
https://stackoverflow.com/questions/71615563
复制相似问题