-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add support for ZipCrypto decryption #129
base: main
Are you sure you want to change the base?
Conversation
Remove unused variable from generateZipParts
For ZipCrypto encrypted files, one of the following MUST be passed in the loadOptions object: * retrievePasswordCallback: a function that returns a password as a string, or * retrieveEncryptionKeysCallback: a function that returns an array of 3 32-bit integers to be used as pre-primed encryption keys If both are set, ZipCrypto will call only retrieveEncryptionKeysCallback. Additionally, invalidPasswordCallback MAY be set and will be called if the supplied password does not validate. invalidPasswordCallback should return `true` if password validation should be ignored. This patch does _not_ add support for PKWARE's Strong Encryption.
* @return {Unit8Array} Decrypted data in the same format as was passed in | ||
*/ | ||
ZipCrypto.prototype.decryptData = function(data, crc32) { | ||
// This doesn't work, how can we check? |
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.
Is it reasonable to believe that the data being decompressed doesn't have to be Unit8Array? I see that there are readers for string and NodeBuffer (not quite sure what that is). If I need to worry about these getting here, then I need to figure out a way to test for Unit8Array. Otherwise, I could just remove this.
Edit: Wow... dyslexia. This whole time I've been reading it as Unit instead of Uint (that makes a lot more sense)
I'll back out and redo the dist update, so please ignore that for now. Also need to update tests. Before I do all of that though, is jszip interested in this patch at all? I'm going to use this for a small project, so I would rather not have to maintain a separate fork. |
if (i == 11 && crc32 !== undefined) { | ||
// Validate checksum | ||
// 12th byte is the high order byte of crc32 | ||
if ( (data[i] & 0xFF) != (crc32 >>> 24) && |
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.
Seems like this is not always set correctly (or maybe I'm doing something wrong here). E.g. encrypted.zip I generated under cygwin (included in the tests) does not validate here, but the contents do get decrypted correctly. Creating a zip with 7zip does validate though.
Reading encrypted zip files sounds good !
Wikipedia says that this ZipCrypto encryption has known weaknesses so I think that a lot of softwares use AES encryption : if we add one, the other will need to follow (or we will get a lot of bug reports). Regarding the API, I wonder if checking the password/decrypting the content when decompressing is a good thing. JSZip doesn't decompress files until necessary so a developer can have a hard time predicting where this will be done. For example, if a user read a zip file (with encrypted content but without password callback), add an image and generate the result, the exception will be thrown in the Regarding the type of the compressed data, it depends of the reader :
You can do the following to get the right type : var dataType = support.uint8array ? "uint8array" : "array";
var data = utils.transformTo(dataType, encryptedData); |
And you don't have to update the |
I'll look into adding AES support. I'm looking into our options for delaying decryption as long as possible (until it's actually needed). If I'm reading the code right, the |
Yes, with the I clearly see the advantages of delaying decryption : speed, the ability to ask the user its password after showing the files list, etc. |
I guess I understand the point here. I do see that in I'm not sure what a better alternative to the current implementation would be though. Asking for a password on load (and not validating it?) would not make much sense, since you only need it to decrypt files right before decompression. There are a number of operations (adding, deleting files) that you could do without needing a password. Additionally, not all file sin the archive have to be encrypted, nor do they have to be encrypted using the same algorithm. (actually, they don't even have to use the same password, but I haven't coded that in, since I don't think that's common) Having thought about this a bit, I would suggest introducing an I'm working on AES implementation in the mean time. |
I have yet another idea, though it feels crude. Could crc32 check just be prevented for the files that are known to be encrypted, but still remain for the other files to check their validity on load()? |
I think that's reasonable. Another reason to ignore encrypted files is that with WinZip's AE-2 encryption, you don't even have a crc32, but instead you are given an HMAC-SHA1-80 hash of the encrypted data. I'm trying to test AES decryption for which I was going to use node-forge package, but the way it |
I made some progress (using crypto-js), but I'm still having issues. I'd like to split this up into two pull requests: one for ZipCrypto now and the other one for AES a little bit later. ZipCrypto is working perfectly now with files generated by 7zip, WinZIP, WinRAR, and ZipInfo's zip (the one in unix/linux). Any further thought on how to handle interaction with the user in regards to password retrieval and validation? Two things are necessary:
|
Wise decision, especially for future references. Smaller pull requests are easier to understand. Always. |
API suggestions:
This way “different passwords for different files” are possible. Interaction with the user (password input, retries, etc.) is left to the application over JSZip. |
Agreed. (That's my current approach actually)
This... idk. Seems like a huge hassle for the user to do
I actually added some new error classes that extend |
Classes extending |
A callback is a better idea than
|
A I'm working on asynchonous methods ( If we don't use a callback we should add a flag
There is one use case covered by a callback and not by this method :
The last part will try to decrypt the files and fail. |
Hi, any updates to this? Password encryption for zip files would really be a great feature/option. |
I second this, would be great if we can protect zip files. |
Ya, this would be awesome. If it helps, I've started https://github.com/cryptocoinjs/aes The problem is, that I need to add |
@jprichardson Zip uses AES-CTR (128, 192 or 256 bit). |
any progress? |
I add some Aes decryption code, please see at #696 |
See the second commit message for explanation.
I think there was some discussion that this would have to be optional. Not sure how you want to control this option exactly, but it would be fairly trivial to add, I think.
Partially addresses #115