Skip to content

Commit

Permalink
Fix for bug #57 - consider latest expiring certificate in case of mul…
Browse files Browse the repository at this point in the history
…tiple ASP.Net Core development certificates (#58)
  • Loading branch information
ansariabr authored Jun 28, 2020
1 parent 22fcb97 commit 7ff27c1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/dotnet-serve/Security/CertificateLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,18 @@ private static X509Certificate2 LoadDeveloperCertificate()

if (certs.Count > 1)
{
throw new InvalidOperationException($"Ambiguous certficiate match. Multiple certificates found with extension '{AspNetHttpsOid}' ({AspNetHttpsOidFriendlyName}).");
// Returning a certificate which has the latest expiry date
var expiryDate = DateTime.MinValue;
var thumbprint = string.Empty;
foreach (var certificate in certs)
{
if (certificate.NotAfter > expiryDate)
{
expiryDate = certificate.NotAfter;
thumbprint = certificate.Thumbprint;
}
}
return certs.Find(X509FindType.FindByThumbprint, thumbprint, validOnly: false)[0];
}

return null;
Expand Down

0 comments on commit 7ff27c1

Please sign in to comment.