2014-09-02 36 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