Remove obsolete Mono.Security.Providers.* assemblies (#3595)
[mono.git] / mcs / class / System / Mono.Net.Security / MonoTlsProviderFactory.cs
index 1a0c2bc584290d3356358948d9beb48938e93cb9..3dc005344f3b50baf23a65d02938a18c479b4fa3 100644 (file)
@@ -69,7 +69,7 @@ namespace Mono.Net.Security
                                        return currentProvider;
 
                                try {
-                                       defaultProvider = CreateDefaultProvider ();
+                                       defaultProvider = GetDefaultProviderInternal ();
                                } catch (Exception ex) {
                                        throw new NotSupportedException ("TLS Support not available.", ex);
                                }
@@ -101,30 +101,15 @@ namespace Mono.Net.Security
                        }
                }
 
-#if MONO_FEATURE_NEW_SYSTEM_SOURCE || (!MONOTOUCH && !XAMMAC)
                static IMonoTlsProvider CreateDefaultProvider ()
                {
 #if SECURITY_DEP
-#if MONO_FEATURE_NEW_SYSTEM_SOURCE
-                       /*
-                        * This is a hack, which is used in the Mono.Security.Providers.NewSystemSource
-                        * assembly, which will provide a "fake" System.dll.  Use the public Mono.Security
-                        * API to get the "real" System.dll's provider via reflection, then wrap it with
-                        * the "fake" version's perceived view.
-                        *
-                        * NewSystemSource needs to compile MonoTlsProviderFactory.cs, IMonoTlsProvider.cs,
-                        * MonoTlsProviderWrapper.cs and CallbackHelpers.cs from this directory and only these.
-                        */
-                       var userProvider = MSI.MonoTlsProviderFactory.GetProvider ();
-                       return new Private.MonoTlsProviderWrapper (userProvider);
-#else
-                       return CreateDefaultProviderImpl ();
+                       MSI.MonoTlsProvider provider = CreateDefaultProviderImpl ();
+                       if (provider != null)
+                               return new Private.MonoTlsProviderWrapper (provider);
 #endif
-#else
                        return null;
-#endif
                }
-#endif
 
                static object locker = new object ();
                static IMonoTlsProvider defaultProvider;
@@ -132,7 +117,7 @@ namespace Mono.Net.Security
 
                #endregion
 
-#if SECURITY_DEP && !MONO_FEATURE_NEW_SYSTEM_SOURCE
+#if SECURITY_DEP
 
                static Dictionary<string,string> providerRegistration;
 
@@ -160,7 +145,7 @@ namespace Mono.Net.Security
                                return null;
 
                        try {
-                               return (MSI.MonoTlsProvider)Activator.CreateInstance (type);
+                               return (MSI.MonoTlsProvider)Activator.CreateInstance (type, true);
                        } catch (Exception ex) {
                                throw new NotSupportedException (string.Format ("Unable to instantiate TLS Provider `{0}'.", type), ex);
                        }
@@ -172,13 +157,17 @@ namespace Mono.Net.Security
                                if (providerRegistration != null)
                                        return;
                                providerRegistration = new Dictionary<string,string> ();
-                               providerRegistration.Add ("newtls", "Mono.Security.Providers.NewTls.NewTlsProvider, Mono.Security.Providers.NewTls, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
-                               providerRegistration.Add ("oldtls", "Mono.Security.Providers.OldTls.OldTlsProvider, Mono.Security.Providers.OldTls, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
+                               providerRegistration.Add ("legacy", "Mono.Net.Security.Private.MonoLegacyTlsProvider");
+#if HAVE_BTLS
+                               if (Mono.Btls.MonoBtlsProvider.IsSupported ())
+                                       providerRegistration.Add ("btls", "Mono.Btls.MonoBtlsProvider");
+#endif
+                               X509Helper2.Initialize ();
                        }
                }
 
-#if !MOBILE
-               static IMonoTlsProvider TryDynamicLoad ()
+#if MOBILE_STATIC || !MOBILE
+               static MSI.MonoTlsProvider TryDynamicLoad ()
                {
                        var variable = Environment.GetEnvironmentVariable ("MONO_TLS_PROVIDER");
                        if (variable == null)
@@ -187,22 +176,18 @@ namespace Mono.Net.Security
                        if (string.Equals (variable, "default", StringComparison.OrdinalIgnoreCase))
                                return null;
 
-                       var provider = LookupProvider (variable, true);
-
-                       return new Private.MonoTlsProviderWrapper (provider);
+                       return LookupProvider (variable, true);
                }
-#endif
 
-               static IMonoTlsProvider CreateDefaultProviderImpl ()
+               static MSI.MonoTlsProvider CreateDefaultProviderImpl ()
                {
-#if !MOBILE
                        var provider = TryDynamicLoad ();
                        if (provider != null)
                                return provider;
-#endif
 
-                       return new Private.MonoDefaultTlsProvider ();
+                       return new Private.MonoLegacyTlsProvider ();
                }
+#endif
 
                #region Mono.Security visible API