代码之家  ›  专栏  ›  技术社区  ›  jspru

ssl httpwebrequest到具有不匹配的Azure证书的站点?

  •  0
  • jspru  · 技术社区  · 17 年前

    我们有一个客户机,其QA环境中的SSL证书不匹配。我们正在从一个Azure Web角色中对那些受SSL保护的Web资源进行httpwebrequest调用。为了绕过他们的证书,我们将servicePointManager.certificatepolicy设置为接受所有证书的新策略。这在完全信任环境中工作,但在尝试在不完全信任的Azure环境中设置证书策略时,由于SecurityPermission异常而失败。有没有一种方法可以让这些调用在我们的Azure服务中工作?

    2 回复  |  直到 17 年前
        1
  •  0
  •   jspru    17 年前

    我自己回答问题!

    显然,要完全信任地运行它,只需在Web角色配置中启用nativecodeexecution=“true”。

        2
  •  0
  •   Ogglas    9 年前

    这会是什么吗?

    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;
    };