gpt4 book ai didi

wcf - 为 IIS 创建有效的测试 SSL 证书

转载 作者:太空宇宙 更新时间:2023-11-03 12:42:25 25 4
gpt4 key购买 nike

我想在 IIS 的开发环境中测试 SSL 连接。为此,我需要创建一个安装在机器商店中的自签名根证书,以及另一个使用根证书签名以安装在 IIS 中的证书。

使用 makecert 执行此操作现已弃用,因此我想知道如何使用 Powershell 和 New-SelfSignedCertificate 命令执行此操作。

如果您的 key 使用设置正确,可加分 :-)

注意:直接在 IIS 中使用自签名证书是行不通的,因为浏览器和 WCF 认为它们无效。


作为引用,以下是使用 makecert 的方法:

# create the self signed root certificate 
makecert -n "CN=root.lan" -r -sv root.pvk root.cer

# create the certificate for IIS that gets signed with the root certificate
makecert -sk "Local Certificate" -iv root.pvk -n "CN=localhost" -ic root.cer -sr localmachine -ss my -sky exchange -pe

# convert to other formats
cert2spc localhost.cer localhost.spc
pvk2pfx -pvk localhost.pvk -spc localhost.spc -pfx localhost.pfx

最佳答案

描述了 Windows 10 中包含的新版本 New-SelfSignedCertificate here .可以使用 New-SelfSignedCertificate -?get-help New-SelfSignedCertificate -examples 获取一些附加信息。

文档和示例对于创建两个证书似乎仍然不够清晰:

  • 一个自签名证书,将用作您示例中的 CA 证书
  • 第二个 SSL 证书,用第一个证书签名。

实现可能如下(我在选项下面写了多行只是为了让文本更易读):

New-SelfSignedCertificate -HashAlgorithm sha384 -KeyAlgorithm RSA -KeyLength 4096
-Subject "CN=My Test (PowerShell) Root Authority,O=OK soft GmbH,C=DE"
-KeyUsage DigitalSignature,CertSign -NotAfter (get-date).AddYears(10)
-CertStoreLocation "Cert:\CurrentUser\My" -Type Custom

输出看起来像

    Directory: Microsoft.PowerShell.Security\Certificate::CurrentUser\My


Thumbprint Subject
---------- -------
B7DE93CB88E99B01D166A986F7BF2D82A0E541FF CN=My Test (PowerShell) Root Authority, O=OK soft GmbH, C=DE

B7DE93CB88E99B01D166A986F7BF2D82A0E541FF 对于使用签名证书很重要。如果忘记值可以通过CN名查找

dir cert:\CurrentUser\My | where Subject -Like "CN=My Test (PowerShell)*"

或使用 certutil.exe -user -store My 在当前用户的我的商店中显示证书。

要创建 SSL 证书并根据先前创建的证书对其进行签名,例如可以执行以下操作

New-SelfSignedCertificate -Type Custom -Subject "CN=ok01.no-ip.org"
-HashAlgorithm sha256 -KeyAlgorithm RSA -KeyLength 2048
-KeyUsage KeyEncipherment,DigitalSignature
-CertStoreLocation "cert:\LocalMachine\My"
-Signer cert:\CurrentUser\My\B7DE93CB88E99B01D166A986F7BF2D82A0E541FF
-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2","2.5.29.17={text}DNS=ok01.no-ip.org&DNS=ok01.fritz.box")

在我看来,最终证书将具有所需的所有属性。很明显,上述参数中的许多值仅包含示例,您必须根据自己的要求在那里进行修改。在Trusted Root中导入根证书、导出证书等其他一些常见的步骤在此不再赘述。这些步骤不是您主要问题的答案。

关于wcf - 为 IIS 创建有效的测试 SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36872152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com