Skip to content

Comments

zip: read AES-encrypted zip files (AE-1 and AE-2)#2966

Open
konimarti wants to merge 11 commits intoc3lang:masterfrom
konimarti:add-aex
Open

zip: read AES-encrypted zip files (AE-1 and AE-2)#2966
konimarti wants to merge 11 commits intoc3lang:masterfrom
konimarti:add-aex

Conversation

@konimarti
Copy link
Contributor

Read AES-encrypyted Zip files using the AE-1 or AE-2 format 1;

@konimarti konimarti marked this pull request as draft February 22, 2026 09:01
@lerno
Copy link
Collaborator

lerno commented Feb 22, 2026

Can the Zip password ever be an empty string?

@konimarti
Copy link
Contributor Author

konimarti commented Feb 22, 2026

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.

@konimarti
Copy link
Contributor Author

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.

@konimarti
Copy link
Contributor Author

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.

@konimarti
Copy link
Contributor Author

Can the Zip password ever be an empty string?

I changed the password handling to a callback which provides for a cleaner api.

@konimarti
Copy link
Contributor Author

konimarti commented Feb 22, 2026

For testing purposes, AES-encrypted zip files can be created with 7z:

7z a -tzip -mem=AES256 -pYourPassword secure.zip file_to_encrypt.txt

@konimarti konimarti marked this pull request as ready for review February 22, 2026 20:17
@lerno
Copy link
Collaborator

lerno commented Feb 23, 2026

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.

@konimarti
Copy link
Contributor Author

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.

konimarti and others added 2 commits February 23, 2026 21:01
- Return PASSWORD_NEEDED for empty password strings.
- Return PASSWORD_MISMATCH if password is wrong.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants