您好,我有一个 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。这是加载应用程序的客户端证书所必需的。
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/