question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Verifying a pdf signature raises an error when accessing SignerInfo native

See original GitHub issue

I followed the example for verifying a pdf signature and I have something like this:

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)

This should be pretty straight forward. I read the pdf, I open the certificates and then I ‘pdf.verify’ to see that everything is in order.

pdf.verify, at one point calls this: signed_data = cms.ContentInfo.load(bcontents)['content'].native which makes ans1crypto raise this error File "/home/vscode/.local/lib/python3.9/site-packages/asn1crypto/core.py", line 4060, in native raise e repeatedly until it gets to

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

I manually tried to replicate what pdf-verify.py does and I noticed that this would work if it didn’t call native and would go directly for the signature:

signature = signed_data['signer_infos'][0].native['signature'] # doesn't work
signature = signed_data['signer_infos'][0]['signature'] # works

I hope this is the place to post issues with the library. If not, I am sorry.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
m32commented, Mar 28, 2022

try next version v2.0.9

0reactions
AdorianMcommented, Mar 28, 2022

I checked this and changing:

signature = signed_data['signer_infos'][0].native['signature'] to signature = signed_data['signer_infos'][0]['signature'].native

provides a valid signature.

Since this is normally part of verifier.py, how should I work around this problem to be able to run pdf.verify(...) ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Verifying a pdf signature with Endesive raises an error when ...
Instead of addressing signer data info like this: signature = signed_data['signer_infos'][0].native['signature'].
Read more >
Releases · m32/endesive - GitHub
en-crypt, de-crypt, si-gn, ve-rify - smime, pdf, xades and plain files in pure ... Verifying a pdf signature raises an error when accessing...
Read more >
Validating digital signatures, Adobe Acrobat
Follow these steps to set up digital signature validation, certify a PDF, timestamp a document, ad validate or remove a digital signature in ......
Read more >
Release 0.16.0-dev1 Matthias Valvekens - pyHanko
Signing PDF files using pyHanko can be very simple or somewhat ... In particular, as_pdf_object() always raises an error, since the ...
Read more >
Release v2.0.9 · m32/endesive · GitHub
Verifying a pdf signature raises an error when accessing SignerInfo native #122. Assets. 2. Source code (zip) · Source code (tar.gz). Footer.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found