繁体   English   中英

客户端处理程序无法识别我信任的 API 证书

[英]Client handler not recognizing my trusted API certificate

我在使用 HttpClientHandler 时遇到问题,当我使用新的实例化 API 调用被认为是不可靠的,当使用本机时这不会发生,有谁知道可能发生了什么? 或者必须做些什么才能使我的处理程序行为正常?

下面是我实例化和使用它的代码片段。

private static HttpClient ConfigureClient(string endpoint)
{
    return new HttpClient(_authenticatedHttpClientHandler)
    {
        BaseAddress = new Uri($"{Endpoints.FULL_URL}/{endpoint}"),
        Timeout = new TimeSpan(0, 0, ServiceConfiguration.TIMEOUT)
    };
}

public static void RegisterContainer(IContainerRegistry container)
{
     _authenticatedHttpClientHandler = new AuthenticatedHttpClientHandler();

    container.RegisterInstance(_authenticatedHttpClientHandler);
}

证书是使用 Let's Encrypt(通配符)教程创建的。

堆栈跟踪:

{System.Net.WebException:错误:TrustFailure(身份验证失败,请参阅内部异常。)---> System.Security.Authentication.AuthenticationException:身份验证失败,请参阅内部异常。 ---> Mono.Security.Interface.TlsException:CertificateUnknown at Mono.AppleTls.AppleTlsContext.EvaluateTrust () [0x000bf] in /Users/builder/jenkins/workspace/xamarin-macios/mx/ /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/ 中的类/System/Mono.AppleTls/AppleTlsContext.cs:306 在 Mono.AppleTls.AppleTlsContext.ProcessHandshake () [0x00075]类/System/Mono.AppleTls/AppleTlsContext.cs:213 在 Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncOperationStatus 状态,System.Boolean 工作空间/xUsers//builder) /xamarin-macios/xamarin-macios/external/mono/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:840 在 Mono.Net.Security.AsyncHandshakeRequest.Run (Mono.Net.Security.AsyncO perationStatus 状态)[0x00000] 在 /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:289 在 Mono.Net。 Security.AsyncProtocolRequest.ProcessOperation (System.Threading.CancellationToken cancelToken) [0x000fc] 在 /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System/Mono.Net.Security/ AsyncProtocolRequest.cs:223 --- End of inner exception stack trace --- at Mono.Net.Security.MobileAuthenticatedStream.ProcessAuthentication (System.Boolean runSynchronously, Mono.Net.Security.MonoSslAuthenticationOptions options, System.Threading.CancellationToken cancellationToken) [ 0x0025c] 在 /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:406 在 Z5D9B47BD3B65072E0D5DAF /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs 中的 55F01DA086Z.Net.Security.MonoTlsStream.CreateStream(System.Net.WebConnectionTunnel 隧道,System.Threading.CancellationToken cancelToken)[0x00176] /class/System/Mono.Net.Security/MonoTlsStream.cs:137 在 System.Net.WebConnection.CreateStream (System.Net.WebOperation 操作,System.Boolean 重用,System.Threading.CancellationToken cancelToken)[0x00170] 在 /Users /builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System/System.Net/WebConnection.cs:222 ---内部异常堆栈跟踪结束---在 System.Net .WebConnection.CreateStream(System.Net.WebOperation 操作,System.Boolean 重用,System.Threading.CancellationToken cancelToken)[0x00208] 在 /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs /class/System/System.Net/WebConnection.cs:234 在 System.Net.WebConnecti /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System/System 中的 on.InitConnection(System.Net.WebOperation 操作,System.Threading.CancellationToken cancelToken)[0x000f7] .Net/WebConnection.cs:263 在 System.Net.WebOperation.Run () [0x00052] 在 /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System/System .Net/WebOperation.cs:268 在 System.Net.WebCompletionSource1[T].WaitForCompletion () [0x0008e] 在 /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/ System/System.Net/WebCompletionSource.cs:111 在 System.Net.HttpWebRequest.RunWithTimeoutWorker[T](System.Threading.Tasks.Task1[TResult] workerTask,System.Int32 超时,System.Action 中止,System.Func`1 [TResult] 中止,System.Threading.CancellationTokenSource cts) [0x000e8] 在 /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System/System.Net/HttpWebRequest.cs :956 在 System.Ne t.Http.MonoWebRequestHandler.SendAsync(System.Net.Http.HttpRequestMessage 请求,System.Threading.CancellationTokencancellationToken)[0x0029b] 在 /Users/builder/jenkins/workspace/xamarin-macios/mx /class/System.Net.Http/MonoWebRequestHandler.cs:485 }

我在使用 HttpClientHandler 时遇到问题,当我使用新的实例化 API 调用被认为是不可靠的,当使用本机时这不会发生,有谁知道可能发生了什么?

根据iOS 的 TLS 的托管部分和 HttpClient 的 Mac托管实现:

它没有与 Apple 操作系统完全集成,并且仅限于 TLS 1.0。 将来它可能无法连接到安全的 web 服务器或云服务

并根据传输层安全 (TLS) 1.2

2018 年 4 月– 由于包括 PCI 合规性在内的安全要求增加,预计主要云提供商和 web 服务器将停止支持早于 1.2 的 TLS 版本。 在以前版本的 Visual Studio 中创建的 Xamarin 项目默认使用旧版本的 TLS。

所以应该始终使用 HttpClient 的本机实现而不是托管方式来支持 TLS1.2+。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM