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

Add password to ZipArchive #1545

Open
Tracked by #62658
neridonk opened this issue Sep 26, 2016 · 34 comments
Open
Tracked by #62658

Add password to ZipArchive #1545

neridonk opened this issue Sep 26, 2016 · 34 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO.Compression
Milestone

Comments

@neridonk
Copy link

can we make that happen?

@ianhays
Copy link
Contributor

ianhays commented Oct 10, 2016

It's certainly possible to add encryption support to ZipArchives. There are a few competing standards for which encryption and accompanying header definitions, but I think the AES one used by 7-zip is one of the more popular ones. There's also basic passwords included in the zip format but iirc those are easily crackable.

The format also has some strong encryption support but it's copyrighted so out of bounds for us.

@karelz
Copy link
Member

karelz commented Oct 12, 2016

We need API proposal to move it further.

@ghost
Copy link

ghost commented Oct 25, 2016

Speaks something against?

namespace System.IO.Compression
{
    public static class ZipFile 
    {
        public static ZipArchive Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding, string password)
    }
}

@karelz
Copy link
Member

karelz commented Nov 3, 2016

@ianhays can you please comment if that is sufficient?

@ianhays
Copy link
Contributor

ianhays commented Nov 3, 2016

@lburkovsky take a look at this issue for a good example of the kind of API proposal that we're looking for. In general, the more implementation details, the better. You can also look at our API Review process doc for more info on the process.

For Zip password support specifically, an API proposal should include analysis on the different methods of password support in Zip, the pros and cons of each, and which you think should be officially supported in .NET.

@danmoseley
Copy link
Member

@neridonk perhaps you would like to make the proposal for us to formally review? as above.

@mfjerome
Copy link

mfjerome commented Jul 9, 2018

Any news or plans about this feature? Would be very useful!

@karelz
Copy link
Member

karelz commented Jul 9, 2018

@mfjerome we are open to API proposal and contribution. Are you interested?

@carlossanlop
Copy link
Member

What do we need this feature for? Is it for reading password-protected files or producing or something else?
@bartonjs can you please chime in?

@bartonjs
Copy link
Member

I'm not quite sure what's being asked of me here. So here are words.

All further comments relate to the WinZIp version:

  • Technically speaking, I think each entry could be encrypted with a different password. In practice, it seems unlikely; so asking for a single decryption password seems reasonable.
  • Key generation uses PBKDF2, which is the algorithm used by System.Security.Cryptography.Rfc2898DeriveBytes.
  • Encryption is done using AES-CTR. We currently don't expose AES-CTR as public API.
    • There are ways to cheat and get it... and people have asked for it... so we might just add it this release with some of the new API.
  • For creating new encrypted ZIP files you probably want to accept an encryption algorithm/mode value. This allows for callers to change from Aes256 to whatever algorithm replaces Aes256 in the future without creating compatibility/tool-interop concerns.

The preference in cryptography API is to never have a default algorithm choice, so creating new encrypted ZIP files would require using a method that took that as an input. That might mean that instead of

public static ZipArchive Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding, string password);

You want

public enum ZipEncryptionMode
{
    Unknown,
    Aes128,
    Aes192,
    Aes256,
}

public static ZipArchive OpenRead(string archiveFileName, Encoding entryNameEncoding, string password);

public static ZipArchive OpenCreate(string archiveFileName, Encoding entryNameEncoding, string password, ZipEncryptionMode encryptionMode);

public static ZipArchive OpenUpdate(string archiveFileName, Encoding entryNameEncoding, string password, ZipEncryptionMode encryptionMode);

Or, you could combine them:

public enum ZipEncryptionMode
{
    Unknown,
    Aes128,
    Aes192,
    Aes256,
}

// Update/Create modes will throw if newFileEncryptionMode is default
public static ZipArchive Open(string archiveFileName, Encoding entryNameEncoding, string password, ZipEncryptionMode newFileEncryptionMode = default);

This is all unfortunate that you're holding the password string in memory. Being able to take it as a ReadOnlySpan would be nicer, but requires moving the encrypt/decrypt to verbs on ZipFileEntry (which may be useful anyways, for degenerate files that use multiple different passwords).

So, short form:

  • Prefer a mode where you don't persist the password to a field.
    • If you feel you need it for high-level usability, well, I guess. So try for "in addition"
  • The encryption mode must be an input for new content. Prefer a parameter input (explicitly specified) over a property (with a default value)... because we're almost never willing to change defaults for choices that apply to persisted files.

@carlossanlop carlossanlop transferred this issue from dotnet/corefx Jan 9, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.IO.Compression untriaged New issue has not been triaged by the area owner labels Jan 9, 2020
@carlossanlop carlossanlop added api-suggestion Early API idea and discussion, it is NOT ready for implementation needs more info and removed untriaged New issue has not been triaged by the area owner labels Jan 9, 2020
@carlossanlop carlossanlop added this to the Future milestone Jan 9, 2020
@soroshsabz
Copy link
Contributor

@ghost ghost added the no-recent-activity label Dec 7, 2020
@dotnet dotnet deleted a comment Dec 7, 2020
@ghost ghost removed the no-recent-activity label Dec 7, 2020
@NgocThachThai
Copy link

We need it.

@adamsitnik adamsitnik added the Bottom Up Work Not part of a theme, epic, or user story label Aug 11, 2021
@adamsitnik
Copy link
Member

@jeffhandley @danmoseley I think it's a good .NET 7 candidate for the "Bottom Up" initiative

@danmoseley
Copy link
Member

Could well be. That's what the 7.0 milestone is for.

@adamsitnik adamsitnik modified the milestones: Future, 7.0.0 Aug 11, 2021
@cgountanis
Copy link

So... can we extract Zips with passwords yet? .NET6-8+

@SuhasParameshwara
Copy link

So we have to use third party library?

@wakuflair
Copy link

Can't believe this issue is still open

@dos-ise
Copy link

dos-ise commented May 16, 2024

dotnetzip is now no longer maintained. And this feature is still not implemented.
This missing feature is still blocking us from using System.IO.Compression.

https://github.com/haf/DotNetZip.Semverd

@tts-sdrissen
Copy link

need this, too

@peter0302

This comment was marked as abuse.

@cgountanis
Copy link

cgountanis commented Jul 9, 2024 via email

@sladecurtis
Copy link

Need this also!
So basic a concept.. please implement in near future.
My use case: SOC junior analysts attempting to take potentially malicious files off a machine that threw an endpoint alert in Azure. We want them to zip and password protect the malicious file and download from a Defender Live Response Session. Currently this cannot be done. Zip is a good start, but all potentially malicious files should be password protected too (standard malware handling procedures). We've tested and cannot even install other modules from a live response session, so it needs to be native to powershell cmdlets. Thanks.

@StarWars999123
Copy link

StarWars999123 commented Jul 19, 2024

@SteveL-MSFT Is there any update to put it on the roadmap by Microsoft?
What about implementations for the legacy .net framework support for NET472, NET48, and NET6 that could previously rely on the maintained DotNetZip library? IMHO this isn't something to be planned for NET9 or whatever, but something that needs to support even the old frameworks asap.

I don't wanna express my honest thoughts regarding this issue, but lets say @peter0302 kept it very polite...

@peter0302
Copy link

peter0302 commented Jul 19, 2024

I don't wanna express my honest thoughts regarding this issue, but lets say @peter0302 kept it very polite...

LOL they marked my comment as abuse. Imagine if I'd expressed my honest thoughts.

The format also has some strong encryption support but it's copyrighted so out of bounds for us.

First it's a patent not a copyright:

https://ppubs.uspto.gov/dirsearch-public/print/downloadPdf/11461487

Priority date is July 16, 2003 with a 242 day administrative extension, plus a 20 year term. That's March 14, 2024, meaning the patent is expired.

Patent gone, carry on. Time to implement this.

@chosh-capa
Copy link

chosh-capa commented Jul 19, 2024

You have to be freakin kidding me. I just was about to add password support and started looking for ZipArchive constructor overloads that took a password, and not finding one, Googled it. This is the last thing I expected to see. What on earth is wrong with you people? How can this not be part of .NET's built-in Zip support? I don't even know what to say.

Absolutely the same feeling.
The support for compressed archive formats is probably the worst part of the .Net experience.

I hope they can prioritize these fundamental experiences that have been missing for decades, so that we can love the .NET ecosystem even more.

@sladecurtis
Copy link

sladecurtis commented Jul 19, 2024 via email

@PracticalCode
Copy link

Above, and almost 8 years ago, ianhays commented [on Nov 3, 2016] @lburkovsky take a look at this issue for a good example of the kind of API proposal that we're looking for. In general, the more implementation details, the better. You can also look at our API Review process doc...

Does anyone know if this was completed?.. (or still relevant in MS processes?) ... while I disagree this should be the reason why this is held up; it's also kinda sad if no one's completed it in almost 8 years. (I'm willing to.. presuming it's still a relevant process.)

@sladecurtis
Copy link

sladecurtis commented Jul 24, 2024 via email

@peter0302
Copy link

Super bummed. This not even possible then?

It's 100% possible. Ionic supported it. The only understandable reason it appears MS didn't initially support it was the patent, which is now expired. So there's no reason not to do it now.

@sladecurtis
Copy link

sladecurtis commented Jul 24, 2024 via email

@NerLOR
Copy link

NerLOR commented Jul 24, 2024

I would suggest an API like this:

public enum ZipEncryptionMode { Unknown, WinZipAes128, WinZipAes192, WinZipAes256 }

public class ZipFile
{
    // current
    public ZipArchiveEntry? GetEntry(string entryName);
    public ZipArchiveEntry CreateEntry(string entryName);
    public ZipArchiveEntry CreateEntry(string entryName, CompressionLevel compressionLevel);
    // suggestion
    public ZipArchiveEntry? GetEntry(string entryName, string? password, bool failIfUnencrypted = false);
    public ZipArchiveEntry CreateEntry(string entryName, ZipEncryptionMode encryptionMode, string password);
    public ZipArchiveEntry CreateEntry(string entryName, CompressionLevel compressionLevel, ZipEncryptionMode encryptionMode, string password);
}

public enum ZipCompressionMethod { Unknown, Store, Deflate, ... }

public class ZipArchiveEntry
{
    // suggestion
    public ZipEncryptionMode EncryptionMode { get; }
    // additional suggestion
    public ZipCompressionMethod CompressionMethod { get; }
}

This allows for each entry to have a different (or no) password (which the WinZip standard allows). The enum values ZipEncryptionMode.WinzipAes256 and so on allow to implement encryption modes other than WinZip in the future.

When decrypting the password alone should be enough (because the encryption mode is saved in the zip archive). When failIfUnencrypted is true GetEntry should throw an exception if the entry is not encrypted. GetEntry should also throw an exception when the wrong password is provided (or the encryption method is unknown).

I think it would be beneficial to allow users to check the EncryptionMode or CompressionMethod used in a ZipArchiveEntry. This would allow for (simple) security checks (like to prohibit unsafe encryption modes or compression methods).

Any comments on my suggestions are appreciated.

http://www.winzip.com/aes_info.htm

@StarWars999123
Copy link

I would really appreciate your idea to encrypt each entry with a different password/method as DotNetZip also did.

@StarWars999123
Copy link

Regarding this API approach (#1545 (comment)), I would like to add, that the support of BasicEncryption would be useful and would like to add it to ZipEncryptionMode.
Reason: It's the only encryption, that the WindowsExplorer supports so far, and as thus, it can be useful for files that should not be accessible for everyone immedeatly, but can be opened with the default tools.

@Matthias-Heinz
Copy link

Any estimate, when this feature will be implemented? Passwords are a pretty common use-case for zip archives in my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO.Compression
Projects
None yet
Development

No branches or pull requests