2014-09-02 82 views
1

Theres是一个在powershell中调用New-SelfSignedCertificate的工具,我们可以为CA建立自签名证书。 但我只是无法弄清楚是否可以创建由New-SelfSignedCertificate此前创建的证书颁发/签名的子证书。其实我可以用makecert.exe做到这一点,但我想在powershell中编写它。PowerShell是否有创建非自签名证书的工具?

例如,在makecert.exe,我执行以下命令:

1)Creating the CA cert: **makecert.exe** -sk RootCA -sky signature -pe -n CN=ca.com -r -sr LocalMachine -ss Root RootCA 

2)Creating another cert for server signed by above CA: **makecert.exe** -sk server -sky exchange -pe -n CN=server.com -ir LocalMachine -is Root -ic RootCA -sr LocalMachine -ss My server.com 

在PowerShell中我只知道创建CA,使用命令:

New-SelfSignedCertificate -DnsName "ca.com" -CertStoreLocation cert:Localmachine/My 

但是,如何创造上面签名的另一个证书?

其他的事情,当我试图把-CertStoreLocation = cert:Localmachine/**Root**我得到一个错误信息说我只能在我的创建证书(我已经以管理员身份运行)

感谢。

回答

0

手动记录证书的哈希值似乎很麻烦。这是简单的做这样的:

# create root zertificate 
    $rootCert = New-SelfSignedCertificate -CertStoreLocation cert:\localmachine\my -DnsName "Root CA Name"; 

    # export root certificate 
    [System.Security.SecureString]$rootcertPassword = ConvertTo-SecureString -String "znft5yeL34pxCu3nATlt1gMazX0NM8FVvr9yZOhcS79yJm8kUVjhA17UuWkQOb0u" -Force -AsPlainText; 
    [String]$rootCertPath = Join-Path -Path 'cert:\localMachine\my\' -ChildPath "$($rootcert.Thumbprint)"; 
    Export-PfxCertificate -Cert $rootCertPath -FilePath 'root-authority.pfx' -Password $rootcertPassword; # private key 
    Export-Certificate -Cert $rootCertPath -FilePath 'root-authority.crt';        # public key 

    # use root certificate to sign gateway certificate 
    $gatewayCert = New-SelfSignedCertificate -CertStoreLocation cert:\localmachine\my -DnsName "*.example.com","*.example.org" -Signer $rootCert; 

    # export gateway certificate 
    [System.Security.SecureString]$gatewayCertPassword = ConvertTo-SecureString -String "Xc8FlsHq8hmLnKXk4AaD8ug6HYH2dpSWLjwg9eNeDIK103d3akbd0OccgZZ6bL48" -Force -AsPlainText; 
    [String]$gatewayCertPath = Join-Path -Path 'cert:\localMachine\my\' -ChildPath "$($gatewayCert.Thumbprint)"; 
    Export-PfxCertificate -Cert $gatewayCertPath -FilePath gateway-certificate.pfx -Password $gatewayCertPassword; # private key 
    Export-Certificate -Cert $gatewayCertPath -FilePath gateway.crt;           # public key 

此外,对于脾淋巴细胞的环境中,你可能想使用ACMESharp创建免费TLS证书。

1

我非常抱歉迟到了,我很清楚这个问题已经过了两年了。

然而,与那些搜索时,谁可能会发现该条目分享 - 现在有(在案this excellent blog by David Christiansen

总之,这是一种

New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname "Your root CA name here" 

记下指纹此命令返回。

接下来,创建一个安全的密码和根CA导出到文件

PowerShell的

$pwd = ConvertTo-SecureString -String "Please-Use-A-Really-Strong-Password" -Force -AsPlainText 
Export-PfxCertificate -cert cert:\localMachine\my\[CA thumbprint] -FilePath root-authority.pfx -Password $pwd 
Export-Certificate -Cert cert:\localMachine\my\[CA thumbprint] -FilePath root-authority.crt 

注意,CRT文件不需要密码,因为它是证书的公共部分。

现在将签名证书加载到内存中,并创建一个由此证书签名的证书,并用密码导出证书。

$rootcert = (Get-ChildItem -Path cert:\LocalMachine\My\[CA Thumbprint]) 
New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname "Your DNS Name Here" -Signer $rootcert 

记下从自签名的cert命令返回的指纹以导出它。

$pwd2 = ConvertTo-SecureString -String "Please-Use-A-Really-Strong-Password" -Force -AsPlainText 
    Export-PfxCertificate -cert cert:\localMachine\my\[Cert Thumbprint] -FilePath gateway-certificate.pfx -Password $pwd2 
    Export-Certificate -Cert cert:\localMachine\my\[Cert Thumbprint] -FilePath gateway.crt