You've already forked linux-packaging-mono
Imported Upstream version 4.8.0.309
Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
parent
ee1447783b
commit
94b2861243
@@ -39,6 +39,7 @@ using System.Security.Cryptography.X509Certificates;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
#if !MOBILE
|
||||
using System.Reflection;
|
||||
@@ -64,74 +65,61 @@ namespace Mono.Net.Security
|
||||
|
||||
internal static IMonoTlsProvider GetProviderInternal ()
|
||||
{
|
||||
#if SECURITY_DEP
|
||||
lock (locker) {
|
||||
if (currentProvider != null)
|
||||
return currentProvider;
|
||||
|
||||
try {
|
||||
defaultProvider = GetDefaultProviderInternal ();
|
||||
} catch (Exception ex) {
|
||||
throw new NotSupportedException ("TLS Support not available.", ex);
|
||||
}
|
||||
|
||||
if (defaultProvider == null)
|
||||
throw new NotSupportedException ("TLS Support not available.");
|
||||
|
||||
currentProvider = defaultProvider;
|
||||
return currentProvider;
|
||||
}
|
||||
}
|
||||
|
||||
internal static IMonoTlsProvider GetDefaultProviderInternal ()
|
||||
{
|
||||
lock (locker) {
|
||||
if (defaultProvider != null)
|
||||
return defaultProvider;
|
||||
|
||||
try {
|
||||
defaultProvider = CreateDefaultProvider ();
|
||||
} catch (Exception ex) {
|
||||
throw new NotSupportedException ("TLS Support not available.", ex);
|
||||
}
|
||||
|
||||
if (defaultProvider == null)
|
||||
throw new NotSupportedException ("TLS Support not available.");
|
||||
|
||||
InitializeInternal ();
|
||||
return defaultProvider;
|
||||
}
|
||||
#else
|
||||
throw new NotSupportedException ("TLS Support not available.");
|
||||
#endif
|
||||
}
|
||||
|
||||
static IMonoTlsProvider CreateDefaultProvider ()
|
||||
{
|
||||
#if SECURITY_DEP
|
||||
MSI.MonoTlsProvider provider = null;
|
||||
#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.
|
||||
*/
|
||||
provider = MSI.MonoTlsProviderFactory.GetProvider ();
|
||||
#else
|
||||
provider = CreateDefaultProviderImpl ();
|
||||
#endif
|
||||
if (provider != null)
|
||||
return new Private.MonoTlsProviderWrapper (provider);
|
||||
#endif
|
||||
return null;
|
||||
internal static void InitializeInternal ()
|
||||
{
|
||||
lock (locker) {
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
MSI.MonoTlsProvider provider;
|
||||
try {
|
||||
provider = CreateDefaultProviderImpl ();
|
||||
} catch (Exception ex) {
|
||||
throw new NotSupportedException ("TLS Support not available.", ex);
|
||||
}
|
||||
|
||||
if (provider == null)
|
||||
throw new NotSupportedException ("TLS Support not available.");
|
||||
|
||||
defaultProvider = new Private.MonoTlsProviderWrapper (provider);
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void InitializeInternal (string provider)
|
||||
{
|
||||
lock (locker) {
|
||||
if (initialized)
|
||||
throw new NotSupportedException ("TLS Subsystem already initialized.");
|
||||
|
||||
var msiProvider = LookupProvider (provider, true);
|
||||
defaultProvider = new Private.MonoTlsProviderWrapper (msiProvider);
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
internal extern static bool IsBtlsSupported ();
|
||||
#endif
|
||||
|
||||
static object locker = new object ();
|
||||
static bool initialized;
|
||||
static IMonoTlsProvider defaultProvider;
|
||||
static IMonoTlsProvider currentProvider;
|
||||
|
||||
#endregion
|
||||
|
||||
#if SECURITY_DEP && !MONO_FEATURE_NEW_SYSTEM_SOURCE
|
||||
#if SECURITY_DEP
|
||||
|
||||
static Dictionary<string,string> providerRegistration;
|
||||
|
||||
@@ -171,13 +159,10 @@ namespace Mono.Net.Security
|
||||
if (providerRegistration != null)
|
||||
return;
|
||||
providerRegistration = new Dictionary<string,string> ();
|
||||
providerRegistration.Add ("legacy", "Mono.Net.Security.Private.MonoLegacyTlsProvider");
|
||||
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");
|
||||
#if HAVE_BTLS
|
||||
if (Mono.Btls.MonoBtlsProvider.IsSupported ())
|
||||
providerRegistration.Add ("legacy", "Mono.Net.Security.LegacyTlsProvider");
|
||||
providerRegistration.Add ("default", "Mono.Net.Security.LegacyTlsProvider");
|
||||
if (IsBtlsSupported ())
|
||||
providerRegistration.Add ("btls", "Mono.Btls.MonoBtlsProvider");
|
||||
#endif
|
||||
X509Helper2.Initialize ();
|
||||
}
|
||||
}
|
||||
@@ -186,11 +171,8 @@ namespace Mono.Net.Security
|
||||
static MSI.MonoTlsProvider TryDynamicLoad ()
|
||||
{
|
||||
var variable = Environment.GetEnvironmentVariable ("MONO_TLS_PROVIDER");
|
||||
if (variable == null)
|
||||
return null;
|
||||
|
||||
if (string.Equals (variable, "default", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
if (string.IsNullOrEmpty (variable))
|
||||
variable = "default";
|
||||
|
||||
return LookupProvider (variable, true);
|
||||
}
|
||||
@@ -201,7 +183,7 @@ namespace Mono.Net.Security
|
||||
if (provider != null)
|
||||
return provider;
|
||||
|
||||
return new Private.MonoLegacyTlsProvider ();
|
||||
return new LegacyTlsProvider ();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -222,13 +204,9 @@ namespace Mono.Net.Security
|
||||
return provider.Provider;
|
||||
}
|
||||
|
||||
internal static MSI.MonoTlsProvider GetDefaultProvider ()
|
||||
internal static bool IsProviderSupported (string name)
|
||||
{
|
||||
var provider = GetDefaultProviderInternal ();
|
||||
if (provider == null)
|
||||
throw new NotSupportedException ("No TLS Provider available.");
|
||||
|
||||
return provider.Provider;
|
||||
return LookupProvider (name, false) != null;
|
||||
}
|
||||
|
||||
internal static MSI.MonoTlsProvider GetProvider (string name)
|
||||
@@ -236,20 +214,30 @@ namespace Mono.Net.Security
|
||||
return LookupProvider (name, false);
|
||||
}
|
||||
|
||||
internal static bool HasProvider {
|
||||
internal static bool IsInitialized {
|
||||
get {
|
||||
lock (locker) {
|
||||
return currentProvider != null;
|
||||
return initialized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SetDefaultProvider (string name)
|
||||
internal static void Initialize ()
|
||||
{
|
||||
lock (locker) {
|
||||
var provider = LookupProvider (name, true);
|
||||
currentProvider = new Private.MonoTlsProviderWrapper (provider);
|
||||
}
|
||||
#if SECURITY_DEP
|
||||
InitializeInternal ();
|
||||
#else
|
||||
throw new NotSupportedException ("TLS Support not available.");
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void Initialize (string provider)
|
||||
{
|
||||
#if SECURITY_DEP
|
||||
InitializeInternal (provider);
|
||||
#else
|
||||
throw new NotSupportedException ("TLS Support not available.");
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static HttpWebRequest CreateHttpsRequest (Uri requestUri, MSI.MonoTlsProvider provider, MSI.MonoTlsSettings settings)
|
||||
|
||||
Reference in New Issue
Block a user