我们通过 Azure 购买了证书,并希望在同一个 VM 上使用它。 我们只需要 .pfx 文件。
我们尝试了几乎所有内容,然后我们收到了下一个错误:
“您无权获取服务主页信息 需要为您的证书分配密钥保管库。请用。登录 帐户是订阅的所有者或管理员 Active Directory配置密钥保管库设置。“
但我们有权限......
答案 0 :(得分:0)
要澄清和检查的一些事项:
如果您完成了所有这些操作,则您的证书现在存储在Azure Key Vault中。创建Azure密钥保管库时,有一个高级访问策略选项“启用对Azure虚拟机的访问以进行部署”(请参见图像)。其帮助信息显示为“指定是否允许Azure虚拟机检索作为密钥库中的密钥存储的证书。”
也就是说,既然你想要一个.pfx文件,下面是从MSDN博客中提取的样本PowerShell脚本。为下面的四个“$”参数提供适当的值,并将脚本另存为copyasc.ps1。
$appServiceCertificateName = ""
$resourceGroupName = ""
$azureLoginEmailId = ""
$subscriptionId = ""
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionId $subscriptionId
$ascResource = Get-AzureRmResource -ResourceName $appServiceCertificateName -ResourceGroupName $resourceGroupName -ResourceType "Microsoft.CertificateRegistration/certificateOrders" -ApiVersion "2015-08-01"
$keyVaultId = ""
$keyVaultSecretName = ""
$certificateProperties=Get-Member -InputObject $ascResource.Properties.certificates[0] -MemberType NoteProperty
$certificateName = $certificateProperties[0].Name
$keyVaultId = $ascResource.Properties.certificates[0].$certificateName.KeyVaultId
$keyVaultSecretName = $ascResource.Properties.certificates[0].$certificateName.KeyVaultSecretName
$keyVaultIdParts = $keyVaultId.Split("/")
$keyVaultName = $keyVaultIdParts[$keyVaultIdParts.Length - 1]
$keyVaultResourceGroupName = $keyVaultIdParts[$keyVaultIdParts.Length - 5]
Set-AzureRmKeyVaultAccessPolicy -ResourceGroupName $keyVaultResourceGroupName -VaultName $keyVaultName -UserPrincipalName $azureLoginEmailId -PermissionsToSecrets get
$secret = Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $keyVaultSecretName
$pfxCertObject=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @([Convert]::FromBase64String($secret.SecretValueText),"", [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$pfxPassword = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 50 | % {[char]$_})
$currentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
[Environment]::CurrentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
[io.file]::WriteAllBytes(".\appservicecertificate.pfx", $pfxCertObject.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, $pfxPassword))
Write-Host "Created an App Service Certificate copy at: $currentDirectory\appservicecertificate.pfx"
Write-Warning "For security reasons, do not store the PFX password. Use it directly from the console as required."
Write-Host "PFX password: $pfxPassword"
在PowerShell控制台中键入以下命令以执行脚本:
Powershell –ExecutionPolicy Bypass
.\copyasc.ps1
执行脚本后,您会在当前目录中看到名为“appservicecertificate.pfx”的新文件。这是受密码保护的PFX,PowerShell控制台会显示相应的密码。