Repository navigation
Truncate the per-object crypt key to min(n/8+5, 16) bytes - #94
Open
djsnowsill wants to merge 3 commits into
Open
djsnowsill wants to merge 3 commits into
djsnowsill wants to merge 3 commits into
Conversation
PDF 32000-1:2008 Algorithm 1 step e takes the first n/8+5 bytes of the MD5 (at most 16) as the object key. cryptKey returned the whole digest, which is right only for a 128-bit key. Every 40-bit RC4 file therefore opened (the password check uses the document key, which was correct) and then panicked with "zlib: invalid header" on its first stream. Two fixtures, the same page encrypted by pdfcpu with RC4 at 40 and 128 bits and an empty user password: the 40-bit one failed before this change and both read after it.
…lter, which this reader does not accept
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.
Summary
cryptKeyreturned the whole 16-byte MD5 as the per-object key. PDF 32000-1:2008 Algorithm 1 step e takes the firstn/8+5bytes, at most 16. That is 16 for a 128-bit key, so those files read, and 10 for a 40-bit key, so every 40-bit RC4 file opened (the document key and the/Ucheck were right) and then panicked withzlib: invalid headeron its first stream./V 1 /R 2) and an empty user password, and a test that fails before the change and passes after it.TestCryptKeyDeterministicAndSaltAwareasserted a 16-byte key for a 6-byte document key, which encoded the defect; it now asserts 11, and 16 for a 16-byte key.Measured on 473 real ASX announcements produced by Adlib (40-bit RC4, empty user password): none read before this change, 20 of 20 sampled read in full after it, matching
pdftotext.Test plan
go test ./green on this branchTestReads40BitRC4WithEmptyUserPasswordfails on master, passes here