瀏覽代碼

兼容无SubjectKeyIdentifier的ca证书

xljiulang 2 年之前
父節點
當前提交
50b1c85b50
共有 1 個文件被更改,包括 3 次插入4 次删除
  1. 3 4
      FastGithub.HttpServer/Certs/CertGenerator.cs

+ 3 - 4
FastGithub.HttpServer/Certs/CertGenerator.cs

@@ -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;