zip: read AES-encrypted zip files (AE-1 and AE-2)#2966
Conversation
Read AES-encrypyted Zip files using the AE-1 or AE-2 format [1]; [1]: https://www.winzip.com/en/support/aes-encryption/
|
Can the Zip password ever be an empty string? |
|
The empty string for the password doesn't make sense but I just added it as the default function value when it's not encrypted. I need to reconsider that. Also, there's an issue with an encrypted deflate stream that I initially didn't see and haven't resolved yet. This needs more work. |
|
I discovered that WinZip’s AES-CTR uses a little-endian counter, so I had to increment the IV starting at the lowest-order byte instead of the highest (which is the common way). After adding a little-endian counter to AES-CTR, the decrypted DEFLATE streams should be correct now. |
|
The failed nix test is because of a stochastic element in std::math::distributions. I thought I removed most of them but apprently not. Will provide a fix for this soon, too. |
I changed the password handling to a callback which provides for a cleaner api. |
|
For testing purposes, AES-encrypted zip files can be created with 7z:
|
|
Are you imagining that the callback would pop some dialog or something? I think more reasonable would be to fail on PASSWORD_NEEDED if the password isn't provided and it's passworded, and a PASSWORD_MISMATCH if the password doesn't work. |
|
It was meant for flexibility: you can have different passwords for different zip entry files in the same archive and an empty string as a password is technically valid. I'm fine with changing it back to have the password in the function signature, though. |
- Return PASSWORD_NEEDED for empty password strings. - Return PASSWORD_MISMATCH if password is wrong.
|
I'm sorry but I think this needs to be merged now. |
| self.file.read(compressed)!; | ||
| data = deflate::decompress(allocator, compressed)!; | ||
| } | ||
| data = io::read_fully(allocator, &reader)!; |
There was a problem hiding this comment.
I am concerned about this change here. It looks like it's completely ignoring the old behaviour?
There was a problem hiding this comment.
ZipArchive.read_file_all duplicates the STORE/DEFLATE dispatch logic that ZipEntryReader.read already handle. The duplication can be removed by just using the ZipEntryReader. Unit tests pass. @ManuLinares can you confirm?
There was a problem hiding this comment.
Yes.
Could you resolve the conflicts so I can review this?
|
LGTM 🚀 |
|
Thank you! |
Read AES-encrypyted Zip files using the AE-1 or AE-2 format 1;