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

发布于 2024-10-08 15:16:14 字数 696 浏览 3 评论 0原文

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

当调用我收到的Web服务的主要方法时;

无法使用权​​限“{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。

替代文本

I must consume a PHP webservice which has a SSL certificate. My .net 3.5 Class library references the webservice with 'Add Service references' in Visualstudio 2010 (WCF right?).

When calling the main method of the webservice I receive;

Could not establish secure channel for SSL/TLS with authority '{base_url_of_WS}'.

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. Before I tried it, I worked with a static wsdl.

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

夜空下最亮的亮点 2024-10-15 15:16:14

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

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

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>
对风讲故事 2024-10-15 15:16:14

问题

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

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

解决方案

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

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

Problem

I was running into the same error message while calling a third party API from my ASP.NET Core MVC project.

Could not establish secure channel for SSL/TLS with authority
'{base_url_of_WS}'.

Solution

It turned out that the third party API's server required 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;
北渚 2024-10-15 15:16:14

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

我的特殊问题是在 2010 年 7 月升级根服务器后,Geotrust Geotrust DV SSL CA 中间证书丢失
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

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. You may need to install one or more intermediate certificates onto the computer calling the webservice. 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

(2020 update deadlink preserved here: https://web.archive.org/web/20140724085537/https://knowledge.geotrust.com/support/knowledge-base/index?page=content&id=AR1422 )

南城追梦 2024-10-15 15:16:14

我们在新的网络服务器上从 .aspx 页面调用网络服务时遇到了这个问题。我们尚未向应用程序池用户授予计算机证书的权限。在我们向应用程序池用户授予权限后,该问题得到解决。

We had this issue on a new webserver from .aspx pages calling a webservice. 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.

别再吹冷风 2024-10-15 15:16:14

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

Ensure you run Visual Studio as an administrator.

橘味果▽酱 2024-10-15 15:16:14

如果它对其他人有帮助,请使用新的 Microsoft Web 服务参考提供程序工具,适用于 .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 服务的正确名称。

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:

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.

So to incorporate the binding with the instantiation of the web service I did this:

 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.

咆哮 2024-10-15 15:16:14

代码有相同的错误:

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

通过添加密码解决:

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

Had same error with code:

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

Solved by adding password:

X509Certificate2 mycert = new X509Certificate2(@"C:\certificate.crt", "password");
不奢求什么 2024-10-15 15:16:14

出现此错误的原因有很多,上次我通过修改 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 站点中。

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.

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.

探春 2024-10-15 15:16:14

对我来说,解决方案是更改SecurityProtocolType

我将此代码放在创建 BasicHttpsBinding 之前。

顺便说一句,我从代码端创建绑定,而不是从配置文件创建绑定。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

For me the solution was changing the SecurityProtocolType.

I put this code before the BasicHttpsBinding creation.

By the way i created binding from the code side, not from the config file.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
浅笑依然 2024-10-15 15:16:14

以下是为我解决的问题:

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"

Here is what fixed for me:

1) Make sure you are running Visual Studio as Administrator

2) Install and run winhttpcertcfg.exe to grant access

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"
心房敞 2024-10-15 15:16:14

服务以不同的用户身份运行,我必须进入管理私钥并添加用户权限

Service was running as a different user, I had to go into manage private key and add the users permissions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文