Skip to content
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

Do not set the StrongEncryption flag for WinZipAes encrypted entries #329

Merged
merged 1 commit into from
Jun 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs
Original file line number Diff line number Diff line change
@@ -1131,10 +1131,9 @@ private void ProcessAESExtraData(ZipExtraData extraData)
{
if (extraData.Find(0x9901))
{
// Set version and flag for Zipfile.CreateAndInitDecryptionStream
// Set version for Zipfile.CreateAndInitDecryptionStream
versionToExtract = ZipConstants.VERSION_AES; // Ver 5.1 = AES see "Version" getter
// Set StrongEncryption flag for ZipFile.CreateAndInitDecryptionStream
Flags = Flags | (int)GeneralBitFlags.StrongEncryption;

//
// Unpack AES extra data field see http://www.winzip.com/aes_info.htm
int length = extraData.ValueLength; // Data size currently 7
40 changes: 24 additions & 16 deletions src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
@@ -3542,23 +3542,9 @@ private Stream CreateAndInitDecryptionStream(Stream baseStream, ZipEntry entry)
{
CryptoStream result = null;

if ((entry.Version < ZipConstants.VersionStrongEncryption)
|| (entry.Flags & (int)GeneralBitFlags.StrongEncryption) == 0)
{
var classicManaged = new PkzipClassicManaged();

OnKeysRequired(entry.Name);
if (HaveKeys == false)
{
throw new ZipException("No password available for encrypted stream");
}

result = new CryptoStream(baseStream, classicManaged.CreateDecryptor(key, null), CryptoStreamMode.Read);
CheckClassicPassword(result, entry);
}
else
if (entry.CompressionMethodForHeader == CompressionMethod.WinZipAES)
{
if (entry.Version == ZipConstants.VERSION_AES)
if (entry.Version >= ZipConstants.VERSION_AES)
{
//
OnKeysRequired(entry.Name);
@@ -3587,6 +3573,28 @@ private Stream CreateAndInitDecryptionStream(Stream baseStream, ZipEntry entry)
throw new ZipException("Decryption method not supported");
}
}
else
{
if ((entry.Version < ZipConstants.VersionStrongEncryption)
|| (entry.Flags & (int)GeneralBitFlags.StrongEncryption) == 0)
{
var classicManaged = new PkzipClassicManaged();

OnKeysRequired(entry.Name);
if (HaveKeys == false)
{
throw new ZipException("No password available for encrypted stream");
}

result = new CryptoStream(baseStream, classicManaged.CreateDecryptor(key, null), CryptoStreamMode.Read);
CheckClassicPassword(result, entry);
}
else
{
// We don't support PKWare strong encryption
throw new ZipException("Decryption method not supported");
}
}

return result;
}