2016-04-26 62 views
6

我想在具有IIS的开发环境中测试SSL连接。为此,我需要创建一个自签名的根证书,该证书将安装在机器存储中,另一个证书需要使用根证书进行签名以便在IIS中进行安装。为IIS创建有效的测试SSL证书

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

如果您只使用RSA密钥,则'MakeCert.exe'就足够了,但最好使用'MakeCert.exe'的其他选项。 'New-SelfSignedCertificate'没有任何优势。在互联网上可用的其他Powershell模块可能会更好。您可以使用[OpenSSL.exe](https://www.openssl.org/)而不是'MakeCert.exe'来创建可在IIS上使用的RSA或椭圆曲线证书。如果您的IIS服务器通过互联网(端口80)可用,那么您可以使用Let's Encrypt获得免费的真正的SSL证书,并且客户端不需要将“CA”证书安装在受信任的根目录中。 – Oleg

+1

问题在于使用'New-SelfSignedCertificate'的原因。我不想使用'MakeCert'或'OpenSSL'。 – MovGP0

+0

只需使用start powershell并使用'New-SelfSignedCertificate - ?'和'get-help New-SelfSignedCertificate -examples'。可能性取决于您使用的Windows版本。将https://technet.microsoft.com/en-us/library/hh848633.aspx与https://technet.microsoft.com/en-us/library/hh848633(v=wps.630).aspx – Oleg

回答

5

New-SelfSignedCertificate新版本,其中包括在Windows 10,描述here。可以使用New-SelfSignedCertificate -?get-help New-SelfSignedCertificate -examples来获得一些附加信息。

的文件,并可能似乎仍然没有明确的例子足以建立两个证书:

  • 一个自签名的证书,这会从你的例子
  • 第二SSL证书作为CA证书,与第一张证书签署。

的实现可能是以下(我写在多行该选项下面才使文本更具可读性):

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") 

在我看来,最终的证书将具有所需的所有属性。很显然,来自以上参数的许多值都包含示例,只有您根据自己的要求修改了这些值。我在这里没有描述其他常见步骤,例如在受信任的根中导入根证书,导出证书等等。这些步骤不是你主要问题的psrt。

+0

非常感谢:-) – MovGP0

+1

@ MovGP0:不客气!我仍然建议您查看Let's Encrypt。看看[这里](http://weblog.west-wind.com/posts/2016/Feb/22/Using-Lets-Encrypt-with-IIS-on-Windows)。我个人使用[letsencrypt-win-simple](https://github.com/Lone-Coder/letsencrypt-win-simple)使用Let's Encrypt在所有计算机上信任的权限创建SSL证书。 – Oleg

+1

我需要为CA证书指定'-KeyUsage DigitalSignature,CertSign',否则Web浏览器将不验证'子'证书。 –