【发布时间】:2017-09-25 09:24:40
【问题描述】:
我正在尝试使用 TLS1.2 从 Xamarin.Forms 发送 POST 事务,但我看到它们以 TLS 1.1 的形式到达服务器。
我已配置 Android 选项:
HttpClient 实现为 Android
SSL/TLS 实现为 Native TLS 1.2+
我在 VisualStudio 2017 中实现和执行,并在模拟器中使用 Android 6.0。
关于代码,我设置了一些环境变量:
System.Environment.SetEnvironmentVariable("MONO_TLS_PROVIDER", "btls");
System.Environment.SetEnvironmentVariable("XA_TLS_PROVIDER", "btls");
System.Environment.SetEnvironmentVariable("XA_HTTP_CLIENT_HANDLER_TYPE", "Xamarin.Android.Net.AndroidClientHandler");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
最后,POST 发送:
using (HttpClient client = new HttpClient())
or
using (HttpClient client = new HttpClient(new NativeMessageHandler()))
or
using (HttpClient client = new HttpClient(new Xamarin.Android.Net.AndroidClientHandler()))
{
try
{
HttpResponseMessage responseHttp = await client.PostAsync(new Uri(new Uri(Constants.ApiBaseUrl), "authorize"), content);
...
Constants.ApiBaseUrl 包含 https:// 格式的 url。
问题是,发送 POST 时我没有异常,但在我的服务器中,我使用 Wireshark 看到的事务为:
HttpWebRequest httpWebRequest = WebRequest.CreateHttp(new Uri(new Uri(Constants.ApiBaseUrl), "authorize"));
httpWebRequest.Method = "POST";
httpWebRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
Stream sw = httpWebRequest.GetRequestStream();
sw.Write(contentByte, 0, contentByte.Length);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
使用和不使用我自己的证书:
httpWebRequest.ClientCertificates = cryptoSvc.x509HostCertificates;
在这种情况下,如果我使用
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
我得到了异常
RestService-SendJsonDataAsync ERROR: Error: SecureChannelFailure
(**Ssl error:100000f0:SSL routines:OPENSSL_internal:UNSUPPORTED_PROTOCOL**
at /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/external/boringssl/ssl/handshake_client.c:808)
如果没有该行,它也将作为 TLS1.1 到达。
请问有人对我的问题有什么想法或建议吗?
非常感谢您的时间和帮助。
【问题讨论】:
标签: android xamarin.forms tls1.2