Azure Web 作业无法与客户端证书建立 SSL/TLS 连接

标签 azure ssl azure-webjobs

您好,我有一个 WebJob,需要使用 HTTPS 和客户端证书与外部 Web 服务进行通信,但我收到(仅在 Azure 上)此错误:无法为具有权限的 SSL/TLS 建立安全通道“wstest.agenziadoganemonopoli.gov.it”。请求已中止:无法创建 SSL/TLS 安全通道。

wstest.agenziadoganemonopoli.gov.it 仅支持 TLS 1.2 ( SSLLabs test ),我已经添加了

ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;

wstest.agenziadoganemonopoli.gov.it 需要每个用户不同的客户端证书,因此我从 blob 加载正确的证书。

我没有按照此处的建议使用WEBSITE_LOAD_CERTIFICATES Use a client certificate in a WebJob主要是因为我从外部存储(Azure Blob 存储)加载证书,并且每个用户都有不同的证书(我有超过 1000 个证书需要管理)。

更新 这是(或多或少)我用来从 Azure Blob 存储加载证书的代码

    public async Task<Result<X509Certificate2>> GetCertificate(Guid merchantId)
    {
        try
        {
            CloudBlobContainer container =
                _client.GetContainerReference($"{ContainerNamePrefix}-{merchantId.ToString().ToLower()}");

            CloudBlockBlob certificateBlobBlock = container.GetBlockBlobReference(CertificateBlobBlockName);

            CloudBlockBlob metadataBlobBlock = container.GetBlockBlobReference(MetadataBlobBlockName);

            AuthenticationCertificateMetadata metadata =
                JsonConvert.DeserializeObject<AuthenticationCertificateMetadata>(
                    await metadataBlobBlock.DownloadTextAsync().ConfigureAwait(false));

            X509Certificate2 certificate = null;

            using (MemoryStream stream = new MemoryStream())
            {
                await certificateBlobBlock.DownloadToStreamAsync(stream).ConfigureAwait(false);

                certificate = new X509Certificate2(stream.ToArray(), metadata.CertificatePassword);
            }

            return Result<X509Certificate2>.Successful(certificate);
        }
        catch (Exception ex)
        {

        }
    }

有什么建议吗?

谢谢! 费德里科

最佳答案

I didn't use WEBSITE_LOAD_CERTIFICATES as suggested

实际上,您需要在应用程序设置中设置 WEBSITE_LOAD_CERTIFICATES。这是加载应用程序的客户端证书所必需的。 enter image description here

I load the certificate from an external store (Azure Blob Storage) and I have a different certificate per user

您可以加载应用程序目录中的证书文件,以便为每个用户获得不同的客户端证书。

例如:

 string certPath = Server.MapPath("~/certs/mycert.pfx");
 X509Certificate2 cert = GetCertificate(certPath, signatureBlob.Thumbprint);

更多详情可以引用这个article .

关于Azure Web 作业无法与客户端证书建立 SSL/TLS 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48876765/

相关文章:

azure - OnStart 与批处理文件的启动脚本?

azure - 如何将数据从blob存储复制到VM?

apache - https url 显示无法连接

azure - 如何使用 C# REST API 生成不记名 token 并使用不记名 token 进行身份验证?

c# - Azure DevOps如何通过引用另一个解决方案中的另一个项目来构建项目

azure - 如何在 Azure ARM 模板中的条件中使用 and 运算符

ssl - 如果定义了 k8s API tls 密码,则 k8s 上的 Rabbitmq 对等发现失败

ssl - 在 Apache Kafka 中禁用 TLS 1.0、TLS 1.1

c# - Azure WebJob 最佳方法

c# - 一个队列上的多个 Azure Webjob 实例(第 2 部分)