Skip to content

Commit a7f258b

Browse files
authored
Disable MD5 tests on Azure Linux
1 parent 1a305e6 commit a7f258b

File tree

11 files changed

+40
-14
lines changed

11 files changed

+40
-14
lines changed

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public interface IRSAProvider
1212
bool SupportsSha2Oaep { get; }
1313
bool SupportsPss { get; }
1414
bool SupportsSha1Signatures { get; }
15+
bool SupportsMd5Signatures { get; }
1516
bool SupportsSha3 { get; }
1617
}
1718

@@ -43,6 +44,7 @@ public static RSA Create(RSAParameters rsaParameters)
4344
public static bool SupportsPss => s_provider.SupportsPss;
4445

4546
public static bool SupportsSha1Signatures => s_provider.SupportsSha1Signatures;
47+
public static bool SupportsMd5Signatures => s_provider.SupportsMd5Signatures;
4648

4749
public static bool SupportsSha3 => s_provider.SupportsSha3;
4850
public static bool NoSupportsSha3 => !SupportsSha3;

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,11 @@ public static IEnumerable<object[]> RoundTripTheories
600600
yield return new object[] { nameof(HashAlgorithmName.SHA1), rsaParameters };
601601
}
602602

603-
yield return new object[] { nameof(HashAlgorithmName.MD5), rsaParameters };
603+
if (RSAFactory.SupportsMd5Signatures)
604+
{
605+
yield return new object[] { nameof(HashAlgorithmName.MD5), rsaParameters };
606+
}
607+
604608
yield return new object[] { nameof(HashAlgorithmName.SHA256), rsaParameters };
605609
}
606610

@@ -1589,7 +1593,11 @@ public static IEnumerable<object[]> HashAlgorithmNames
15891593
yield return new object[] { HashAlgorithmName.SHA256.Name };
15901594
yield return new object[] { HashAlgorithmName.SHA384.Name };
15911595
yield return new object[] { HashAlgorithmName.SHA512.Name };
1592-
yield return new object[] { HashAlgorithmName.MD5.Name };
1596+
1597+
if (RSAFactory.SupportsMd5Signatures)
1598+
{
1599+
yield return new object[] { HashAlgorithmName.MD5.Name };
1600+
}
15931601

15941602
if (RSAFactory.SupportsSha1Signatures)
15951603
{

src/libraries/Common/tests/System/Security/Cryptography/SignatureSupport.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ namespace System.Security.Cryptography.Tests
55
{
66
internal static class SignatureSupport
77
{
8-
internal static bool CanProduceSha1Signature(AsymmetricAlgorithm algorithm)
8+
internal static bool CanProduceSha1Signature(AsymmetricAlgorithm algorithm) => CanProduceSignature(algorithm, HashAlgorithmName.SHA1);
9+
internal static bool CanProduceMd5Signature(AsymmetricAlgorithm algorithm) => CanProduceSignature(algorithm, HashAlgorithmName.MD5);
10+
11+
private static bool CanProduceSignature(AsymmetricAlgorithm algorithm, HashAlgorithmName hashAlgorithmName)
912
{
1013
using (algorithm)
1114
{
1215
#if NETFRAMEWORK
1316
return true;
1417
#else
15-
// We expect all non-Linux platforms to support SHA1 signatures, currently.
18+
// We expect all non-Linux platforms to support any signatures, currently.
1619
if (!OperatingSystem.IsLinux())
1720
{
1821
return true;
@@ -23,7 +26,7 @@ internal static bool CanProduceSha1Signature(AsymmetricAlgorithm algorithm)
2326
case ECDsa ecdsa:
2427
try
2528
{
26-
ecdsa.SignData(Array.Empty<byte>(), HashAlgorithmName.SHA1);
29+
ecdsa.SignData(Array.Empty<byte>(), hashAlgorithmName);
2730
return true;
2831
}
2932
catch (CryptographicException)
@@ -33,7 +36,7 @@ internal static bool CanProduceSha1Signature(AsymmetricAlgorithm algorithm)
3336
case RSA rsa:
3437
try
3538
{
36-
rsa.SignData(Array.Empty<byte>(), HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
39+
rsa.SignData(Array.Empty<byte>(), hashAlgorithmName, RSASignaturePadding.Pkcs1);
3740
return true;
3841
}
3942
catch (CryptographicException)

src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static partial class PlatformDetection
2828
public static bool IsFedora => IsDistroAndVersion("fedora");
2929
public static bool IsLinuxBionic => IsBionic();
3030
public static bool IsRedHatFamily => IsRedHatFamilyAndVersion();
31+
public static bool IsAzureLinux => IsDistroAndVersionOrHigher("azurelinux", 3);
3132

3233
public static bool IsMonoLinuxArm64 => IsMonoRuntime && IsLinux && IsArm64Process;
3334
public static bool IsNotMonoLinuxArm64 => !IsMonoLinuxArm64;

src/libraries/System.Security.Cryptography.Cng/tests/RSACngProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public bool Supports384PrivateKey
3737

3838
public bool SupportsSha1Signatures => true;
3939

40+
public bool SupportsMd5Signatures => true;
41+
4042
public bool SupportsSha3 { get; } = SHA3_256.IsSupported; // If SHA3_256 is supported, assume 384 and 512 are, too.
4143
}
4244

src/libraries/System.Security.Cryptography.Csp/tests/RSACryptoServiceProviderBackCompat.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,12 @@ public static void VerifyLegacySignVerifyHash(bool useLegacySign, bool useLegacy
156156

157157
public static IEnumerable<object[]> AlgorithmIdentifiers()
158158
{
159-
yield return new object[] { "MD5", MD5.Create() };
160-
yield return new object[] { "MD5", typeof(MD5) };
161-
yield return new object[] { "MD5", "1.2.840.113549.2.5" };
159+
if (RSAFactory.SupportsMd5Signatures)
160+
{
161+
yield return new object[] { "MD5", MD5.Create() };
162+
yield return new object[] { "MD5", typeof(MD5) };
163+
yield return new object[] { "MD5", "1.2.840.113549.2.5" };
164+
}
162165

163166
if (RSAFactory.SupportsSha1Signatures)
164167
{

src/libraries/System.Security.Cryptography.Csp/tests/RSACryptoServiceProviderProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace System.Security.Cryptography.Rsa.Tests
99
public class RSACryptoServiceProviderProvider : IRSAProvider
1010
{
1111
private bool? _supportsSha1Signatures;
12+
private bool? _supportsMd5Signatures;
1213

1314
public RSA Create() => new RSACryptoServiceProvider();
1415

@@ -23,6 +24,7 @@ public class RSACryptoServiceProviderProvider : IRSAProvider
2324
public bool SupportsPss => false;
2425

2526
public bool SupportsSha1Signatures => _supportsSha1Signatures ??= SignatureSupport.CanProduceSha1Signature(Create());
27+
public bool SupportsMd5Signatures => _supportsMd5Signatures ??= SignatureSupport.CanProduceMd5Signature(Create());
2628

2729
public bool SupportsSha3 => false;
2830
}

src/libraries/System.Security.Cryptography.OpenSsl/tests/RSAOpenSslProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace System.Security.Cryptography.Rsa.Tests
88
public class RSAOpenSslProvider : IRSAProvider
99
{
1010
private bool? _supportsSha1Signatures;
11+
private bool? _supportsMd5Signatures;
1112

1213
public RSA Create() => new RSAOpenSsl();
1314

@@ -22,6 +23,7 @@ public class RSAOpenSslProvider : IRSAProvider
2223
public bool SupportsPss => true;
2324

2425
public bool SupportsSha1Signatures => _supportsSha1Signatures ??= SignatureSupport.CanProduceSha1Signature(Create());
26+
public bool SupportsMd5Signatures => _supportsMd5Signatures ??= SignatureSupport.CanProduceMd5Signature(Create());
2527

2628
public bool SupportsSha3 => SHA3_256.IsSupported; // If SHA3_256 is supported, assume 384 and 512 are, too.
2729
}

src/libraries/System.Security.Cryptography/tests/DefaultRSAProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class DefaultRSAProvider : IRSAProvider
1010
{
1111
private bool? _supports384PrivateKey;
1212
private bool? _supportsSha1Signatures;
13+
private bool? _supportsMd5Signatures;
1314

1415
public RSA Create() => RSA.Create();
1516

@@ -41,6 +42,7 @@ public bool Supports384PrivateKey
4142
}
4243

4344
public bool SupportsSha1Signatures => _supportsSha1Signatures ??= SignatureSupport.CanProduceSha1Signature(Create());
45+
public bool SupportsMd5Signatures => _supportsMd5Signatures ??= SignatureSupport.CanProduceMd5Signature(Create());
4446

4547
public bool SupportsLargeExponent => true;
4648

src/libraries/System.Security.Cryptography/tests/HKDFTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public abstract class HKDFTests
1414
protected abstract byte[] Expand(HashAlgorithmName hash, byte[] prk, int outputLength, byte[] info);
1515
protected abstract byte[] DeriveKey(HashAlgorithmName hash, byte[] ikm, int outputLength, byte[] salt, byte[] info);
1616

17+
internal static bool MD5Supported => !PlatformDetection.IsBrowser && !PlatformDetection.IsAzureLinux;
18+
1719
[Theory]
1820
[MemberData(nameof(GetHkdfTestCases))]
1921
public void ExtractTests(HkdfTestCase test)
@@ -22,9 +24,8 @@ public void ExtractTests(HkdfTestCase test)
2224
Assert.Equal(test.Prk, prk);
2325
}
2426

25-
[Theory]
27+
[ConditionalTheory(nameof(MD5Supported))]
2628
[MemberData(nameof(GetHkdfTestCases))]
27-
[SkipOnPlatform(TestPlatforms.Browser, "MD5 is not supported on Browser")]
2829
public void ExtractTamperHashTests(HkdfTestCase test)
2930
{
3031
byte[] prk = Extract(HashAlgorithmName.MD5, 128 / 8, test.Ikm, test.Salt);
@@ -257,7 +258,7 @@ public static IEnumerable<object[]> GetPrkTooShortTestCases()
257258
yield return new object[] { HashAlgorithmName.SHA256, 256 / 8 - 1 };
258259
yield return new object[] { HashAlgorithmName.SHA512, 512 / 8 - 1 };
259260

260-
if (!PlatformDetection.IsBrowser)
261+
if (MD5Supported)
261262
{
262263
yield return new object[] { HashAlgorithmName.MD5, 128 / 8 - 1 };
263264
}

0 commit comments

Comments
 (0)