【问题标题】:SSL HttpWebRequest to site with mismatched certificate on Azure?SSL HttpWebRequest 到 Azure 上证书不匹配的站点?
【发布时间】:2009-05-28 00:27:27
【问题描述】:

我们的客户在其 QA 环境中的 SSL 证书不匹配。我们正在从 Azure Web 角色中对这些受 SSL 保护的 Web 资源进行 HttpWebRequest 调用。为了绕过他们的证书,我们将 ServicePointManager.CertificatePolicy 设置为接受所有证书的新策略。这适用于完全信任的环境,但当我们尝试在不太完全信任的 Azure 环境中设置 CertificatePolicy 时,会失败并出现 SecurityPermission 异常。有没有一种方法可以让我们在 Azure 服务中进行这些调用?

【问题讨论】:

    标签: c# ssl httpwebrequest azure


    【解决方案1】:

    我会回答我自己的问题!

    显然,要在完全信任的情况下运行它,您只需要在 Web 角色配置中启用NativeCodeExecution="true"。

    【讨论】:

      【解决方案2】:

      这可能是什么?

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

      【讨论】:

        猜你喜欢
        • 2011-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-02
        • 1970-01-01
        相关资源
        最近更新 更多