【发布时间】:2018-07-30 07:31:49
【问题描述】:
您好,我有一个需要使用 HTTPS 和客户端证书与外部 Web 服务通信的 WebJob,但我(仅在 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)
{
}
}
有什么建议吗?
谢谢! 费德里科
【问题讨论】:
-
如何获得证书并使用它?你能分享一些代码吗?
-
客户端证书的颁发者是谁?不确定,但您应该在调用机器上拥有完整的信任链(在您的情况下为 webjob 服务器)。
-
@FabrizioAccatino 我添加了用于加载证书的代码。证书是从某种意大利 CA 颁发的,但我猜微软不支持它:) 顺便说一句,我猜使用
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;证书是否有效并不重要。
标签: azure ssl azure-webjobs