Skip to content

Commit

Permalink
Enable skipped SSC.Algorithms tests on Andorid
Browse files Browse the repository at this point in the history
DSAKeyGeneration.GenerateSecondMinKey and DSAKeyGeneration.GenerateMinKey no longer fail.  Added validation in RSAAndroid.cs to make RSAXml.FromNonsenseXml pass.

Fixes dotnet#50580
Fixes dotnet#50581
  • Loading branch information
Steve Pfister committed Jul 29, 2021
1 parent a8dacd5 commit b80aafd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,53 @@ public override void ImportParameters(RSAParameters parameters)
ValidateParameters(ref parameters);
ThrowIfDisposed();

if (parameters.Exponent == null || parameters.Modulus == null)
{
throw new CryptographicException(SR.Cryptography_InvalidRsaParameters);
}

if (parameters.D == null)
{
if (parameters.P != null ||
parameters.DP != null ||
parameters.Q != null ||
parameters.DQ != null ||
parameters.InverseQ != null)
{
throw new CryptographicException(SR.Cryptography_InvalidRsaParameters);
}
}
else
{
if (parameters.P == null ||
parameters.DP == null ||
parameters.Q == null ||
parameters.DQ == null ||
parameters.InverseQ == null)
{
throw new CryptographicException(SR.Cryptography_InvalidRsaParameters);
}

// Half, rounded up.
int halfModulusLength = (parameters.Modulus.Length + 1) / 2;

// The same checks are done by RSACryptoServiceProvider on import (when building the key blob)
// Historically RSACng let CNG handle this (reporting NTE_NOT_SUPPORTED), but on RS1 CNG let the
// import succeed, then on private key use (e.g. signing) it would report NTE_INVALID_PARAMETER.
//
// Doing the check here prevents the state in RS1 where the Import succeeds, but corrupts the key,
// and makes for a friendlier exception message.
if (parameters.D.Length != parameters.Modulus.Length ||
parameters.P.Length != halfModulusLength ||
parameters.Q.Length != halfModulusLength ||
parameters.DP.Length != halfModulusLength ||
parameters.DQ.Length != halfModulusLength ||
parameters.InverseQ.Length != halfModulusLength)
{
throw new CryptographicException(SR.Cryptography_InvalidRsaParameters);
}
}

SafeRsaHandle key = Interop.AndroidCrypto.RsaCreate();
bool imported = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ public static void VerifyDefaultKeySize_Fips186_2()
}

[ConditionalFact(nameof(SupportsKeyGeneration))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/50580", TestPlatforms.Android)]
public static void GenerateMinKey()
{
GenerateKey(dsa => GetMin(dsa.LegalKeySizes));
}

[ConditionalFact(nameof(SupportsKeyGeneration), nameof(HasSecondMinSize))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/50580", TestPlatforms.Android)]
public static void GenerateSecondMinKey()
{
GenerateKey(dsa => GetSecondMin(dsa.LegalKeySizes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,6 @@ public static void FromInvalidXml()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/29515", TestPlatforms.OSX | TestPlatforms.Android)]
public static void FromNonsenseXml()
{
// This is DiminishedDPParameters XML, but with a P that is way too long.
Expand Down

0 comments on commit b80aafd

Please sign in to comment.