@@ -388,6 +388,7 @@ public void EnsureCreateHttpsCertificate_ReturnsExpiredCertificateIfVersionIsInc
388
388
ListCertificates ( ) ;
389
389
390
390
_manager . AspNetHttpsCertificateVersion = 2 ;
391
+ _manager . MinimumAspNetHttpsCertificateVersion = 2 ;
391
392
392
393
var httpsCertificateList = _manager . ListCertificates ( StoreName . My , StoreLocation . CurrentUser , isValid : true ) ;
393
394
Assert . Empty ( httpsCertificateList ) ;
@@ -400,17 +401,40 @@ public void EnsureCreateHttpsCertificate_ReturnsExpiredCertificateForEmptyVersio
400
401
401
402
var now = DateTimeOffset . UtcNow ;
402
403
now = new DateTimeOffset ( now . Year , now . Month , now . Day , now . Hour , now . Minute , now . Second , 0 , now . Offset ) ;
404
+ _manager . MinimumAspNetHttpsCertificateVersion = 0 ;
403
405
_manager . AspNetHttpsCertificateVersion = 0 ;
404
406
var creation = _manager . EnsureAspNetCoreHttpsDevelopmentCertificate ( now , now . AddYears ( 1 ) , path : null , trust : false , isInteractive : false ) ;
405
407
Output . WriteLine ( creation . ToString ( ) ) ;
406
408
ListCertificates ( ) ;
407
409
408
410
_manager . AspNetHttpsCertificateVersion = 1 ;
411
+ _manager . MinimumAspNetHttpsCertificateVersion = 1 ;
409
412
410
413
var httpsCertificateList = _manager . ListCertificates ( StoreName . My , StoreLocation . CurrentUser , isValid : true ) ;
411
414
Assert . Empty ( httpsCertificateList ) ;
412
415
}
413
416
417
+ [ ConditionalFact ]
418
+ [ SkipOnHelix ( "https://github.com/dotnet/aspnetcore/issues/6720" , Queues = "All.OSX" ) ]
419
+ public void EnsureCreateHttpsCertificate_DoNotOverrideValidOldCertificate ( )
420
+ {
421
+ _fixture . CleanupCertificates ( ) ;
422
+
423
+ var now = DateTimeOffset . UtcNow ;
424
+ now = new DateTimeOffset ( now . Year , now . Month , now . Day , now . Hour , now . Minute , now . Second , 0 , now . Offset ) ;
425
+ var creation = _manager . EnsureAspNetCoreHttpsDevelopmentCertificate ( now , now . AddYears ( 1 ) , path : null , trust : false , isInteractive : false ) ;
426
+ Output . WriteLine ( creation . ToString ( ) ) ;
427
+ ListCertificates ( ) ;
428
+
429
+ // Simulate a tool with the same min version as the already existing cert but with a more
430
+ // recent generation version
431
+ _manager . MinimumAspNetHttpsCertificateVersion = 1 ;
432
+ _manager . AspNetHttpsCertificateVersion = 2 ;
433
+ var alreadyExist = _manager . EnsureAspNetCoreHttpsDevelopmentCertificate ( now , now . AddYears ( 1 ) , path : null , trust : false , isInteractive : false ) ;
434
+ Output . WriteLine ( alreadyExist . ToString ( ) ) ;
435
+ Assert . Equal ( EnsureCertificateResult . ValidCertificatePresent , alreadyExist ) ;
436
+ }
437
+
414
438
[ ConditionalFact ]
415
439
[ SkipOnHelix ( "https://github.com/dotnet/aspnetcore/issues/6720" , Queues = "All.OSX" ) ]
416
440
public void EnsureCreateHttpsCertificate_ReturnsValidIfVersionIsZero ( )
@@ -419,7 +443,7 @@ public void EnsureCreateHttpsCertificate_ReturnsValidIfVersionIsZero()
419
443
420
444
var now = DateTimeOffset . UtcNow ;
421
445
now = new DateTimeOffset ( now . Year , now . Month , now . Day , now . Hour , now . Minute , now . Second , 0 , now . Offset ) ;
422
- _manager . AspNetHttpsCertificateVersion = 0 ;
446
+ _manager . MinimumAspNetHttpsCertificateVersion = 0 ;
423
447
var creation = _manager . EnsureAspNetCoreHttpsDevelopmentCertificate ( now , now . AddYears ( 1 ) , path : null , trust : false , isInteractive : false ) ;
424
448
Output . WriteLine ( creation . ToString ( ) ) ;
425
449
ListCertificates ( ) ;
@@ -441,7 +465,7 @@ public void EnsureCreateHttpsCertificate_ReturnValidIfCertIsNewer()
441
465
Output . WriteLine ( creation . ToString ( ) ) ;
442
466
ListCertificates ( ) ;
443
467
444
- _manager . AspNetHttpsCertificateVersion = 1 ;
468
+ _manager . MinimumAspNetHttpsCertificateVersion = 1 ;
445
469
var httpsCertificateList = _manager . ListCertificates ( StoreName . My , StoreLocation . CurrentUser , isValid : true ) ;
446
470
Assert . NotEmpty ( httpsCertificateList ) ;
447
471
}
@@ -455,16 +479,24 @@ public void ListCertificates_AlwaysReturnsTheCertificate_WithHighestVersion()
455
479
var now = DateTimeOffset . UtcNow ;
456
480
now = new DateTimeOffset ( now . Year , now . Month , now . Day , now . Hour , now . Minute , now . Second , 0 , now . Offset ) ;
457
481
_manager . AspNetHttpsCertificateVersion = 1 ;
482
+ _manager . MinimumAspNetHttpsCertificateVersion = 1 ;
458
483
var creation = _manager . EnsureAspNetCoreHttpsDevelopmentCertificate ( now , now . AddYears ( 1 ) , path : null , trust : false , isInteractive : false ) ;
459
484
Output . WriteLine ( creation . ToString ( ) ) ;
460
485
ListCertificates ( ) ;
461
486
462
487
_manager . AspNetHttpsCertificateVersion = 2 ;
488
+ _manager . MinimumAspNetHttpsCertificateVersion = 2 ;
463
489
creation = _manager . EnsureAspNetCoreHttpsDevelopmentCertificate ( now , now . AddYears ( 1 ) , path : null , trust : false , isInteractive : false ) ;
464
490
Output . WriteLine ( creation . ToString ( ) ) ;
465
491
ListCertificates ( ) ;
466
492
467
- _manager . AspNetHttpsCertificateVersion = 1 ;
493
+ _manager . AspNetHttpsCertificateVersion = 3 ;
494
+ _manager . MinimumAspNetHttpsCertificateVersion = 3 ;
495
+ creation = _manager . EnsureAspNetCoreHttpsDevelopmentCertificate ( now , now . AddYears ( 1 ) , path : null , trust : false , isInteractive : false ) ;
496
+ Output . WriteLine ( creation . ToString ( ) ) ;
497
+ ListCertificates ( ) ;
498
+
499
+ _manager . MinimumAspNetHttpsCertificateVersion = 2 ;
468
500
var httpsCertificateList = _manager . ListCertificates ( StoreName . My , StoreLocation . CurrentUser , isValid : true ) ;
469
501
Assert . Equal ( 2 , httpsCertificateList . Count ) ;
470
502
@@ -475,13 +507,13 @@ public void ListCertificates_AlwaysReturnsTheCertificate_WithHighestVersion()
475
507
firstCertificate . Extensions . OfType < X509Extension > ( ) ,
476
508
e => e . Critical == false &&
477
509
e . Oid . Value == CertificateManager . AspNetHttpsOid &&
478
- e . RawData [ 0 ] == 2 ) ;
510
+ e . RawData [ 0 ] == 3 ) ;
479
511
480
512
Assert . Contains (
481
513
secondCertificate . Extensions . OfType < X509Extension > ( ) ,
482
514
e => e . Critical == false &&
483
515
e . Oid . Value == CertificateManager . AspNetHttpsOid &&
484
- e . RawData [ 0 ] == 1 ) ;
516
+ e . RawData [ 0 ] == 2 ) ;
485
517
}
486
518
487
519
[ ConditionalFact ]
@@ -532,6 +564,8 @@ public CertFixture()
532
564
533
565
internal void CleanupCertificates ( )
534
566
{
567
+ Manager . MinimumAspNetHttpsCertificateVersion = 1 ;
568
+ Manager . AspNetHttpsCertificateVersion = 1 ;
535
569
Manager . RemoveAllCertificates ( StoreName . My , StoreLocation . CurrentUser ) ;
536
570
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) || RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
537
571
{
0 commit comments