我的最终目标是使用Python脚本自动化此过程,因此我首先要熟悉Azure门户中所需的工作流程。
第1步是创建应用服务证书。在代码中,我拨打的电话是: https://management.azure.com/subscriptions/aaaa-bbbb-cccc-dddd/resourceGroups/my-rg/providers/Microsoft.CertificateRegistration/certificateOrders/my-cert-order?api-version=2015-08-01
有效载荷为:
{
"location": "global",
"properties": {
"productType": "StandardDomainValidatedSsl",
"autoRenew": true,
"distinguishedName":"CN=mydomain.com"
}
}
第2步是将其与特定的密钥库关联。同样,在代码中,调用为: https://management.azure.com/subscriptions/aaaa-bbbb-cccc-dddd/resourceGroups/my-rg/providers/Microsoft.CertificateRegistration/certificateOrders/my-cert-order/certificates/my-cert?api-version=2015-08-01
有效载荷为
{
"location":"global",
"properties": {
"keyVaultId":"/subscriptions/aaaa-bbbb-cccc-dddd/resourceGroups/my-rg/providers/Microsoft.KeyVault/vaults/my-keyvault",
"keyVaultSecretName":"my-secret-name"
}
}
第3步是验证与刚创建的证书相关联的域。门户中的说明说要使用提供的域验证令牌在我的域的根目录下创建TXT条目。我已经这样做了,但是Azure不喜欢它,因为即使在几个小时之后,它也从未报告该证书已通过验证。我已经尝试对我创建的TXT记录进行手动查找,并且现在肯定可以使用它,所以我不认为这就是Azure所抱怨的。
我知道门户使用的REST调用是verify-domain-ownership,如此处所述:
我尝试在代码中显式进行此调用,并且可以看到它返回400错误以及以下JSON blob:
{
"Code": "CertificateResellerWebService_NOT_FOUND_TOKEN",
"Message": "All remaining domain control tokens were not found",
"Target": null,
"Details": [
{
"Message": "All remaining domain control tokens were not found"
},
{
"Code": "CertificateResellerWebService_NOT_FOUND_TOKEN"
},
{
"ErrorEntity": null
}
],
"Innererror": null
}
它在这里抱怨的域控制令牌是否与域验证令牌相同?无论如何,该调用始终会失败,并出现相同的错误。我不清楚是什么导致了这个问题。任何建议,将不胜感激。
更新:这是我用于此过程的主要算法:
token = get_auth_token()
# First, put in a certificate request
cert_order = create_cert_order(token, CERT_NAME)
while cert_order.status_code == 201:
cert_order = get_cert_order(token, CERT_NAME)
cert_order = cert_order.json()
# Then assign it to a specific key vault
cert = update_cert(token, CERT_NAME, KEY_VAULT_ID, KEY_VAULT_SECRET_NAME)
while cert.status_code == 201:
cert = get_cert(token, CERT_NAME)
# Next, create a TXT entry in the root domain matching the
# domain verification token and wait for that record to be
# discoverable by nslookup.
domain_verification_token = cert_order["properties"]["domainVerificationToken"]
create_txt_record(domain_verification_token)
waitfor_txt_record(domain_verification_token)
# Finally, ask to have to domain ownersip verified.
response = verify_domain_ownership(token, CERT_NAME)
if response.status_code != 204:
print("Domain ownership verification failed")
此处引用的函数create_cert_order,update_cert和verify_domain_ownership代表我上面提到的REST调用。我很确定这个工作流程是正确的,但是我不知道为什么最后一次通话失败了。