【问题标题】:Could not establish secure channel for SSL/TLS with authority '*'无法为具有权限“*”的 SSL/TLS 建立安全通道
【发布时间】:2011-05-26 16:43:01
【问题描述】:

我必须使用具有 SSL 证书的 PHP 网络服务。我的 .net 3.5 类库在 Visualstudio 2010 中使用“添加服务引用”引用 Web 服务(WCF 对吗?)。

调用我收到的webservice的main方法时;

无法为具有权限“{base_url_of_WS}”的 SSL/TLS 建立安全通道。

我尝试了很多,比如

System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); 
 public bool CheckValidationResult(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
        return true;
    }

但这行不通。我还在自己的机器上安装了证书。

*额外信息;当我在“添加服务引用”中使用 wsdl 位置时,会发生相同的错误。在尝试之前,我使用的是静态 wsdl。

【问题讨论】:

  • 完全没有,刚刚发签过
  • 有什么方法可以尝试通过浏览器连接到 Web 服务(例如查看服务元数据)?这将有助于确定问题是出在证书上还是在 WCF 内。
  • 我有类似的异常 - 请参阅:stackoverflow.com/questions/8594684/…
  • @PaulTurner 如果 Web 服务通过浏览器运行,这表明什么? WCF 内部有问题?

标签: .net wcf web-services ssl https


【解决方案1】:

这正是我面临的问题。在其他一些文章中,我得到了更改配置的提示。对我来说这是可行的:

<bindings>
  <basicHttpBinding>
    <binding name="xxxBinding">
      <security mode="Transport">
        <transport clientCredentialType="Certificate"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

【讨论】:

  • 谢谢。运输部分正是我所需要的!经过数小时的测试后修复了它。 :)
  • 运输线也帮我修好了。即使我在代码中手动添加了正确的、受信任的证书,它也无法正确识别它,直到在我的 .config 文件中添加该行。谢谢!
  • 同样的问题,通过这个配置设置解决了。谢谢,我花了 3 个小时在上面
  • 谢谢!解决了我的问题,但在 标签内
【解决方案2】:

问题

我在从我的 ASP.NET Core MVC 项目调用第三方 API 时遇到了同样的错误消息。

无法为具有权限的 SSL/TLS 建立安全通道 '{base_url_of_WS}'。

解决方案

原来第三方 API 的服务器需要 TLS 1.2。为了解决这个问题,我在控制器的构造函数中添加了以下代码行:

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

【讨论】:

  • 除非您特别不想要 SSL 连接,否则您应该 OR TLS 值而不是分配:System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;
【解决方案3】:

是的,不受信任的证书可能会导致这种情况。通过在浏览器中打开 websservice 来查看 webservice 的证书路径,然后使用浏览器工具查看证书路径。您可能需要在调用 Web 服务的计算机上安装一个或多个中间证书。当您进一步调查时,您可能会在浏览器中看到带有“安装证书”选项的“证书错误”——这可能是您缺少的证书。

我的特殊问题是 Geotrust Geotrust DV SSL CA 中间证书在 2010 年 7 月升级到他们的根服务器后丢失 https://knowledge.geotrust.com/support/knowledge-base/index?page=content&id=AR1422

2020 更新此处保留了死链接:https://web.archive.org/web/20140724085537/https://knowledge.geotrust.com/support/knowledge-base/index?page=content&id=AR1422

【讨论】:

    【解决方案4】:

    我们在从 .aspx 页面调用 Web 服务的新 Web 服务器上遇到了这个问题。我们没有向应用程序池用户授予机器证书的权限。在我们向应用程序池用户授予权限后,该问题已得到解决。

    【讨论】:

      【解决方案5】:

      确保以管理员身份运行 Visual Studio。

      【讨论】:

        【解决方案6】:

        如果它可以帮助其他人,使用新的Microsoft Web Service Reference Provider tool,它适用于 .NET Standard 和 .NET Core,我必须将以下行添加到绑定定义中,如下所示:

        binding.Security.Mode = BasicHttpSecurityMode.Transport;
        binding.Security.Transport = new HttpTransportSecurity{ClientCredentialType = HttpClientCredentialType.Certificate};
        

        这实际上与 Micha 的答案相同,但在代码中因为没有配置文件。

        因此,为了将绑定与 Web 服务的实例化结合起来,我这样做了:

         System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();
         binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
         binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Certificate;
         var client = new WebServiceClient(binding, GetWebServiceEndpointAddress());
        

        其中 WebServiceClient 是您定义的 Web 服务的正确名称。

        【讨论】:

          【解决方案7】:

          出现这个错误的原因有很多,上次我通过修改Reference.svcmap文件,改变WSDL文件的引用方式解决了。

          抛出异常:

          <MetadataSource Address="C:\Users\Me\Repo\Service.wsdl" Protocol="file" SourceId="1" />
          <MetadataFile FileName="Service.wsdl" ... SourceUrl="file:///C:/Users/Me/Repo/Service.wsdl" />
          

          工作正常:

          <MetadataSource Address="https://server.domain/path/Service.wsdl" Protocol="http" SourceId="1" />
          <MetadataFile FileName="Service.wsdl" ... SourceUrl="https://server.domain/path/Service.wsdl" />
          

          这看起来很奇怪,但我已经复制了它。这是 .NET 4.5 和 4.7 上的控制台应用程序,以及 4.7 上的 .NET WebAPI 站点。

          【讨论】:

            【解决方案8】:

            这是为我解决的问题:

            1) 确保您以管理员身份运行 Visual Studio

            2) 安装并运行 winhttpcertcfg.exe 以授予访问权限

            https://msdn.microsoft.com/en-us/library/windows/desktop/aa384088(v=vs.85).aspx

            命令类似如下:(输入您的证书主题和服务名称)

            winhttpcertcfg -g -c LOCAL_MACHINE\MY -s "certificate subject" -a "NetworkService"
            winhttpcertcfg -g -c LOCAL_MACHINE\MY -s "certificate subject" -a "LOCAL SERVICE"
            winhttpcertcfg -g -c LOCAL_MACHINE\MY -s "certificate subject" -a "My Apps Service Account"
            

            【讨论】:

            【解决方案9】:

            代码有同样的错误:

            X509Certificate2 mycert = new X509Certificate2(@"C:\certificate.crt");
            

            加密码解决:

            X509Certificate2 mycert = new X509Certificate2(@"C:\certificate.crt", "password");
            

            【讨论】:

            • 这是您要通过的中间证书吗?
            猜你喜欢
            • 2014-11-26
            • 2019-12-05
            • 2018-04-21
            • 1970-01-01
            • 2020-08-05
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多