我想从 azure 中的虚拟网络创建点到站点 vpn。对于我想使用证书的身份验证,根证书是在 azure key vault 中生成的。我不想使用 rootCertificate.pfx 而是使用 clientCertificate.pfx 进行身份验证。
要求是
- 我不使用外部证书提供程序。
- 我尽可能多地使用powershell
我们按照此文档在密钥保管库中创建自签名证书。
https://blogs.technet.microsoft.com/kv/2016/09/26/get-started-with-azure-key-vault-certificates/
创建根证书后,它被放置在密钥保管库中。(秘密中的公共部分,密钥中的私人部分)
接下来我们复制/粘贴虚拟网络网关中的公共部分(Base64) -> 点到站点配置 -> 根证书
然后我使用这个 powershell 脚本从我们之前创建的 rootCertificate 生成一个 clientCertificate。我们将其导出到本地硬盘。
Login-AzureRmAccount
$kvSecret = Get-AzureKeyVaultSecret -VaultName "akv-contoso-test" -Name "ContosoFirstCertificate"
$kvSecretBytes = [System.Convert]::FromBase64String($kvSecret.SecretValueText)
$rootCertificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @($kvSecretBytes, $null, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$certStore = New-Object System.Security.Cryptography.X509Certificates.X509Store
$certStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$certStore.Add($rootCertificate)
$clientCertificate = New-SelfSignedCertificate -Type Custom -KeySpec Signature -Subject "CN=Point To Site VPN Client" -KeyExportPolicy Exportable -HashAlgorithm sha256 -KeyLength 2048 -Signer $rootCertificate -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.2")
$securePassword = ConvertTo-SecureString -String "mysecret" -AsPlainText -Force
Export-PfxCertificate -Cert $clientCertificate -Password $securePassword -FilePath "C:\Users\User\Desktop\Certificates\Point To Site VPN Client.pfx" -ChainOption BuildChain
$certStore.Close()
之后我们安装“Point To Site VPN Client.pfx”
公共根证书安装在受信任的根证书颁发机构中。在我的客户端证书的信任链中,根证书显示以下“此证书对所选用途无效”。
现在我想使用客户端证书连接到 vpn。
他说收到的消息出乎意料或格式错误。
我的猜测是,当我们想从密钥库(上面的脚本)生成客户端证书时会出现问题。