Repository navigation
Conversation
The signature is written into an encrypted file after the encryption, hence its value isn't encrypted. Decrypting it broke the PKCS#7 data returned by `getSignatureData` for encrypted PDFs.
Snuffleupagus
left a comment
Collaborator
There was a problem hiding this comment.
Sorry, but as-is this looks more like a "hacky" work-around rather than a proper solution.
Instead of special-casing signature dictionaries in the parser and the writer, `getSignatureData` now reads the /Contents value of an encrypted PDF from the gap between the two /ByteRange spans, where it's stored unencrypted, and falls back to the parsed value if the gap doesn't hold a single string.
Author
|
I've reworked it: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In an encrypted PDF, the parser decrypts every string, including the
/Contentsof signature dictionaries. That value isn't encrypted, though: the signature is written into the space reserved for it only after the file has been encrypted. As a result, thepkcs7data thatgetSignatureDatareturns for an encrypted signed PDF is garbage, and the signature can't be verified.issue17069.pdffrom the test suite is an example. Onmaster, its PKCS#7 data starts withc9 1a 1e 12, andopenssl cms -verify -binary -inform DER -noverifycan't parse it ("wrong tag"). The same happens with qpdf'sminimal-signed-restricted.pdf, which is signed by Adobe Acrobat Sign. With this patch, the data of both files starts with the DER header30 82, and openssl reports "CMS Verification successful" against the signed byte ranges thatgetSignatureDatareturns.PDFBox and PDFium don't decrypt this value either. With this patch,
getSignatureDatareads the/Contentsvalue of an encrypted PDF from the file, in the gap between the two/ByteRangespans, where it's stored unencrypted, and falls back to the parsed value if the gap doesn't hold a single string. The parser, the writer and unencrypted documents are unchanged.The new
api_spec.jstest reads the signature ofissue17069.pdfand checks the length and the DER header of its PKCS#7 data. It fails without this change.