Skip to content

Commit dc6cc9e

Browse files
authored
Never attempt to process an RSA 16K key on Android
Android's Conscrypt does not appear to process RSA 16K keys. It also does not appropriately clear BoringSSL's error queue, so when you attempt to import an RSA 16K key, the error may appear elsewhere, which can produce nonsense errors. For example, attempting to import an RSA 16K key, then doing ChaCha20Poly1305 with a bad tag would raise an `java.security.InvalidKeyException: error:04000080:RSA routines:OPENSSL_internal:MODULUS_TOO_LARGE`, which is of course an incorrect exception for Cipher's ChaCha20/Poly1305 to raise. The "best" fix for this currently is to simply never touch an RSA 16K key from our unit tests. We don't have direct access to BoringSSL's error queue, so we can't manage it or inspect it to fix the problem on the RSA side. Actual APIs that clear the error queue are somewhat costly. We can investigate some of those but we are relying on side effects that may not always hold. This is the easiest fix so far that doesn't require somewhat undesirable changes in actual product code.
1 parent 92236e1 commit dc6cc9e

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ public void RsaDecryptAfterExport()
644644
Assert.Equal(TestData.HelloBytes, output);
645645
}
646646

647-
[Fact]
647+
[ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))]
648648
public void LargeKeyCryptRoundtrip()
649649
{
650650
byte[] output;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static void PaddedExport()
6969
RSATestHelpers.AssertKeyEquals(diminishedDPParameters, exported);
7070
}
7171

72-
[Fact]
72+
[ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))]
7373
public static void LargeKeyImportExport()
7474
{
7575
RSAParameters imported = TestData.RSA16384Params;
@@ -367,6 +367,13 @@ internal static RSAParameters MakePublic(in RSAParameters rsaParams)
367367

368368
private static bool TestRsa16384()
369369
{
370+
if (PlatformDetection.IsAndroid)
371+
{
372+
// We cannot detect this on Android at the moment. Even attempting to generate or import a 16K RSA key
373+
// may leave the error queue in the incorrect state. See https://github.com/google/conscrypt/issues/1507
374+
return false;
375+
}
376+
370377
try
371378
{
372379
using (RSA rsa = RSAFactory.Create())

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ public void VerifyExpectedSignature_PssSha256_RSA2048()
10221022
modulus2048Signature);
10231023
}
10241024

1025-
[Fact]
1025+
[ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))]
10261026
public void VerifyExpectedSignature_PssSha256_RSA16384()
10271027
{
10281028
byte[] modulus2048Signature = (
@@ -1098,7 +1098,7 @@ public void VerifyExpectedSignature_PssSha256_RSA16384()
10981098
modulus2048Signature);
10991099
}
11001100

1101-
[Fact]
1101+
[ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))]
11021102
public void VerifyExpectedSignature_PssSha384()
11031103
{
11041104
byte[] bigModulusSignature = (

0 commit comments

Comments
 (0)