Skip to content

Commit 4f7a096

Browse files
authored
Remove AES and SubtleCrypto from WASM (#74165)
* Revert 6a02d5d * Revert relevant parts of 4222e69 and AES pieces of 8f75cc9 * Remove Subtle Crypto interop code Fix #73858
1 parent 304ee17 commit 4f7a096

File tree

62 files changed

+683
-3445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+683
-3445
lines changed

eng/liveBuilds.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@
179179
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'Browser'"
180180
Include="
181181
$(LibrariesNativeArtifactsPath)dotnet.js;
182-
$(LibrariesNativeArtifactsPath)src\dotnet-crypto-worker.js;
183182
$(LibrariesNativeArtifactsPath)dotnet.d.ts;
184183
$(LibrariesNativeArtifactsPath)dotnet-legacy.d.ts;
185184
$(LibrariesNativeArtifactsPath)package.json;

src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Apple.dylib" IsNative="true" />
9696
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Android.a" IsNative="true" />
9797
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Android.so" IsNative="true" />
98-
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Browser.a" IsNative="true" />
9998
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.a" IsNative="true" />
10099
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.dylib" IsNative="true" />
101100
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.so" IsNative="true" />
@@ -220,7 +219,6 @@
220219
<PlatformManifestFileEntry Include="libmono-profiler-aot.a" IsNative="true" />
221220
<PlatformManifestFileEntry Include="libmono-wasm-eh-js.a" IsNative="true" />
222221
<PlatformManifestFileEntry Include="libmono-wasm-eh-wasm.a" IsNative="true" />
223-
<PlatformManifestFileEntry Include="dotnet-crypto-worker.js" IsNative="true" />
224222
<PlatformManifestFileEntry Include="dotnet.js" IsNative="true" />
225223
<PlatformManifestFileEntry Include="dotnet.worker.js" IsNative="true" />
226224
<PlatformManifestFileEntry Include="dotnet.js.symbols" IsNative="true" />

src/libraries/Common/src/Interop/Browser/Interop.Libraries.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ internal static partial class Libraries
77
{
88
// Shims
99
internal const string SystemNative = "libSystem.Native";
10-
internal const string CryptoNative = "libSystem.Security.Cryptography.Native.Browser";
1110
}
1211
}

src/libraries/Common/src/Interop/Browser/System.Security.Cryptography.Native.Browser/Interop.SubtleCrypto.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/libraries/Common/src/System/Security/Cryptography/Helpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Internal.Cryptography
1111
internal static partial class Helpers
1212
{
1313
[UnsupportedOSPlatformGuard("browser")]
14-
internal static bool HasNonAesSymmetricEncryption =>
14+
internal static bool HasSymmetricEncryption { get; } =
1515
#if NETCOREAPP
1616
!OperatingSystem.IsBrowser();
1717
#else

src/libraries/Common/src/System/Security/Cryptography/PasswordBasedEncryption.cs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,19 @@ internal static unsafe int Decrypt(
7474
{
7575
Debug.Assert(destination.Length >= encryptedData.Length);
7676

77-
// Don't check that algorithmIdentifier.Parameters is set here.
78-
// Maybe some future PBES3 will have one with a default.
79-
80-
if (algorithmIdentifier.Algorithm == Oids.PasswordBasedEncryptionScheme2)
81-
{
82-
return Pbes2Decrypt(
83-
algorithmIdentifier.Parameters,
84-
password,
85-
passwordBytes,
86-
encryptedData,
87-
destination);
88-
}
89-
90-
if (!Helpers.HasNonAesSymmetricEncryption)
77+
if (!Helpers.HasSymmetricEncryption)
9178
{
9279
throw new CryptographicException(
9380
SR.Format(
9481
SR.Cryptography_UnknownAlgorithmIdentifier,
9582
algorithmIdentifier.Algorithm));
9683
}
9784

85+
// Don't check that algorithmIdentifier.Parameters is set here.
86+
// Maybe some future PBES3 will have one with a default.
87+
9888
HashAlgorithmName digestAlgorithmName;
99-
SymmetricAlgorithm cipher;
89+
SymmetricAlgorithm? cipher = null;
10090

10191
bool pkcs12 = false;
10292

@@ -141,6 +131,13 @@ internal static unsafe int Decrypt(
141131
cipher.KeySize = 40;
142132
pkcs12 = true;
143133
break;
134+
case Oids.PasswordBasedEncryptionScheme2:
135+
return Pbes2Decrypt(
136+
algorithmIdentifier.Parameters,
137+
password,
138+
passwordBytes,
139+
encryptedData,
140+
destination);
144141
default:
145142
throw new CryptographicException(
146143
SR.Format(
@@ -149,6 +146,7 @@ internal static unsafe int Decrypt(
149146
}
150147

151148
Debug.Assert(digestAlgorithmName.Name != null);
149+
Debug.Assert(cipher != null);
152150

153151
using (cipher)
154152
{
@@ -239,6 +237,14 @@ internal static void InitiateEncryption(
239237
{
240238
Debug.Assert(pbeParameters != null);
241239

240+
if (!Helpers.HasSymmetricEncryption)
241+
{
242+
throw new CryptographicException(
243+
SR.Format(
244+
SR.Cryptography_UnknownAlgorithmIdentifier,
245+
pbeParameters.EncryptionAlgorithm));
246+
}
247+
242248
isPkcs12 = false;
243249

244250
switch (pbeParameters.EncryptionAlgorithm)
@@ -258,7 +264,7 @@ internal static void InitiateEncryption(
258264
cipher.KeySize = 256;
259265
encryptionAlgorithmOid = Oids.Aes256Cbc;
260266
break;
261-
case PbeEncryptionAlgorithm.TripleDes3KeyPkcs12 when Helpers.HasNonAesSymmetricEncryption:
267+
case PbeEncryptionAlgorithm.TripleDes3KeyPkcs12:
262268
cipher = TripleDES.Create();
263269
cipher.KeySize = 192;
264270
encryptionAlgorithmOid = Oids.Pkcs12PbeWithShaAnd3Key3Des;
@@ -566,6 +572,12 @@ private static SymmetricAlgorithm OpenCipher(
566572
{
567573
string? algId = encryptionScheme.Algorithm;
568574

575+
if (!Helpers.HasSymmetricEncryption)
576+
{
577+
throw new CryptographicException(
578+
SR.Format(SR.Cryptography_AlgorithmNotSupported, algId));
579+
}
580+
569581
if (algId == Oids.Aes128Cbc ||
570582
algId == Oids.Aes192Cbc ||
571583
algId == Oids.Aes256Cbc)
@@ -604,12 +616,6 @@ private static SymmetricAlgorithm OpenCipher(
604616
return aes;
605617
}
606618

607-
if (!Helpers.HasNonAesSymmetricEncryption)
608-
{
609-
throw new CryptographicException(
610-
SR.Format(SR.Cryptography_AlgorithmNotSupported, algId));
611-
}
612-
613619
if (algId == Oids.TripleDesCbc)
614620
{
615621
// https://tools.ietf.org/html/rfc8018#appendix-B.2.2

0 commit comments

Comments
 (0)