Add support for Info-Zip password check spec for ZipCrypto. #472
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.
Introduction
Currently, ADM-ZIP ZipCrypto (PKCRYPT method) rejects valid passwords that use the Info-Zip standard of password validation.
This specification uses the high bit of the headers modified time, instead of the crc to compare against the LSB of the decrypted 12 bit salt and is only applicable when bit 3 of the general purpose bit flag is set.
This method of password checking looks like it originated in the Info-Zip standard, is still used by a number of older zip generators and is gracefully handled by all other zip tools I tried (7zip, WinZip, Windows etc).
Spec References:
Info-Zip Standard - Line 2806
minizip-ng implementation - Line 193
Relates to issue #471
Possibly relates to #467 and #385
The changes
The code does the following:
headers/entryHeader.js
: The high byte of the headers modified time is exposed as timeHighByte()methods/zipcrypto.js
: The header flags are read to see if bit 3 is set. If it is, the password salt check is based on the high byte of the modified time, rather than the crc. If the flags are undefined (and I'm not sure when they would be), then the crc is used.test/methods/zipcrypto.test.js
: Header flags are provided into the getData function calls, to better represent the reality of a zip file and to allow the two code paths to be tested. Additional tests have been added to test the Info-Zip paths.test/issue_471/infozip-password.test.js
: A full file decryption test for Info-Zip generated files that tests valid and invalid passwords.Testing
I've run the test suite and all tests pass. I've also added the testing route for Info-Zip generated encrypted zips.
To: @cthackers