-
Notifications
You must be signed in to change notification settings - Fork 317
Adds support AES decryption #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few initial remarks from what I have read.
amount_to_read -= BLOCK_SIZE | ||
@counter += 1 | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are missing the check of the CRC, we should check that the decrypted content hasn't been tampered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to integrate the AES integrity check, but it doesn't work.
If you have an idea, I'd love to hear it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've finally found the problem, I've finished the implementation and I'm going to write the tests.
Hi @hainesr, What do you think about merging this first version without integrating the integrity test? |
Hi @hainesr, ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Here are a few more comments, thanks for your work.
return unless @decrypter.kind_of?(::Zip::AESDecrypter) | ||
return unless input_finished? | ||
|
||
@decrypter.check_integrity(@io.read(::Zip::AESEncryption::AUTHENTICATION_CODE_LENGTH)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that this line fully respects the specification, when checking integrity of the file, with VERSION_AE_1
we should use the CRC field while with VERSION_AE_2
it should use the authentication code which is byte-aligned.
I do not fully understand your code, but I found nothing like this.
See https://www.winzip.com/en/support/aes-encryption/#CRC:
## CRC value
For files encrypted using the AE-2 method, the standard Zip CRC value is not used, and a 0 must be stored in this field. Corruption of encrypted data within a Zip file is instead detected via the [authentication code](https://www.winzip.com/en/support/aes-encryption/#authentication-code) field.
Files encrypted using the AE-1 method do include the standard Zip CRC value. This, along with the fact that the vendor version stored in the AES extra data field is 0x0001 for AE-1 and 0x0002 for AE-2, is the only difference between the AE-1 and AE-2 formats.
NOTE: Zip utilities that support the AE-2 format are required to be able to read files that were created in the AE-1 format, and during decryption/extraction of files in AE-1 format should verify that the file's CRC matches the value stored in the CRC field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into it in the next few days, thx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ph0tonic I reread the spec and the integrity check must be performed in all cases.
The only difference is that with AE-1, you also get a CRC
@key_length = KEY_LENGTHS[@strength] | ||
@salt_length = SALT_LENGTHS[@strength] | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we had decryption, we should also implement encryption. This would provide a way to test the full stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not going to have time to implement encryption
Hi all, Many, many thanks for this work, and many, many apologies for taking so long to acknowledge it. I will try and look at this as soon as possible. I won't be able to include it in version 3 - I really just need to get that out, it's been dragging on too long as it is - but as this is added functionality we should be safe to release this in version 3.1. Thanks, |
#573 #179 @Ph0tonic