Skip to content

Commit d947f9e

Browse files
committed
Use SHA256 and check by OID instead of extension type
1 parent ee8f30b commit d947f9e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Shared/CertificateGeneration/CertificateManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ internal abstract class CertificateManager
3030
private const string ServerAuthenticationEnhancedKeyUsageOid = "1.3.6.1.5.5.7.3.1";
3131
private const string ServerAuthenticationEnhancedKeyUsageOidFriendlyName = "Server Authentication";
3232

33+
internal const string SubjectKeyIdentifierOid = "2.5.29.14";
34+
internal const string AuthorityKeyIdentifierOid = "2.5.29.35";
35+
3336
// dns names of the host from a container
3437
private const string LocalhostDockerHttpsDnsName = "host.docker.internal";
3538
private const string ContainersDockerHttpsDnsName = "host.containers.internal";
@@ -832,10 +835,10 @@ internal static X509Certificate2 CreateSelfSignedCertificate(
832835
// Only add the SKI and AKI extensions if neither is already present.
833836
// OpenSSL needs these to correctly identify the trust chain for a private key. If multiple certificates don't have a subject key identifier and share the same subject,
834837
// the wrong certificate can be chosen for the trust chain, leading to validation errors.
835-
if (!request.CertificateExtensions.OfType<X509SubjectKeyIdentifierExtension>().Any() && !request.CertificateExtensions.OfType<X509AuthorityKeyIdentifierExtension>().Any())
838+
if (!request.CertificateExtensions.Any(ext => ext.Oid?.Value is SubjectKeyIdentifierOid or AuthorityKeyIdentifierOid))
836839
{
837840
// RFC 5280 section 4.2.1.2
838-
var subjectKeyIdentifier = new X509SubjectKeyIdentifierExtension(new PublicKey(key), critical: false);
841+
var subjectKeyIdentifier = new X509SubjectKeyIdentifierExtension(request.PublicKey, X509SubjectKeyIdentifierHashAlgorithm.Sha256, critical: false);
839842
// RFC 5280 section 4.2.1.1
840843
var authorityKeyIdentifier = X509AuthorityKeyIdentifierExtension.CreateFromSubjectKeyIdentifier(subjectKeyIdentifier);
841844

0 commit comments

Comments
 (0)