【问题标题】:Does the Managed Xamarin HttpClient Implementation support TLS 1.2?托管 Xamarin HttpClient 实现是否支持 TLS 1.2?
【发布时间】:2018-06-20 14:44:49
【问题描述】:

应用程序传输层安全性的官方 Xamarin 文档(iOSAndroid)指出托管 HttpClient 实现仅支持 TLS 1.0。它强烈建议将 Xamarin 应用程序更新为本机 HttpClient 实现以支持 TLS 1.2。 Visual Studio 也说明了这一点:

但是,文档是矛盾的。在描述托管 HttpClient 实现时,它声明如下:

它没有与操作系统完全集成(例如,仅限于 TLS 1.0)。

后面的文档有矛盾的陈述,例如:

从 Xamarin.Android 8.3 开始,HttpClientHandler 默认为 Boring SSL ...它支持 TLS 1.2+。

此外,very helpful Xamarin blog post 指出,通过选择 SSL/TLS 选项“native TLS 1.2”(这是 iOS 上的默认设置,不能在 iOS 上更改)。

最后但并非最不重要的一点是,我针对仅支持 TLS 1.2 的 https://www.nist.gov 测试了当前稳定 Xamarin 版本1 的 HttpClient。我验证了服务器只接受 TLS 1.2:

openssl s_client -connect nist.gov:443 -no_tls1_2

如果托管的 HttpClient 实现确实只支持 TLS 1.0,我预计以下连接会失败:

var client = new HttpClient();
var result = await client.GetStringAsync("https://www.nist.gov");

但是,通过以下设置连接成功:

  • iOS:HttpClient 实现托管
  • Android:HttpClient 实现 Managed (HttpClientHandler)Default,以及 SSL/TLS 实现 Native TLS 1.2

这导致我提出以下问题:

  1. 在声明托管 HttpClient 实现仅支持 TLS 1.0 时,Xamarin 文档是否已过时?
  2. 我对@9​​87654326@ 的测试有效吗?它是否确实表明托管的 HttpClient 实现支持 TLS 1.2?还是我错过了什么?

1 Visual Studio 7.5.2(内部版本 40)、Xamarin.iOS 11.12.0.4、Xamarin.Android 8.3.3.2

【问题讨论】:

  • 托管提供程序不支持 TLS1.2...不确定您的测试,但您可以查看 Mono 存储库中的代码,并且不支持 1.2。
  • @SushiHangover 是的,我相信这就是 SSL/TLS 实现HttpClient 实现 这两个设置发挥作用的地方。据我了解,托管 HttpClient 实现 可以在支持 TLS 1.2 的 Xamarin.Android 和 Xamarin.iOS 上使用 本机 SSL/TLS 提供程序。托管 TLS 提供程序仅支持 TLS 1.0,但在当前默认 Xamarin 项目设置中不活动。例如。 this blogpost 讲这个,如果我的理解是正确的。

标签: xamarin xamarin.ios xamarin.android tls1.2


【解决方案1】:

如果您使用“本机”处理程序(Android 或 iOS),它使用本机 API 来实现 HttpClientHandler 功能,因此“平台依赖”取决于是否支持 TLS1.2,即 Android 5 /API-21 本身不支持 TLS1.2,大多数 Android 开发者使用 3rd-party 库...

当您启用“本机 SSL/TLS”时,它是使用 Google 的 BoringSSL(现在包含在您的应用程序包中)和不是本机平台 API。因此,即使使用“托管”HttpClientHandler 也支持 TLS1.2。此选项允许“.Net framework/Mono”支持 iOS 和 Android 上最新的 SSL/TLS,例如 .Net Sockets、WebClient 等。当然还有 HttpClient。

https://www.nist.gov测试:

Android Handler / Managed SSL    :  No exception
Managed Handler / Native SSL/TLS :  No exception
Android Handler / Native SSL/TLS :  No exception
Managed Handler / Managed SSL    :  Error: SecureChannelFailure 

SecureChannelFailure

MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: SecureChannelFailure (The authentication or decryption has failed.) --->
System.IO.IOException: The authentication or decryption has failed. --->
System.IO.IOException: Error while sending TLS Alert (Fatal:InternalError): System.IO.IOException: The authentication or decryption has failed. --->
System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer. ---> 
System.Net.Sockets.SocketException: Connection reset by peer

【讨论】:

    猜你喜欢
    • 2020-04-10
    • 2016-09-12
    • 1970-01-01
    • 1970-01-01
    • 2021-11-20
    • 2018-08-23
    • 1970-01-01
    • 2018-02-11
    • 1970-01-01
    相关资源
    最近更新 更多