我想在使用IIS的开发环境中测试SSL连接。为此,我需要创建一个安装在机器商店中的自签名根证书,以及另一个使用根证书签名以在IIS中安装的证书。
现在不推荐使用makecert
,所以我想知道如何使用Powershell和New-SelfSignedCertificate
命令。
如果您获得正确的密钥使用设置,则可获得积分:-)
注意:直接在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
答案 0 :(得分:7)
{10}中包含的新版New-SelfSignedCertificate
被描述为here。可以使用New-SelfSignedCertificate -?
和get-help New-SelfSignedCertificate -examples
来获取一些其他信息。
文档和示例似乎仍然不够清晰,无法创建两个证书:
实现可能如下(我在下面写了多行选项只是为了使文本更具可读性):
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")
在我看来,最终证书将包含所有必需的属性。很明显,来自上述参数的许多值只包含您根据自己的要求修改的示例。我不会在这里描述一些其他常见步骤,例如在受信任的根中导入根证书,导出证书等。这些步骤不是你主要问题的答案。