简体   繁体   English

无法创建 SSL/TLS 安全通道。 安全通道故障

[英]Could not create SSL/TLS secure channel. SecureChannelFailure

I'm getting an SSL error when making a SOAP call with an SSL certificate:使用 SSL 证书进行 SOAP 调用时出现 SSL 错误:

The request was aborted: Could not create SSL/TLS secure channel.请求被中止:无法创建 SSL/TLS 安全通道。

The weird thing is that if I load the certificate in Firefox and visit the endpoint or make a call to the API without sending any data, I don't get any error message and it connects successfully.奇怪的是,如果我在 Firefox 中加载证书并访问端点或调用 API 而不发送任何数据,我不会收到任何错误消息并且连接成功。 The company exposing the API has also mentioned that the certificate is kosher.公开 API 的公司也提到该证书是 kosher 的。

The certificate I'm loading has full privileges to "Everyone".我正在加载的证书对“所有人”具有完全权限。 I've tried every solution I've seen on the internet but still getting the error.我已经尝试了我在互联网上看到的所有解决方案,但仍然出现错误。

Here is my code that creates the request:这是我创建请求的代码:

 ServicePointManager.Expect100Continue = true;
 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
 var request = (HttpWebRequest)WebRequest.Create(plugin.EndPoint);
 request.ContentType = "text/xml; charset=utf-8";
 request.Method = "POST";

The code to get the certificate (I've also tried with a pfx):获取证书的代码(我也尝试过使用 pfx):

var cert = new 
 509Certificate2(@"C:\clientcert.p12", "FakePassword");
request.ClientCertificates.Add(cert);

and the code for the request:和请求的代码:

  byte[] byteArray = Encoding.UTF8.GetBytes(xml);
    request.ContentLength = byteArray.Length;
    using (var dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Close();


                    using (WebResponse response = request.GetResponse())
                    {
                        using (var responseStream = response.GetResponseStream())
                        {
                            StreamReader reader = 
new StreamReader(responseStream ?? throw new InvalidOperationException());
                            return reader.ReadToEnd();
                        }
                    }

                }

Edit:编辑:

Here is the trace output from running the request:这是运行请求的跟踪输出:

System.Net Information: 0 : [11844] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=0, returned code=CertUnknown). System.Net 信息:0:[11844] InitializeSecurityContext(In-Buffers count=2,Out-Buffer length=0,返回的代码=CertUnknown)。 System.Net Error: 0 : [11844] Exception in HttpWebRequest#63832831:: - The request was aborted: Could not create SSL/TLS secure channel.. System.Net Error: 0 : [11844] Exception in HttpWebRequest#63832831::EndGetRequestStream - The request was aborted: Could not create SSL/TLS secure channel.. System.Net 错误:0:[11844] HttpWebRequest 中的异常#63832831:: - 请求被中止:无法创建 SSL/TLS 安全通道.. System.Net 错误:0:[11844] HttpWebRequest 中的异常#63832831:: EndGetRequestStream - 请求被中止:无法创建 SSL/TLS 安全通道..

I also changed the SecurityProtocol:我还更改了 SecurityProtocol:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; 

Second Edit: I can get it to work in SoapUI but not in the .NET application by just loading the SSL certificate from the file system in SOAP UI.第二次编辑:我可以通过在 SOAP UI 中从文件系统加载 SSL 证书,让它在 SoapUI 中工作,但不能在 .NET 应用程序中工作。

Out of interest, your app is using the TLS 1.0, 1.1 and 1.2 protocols, but is its use enabled in Internet Explorer?出于兴趣,您的应用程序使用 TLS 1.0、1.1 和 1.2 协议,但它是否在 Internet Explorer 中启用?

If it's not in the web.config, add it如果它不在 web.config 中,请添加它

<appSettings>
    <add key="SecurityProtocol" value="Tls12" />
</appSettings>

Then also check it's enabled in IE in the advanced settings tab: "Use TLS 1.2"然后在高级设置选项卡中检查它是否在 IE 中启用:“使用 TLS 1.2”

Your SSL certificate is signed by a root certificate that isn't installed in Windows.您的 SSL 证书由未安装在 Windows 中的根证书签名。

Firefox ships with it's own trusted root cert list that contains the root cert for the cert you're using. Firefox 附带了它自己的受信任根证书列表,其中包含您正在使用的证书的根证书。 Just because Firefox trusts a cert doesn't mean that Windows trusts it.仅仅因为 Firefox 信任证书并不意味着 Windows 信任它。

The solution is to install your cert's root cert or cert chain on the computer running your app.解决方案是在运行您的应用程序的计算机上安装您的证书的根证书或证书链。

https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-temporary-certificates-for-use-during-development https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-temporary-certificates-for-use-during-development

If this is an app with a wide audience, an easier solution is to switch to an SSL provider that already uses a root cert that ships with Windows.如果这是一个拥有广泛受众的应用程序,更简单的解决方案是切换到已经使用 Windows 附带的根证书的 SSL 提供程序。

Sometimes I have this error as well.有时我也有这个错误。 The steps I take to overcome this problem are as follows:我为克服这个问题所采取的步骤如下:

  1. Export your certificate from IIS从 IIS 导出您的证书
  2. Double click the certificate and follow the wizard双击证书并按照向导操作
  3. Store location 'Local machine' next ->下一个存储位置“本地机器”->
  4. Fill in the password you have picked during the export填写导出时选择的密码
  5. Check the option to place the certificate in a store and choose your 'Trusted Root Certification Authorities'选中将证书放入商店的选项,然后选择“受信任的根证书颁发机构”
  6. Finish -> to check if the import was successful type in 'Windows search' 'certmgr.msc' navigate to the 'Trusted Root Certification Authorities' and then the certificates folder.完成 -> 检查导入是否成功,输入“Windows 搜索”“certmgr.msc”,导航到“受信任的根证书颁发机构”,然后导航到证书文件夹。 The imported certificate should be present.应提供导入的证书。
  7. Test with your application.使用您的应用程序进行测试。

I hope it helps我希望它有帮助

暂无
暂无

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

相关问题 无法创建ssl / tls安全通道。 Html敏捷 - Could Not create ssl/tls secure channel. Html Agility 无法创建 SSL/TLS 安全通道。 (SSIS) - Could not create SSL/TLS secure channel. (SSIS) 错误“无法创建SSL / TLS安全通道。”尽管手动设置了TLS - Error “Could not create SSL/TLS secure channel.” despite manually setting TLS 该请求已中止:无法创建SSL / TLS安全通道。 | System.Net.WebException - The request was aborted: Could not create SSL/TLS secure channel. | System.Net.WebException 无法创建SSL / TLS安全通道。客户端和服务器无法通信,因为它们没有通用算法 - Could not create SSL/TLS secure channel. The client and server cannot communicate, because they do not possess a common algorithm 该请求已中止:无法创建SSL / TLS安全通道。 调用PostAsJsonAsync时 - The request was aborted: Could not create SSL/TLS secure channel. when calling PostAsJsonAsync HttpWebrequest 因 yande.re(以及 IE 和 curl)而失败[“请求已中止:无法创建 SSL/TLS 安全通道。”] - HttpWebrequest fails with yande.re (and IE and curl)["The request was aborted: Could not create SSL/TLS secure channel."] 该请求已中止:无法创建SSL / TLS安全通道。 用于HttpWebRequest和WebClient - The request was aborted: Could not create SSL/TLS secure channel. for HttpWebRequest and WebClient 请求被中止:无法创建 SSL/TLS 安全通道。 在本地工作但不住在 - The request was aborted: Could not create SSL/TLS secure channel. Working locally but not live 错误请求被中止:无法创建 SSL/TLS 安全通道。 仅在 Windows 服务器 2012 上 - Error The request was aborted: Could not create SSL/TLS secure channel. only on Windows Server 2012
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM