简体   繁体   English

无法为具有权限“*”的 SSL/TLS 建立安全通道

[英]Could not establish secure channel for SSL/TLS with authority '*'

I must consume a PHP webservice which has a SSL certificate.我必须使用具有 SSL 证书的 PHP 网络服务。 My .net 3.5 Class library references the webservice with 'Add Service references' in Visualstudio 2010 (WCF right?).我的 .net 3.5 类库在 Visualstudio 2010 中使用“添加服务引用”来引用 Web 服务(WCF 对吗?)。

When calling the main method of the webservice I receive;调用我收到的网络服务的主要方法时;

Could not establish secure channel for SSL/TLS with authority '{base_url_of_WS}'.无法为具有权限“{base_url_of_WS}”的 SSL/TLS 建立安全通道。

I tried a lot, like我尝试了很多,比如

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

But It wouldn't work.但这行不通。 Also I have the certificate installed on my own machine.我还在我自己的机器上安装了证书。

*Extra info; *额外信息; When I use the wsdl location in 'Add service reference' the same error occurs.当我在“添加服务引用”中使用 wsdl 位置时,会发生同样的错误。 Before I tried it, I worked with a static wsdl.在我尝试之前,我使用了一个静态 wsdl。

替代文字

This was exact the problem I was facing.这正是我面临的问题。 At some other article I got a hint to change the configuration.在其他一些文章中,我得到了更改配置的提示。 For me this works:对我来说,这有效:

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

Problem问题

I was running into the same error message while calling a third party API from my ASP.NET Core MVC project.从我的 ASP.NET Core MVC 项目调用第三方 API 时,我遇到了相同的错误消息。

Could not establish secure channel for SSL/TLS with authority '{base_url_of_WS}'.无法为具有权限“{base_url_of_WS}”的 SSL/TLS 建立安全通道。

Solution解决方案

It turned out that the third party API's server required TLS 1.2.事实证明,第三方 API 的服务器需要 TLS 1.2。 To resolve this issue, I added the following line of code to my controller's constructor:为了解决这个问题,我在控制器的构造函数中添加了以下代码行:

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

Yes an Untrusted certificate can cause this.是的,不受信任的证书可能会导致这种情况。 Look at the certificate path for the webservice by opening the websservice in a browser and use the browser tools to look at the certificate path.通过在浏览器中打开 websservice 来查看 webservice 的证书路径,然后使用浏览器工具查看证书路径。 You may need to install one or more intermediate certificates onto the computer calling the webservice.您可能需要在调用 Web 服务的计算机上安装一个或多个中间证书。 In the browser you may see "Certificate errors" with an option to "Install Certificate" when you investigate further - this could be the certificate you missing.当您进一步调查时,您可能会在浏览器中看到带有“安装证书”选项的“证书错误”——这可能是您缺少的证书。

My particular problem was a Geotrust Geotrust DV SSL CA intermediate certificate missing following an upgrade to their root server in July 2010 https://knowledge.geotrust.com/support/knowledge-base/index?page=content&id=AR1422我的特殊问题是 2010 年 7 月升级到其根服务器后缺少 Geotrust Geotrust DV SSL CA 中间证书https://knowledge.geotrust.com/support/knowledge-base/index?page=content&id=AR1422

( 2020 update deadlink preserved here: https://web.archive.org/web/20140724085537/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)

We had this issue on a new webserver from .aspx pages calling a webservice.我们在从 .aspx 页面调用 Web 服务的新 Web 服务器上遇到了这个问题。 We had not given permission to the app pool user to the machine certificate.我们没有向应用程序池用户授予机器证书的权限。 The issue was fixed after we granted permission to the app pool user.在我们向应用程序池用户授予权限后,该问题已得到解决。

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

In case it helps anyone else, using the new Microsoft Web Service Reference Provider tool , which is for .NET Standard and .NET Core, I had to add the following lines to the binding definition as below:如果它对其他人有帮助,请使用适用于 .NET Standard 和 .NET Core 的新Microsoft Web Service Reference Provider tool ,我必须将以下几行添加到绑定定义中,如下所示:

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

This is effectively the same as Micha's answer but in code as there is no config file.这实际上与 Micha 的答案相同,但在代码中,因为没有配置文件。

So to incorporate the binding with the instantiation of the web service I did this:因此,为了将绑定与 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());

Where WebServiceClient is the proper name of your web service as you defined it.其中 WebServiceClient 是您定义的 Web 服务的正确名称。

This error can occur for lots of reasons, and the last time, I solved it by modifying the Reference.svcmap file, and changing how the WSDL file is referenced.出现此错误的原因有很多,上次我通过修改Reference.svcmap文件以及更改 WSDL 文件的引用方式来解决它。

Throwing exception:抛出异常:

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

Working fine:工作正常:

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

This seems weird, but I have reproduced it.这看起来很奇怪,但我已经复制了它。 This was in a console application on .NET 4.5 and 4.7, as well as a .NET WebAPI site on 4.7.这是 .NET 4.5 和 4.7 上的控制台应用程序,以及 4.7 上的 .NET WebAPI 站点。

Here is what fixed for me:这是为我解决的问题:

1) Make sure you are running Visual Studio as Administrator 1) 确保您以管理员身份运行 Visual Studio

2) Install and run winhttpcertcfg.exe to grant access 2) 安装并运行 winhttpcertcfg.exe 以授予访问权限

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

The command is similar to below: (enter your certificate subject and service name)该命令类似于以下:(输入您的证书主题和服务名称)

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"

Had same error with code:代码有同样的错误:

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

Solved by adding password:通过添加密码解决:

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

For me the solution was changing the SecurityProtocolType .对我来说,解决方案是更改SecurityProtocolType

I put this code before the BasicHttpsBinding creation.我将此代码放在BasicHttpsBinding创建之前。

By the way i created binding from the code side, not from the config file.顺便说一句,我从代码端创建绑定,而不是从配置文件。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通信后无法使用授权建立SSL / TLS的安全通道 - Could not establish secure channel for SSL/TLS with authority after communication 客户端证书:无法为具有权限的SSL / TLS建立安全通道(再次!) - Client certificate: Could not establish secure channel for SSL/TLS with authority (Again!) WCF-升级到.Net 4.6.1后,无法使用授权建立SSL / TLS的安全通道 - WCF - Could not establish secure channel for SSL/TLS with authority after upgrade to .Net 4.6.1 .NET 4.6.2 中 SOAP 的“无法为具有授权的 SSL/TLS 安全通道建立信任关系” - “Could not establish trust relationship for the SSL/TLS secure channel with authority” for SOAP in .NET 4.6.2 如何解决“无法为具有权限的 SSL/TLS 安全通道建立信任关系” - How to solve "Could not establish trust relationship for the SSL/TLS secure channel with authority" 随机抛出“无法建立SSL / TLS安全通道的信任关系” - Randomly throwing “Could not establish trust relationship for the SSL/TLS secure channel” WCF错误“无法为SSL / TLS建立安全通道……” - WCF Error “Could not establish secure channel for SSL/TLS …” out of the blue 随机“无法为SSL / TLS建立安全通道”错误 - Random “could not establish secure channel for SSL/TLS” errors 无法为SOAP调用建立SSL / TLS的安全通道 - Could not establish secure channel for SSL/TLS for SOAP call 无法为 SSL/TLS 安全通道建立信任关系 -- SOAP - Could not establish trust relationship for SSL/TLS secure channel -- SOAP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM