[mtouch][mmp] Only allow `appletls` for the TLS provider (#1132)

The old `legacy` option will now be reported as a warning. 

That's by design an warning would require manually editing the .csproj
file (when the UI gets removed, as planned, from the IDE). 

This is part of
https://trello.com/c/SrgU38DN/647-only-ship-support-appletls

Note: The BCL changes will happen in later stages.
This commit is contained in:
Sebastien Pouliot 2016-11-08 14:42:40 -05:00 коммит произвёл GitHub
Родитель d42a9f4909
Коммит c92934eb6d
14 изменённых файлов: 37 добавлений и 215 удалений

Просмотреть файл

@ -835,7 +835,11 @@ This generally indicates that there is a problem with your Xamarin.iOS installat
<h3><a name="MT2010"/>MT2010: Unknown HttpMessageHandler `*`. Valid values are HttpClientHandler (default), CFNetworkHandler or NSUrlSessionHandler</h3>
<h3><a name="MT2011"/>MT2011: Unknown TlsProvider `*`. Valid values are default, legacy or appletls.</h3>
<h3><a name="MT2011"/>MT2011: Unknown TlsProvider `*`. Valid values are default or appletls.</h3>
The value given to `tls-provider=` is not a valid TLS (Transport Layer Security) provider.
The `default` and `appletls` are the only valid values and both represent the same option, which is to provide the SSL/TLS support using the native Apple TLS API.
<!--- 2012 used by mmp -->
@ -847,6 +851,12 @@ Earlier versions of our preview tools generated by default an invalid value in t
To fix this warning, open the project file in a text editor, and remove all HttpMessageHandler nodes from the XML.
<h3><a name="MT2016"/>MT2016: Invalid TlsProvider `legacy` option. The only valid value `appletls` will be used.</h3>
The `legacy` provider, which was a fully managed SSLv3 / TLSv1 only provider, is not shipped with Xamarin.iOS anymore. Projects that were using this old provider and now build with the newer `appletls` one.
To fix this warning, open the project file in a text editor, and remove all `MtouchTlsProvider`` nodes from the XML.
<h3><a name="MT202x"/>MT202x: Binding Optimizer failed processing `...`.</h3>
Something unexpected occured when trying to optimize generated binding code. The element causing the issue is named in the error message. In order to fix this issue the assembly named (or containing the type or method named) will need to be provided in a [bug report](http://bugzilla.xamarin.com) along with a complete build log with verbosity enabled (i.e. `-v -v -v -v` in the **Additional mtouch arguments**).

Просмотреть файл

@ -271,10 +271,9 @@ namespace XamCore.ObjCRuntime {
}
#if !COREBUILD && (XAMARIN_APPLETLS || XAMARIN_NO_TLS)
// This method is rewritten by the linker in CoreTlsProviderStep.
static MonoTlsProvider TlsProviderFactoryCallback ()
{
return RuntimeOptions.GetTlsProvider ();
return new AppleTlsProvider ();
}
#endif

Просмотреть файл

@ -88,17 +88,17 @@ namespace XamCore.ObjCRuntime {
// default
case null:
return DefaultTlsProviderValue;
case LegacyTlsProviderValue:
case DefaultTlsProviderValue:
case AppleTlsProviderValue:
return value;
case LegacyTlsProviderValue:
ErrorHelper.Warning (2016, "Invalid TlsProvider `{0}` option. The only valid value `{1}` will be used.", value, AppleTlsProviderValue);
return AppleTlsProviderValue;
default:
throw ErrorHelper.CreateError (2011, "Unknown TlsProvider `{0}`. Valid values are default, legacy or appletls", value);
throw ErrorHelper.CreateError (2011, "Unknown TlsProvider `{0}`. Valid values are default or appletls", value);
}
}
string GenerateMessageHandlerValue ()
{
#if MONOMAC
@ -131,10 +131,6 @@ namespace XamCore.ObjCRuntime {
content.AppendLine ("<key>HttpMessageHandler</key>");
content.Append ("<string>");
content.AppendLine (GenerateMessageHandlerValue ());
content.AppendLine ("<key>TlsProvider</key>");
content.Append ("<string>");
content.Append (tls_provider);
content.AppendLine ("</string>");
content.AppendLine ("</dict>");
content.AppendLine ("</plist>");
@ -142,27 +138,6 @@ namespace XamCore.ObjCRuntime {
File.WriteAllText (file_name, content.ToString ());
}
// Called from CoreTlsProviderStep
internal static TypeDefinition GetTlsProvider (RuntimeOptions options, ModuleDefinition module)
{
var provider = options != null ? options.tls_provider : DefaultTlsProviderValue;
TypeDefinition type;
switch (provider) {
case DefaultTlsProviderValue:
case AppleTlsProviderValue:
type = module.GetType (Namespaces.Security + ".Tls.AppleTlsProvider");
break;
case LegacyTlsProviderValue:
type = module.GetType (Namespaces.Security + ".Tls.OldTlsProvider");
break;
default:
throw new InvalidOperationException (string.Format ("Unknown TlsProvider `{0}`.", provider));
}
if (type == null)
throw new InvalidOperationException (string.Format ("Cannot load TlsProvider `{0}`.", provider));
return type;
}
// Called from CoreHttpMessageHandler
internal static TypeDefinition GetHttpMessageHandler (RuntimeOptions options, ModuleDefinition httpModule, ModuleDefinition platformModule = null)
{
@ -227,35 +202,10 @@ namespace XamCore.ObjCRuntime {
using (var plist = NSDictionary.FromFile (plist_path)) {
var options = new RuntimeOptions ();
options.http_message_handler = (NSString) plist ["HttpMessageHandler"];
options.tls_provider = (NSString) plist ["TlsProvider"];
return options;
}
}
#if !COREBUILD && (XAMARIN_APPLETLS || XAMARIN_NO_TLS)
internal static MonoTlsProvider GetTlsProvider ()
{
#if XAMARIN_NO_TLS
return new OldTlsProvider ();
#else
var options = Read ();
if (options == null)
return null;
switch (options.tls_provider) {
case null:
case DefaultTlsProviderValue:
case AppleTlsProviderValue:
return new AppleTlsProvider ();
case LegacyTlsProviderValue:
return new OldTlsProvider ();
default:
throw new InvalidOperationException (string.Format ("Invalid TLS Provider `{0}'.", options.tls_provider));
}
#endif
}
#endif
#if SYSTEM_NET_HTTP || (MONOMAC && XAMCORE_2_0)
#if MONOMAC
[Preserve]

Просмотреть файл

@ -518,30 +518,16 @@ namespace LinkAll {
Assert.NotNull (nix);
}
#if !__WATCHOS__
[Test]
public void TlsProvider_Legacy ()
{
var provider = Mono.Security.Interface.MonoTlsProviderFactory.GetProvider ();
Assert.NotNull (provider, "provider");
Assert.That (provider.ID, Is.EqualTo (new Guid ("809e77d5-56cc-4da8-b9f0-45e65ba9cceb")), "correct provider");
}
[Test]
public void OldTlsProvider_Selected ()
{
// make test work for classic (monotouch) and unified (iOS, tvOS and watchOS)
var fqn = typeof (NSObject).AssemblyQualifiedName.Replace ("Foundation.NSObject", "Security.Tls.OldTlsProvider");
Assert.NotNull (Type.GetType (fqn), "Should be included");
}
#endif // !__WATCHOS__
[Test]
public void AppleTls_OptOut ()
public void AppleTls ()
{
// make test work for classic (monotouch) and unified (iOS, tvOS and watchOS)
var fqn = typeof (NSObject).AssemblyQualifiedName.Replace ("Foundation.NSObject", "Security.Tls.AppleTlsProvider");
Assert.Null (Type.GetType (fqn), "Should not be included");
#if __WATCHOS__
Assert.Null (Type.GetType (fqn), "Should NOT be included (no SslStream or Socket support)");
#else
Assert.NotNull (Type.GetType (fqn), "Should be included");
#endif
}
}
}

Просмотреть файл

@ -25,7 +25,7 @@
<MtouchDebug>True</MtouchDebug>
<MtouchLink>Full</MtouchLink>
<MtouchI18n>mideast,other</MtouchI18n>
<MtouchExtraArgs>--registrar=static --tls-provider=legacy</MtouchExtraArgs>
<MtouchExtraArgs>--registrar=static</MtouchExtraArgs>
<MtouchArch>i386, x86_64</MtouchArch>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
@ -38,7 +38,7 @@
<MtouchI18n>mideast,other</MtouchI18n>
<MtouchArch>i386, x86_64</MtouchArch>
<DefineConstants>LINKALL;;$(DefineConstants)</DefineConstants>
<MtouchExtraArgs>--tls-provider=legacy</MtouchExtraArgs>
<MtouchExtraArgs></MtouchExtraArgs>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>True</DebugSymbols>
@ -53,7 +53,7 @@
<MtouchLink>Full</MtouchLink>
<MtouchI18n>mideast,other</MtouchI18n>
<MtouchArch>ARMv7, ARM64</MtouchArch>
<MtouchExtraArgs>--tls-provider=legacy -gcc_flags="-UhoItsB0rken"</MtouchExtraArgs>
<MtouchExtraArgs>-gcc_flags="-UhoItsB0rken"</MtouchExtraArgs>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug32|iPhone' ">
<DebugSymbols>True</DebugSymbols>
@ -68,7 +68,7 @@
<MtouchLink>Full</MtouchLink>
<MtouchI18n>mideast,other</MtouchI18n>
<MtouchArch>ARMv7</MtouchArch>
<MtouchExtraArgs>--tls-provider=legacy -gcc_flags="-UhoItsB0rken"</MtouchExtraArgs>
<MtouchExtraArgs>-gcc_flags="-UhoItsB0rken"</MtouchExtraArgs>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug64|iPhone' ">
<DebugSymbols>True</DebugSymbols>
@ -83,7 +83,7 @@
<MtouchLink>Full</MtouchLink>
<MtouchI18n>mideast,other</MtouchI18n>
<MtouchArch>ARM64</MtouchArch>
<MtouchExtraArgs>--tls-provider=legacy -gcc_flags="-UhoItsB0rken"</MtouchExtraArgs>
<MtouchExtraArgs>-gcc_flags="-UhoItsB0rken"</MtouchExtraArgs>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
@ -96,7 +96,7 @@
<MtouchI18n>mideast,other</MtouchI18n>
<MtouchUseLlvm>True</MtouchUseLlvm>
<MtouchArch>ARMv7, ARM64</MtouchArch>
<MtouchExtraArgs>-v -v -v -v --tls-provider=legacy</MtouchExtraArgs>
<MtouchExtraArgs>-v -v -v -v</MtouchExtraArgs>
<DefineConstants>LINKALL;;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release32|iPhone' ">
@ -110,7 +110,7 @@
<MtouchI18n>mideast,other</MtouchI18n>
<MtouchUseLlvm>True</MtouchUseLlvm>
<MtouchArch>ARMv7</MtouchArch>
<MtouchExtraArgs>-v -v -v -v --tls-provider=legacy</MtouchExtraArgs>
<MtouchExtraArgs>-v -v -v -v</MtouchExtraArgs>
<DefineConstants>LINKALL;;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release64|iPhone' ">
@ -124,7 +124,7 @@
<MtouchI18n>mideast,other</MtouchI18n>
<MtouchUseLlvm>True</MtouchUseLlvm>
<MtouchArch>ARM64</MtouchArch>
<MtouchExtraArgs>-v -v -v -v --tls-provider=legacy</MtouchExtraArgs>
<MtouchExtraArgs>-v -v -v -v</MtouchExtraArgs>
<DefineConstants>LINKALL;;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release-bitcode|iPhone' ">
@ -138,7 +138,7 @@
<MtouchI18n>mideast,other</MtouchI18n>
<MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchArch>ARMv7, ARM64</MtouchArch>
<MtouchExtraArgs>-v -v -v -v --tls-provider=legacy --bitcode:full</MtouchExtraArgs>
<MtouchExtraArgs>-v -v -v -v --bitcode:full</MtouchExtraArgs>
<DefineConstants>LINKALL;;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -1,115 +0,0 @@
// Copyright 2015 Xamarin Inc. All rights reserved.
using System;
using Mono.Linker;
using Mono.Tuner;
using Mono.Cecil;
using Mono.Cecil.Cil;
#if MTOUCH
using MonoTouch;
using MonoTouch.Tuner;
using Xamarin.Bundler;
#elif MMP || MMP_TEST
using MonoMac;
using MonoMac.Tuner;
using Xamarin.Bundler;
#else
using XamCore.ObjCRuntime;
#endif
namespace Xamarin.Linker.Steps {
public class CoreTlsProviderStep : BaseSubStep {
public CoreTlsProviderStep (LinkerOptions options)
{
Options = options;
}
public LinkerOptions Options { get; private set; }
public override SubStepTargets Targets {
get { return SubStepTargets.Type; }
}
public override bool IsActiveFor (AssemblyDefinition assembly)
{
#if XAMARIN_NO_TLS
return false;
#else
#if MONOMAC
// this is only supported on the profiles where we ship mono (not classic with a system mono)
if (!(Profile.Current is MacMobileProfile))
return false;
#endif
if (assembly.Name.Name != (Profile.Current as BaseProfile).ProductAssembly)
return false;
// process only assemblies where the linker is enabled (e.g. --linksdk, --linkskip)
return Annotations.GetAction (assembly) == AssemblyAction.Link;
#endif
}
static MethodDefinition FindDefaultCtor (TypeDefinition type)
{
foreach (var m in type.Methods) {
if (m.IsStatic || !m.IsConstructor || m.HasParameters)
continue;
return m;
}
return null;
}
MethodReference FindProviderConstructor (ModuleDefinition module)
{
var providerType = RuntimeOptions.GetTlsProvider (Options.RuntimeOptions, module);
if (providerType == null)
return null;
var ctor = FindDefaultCtor (providerType);
if (ctor == null)
throw new InvalidOperationException ();
return module.ImportReference (ctor);
}
public override void ProcessType (TypeDefinition type)
{
#if XAMARIN_NO_TLS
return;
#else
if (!type.Is (Namespaces.ObjCRuntime, "Runtime"))
return;
MethodDefinition callbackMethod = null;
foreach (var m in type.Methods) {
if (!m.IsStatic || m.HasParameters)
continue;
if (m.Name.Equals ("TlsProviderFactoryCallback", StringComparison.Ordinal)) {
callbackMethod = m;
break;
}
}
if (callbackMethod == null)
throw new Exception ("Could not set the default TlsProvider");
var providerCtor = FindProviderConstructor (type.Module);
if (providerCtor == null)
return;
// re-write TlsProviderFactoryCallback()
var body = new MethodBody (callbackMethod);
var il = body.GetILProcessor ();
if (providerCtor != null)
il.Emit (OpCodes.Newobj, providerCtor);
else
il.Emit (OpCodes.Ldnull);
il.Emit (OpCodes.Ret);
callbackMethod.Body = body;
#endif
}
}
}

Просмотреть файл

@ -74,7 +74,6 @@ tuner_sources = \
$(TOP)/tools/linker/CorePreserveCode.cs \
$(TOP)/tools/linker/CoreRemoveAttributes.cs \
$(TOP)/tools/linker/CoreHttpMessageHandler.cs \
$(TOP)/tools/linker/CoreTlsProviderStep.cs \
$(TOP)/tools/linker/CoreRemoveSecurity.cs \
$(TOP)/tools/linker/ObjCExtensions.cs \
$(TOP)/tools/linker/MarkNSObjects.cs \

Просмотреть файл

@ -162,7 +162,6 @@ namespace MonoMac.Tuner {
new RemoveUserResourcesSubStep (),
new CoreRemoveAttributes (),
new CoreHttpMessageHandler (options),
new CoreTlsProviderStep (options),
new MarkNSObjects (),
});

Просмотреть файл

@ -63,10 +63,12 @@ namespace Xamarin.Bundler {
// MM2007 Xamarin.Mac Unified API against a full .NET profile does not support linking. Pass the -nolink flag.
// MM2009 Referenced by {0}.{1} ** This message is related to MM2006 **
// MM2010 Unknown HttpMessageHandler `{0}`. Valid values are HttpClientHandler (default), CFNetworkHandler or NSUrlSessionHandler
// MM2011 Unknown TLSProvider `{0}. Valid values are default, legacy or appletls
// MM2011 Unknown TLSProvider `{0}. Valid values are default or appletls
// MM2012 Only first {0} of {1} "Referenced by" warnings shown. ** This message related to 2009 **
// Warning MM2013 Failed to resolve the reference to "{0}", referenced in "{1}". The app will not include the referenced assembly, and may fail at runtime.
// Warning MT2014 Xamarin.Mac Extensions do not support linking. Request for linking will be ignored.
// Warning MM2014 Xamarin.Mac Extensions do not support linking. Request for linking will be ignored.
// MM2015 *** Reserved mtouch ***
// Warning MM2016 Invalid TlsProvider `{0}` option. The only valid value `{1}` will be used.
// MM202x Binding Optimizer failed processing `...`.
// MM4xxx code generation
// MM40xx driver.m

Просмотреть файл

@ -236,9 +236,6 @@
<Compile Include="..\linker\MobileSweepStep.cs">
<Link>Xamarin.Linker\MobileSweepStep.cs</Link>
</Compile>
<Compile Include="..\linker\CoreTlsProviderStep.cs">
<Link>Xamarin.Linker\CoreTlsProviderStep.cs</Link>
</Compile>
<Compile Include="..\linker\CoreOptimizeGeneratedCode.cs">
<Link>Xamarin.Linker\CoreOptimizeGeneratedCode.cs</Link>
</Compile>

Просмотреть файл

@ -69,7 +69,6 @@ LINKER_SOURCES = \
$(TOP)/tools/linker/ApplyPreserveAttribute.cs \
$(TOP)/tools/linker/BaseProfile.cs \
$(TOP)/tools/linker/CoreHttpMessageHandler.cs \
$(TOP)/tools/linker/CoreTlsProviderStep.cs \
$(TOP)/tools/linker/CoreMarkStep.cs \
$(TOP)/tools/linker/CoreOptimizeGeneratedCode.cs \
$(TOP)/tools/linker/CorePreserveCode.cs \

Просмотреть файл

@ -121,8 +121,6 @@ namespace MonoTouch.Tuner {
sub.Add (new MarkNSObjects ());
sub.Add (new PreserveSoapHttpClients ());
sub.Add (new CoreHttpMessageHandler (options));
if (Driver.App.Platform != Xamarin.Utils.ApplePlatform.WatchOS)
sub.Add (new CoreTlsProviderStep (options));
return sub;
}

Просмотреть файл

@ -202,11 +202,12 @@ namespace Xamarin.Bundler {
// MT2007 ** reserved Xamarin.Mac **
// MT2009 ** reserved Xamarin.Mac **
// MT2010 Unknown HttpMessageHandler `{0}`. Valid values are HttpClientHandler (default), CFNetworkHandler or NSUrlSessionHandler
// MT2011 Unknown TlsProvider `{0}`. Valid values are default, legacy or appletls.
// MT2011 Unknown TlsProvider `{0}`. Valid values are default or appletls.
// MT2012 ** reserved Xamarin.Mac **
// MT2013 ** reserved Xamarin.Mac **
// MT2014 ** reserved Xamarin.Mac **
// Warning MT2015 Invalid HttpMessageHandler `{0}` for watchOS. The only valid value is NSUrlSessionHandler.
// Warning MT2016 Invalid TlsProvider `{0}` option. The only valid value `{1}` will be used.
// MT202x Binding Optimizer failed processing `...`.
// MT203x Removing User Resources failed processing `...`.
// MT3xxx AOT

Просмотреть файл

@ -241,9 +241,6 @@
<Compile Include="..\linker\CoreHttpMessageHandler.cs">
<Link>Xamarin.Linker\CoreHttpMessageHandler.cs</Link>
</Compile>
<Compile Include="..\linker\CoreTlsProviderStep.cs">
<Link>Xamarin.Linker\CoreTlsProviderStep.cs</Link>
</Compile>
<Compile Include="..\linker\MobileResolveMainAssemblyStep.cs">
<Link>Xamarin.Linker\MobileResolveMainAssemblyStep.cs</Link>
</Compile>