Skip to content

Commit 75cd6d8

Browse files
[Android] Remove unnecessary X509Chain memory leak test (#128493)
Follow-up to #128284 Follow-up to #128385 This PR removes an unnecessary long running unit test added in #128284 /cc @jkotas
1 parent 3be408d commit 75cd6d8

1 file changed

Lines changed: 0 additions & 77 deletions

File tree

  • src/libraries/System.Security.Cryptography/tests/X509Certificates

src/libraries/System.Security.Cryptography/tests/X509Certificates/ChainTests.cs

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Linq;
7-
using System.Security.Cryptography.X509Certificates.Tests.Common;
87
using System.Text;
98
using System.Threading;
109
using Test.Cryptography;
@@ -377,82 +376,6 @@ public static void BuildChainCustomTrustStore(
377376
}
378377
}
379378

380-
[PlatformSpecific(TestPlatforms.Android)]
381-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotInHelix))]
382-
public static void BuildChainRepeatedly_DoesNotExhaustGlobalReferences()
383-
{
384-
// Android aborts the process when its JNI global reference table overflows. This
385-
// 6-certificate chain leaks 6 JNI global refs per successful build without the Android
386-
// PAL cleanup, so 8,600 builds would leak 51,600 certificate refs. 8,400 iterations
387-
// completed without the fix during threshold testing, while 8,500 iterations crashed
388-
// with "global reference table overflow (max=51200)".
389-
// This tests runs for ~10 minutes on an Android emulator.
390-
const int Iterations = 8_600;
391-
392-
CertificateAuthority.BuildPrivatePki(
393-
PkiOptions.AllRevocation,
394-
out RevocationResponder responder,
395-
out CertificateAuthority root,
396-
out CertificateAuthority[] intermediates,
397-
out X509Certificate2 endCert,
398-
intermediateAuthorityCount: 4,
399-
registerAuthorities: false,
400-
keyFactory: CertificateAuthority.KeyFactory.RSASize(2048));
401-
402-
using (responder)
403-
using (root)
404-
using (CertificateAuthority intermediate1 = intermediates[0])
405-
using (CertificateAuthority intermediate2 = intermediates[1])
406-
using (CertificateAuthority intermediate3 = intermediates[2])
407-
using (CertificateAuthority intermediate4 = intermediates[3])
408-
using (endCert)
409-
using (ImportedCollection issuerHolder = new ImportedCollection(new X509Certificate2Collection
410-
{
411-
intermediate4.CloneIssuerCert(),
412-
intermediate3.CloneIssuerCert(),
413-
intermediate2.CloneIssuerCert(),
414-
intermediate1.CloneIssuerCert(),
415-
root.CloneIssuerCert(),
416-
}))
417-
using (ChainHolder chainHolder = new ChainHolder())
418-
{
419-
X509Certificate2Collection issuers = issuerHolder.Collection;
420-
X509Chain chain = CreateChain(chainHolder, endCert, issuers);
421-
422-
// Each successful Android chain build materializes the chain from caller-owned JNI
423-
// global references. Without releasing those native-returned references, this
424-
// sequential public-API loop eventually exhausts Android process resources.
425-
for (int i = 0; i < Iterations; i++)
426-
{
427-
if (!chain.Build(endCert))
428-
{
429-
Assert.Fail($"Chain build failed on iteration {i} with '{chain.AllStatusFlags()}'.");
430-
}
431-
432-
if (i == 0)
433-
{
434-
Assert.Equal(issuers.Count + 1, chain.ChainElements.Count);
435-
}
436-
437-
chainHolder.DisposeChainElements();
438-
}
439-
}
440-
441-
static X509Chain CreateChain(ChainHolder chainHolder, X509Certificate2 endCert, X509Certificate2Collection issuers)
442-
{
443-
X509Chain chain = chainHolder.Chain;
444-
445-
chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
446-
chain.ChainPolicy.VerificationTime = endCert.NotBefore.AddSeconds(1);
447-
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
448-
chain.ChainPolicy.DisableCertificateDownloads = true;
449-
chain.ChainPolicy.ExtraStore.AddRange(issuers);
450-
chain.ChainPolicy.CustomTrustStore.Add(issuers[issuers.Count - 1]);
451-
452-
return chain;
453-
}
454-
}
455-
456379
[Fact]
457380
public static void BuildChainWithSystemTrustAndCustomTrustCertificates()
458381
{

0 commit comments

Comments
 (0)