Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/Aspire.Hosting/DeveloperCertificateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@ public DeveloperCertificateService(ILogger<DeveloperCertificateService> logger,
// so we want to ensure the certificate that will be used by ASP.NET Core is the first one in the bundle.
// Match the ordering logic ASP.NET Core uses, including DateTimeOffset.Now for current time: https://github.com/dotnet/aspnetcore/blob/0aefdae365ff9b73b52961acafd227309524ce3c/src/Shared/CertificateGeneration/CertificateManager.cs#L122
var now = DateTimeOffset.Now;

// Get all valid ASP.NET Core development certificates
var validCerts = store.Certificates
.Where(c => c.IsAspNetCoreDevelopmentCertificate())
.Where(c => c.NotBefore <= now && now <= c.NotAfter)
.ToList();

// If any certificate has a Subject Key Identifier extension, exclude certificates without it
if (validCerts.Any(c => c.HasSubjectKeyIdentifier()))
{
validCerts = validCerts.Where(c => c.HasSubjectKeyIdentifier()).ToList();
}
Comment on lines +43 to +47
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new filtering logic that excludes certificates without Subject Key Identifier when at least one certificate has it lacks test coverage. Consider adding unit tests that verify the filtering behavior with scenarios such as:

  • All certificates have SKI: all should be included
  • Some certificates have SKI, some don't: only those with SKI should be included
  • No certificates have SKI: all should be included
  • Mixed valid/invalid SKI values

This would ensure the filtering logic works correctly across different certificate store states.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite ready to add tests that write certificates to the store to make these tests viable.


// Take the highest version valid certificate for each unique SKI
devCerts.AddRange(
store.Certificates
.Where(c => c.IsAspNetCoreDevelopmentCertificate())
.Where(c => c.NotBefore <= now && now <= c.NotAfter)
validCerts
.GroupBy(c => c.Extensions.OfType<X509SubjectKeyIdentifierExtension>().FirstOrDefault()?.SubjectKeyIdentifier)
.SelectMany(g => g.OrderByDescending(c => c.GetCertificateVersion()).ThenByDescending(c => c.NotAfter).Take(1))
.OrderByDescending(c => c.GetCertificateVersion()).ThenByDescending(c => c.NotAfter));
Expand Down
Loading