System.Net.Http.HttpRequestException:SSL [英] System.Net.Http.HttpRequestException: SSL

查看:548
本文介绍了System.Net.Http.HttpRequestException:SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能应用程序,我收到此错误: 

I have a function app in which I get this error : 

有时可以正常工作,有时却不行。具有相同的查询参数且无更改。 

It works ok sometimes and doesn't at other times. With the same query parameters and no changes. 

System.Net.Http.HttpRequestException:无法建立SSL连接,请参阅内在的例外。 ---> System.Security.Authentication.AuthenticationException:根据验证程序,远程证书无效。

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.




推荐答案

从描述中有功能应用程序中的代码对使用仅在您的网络中受信任的证书
的后端服务的HTTPS请求。由于Web应用程序/功能应用程序服务器没有受信任的根证书,因此失败并显示"不受信任"错误。如果我误解了配置,请告诉我。

但是,以下信息基于该特定假设。

遗憾的是,由于安全问题,无法将证书导入Azure Web Apps / Function应用程序中的受信任根存储。解决此
错误的唯一选择是在应用程序代码中处理类似于此处描述的验证:  https://stackoverflow.com/a/34204814
我们过去曾成功使用过这些步骤,例如:



  1. 创建新证书以获取要上传的PFX文件。
  2. 将PFX上传到SSL证书区域中的应用服务
  3. 按照此链接中的步骤1和2加载证书:  https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applica tions /
  4. 在上面的链接和代码中添加第3步中代码的组合:  Azure
    Web应用程序使用自签名SSL证书调用本地服务
    。本质上,从证书存储区获取证书,但是从ServerCertificateValidationCallback函数中获取证书然后如果证书匹配验证,则返回true。代码看起来是
    ,如下所示:
  1. Create a new certificate to obtain a PFX file to upload.
  2. Upload the PFX to app service in the SSL Certificates area
  3. Follow steps 1 and 2 from this link to load the certificate: https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/
  4. Add a combination of the code in step 3 from the above link and the code here: Azure Web App calling on-prem service with Self-Signed SSL Cert. Essentially, get the certificate from the cert store, but from within the ServerCertificateValidationCallback function and then return true if the certs match for validation. The code looks something like this:

ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
            {
                if (sslPolicyErrors == SslPolicyErrors.None)
                {
                    return true;
                }
 
                var certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
                certStore.Open(OpenFlags.ReadOnly);
                var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, "THUMBPRINT", false);
 
                if (certCollection.Count > 0)
                {
                    var validCertificate = certCollection[0];
                    var passedCert = new X509Certificate2(certificate);
                    certStore.Close();
 
                    return validCertificate.Equals(passedCert);
                }
                certStore.Close();
                return false;
            };


这篇关于System.Net.Http.HttpRequestException:SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆