使用密钥保管库生成客户端证书

Ide*_*ity 6 certificate azure azure-keyvault

对于我们的点到站点 VPN,我们要创建一个根证书。因此,我们可以为需要登录我们 VPN 的所有合作伙伴创建任意数量的客户端证书。(Azure 虚拟网络)

手动执行此操作非常完美。我们生成一个作为根 ca 的证书(自签名)。我们可以像这样在 powershell 中做到这一点:

$cert = New-SelfSignedCertificate -Type Custom -KeySpec Signature -Subject "CN=Kratos Point To Site VPN Root Certificate Win10" -KeyExportPolicy Exportable -HashAlgorithm sha256 -KeyLength 2048 -CertStoreLocation "Cert:\CurrentUser\My" -KeyUsageProperty Sign -KeyUsage CertSign

$clientCert = New-SelfSignedCertificate -Type Custom -KeySpec Signature -Subject "CN=Digicreate Point To Site VPN Client Certificate Win10" -KeyExportPolicy Exportable -HashAlgorithm sha256 -KeyLength 2048 -CertStoreLocation "Cert:\CurrentUser\My" -Signer $cert -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.2")
Run Code Online (Sandbox Code Playgroud)

但是,我们更喜欢使用密钥保管库进行证书管理。这个想法是使用以下命令直接在密钥保管库中创建证书:Add-AzureKeyVaultCertificate(私钥不可导出)

创建根证书工作正常。但是我无法找到如何使用密钥保管库中的“签名”操作来签署新证书。

你有关于如何做到这一点的样本吗?

Jas*_* Ye 0

但我想使用 azure key Vault cmdlet 基于此根证书创建客户端证书。这可能吗?

您的意思是要下载证书吗?如果是的话,我们可以使用这个脚本来下载它:

将私有证书下载到您的 D:\cert:

$kvSecret = Get-AzureKeyVaultSecret -VaultName 'jasontest2' -Name 'TestCert01'
$kvSecretBytes = [System.Convert]::FromBase64String($kvSecret.SecretValueText)
$certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
$certCollection.Import($kvSecretBytes,$null,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$protectedCertificateBytes = $certCollection.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, 'test')
$pfxPath = 'D:\cert\test.pfx'
[System.IO.File]::WriteAllBytes($pfxPath, $protectedCertificateBytes)
Run Code Online (Sandbox Code Playgroud)

将公共证书下载到您的 D:\cert:

$cert = Get-AzureKeyVaultCertificate -VaultName 'jasontest2' -Name 'TestCert01'
$filePath ='D:\cert\TestCertificate.cer'
$certBytes = $cert.Certificate.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert)
[System.IO.File]::WriteAllBytes($filePath, $certBytes)
Run Code Online (Sandbox Code Playgroud)

更新:

$certificateOperation.CertificateSigningRequest 是证书的 base4 编码的证书签名请求。

Import-AzureKeyVaultCertificate -VaultName $vaultName -Name $certificateName -FilePath C:\test\OutputCertificateFile.cer
Run Code Online (Sandbox Code Playgroud)

更多信息请参考此博客


更新:
我们应该使用您的 CA 服务器的签名操作来签署 CertificateSignRequest。

企业证书:
如果您使用企业证书解决方案,请生成通用名称值格式“name@yourdomain.com”的客户端证书,而不是“域名\用户名”格式。确保客户端证书基于使用列表中第一项为“客户端身份验证”的“用户”证书模板,而不是“智能卡登录”等。您可以通过双击客户端证书并查看证书查看详细信息 > 增强的密钥用法。

  • 我想使用自定义根 CA 签署新创建的证书。我不想将 CA 的私钥暴露给密钥保管库。其想法是使用根 CA 的私钥通过密钥保管库中的签名操作对 CertificateSignRequest 进行签名。但是,我找不到任何有关如何在 powershell 中执行此操作的示例...... (2认同)
  • 您是否有关于如何签署此 CSR 并更新客户端证书以使其正常工作的示例?我有一个用于点到站点 VPN 的根 CA。要创建客户端证书,我需要使用根 CA 的密钥保管库中的签名操作对 CSR 进行签名。我能够创建我的根 CA,但我找不到有关如何正确签署此客户端证书的示例... (2认同)