|
4 | 4 | using System.Collections.Generic; |
5 | 5 | using System.IO; |
6 | 6 | using System.Linq; |
7 | | -using System.Security.Cryptography.X509Certificates.Tests.Common; |
8 | 7 | using System.Text; |
9 | 8 | using System.Threading; |
10 | 9 | using Test.Cryptography; |
@@ -377,82 +376,6 @@ public static void BuildChainCustomTrustStore( |
377 | 376 | } |
378 | 377 | } |
379 | 378 |
|
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 | | - |
456 | 379 | [Fact] |
457 | 380 | public static void BuildChainWithSystemTrustAndCustomTrustCertificates() |
458 | 381 | { |
|
0 commit comments