我正在开发一个需要连接到https站点的项目.每次连接时,我的代码都会抛出异常,因为该站点的证书来自不受信任的站点.有没有办法绕过证书检查.net核心http?
我在以前版本的.NET中看到了这段代码.我想我只需要这样的东西.
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用无效证书连接到SignalR服务器.不出所料我收到以下错误:
System.Net.Http.HttpRequestException : An error occurred while sending the request.
----> System.Net.WebException : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
----> System.Security.Authentication.AuthenticationException : The remote certificate is invalid according to the validation procedure.
Run Code Online (Sandbox Code Playgroud)
使用正常的.Net,HttpClient您可以使用WebRequestHandler具有ServerCertificateValidationCallback委托的构造它,允许您更改证书验证行为.SignalR HttpClient似乎没有这个.
无法通过证书验证解决问题.
有Web API服务器,它使用HTTPS来处理请求.服务器的证书具有以下认证路径:RCA(root) - > ICA(中间) - > Web API服务器.RCA,ICA和Web API服务器是同一Active Directory域的成员.
客户端应用程序(桌面,计算机加入同一域)用于HttpClient与服务器通信并支持两种方案:
两种方案都使用基本身份验
RCA和ICA证书分别放在"受信任的根证书颁发机构"和"中间证书颁发机构"中,用于本地计算机帐户.RCA证书是自签名的.
现在,当客户端连接到公司网络时,证书验证按预期工作,用户可以与Web API"对话".
当客户端断开连接(只有Internet连接可用)时,证书验证失败AuthenticationException("远程证书根据验证过程无效").
我不想完全关闭证书验证,但只需要告诉验证系统,这个特定证书是有效的.此外,客户端应用程序使用SignalR,它默认使用它自己的传输.因此,这和这不是选项.
为什么将RCA ICA证书放到"Trusted ..."和"Intermediate ..."文件夹中没有帮助?
有没有解决方法?
从我的 Xamarin 客户端调用 SignalR StartAsync 会抛出我:
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> Mono.Btls.MonoBtlsException: Ssl error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决这个 CERTIFICATE_VERIFY_FAILED 吗?
这是堆栈跟踪:
[错误] 致命未处理异常:System.Net.Http.HttpRequestException:无法建立 SSL 连接,请参阅内部异常。---> System.Security.Authentication.AuthenticationException:身份验证失败,请参阅内部异常。---> Mono.Btls.MonoBtlsException: Ssl 错误:1000007d:SSL 例程:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED 03-21 23:59:57.526 E/mono-rt (6307): 在 /Users/builder/jenkinive mono/2019-08/android/release/external/boringssl/ssl/handshake_client.c:1132 03-21 23:59:57.526 E/mono-rt (6307): 在 Mono.Btls.MonoBtlsContext.ProcessHandshake () [20x000 ] 在 /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/mcs/class/System/Mono.Btls/MonoBtlsContext.cs:220 03-21 23:59:57.526 E/mono- rt(6307):在 Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake(Mono.
1[TResult].get_Result () [0x0001b] in /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/external/corefx/src/Common/src/CoreLib/System/Threading/Tasks/ValueTask.cs:813 03-21 23:59:57.526 E/mono-rt ( 6307): at …