兼容无SubjectKeyIdentifier的ca证书

This commit is contained in:
xljiulang 2022-09-18 02:14:21 +08:00
parent 2a6289ecf6
commit 50b1c85b50

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Net; using System.Net;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
@ -136,11 +135,11 @@ namespace FastGithub.HttpServer.Certs
private static X509Extension GetAuthorityKeyIdentifierExtension(X509Certificate2 certificate) private static X509Extension GetAuthorityKeyIdentifierExtension(X509Certificate2 certificate)
{ {
var extension = new X509SubjectKeyIdentifierExtension(certificate.PublicKey, false);
#if NET7_0_OR_GREATER #if NET7_0_OR_GREATER
return X509AuthorityKeyIdentifierExtension.CreateFromCertificate(certificate, true, false); return X509AuthorityKeyIdentifierExtension.CreateFromSubjectKeyIdentifier(extension);
#else #else
var extension = certificate.Extensions.OfType<X509SubjectKeyIdentifierExtension>().First();
var subjectKeyIdentifier = extension.RawData.AsSpan(2); var subjectKeyIdentifier = extension.RawData.AsSpan(2);
var rawData = new byte[subjectKeyIdentifier.Length + 4]; var rawData = new byte[subjectKeyIdentifier.Length + 4];
rawData[0] = 0x30; rawData[0] = 0x30;