SSL HttpWebRequest到Azure上存在不匹配证书的站点?
问题描述:
我们的客户在质量保证环境中存在不匹配的SSL证书。我们正在使用Azure Web角色对这些受SSL保护的Web资源进行HttpWebRequest调用。为了绕过他们的证书,我们将ServicePointManager.CertificatePolicy设置为接受所有证书的新策略。这可以在完全信任的环境中运行,但是当我们尝试在低于完全信任的Azure环境中设置CertificatePolicy时,会出现SecurityPermission异常。有没有办法让我们可以在Azure服务中使用这些调用?SSL HttpWebRequest到Azure上存在不匹配证书的站点?
答
我会回答我自己的问题!
显然,要完全信任地运行它,只需在Web角色配置中启用enableNativeCodeExecution =“true”即可。
答
请问这是什么?
System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate (
object sender,
X509Certificate cert,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
{
return true; //Is valid
}
//Add the mismatched certificate hashstring below.
//That way only that resource will be affected and not all certificates will be trusted.
if (cert.GetCertHashString() == "99E92D8447AEF30483B1D7527812C9B7B3A915A7")
{
return true;
}
return false;
};