Skip to content

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

Adds support AES decryption #579

wants to merge 8 commits into from

Conversation

jplot
Copy link

@jplot jplot commented Apr 26, 2024

Copy link
Contributor

@Ph0tonic Ph0tonic left a 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

Copy link
Contributor

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.

Copy link
Author

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.

jplot@21bdb68

Copy link
Author

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.

@jplot
Copy link
Author

jplot commented Jun 11, 2024

Hi @hainesr,

What do you think about merging this first version without integrating the integrity test?
And make in a second time the integrity test with the possibility of creating an AES archive.

@coveralls
Copy link

Coverage Status

coverage: 95.115% (-1.9%) from 96.98%
when pulling b8c6c39 on jplot:master
into 5c6a7c9 on rubyzip:master.

@jplot
Copy link
Author

jplot commented Jun 12, 2024

Hi @hainesr,

ready for review.

Copy link
Contributor

@Ph0tonic Ph0tonic left a 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))
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

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

Copy link
Contributor

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.

Copy link
Author

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

@jplot jplot marked this pull request as draft August 27, 2024 08:51
@hainesr
Copy link
Member

hainesr commented Feb 1, 2025

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,
Rob

@hainesr hainesr self-assigned this Feb 2, 2025
@hainesr hainesr added this to the Future milestone Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy