Revert changes that I accidentally pushed on top of PR #4756.
authorMartin Baulig <mabaul@microsoft.com>
Wed, 26 Apr 2017 21:20:49 +0000 (17:20 -0400)
committerMartin Baulig <mabaul@microsoft.com>
Wed, 26 Apr 2017 21:21:21 +0000 (17:21 -0400)
mcs/class/System/Mono.AppleTls/AppleTlsProvider.cs
mcs/class/System/Mono.Btls/MonoBtlsProvider.cs
mcs/class/System/Mono.Net.Security/LegacyTlsProvider.cs
mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.Apple.cs [new file with mode: 0644]
mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.Droid.cs [new file with mode: 0644]
mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.cs
mcs/class/System/monodroid_System.dll.sources
mcs/class/System/monotouch_System.dll.sources
mcs/class/System/monotouch_watch_System.dll.exclude.sources
mcs/class/System/xammac_System.dll.sources
mcs/class/System/xammac_net_4_5_System.dll.sources

index 4fdabfd3ae3d22b8658a5a86dd5db672cc0edcd1..cf774bf9ba35280e6f26dd93b88bc2ee26334d77 100644 (file)
@@ -31,12 +31,14 @@ namespace Mono.AppleTls
 {
        class AppleTlsProvider : MonoTlsProvider
        {
+               static readonly Guid id = new Guid ("981af8af-a3a3-419a-9f01-a518e3a17c1c");
+
                public override string Name {
                        get { return "apple-tls"; }
                }
 
                public override Guid ID {
-                       get { return MNS.MonoTlsProviderFactory.AppleTlsId; }
+                       get { return id; }
                }
 
                public override IMonoSslStream CreateSslStream (
index bd979345e0debc693cfe43b9c5db0c7ca096277e..6f132e1c7efc4a26bb8354545238ba867c2d55d2 100644 (file)
@@ -50,8 +50,10 @@ namespace Mono.Btls
 {
        class MonoBtlsProvider : MonoTlsProvider
        {
+               static readonly Guid id = new Guid ("432d18c9-9348-4b90-bfbf-9f2a10e1f15b");
+
                public override Guid ID {
-                       get { return MNS.MonoTlsProviderFactory.BtlsId; }
+                       get { return id; }
                }
                public override string Name {
                        get { return "btls"; }
index a67b1ff069e9c67c83a61f73e65c04165ad54af6..7d1369ee860ded993e78de32eaac014e2f27decf 100644 (file)
@@ -48,8 +48,10 @@ namespace Mono.Net.Security
         */
        class LegacyTlsProvider : MSI.MonoTlsProvider
        {
+               static readonly Guid id = new Guid ("809e77d5-56cc-4da8-b9f0-45e65ba9cceb");
+
                public override Guid ID {
-                       get { return MonoTlsProviderFactory.LegacyId; }
+                       get { return id; }
                }
 
                public override string Name {
diff --git a/mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.Apple.cs b/mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.Apple.cs
new file mode 100644 (file)
index 0000000..e5f2f0c
--- /dev/null
@@ -0,0 +1,120 @@
+//
+// MonoTlsProviderFactory.cs
+//
+// Author:
+//      Chris Hamons  <chris.hamons@xamarin.com>
+//       Martin Baulig <martin.baulig@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#if !ONLY_APPLETLS
+#error Use MonoTlsProviderFactory.cs instead
+#endif
+
+#if SECURITY_DEP
+
+#if MONO_SECURITY_ALIAS
+extern alias MonoSecurity;
+using MSI = MonoSecurity::Mono.Security.Interface;
+using MX = MonoSecurity::Mono.Security.X509;
+#else
+using MSI = Mono.Security.Interface;
+using MX = Mono.Security.X509;
+#endif
+using System.Security.Cryptography.X509Certificates;
+using Mono.AppleTls;
+
+using System;
+using System.Net;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+
+namespace Mono.Net.Security
+{
+       /*
+        * Keep in sync with Mono.Security/Mono.Security.Interface/MonoTlsProvider.cs.
+        * Simple implementation that does hard codes only a single provider
+        */
+       static partial class MonoTlsProviderFactory
+       {
+               #region Internal API
+
+               /*
+                * APIs in this section are for consumption within System.dll only - do not access via
+                * reflection or from friend assemblies.
+                * 
+                */
+               internal static MSI.MonoTlsProvider GetProviderInternal ()
+               {
+                       return GetTlsProvider ();
+               }
+               
+               #endregion
+
+               static object locker = new object ();
+               static MSI.MonoTlsProvider provider;
+               static MSI.MonoTlsProvider GetTlsProvider ()
+               {
+                       lock (locker) {
+                               if (provider == null)
+                                       provider = new AppleTlsProvider ();
+                               return provider;
+                       }
+               }
+
+
+               #region Mono.Security visible API
+
+               /*
+                * "Public" section, intended to be consumed via reflection.
+                * 
+                * Mono.Security.dll provides a public wrapper around these.
+                */
+
+               internal static MSI.MonoTlsProvider GetProvider ()
+               {
+                       return GetTlsProvider ();
+               }
+
+               internal static bool IsProviderSupported (string name)
+               {
+                       return true;
+               }
+
+               internal static MSI.MonoTlsProvider GetProvider (string name)
+               {
+                       return GetTlsProvider ();
+               }
+
+               internal static bool IsInitialized => true;
+
+               internal static void Initialize ()
+               {
+               }
+
+               internal static void Initialize (string provider)
+               {
+               }
+               #endregion
+       }
+}
+#endif
+
diff --git a/mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.Droid.cs b/mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.Droid.cs
new file mode 100644 (file)
index 0000000..49ac9fd
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright 2015 Xamarin Inc. All rights reserved.
+#if SECURITY_DEP
+
+#if MONO_SECURITY_ALIAS
+extern alias MonoSecurity;
+using MSI = MonoSecurity::Mono.Security.Interface;
+#else
+using MSI = Mono.Security.Interface;
+#endif
+
+#if MONO_FEATURE_BTLS
+using Mono.Btls;
+#endif
+
+using System;
+
+namespace Mono.Net.Security
+{
+       static partial class MonoTlsProviderFactory
+       {
+               static MSI.MonoTlsProvider CreateDefaultProviderImpl ()
+               {
+                       MSI.MonoTlsProvider provider = null;
+                       var type = Environment.GetEnvironmentVariable ("XA_TLS_PROVIDER");
+                       switch (type) {
+                       case null:
+                       case "default":
+                       case "legacy":
+                               return new LegacyTlsProvider ();
+#if MONO_FEATURE_BTLS
+                       case "btls":
+                               if (!IsBtlsSupported ())
+                                       throw new NotSupportedException ("BTLS in not supported!");
+                               return new MonoBtlsProvider ();
+#endif
+                       default:
+                               throw new NotSupportedException (string.Format ("Invalid TLS Provider: `{0}'.", provider));
+                       }
+               }
+       }
+}
+#endif
index 0fe5ef8294ed7dc48b4190e2c8ffd958e8ff0c12..b9185964572f6c861442843fb937e13dde8072e4 100644 (file)
@@ -24,7 +24,7 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
-#if SECURITY_DEP
+#if SECURITY_DEP && !ONLY_APPLETLS // ONLY_APPLETLS uses MonoTlsProviderFactory.Apple.cs instead
 
 #if MONO_SECURITY_ALIAS
 extern alias MonoSecurity;
@@ -41,10 +41,6 @@ using System.Net;
 using System.Collections.Generic;
 using System.Runtime.CompilerServices;
 
-#if MONO_FEATURE_BTLS
-using Mono.Btls;
-#endif
-
 #if !MOBILE
 using System.Reflection;
 #endif
@@ -57,7 +53,7 @@ namespace Mono.Net.Security
         */
        static partial class MonoTlsProviderFactory
        {
-#region Internal API
+               #region Internal API
 
                /*
                 * APIs in this section are for consumption within System.dll only - do not access via
@@ -89,11 +85,6 @@ namespace Mono.Net.Security
                                if (provider == null)
                                        throw new NotSupportedException ("TLS Support not available.");
 
-                               if (!providerCache.ContainsKey (provider.ID))
-                                       providerCache.Add (provider.ID, provider);
-
-                               X509Helper2.Initialize ();
-
                                defaultProvider = provider;
                                initialized = true;
                        }
@@ -106,162 +97,76 @@ namespace Mono.Net.Security
                                        throw new NotSupportedException ("TLS Subsystem already initialized.");
 
                                defaultProvider = LookupProvider (provider, true);
-
-                               X509Helper2.Initialize ();
                                initialized = true;
                        }
                }
 
+               [MethodImpl (MethodImplOptions.InternalCall)]
+               internal extern static bool IsBtlsSupported ();
+
                static object locker = new object ();
                static bool initialized;
 
                static MSI.MonoTlsProvider defaultProvider;
 
-               /*
-                * @providerRegistration maps provider names to a tuple containing its ID and full type name.
-                * On non-reflection enabled systems (such as XI and XM), we can use the Guid to uniquely
-                * identify the provider.
-                *
-                * @providerCache maps the provider's Guid to the MSI.MonoTlsProvider instance.
-                *
-                */
-               static Dictionary<string,Tuple<Guid,string>> providerRegistration;
-               static Dictionary<Guid,MSI.MonoTlsProvider> providerCache;
+               #endregion
+
+               static Dictionary<string,string> providerRegistration;
 
-#if !ONLY_APPLETLS && !MONOTOUCH && !XAMMAC
                static Type LookupProviderType (string name, bool throwOnError)
                {
                        lock (locker) {
                                InitializeProviderRegistration ();
-                               Tuple<Guid,string> entry;
-                               if (!providerRegistration.TryGetValue (name, out entry)) {
+                               string typeName;
+                               if (!providerRegistration.TryGetValue (name, out typeName)) {
                                        if (throwOnError)
                                                throw new NotSupportedException (string.Format ("No such TLS Provider: `{0}'.", name));
                                        return null;
                                }
-                               var type = Type.GetType (entry.Item2, false);
+                               var type = Type.GetType (typeName, false);
                                if (type == null && throwOnError)
-                                       throw new NotSupportedException (string.Format ("Could not find TLS Provider: `{0}'.", entry.Item2));
+                                       throw new NotSupportedException (string.Format ("Could not find TLS Provider: `{0}'.", typeName));
                                return type;
                        }
                }
-#endif
 
                static MSI.MonoTlsProvider LookupProvider (string name, bool throwOnError)
                {
-                       lock (locker) {
-                               InitializeProviderRegistration ();
-                               Tuple<Guid,string> entry;
-                               if (!providerRegistration.TryGetValue (name, out entry)) {
-                                       if (throwOnError)
-                                               throw new NotSupportedException (string.Format ("No such TLS Provider: `{0}'.", name));
-                                       return null;
-                               }
-
-                               // Check cache before doing the reflection lookup.
-                               MSI.MonoTlsProvider provider;
-                               if (providerCache.TryGetValue (entry.Item1, out provider))
-                                       return provider;
-
-#if !ONLY_APPLETLS && !MONOTOUCH && !XAMMAC
-                               var type = Type.GetType (entry.Item2, false);
-                               if (type == null && throwOnError)
-                                       throw new NotSupportedException (string.Format ("Could not find TLS Provider: `{0}'.", entry.Item2));
-
-                               try {
-                                       provider = (MSI.MonoTlsProvider)Activator.CreateInstance (type, true);
-                               } catch (Exception ex) {
-                                       throw new NotSupportedException (string.Format ("Unable to instantiate TLS Provider `{0}'.", type), ex);
-                               }
-#endif
-
-                               if (provider == null) {
-                                       if (throwOnError)
-                                               throw new NotSupportedException (string.Format ("No such TLS Provider: `{0}'.", name));
-                                       return null;
-                               }
-
-                               providerCache.Add (entry.Item1, provider);
-                               return provider;
+                       var type = LookupProviderType (name, throwOnError);
+                       if (type == null)
+                               return null;
+
+                       try {
+                               return (MSI.MonoTlsProvider)Activator.CreateInstance (type, true);
+                       } catch (Exception ex) {
+                               throw new NotSupportedException (string.Format ("Unable to instantiate TLS Provider `{0}'.", type), ex);
                        }
                }
 
-#endregion
-
-               internal static readonly Guid AppleTlsId = new Guid ("981af8af-a3a3-419a-9f01-a518e3a17c1c");
-               internal static readonly Guid BtlsId = new Guid ("432d18c9-9348-4b90-bfbf-9f2a10e1f15b");
-               internal static readonly Guid LegacyId = new Guid ("809e77d5-56cc-4da8-b9f0-45e65ba9cceb");
-
                static void InitializeProviderRegistration ()
                {
                        lock (locker) {
                                if (providerRegistration != null)
                                        return;
-                               providerRegistration = new Dictionary<string,Tuple<Guid,string>> ();
-                               providerCache = new Dictionary<Guid,MSI.MonoTlsProvider> ();
-
-                               var appleTlsEntry = new Tuple<Guid,String> (AppleTlsId, "Mono.AppleTls.AppleTlsProvider");
-
-#if ONLY_APPLETLS || MONOTOUCH || XAMMAC
-                               providerRegistration.Add ("default", appleTlsEntry);
-                               providerRegistration.Add ("apple", appleTlsEntry);
-#else
-                               var legacyEntry = new Tuple<Guid,String> (BtlsId, "Mono.Net.Security.LegacyTlsProvider");
-#if MONO_FEATURE_BTLS
-                               var btlsEntry = new Tuple<Guid,String> (LegacyId, "Mono.Btls.MonoBtlsProvider");
-#endif
-
-                               providerRegistration.Add ("legacy", legacyEntry);
-
+                               providerRegistration = new Dictionary<string,string> ();
+                               providerRegistration.Add ("legacy", "Mono.Net.Security.LegacyTlsProvider");
+                       
                                if (Platform.IsMacOS)
-                                       providerRegistration.Add ("default", appleTlsEntry);
+                                       providerRegistration.Add ("default", "Mono.AppleTls.AppleTlsProvider");
                                else
-                                       providerRegistration.Add ("default", legacyEntry);
+                                       providerRegistration.Add ("default", "Mono.Net.Security.LegacyTlsProvider");
 
-#if MONO_FEATURE_BTLS
                                if (IsBtlsSupported ())
-                                       providerRegistration.Add ("btls", btlsEntry);
-#endif
-
-                               providerRegistration.Add ("apple", appleTlsEntry);
-#endif
+                                       providerRegistration.Add ("btls", "Mono.Btls.MonoBtlsProvider");
+                       
+                               providerRegistration.Add ("apple", "Mono.AppleTls.AppleTlsProvider");
+                               
+                               X509Helper2.Initialize ();
                        }
                }
 
-#region Platform-Specific code
-
-#if MONO_FEATURE_BTLS
-               [MethodImpl (MethodImplOptions.InternalCall)]
-               internal extern static bool IsBtlsSupported ();
-#endif
-
-#if MONODROID
-               static MSI.MonoTlsProvider CreateDefaultProviderImpl ()
-               {
-                       MSI.MonoTlsProvider provider = null;
-                       var type = Environment.GetEnvironmentVariable ("XA_TLS_PROVIDER");
-                       switch (type) {
-                       case null:
-                       case "default":
-                       case "legacy":
-                               return new LegacyTlsProvider ();
-#if MONO_FEATURE_BTLS
-                       case "btls":
-                               if (!IsBtlsSupported ())
-                                       throw new NotSupportedException ("BTLS in not supported!");
-                               return new MonoBtlsProvider ();
-#endif
-                       default:
-                               throw new NotSupportedException (string.Format ("Invalid TLS Provider: `{0}'.", provider));
-                       }
-               }
-#elif ONLY_APPLETLS || MONOTOUCH || XAMMAC
-               static MSI.MonoTlsProvider CreateDefaultProviderImpl ()
-               {
-                       return new AppleTlsProvider ();
-               }
-#else
-               static MSI.MonoTlsProvider CreateDefaultProviderImpl ()
+#if !MONODROID && !MONOTOUCH && !XAMMAC
+               static MSI.MonoTlsProvider TryDynamicLoad ()
                {
                        var variable = Environment.GetEnvironmentVariable ("MONO_TLS_PROVIDER");
                        if (string.IsNullOrEmpty (variable))
@@ -269,11 +174,18 @@ namespace Mono.Net.Security
 
                        return LookupProvider (variable, true);
                }
-#endif
 
-#endregion
+               static MSI.MonoTlsProvider CreateDefaultProviderImpl ()
+               {
+                       var provider = TryDynamicLoad ();
+                       if (provider != null)
+                               return provider;
 
-#region Mono.Security visible API
+                       return new LegacyTlsProvider ();
+               }
+#endif
+
+               #region Mono.Security visible API
 
                /*
                 * "Public" section, intended to be consumed via reflection.
@@ -292,10 +204,7 @@ namespace Mono.Net.Security
 
                internal static bool IsProviderSupported (string name)
                {
-                       lock (locker) {
-                               InitializeProviderRegistration ();
-                               return providerRegistration.ContainsKey (name);
-                       }
+                       return LookupProvider (name, false) != null;
                }
 
                internal static MSI.MonoTlsProvider GetProvider (string name)
@@ -320,7 +229,7 @@ namespace Mono.Net.Security
                {
                        InitializeInternal (provider);
                }
-#endregion
+               #endregion
        }
 }
 #endif
index c6769c373a7eac6f111f5342562e19c338835c9c..c2950c536caf33f5d6f337df9463118118f248e8 100644 (file)
@@ -1,3 +1,4 @@
 #include mobile_System.dll.sources
 System/AndroidPlatform.cs
+Mono.Net.Security/MonoTlsProviderFactory.Droid.cs
 Mono.Btls/MonoBtlsX509LookupAndroid.cs
index e478e8894eb5696c35639010f27ac26b0ef445cd..8d2f2fdbbc49f35167282c102740833693c5cf95 100644 (file)
@@ -1,2 +1,5 @@
 #include mobile_System.dll.sources
 
+System.Net/MacProxy.cs
+
+Mono.Net.Security/MonoTlsProviderFactory.Apple.cs
index 650f8849d531c7ff7b49c3d8f4817698d38e8826..c7317052010936abeedd43400c3c7673b60e458f 100644 (file)
@@ -8,6 +8,7 @@ Mono.Net.Security/LegacyTlsProvider.cs
 Mono.Net.Security/LegacyTlsProvider.cs
 Mono.Net.Security/MobileAuthenticatedStream.cs
 Mono.Net.Security/MobileTlsContext.cs
+Mono.Net.Security/MonoTlsProviderFactory.Apple.cs
 Mono.Net.Security/MonoTlsProviderFactory.cs
 Mono.Net.Security/MonoTlsProviderImpl.cs
 Mono.Net.Security/MonoTlsStream.cs
index 70a77a6dbff401e4d973b5d5f8ce11321a969f9a..73405e102667f3ff0b2206a456a1a2cdef234b89 100644 (file)
@@ -1 +1,2 @@
 #include mobile_System.dll.sources
+Mono.Net.Security/MonoTlsProviderFactory.Apple.cs
index beb6f2415cf1c7c2da9e4ba40f1a04757013f3b9..fe68fff758f91170508456245fee3a8f194fabee 100644 (file)
@@ -1 +1,2 @@
 #include net_4_x_System.dll.sources
+Mono.Net.Security/MonoTlsProviderFactory.Apple.cs