.net VS2022带有DNS IP地址的Kestrel自签名证书

hlswsv35  于 2023-05-19  发布在  .NET
关注(0)|答案(1)|浏览(180)

目标是我可以从VS2022(Kestrel)启动我的.Net Blazor Server应用程序,使用我的开发人员机器的IP地址(所以不是127.0.0.1或localhost),而是我的有效机器IP(172.23.110.47),并且我可以在这样做的同时拥有正确的HTTPS连接。我在PowerShell中运行了以下代码

PS C:\windows\system32> New-SelfSignedCertificate -Subject "localhost" -TextExtension @("2.5.29.17={text}DNS=localhost&IPAddress=127.0.0.1&IPAddress=::1&IPAddress=172.23.110.47")
   PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\MY

Thumbprint                                Subject
----------                                -------
53E7417A264B229B4F52638B15433F7C09476224  CN=localhost

PS C:\windows\system32> $mypwd = ConvertTo-SecureString -String "ControlTech" -Force -AsPlainText
PS C:\windows\system32> Get-ChildItem -Path cert:\localMachine\my\53E7417A264B229B4F52638B15433F7C09476224 | Export-PfxCertificate -FilePath C:\temp\MyJpfCertificate.pfx -Password $mypwd

    Verzeichnis: C:\temp

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        21.03.2023     09:05           2685 MyJpfCertificate.pfx

PS C:\windows\system32> dotnet dev-certs https --clean --import C:\Temp\MyJpfCertificate.pfx -p ControlTech
Cleaning HTTPS development certificates from the machine. A prompt might get displayed to confirm the removal of some of the certificates.
HTTPS development certificates successfully removed from the machine.
The certificate at 'C:\Temp\MyJpfCertificate.pfx' is not a valid ASP.NET Core HTTPS development certificate.

C:\Temp\MyJpfCertificate.pfx中的证书不是有效的ASP.NET Core HTTPS开发证书。我错过了什么?

s4n0splo

s4n0splo1#

你可以试试:

$params = @{
    Subject           = 'CN=172.23.110.47'
    FriendlyName      = 'Local HTTPS development certificate'
    TextExtension     = @('2.5.29.37={text}1.3.6.1.5.5.7.3.1',  # SSLServerAuthentication
                          '2.5.29.17={text}ipaddress=172.23.110.47')
    NotAfter          = (Get-Date).AddDays(397)                 # Max TLS validity period
    CertStoreLocation = 'Cert:\LocalMachine\My'
}
$cert = New-SelfSignedCertificate @params

证书将具有EKU扩展名和服务器身份验证OID,并且在DnsNameList中不具有“localhost”。

相关问题