From 53bcf69f914e83b1dcf6c1108186268f979131d6 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Wed, 27 Jul 2016 21:59:24 -0400 Subject: [PATCH] [msbuild]: Add TLS Provider selection for BTLS. * Tasks/BuildApk.cs: Add 'TlsProvider' parameter. * Xamarin.Android.Common.targets: Add property and pass it to BuildApk. Add this to your .csproj file to select the TLS Provider. Valid values are "legacy" and "btls". We now add a new 'XA_TLS_PROVIDER' environment variable to the .apk, which is read by System/Mono.Net.Security/MonoTlsProviderFactory.Droid.cs to select the TLS Provider. Linker support (to eliminate the unused provider, similar to how it's already done in xamarin-macios) is coming shortly. --- src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs | 8 ++++++++ .../Xamarin.Android.Common.targets | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs index 1e1fd67e3..cb3862c0a 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs @@ -85,6 +85,7 @@ namespace Xamarin.Android.Tasks public string AndroidGdbDebugServer { get; set; } public string AndroidEmbedProfilers { get; set; } public string HttpClientHandlerType { get; set; } + public string TlsProvider { get; set; } [Output] public ITaskItem[] OutputFiles { get; set; } @@ -201,6 +202,7 @@ namespace Xamarin.Android.Tasks Log.LogDebugTaskItems (" LibraryProjectJars:", LibraryProjectJars); Log.LogDebugTaskItems (" AdditionalNativeLibraryReferences:", AdditionalNativeLibraryReferences); Log.LogDebugTaskItems (" HttpClientHandlerType:", HttpClientHandlerType); + Log.LogDebugTaskItems (" TlsProvider:", TlsProvider); Aot.TryGetSequencePointsMode (AndroidSequencePointsMode, out sequencePointsMode); @@ -323,6 +325,7 @@ namespace Xamarin.Android.Tasks const string defaultLogLevel = "MONO_LOG_LEVEL=info"; const string defaultMonoDebug = "MONO_DEBUG=gen-compact-seq-points"; const string defaultHttpMessageHandler = "XA_HTTP_CLIENT_HANDLER_TYPE=Xamarin.Android.Net.AndroidClientHandler"; + const string defaultTlsProvider = "XA_TLS_PROVIDER=default"; string xamarinBuildId = string.Format ("XAMARIN_BUILD_ID={0}", buildId); if (Environments == null) { @@ -340,6 +343,7 @@ namespace Xamarin.Android.Tasks bool haveMonoDebug = false; bool havebuildId = false; bool haveHttpMessageHandler = false; + bool haveTlsProvider = false; foreach (ITaskItem env in Environments) { environment.WriteLine ("## Source File: {0}", env.ItemSpec); @@ -356,6 +360,8 @@ namespace Xamarin.Android.Tasks } if (lineToWrite.StartsWith ("XA_HTTP_CLIENT_HANDLER_TYPE=", StringComparison.Ordinal)) haveHttpMessageHandler = true; + if (lineToWrite.StartsWith ("XA_TLS_PROVIDER=", StringComparison.Ordinal)) + haveTlsProvider = true; environment.WriteLine (lineToWrite); } } @@ -373,6 +379,8 @@ namespace Xamarin.Android.Tasks if (!haveHttpMessageHandler) environment.WriteLine (HttpClientHandlerType == null ? defaultHttpMessageHandler : $"XA_HTTP_CLIENT_HANDLER_TYPE={HttpClientHandlerType.Trim ()}"); + if (!haveTlsProvider) + environment.WriteLine (TlsProvider == null ? defaultTlsProvider : $"XA_TLS_PROVIDER={TlsProvider.Trim ()}"); apk.AddEntry ("environment", environment.ToString (), new UTF8Encoding (encoderShouldEmitUTF8Identifier:false)); diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index eae8eff69..b33152e24 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -2243,7 +2243,8 @@ because xbuild doesn't support framework reference assemblies. LibraryProjectJars="@(ExtractedJarImports)" AndroidEmbedProfilers="$(AndroidEmbedProfilers)" AndroidGdbDebugServer="$(AndroidGdbDebugServer)" - HttpClientHandlerType="$(AndroidHttpClientHandlerType)"> + HttpClientHandlerType="$(AndroidHttpClientHandlerType)" + TlsProvider="$(AndroidTlsProvider)">