【问题标题】:Importing a certificate to Azure key vaullt: Operation returned an invalid status code 'Conflict'将证书导入 Azure 密钥保管库:操作返回无效状态代码“冲突”
【发布时间】:2019-11-25 08:18:05
【问题描述】:

我正在尝试使用以下代码将 .PFX 文件(首先转换为 base64 文件)导入 Azure Keyvault。

但是我收到错误:操作返回了无效的状态代码“冲突”

Azure KeyVault 上绝对没有其他证书。

 public async Task ImportCertificate(string base64FileCertFile, string CertPasswordText, string name)
        {
            AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
            KeyVaultClient keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));

            Message = "Your application description page.";
            int retries = 0;

            //byte[] fileData = null;
            //using (var binaryReader = new BinaryReader(request.Files[0].InputStream))
            //{
            //        fileData = binaryReader.ReadBytes(request.Files[0].ContentLength);
            //}

            //var base64EncodedCertificate = Convert.ToBase64String(fileData);
            bool retry = false;
            try
            {
                /* The below do while logic is to handle throttling errors thrown by Azure Key Vault. It shows how to do exponential backoff which is the recommended client side throttling*/
                do
                {
                    long waitTime = Math.Min(GetWaitTime(retries), 2000000);
                    var result = await keyVaultClient.ImportCertificateAsync(ConfigurationManager.AppSettings["VaultUrl"].ToString(), name, base64FileCertFile, CertPasswordText);

                    Message = result.Id;
                    retry = false;
                }
                while (retry && (retries++ < 10));
             }
            /// <exception cref="KeyVaultErrorException">
            /// Thrown when the operation returned an invalid status code
            /// </exception>
            catch (KeyVaultErrorException keyVaultException)
            {
                Message = keyVaultException.Message;
                if ((int)keyVaultException.Response.StatusCode == 429)
                    retry = true;
            }
        }

【问题讨论】:

  • 能否请您移除try catch 模块以获取异常详细信息或使用fiddler 捕获请求以获取详细错误信息?

标签: c# asp.net .net azure azure-keyvault


【解决方案1】:

关于这个问题,根据我的研究,当第一次创建KV证书时,也会创建一个与证书同名的可寻址密钥和秘密。如果名称已在使用中,则操作将失败并返回 http 状态代码 409(冲突)。更多详情请参考document。所以我建议你改名字。

【讨论】:

    猜你喜欢
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-19
    • 2021-08-25
    • 1970-01-01
    • 2013-09-11
    相关资源
    最近更新 更多