-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Avoid rooting cryptography through ZipArchive on browser #130688
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: main
Are you sure you want to change the base?
Changes from all commits
8cf8ad5
c315ffb
119fe70
7ad6074
88e7cf0
84240f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace System.IO.Compression | ||
| { | ||
| internal readonly struct WinZipAesKeyMaterial; | ||
|
|
||
| internal static class WinZipAesStream | ||
| { | ||
|
Comment on lines
+7
to
+12
|
||
| internal static int GetSaltSize(int keySizeBits) => throw CreateException(); | ||
|
|
||
| internal static WinZipAesKeyMaterial CreateKey(ReadOnlySpan<char> password, byte[]? salt, int keySizeBits) => throw CreateException(); | ||
|
|
||
| internal static Stream Create(Stream baseStream, WinZipAesKeyMaterial keyMaterial, long totalStreamSize, bool encrypting, bool leaveOpen = false) => throw CreateException(); | ||
|
|
||
| internal static Task<Stream> CreateAsync(Stream baseStream, WinZipAesKeyMaterial keyMaterial, long totalStreamSize, bool encrypting, bool leaveOpen = false, CancellationToken cancellationToken = default) => throw CreateException(); | ||
|
|
||
| private static PlatformNotSupportedException CreateException() => new(SR.WinZipEncryptionNotSupportedOnBrowser); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |
| using System.Buffers; | ||
| using System.Buffers.Binary; | ||
| using System.Diagnostics; | ||
| using System.Security.Cryptography; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
@@ -138,7 +137,7 @@ internal static ZipCryptoKeys CreateKey(ReadOnlySpan<char> password) | |
| } | ||
| finally | ||
| { | ||
| CryptographicOperations.ZeroMemory(passwordBytes); | ||
| Array.Clear(passwordBytes); | ||
| ArrayPool<byte>.Shared.Return(passwordBytes); | ||
| } | ||
|
|
||
|
|
@@ -150,7 +149,9 @@ private void CalculateHeader(Span<byte> header) | |
| Debug.Assert(header.Length == 12); | ||
|
|
||
| // bytes 0..9 random | ||
| RandomNumberGenerator.Fill(header.Slice(0, 10)); | ||
| Span<byte> randomBytes = stackalloc byte[16]; | ||
| Guid.NewGuid().TryWriteBytes(randomBytes); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This replaces a cryptographically-secure For the legacy ZipCrypto scheme (already weak by design) this is likely acceptable in practice, and the goal of dropping the |
||
| randomBytes.Slice(0, 10).CopyTo(header); | ||
|
Comment on lines
+152
to
+154
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guid does guarantee uniqueness, not randomness, so I don't think this is good. Since ZipCrypto is broken anyway, maybe using cc @bartonjs, @GrabYourPitchforks for opinions. |
||
|
|
||
| // bytes 10..11 verifier | ||
| if (_crc32ForHeader.HasValue) | ||
|
|
||
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.
This whitespace change should be reverted