Imported Upstream version 5.12.0.220

Former-commit-id: c477e03582759447177c6d4bf412cd2355aad476
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-04-24 09:31:23 +00:00
parent 8bd104cef2
commit 8fc30896db
1200 changed files with 29534 additions and 26161 deletions

View File

@@ -226,45 +226,79 @@ namespace Mono.Net.Security
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> (LegacyId, "Mono.Net.Security.LegacyTlsProvider");
providerRegistration.Add ("legacy", legacyEntry);
Tuple<Guid,String> btlsEntry = null;
#if MONO_FEATURE_BTLS
if (IsBtlsSupported ()) {
btlsEntry = new Tuple<Guid,String> (BtlsId, "Mono.Btls.MonoBtlsProvider");
providerRegistration.Add ("btls", btlsEntry);
}
#endif
if (Platform.IsMacOS)
providerRegistration.Add ("default", appleTlsEntry);
else if (btlsEntry != null)
providerRegistration.Add ("default", btlsEntry);
else
providerRegistration.Add ("default", legacyEntry);
providerRegistration.Add ("apple", appleTlsEntry);
#endif
PopulateProviders ();
}
}
#region Platform-Specific code
#if ONLY_APPLETLS || MONOTOUCH || XAMMAC
// TODO: Should be redundant
static void PopulateProviders ()
{
var appleTlsEntry = new Tuple<Guid,String> (AppleTlsId, typeof (Mono.AppleTls.AppleTlsProvider).FullName);
providerRegistration.Add ("default", appleTlsEntry);
providerRegistration.Add ("apple", appleTlsEntry);
}
#elif MONODROID
// TODO: Should be redundant
static void PopulateProviders ()
{
var legacyEntry = new Tuple<Guid,String> (LegacyId, typeof (Mono.Net.Security.LegacyTlsProvider).FullName);
providerRegistration.Add ("legacy", legacyEntry);
#if MONO_FEATURE_BTLS
var btlsEntry = new Tuple<Guid,String> (BtlsId, typeof (Mono.Btls.MonoBtlsProvider).FullName);
if (btlsEntry != null)
providerRegistration.Add ("default", btlsEntry);
else
#endif
providerRegistration.Add ("default", legacyEntry);
}
#else
static void PopulateProviders ()
{
#if MONO_FEATURE_APPLETLS
var appleTlsEntry = new Tuple<Guid,String> (AppleTlsId, typeof (Mono.AppleTls.AppleTlsProvider).FullName);
#endif
var legacyEntry = new Tuple<Guid,String> (LegacyId, typeof (Mono.Net.Security.LegacyTlsProvider).FullName);
providerRegistration.Add ("legacy", legacyEntry);
Tuple<Guid,String> btlsEntry = null;
#if MONO_FEATURE_BTLS
if (IsBtlsSupported ()) {
btlsEntry = new Tuple<Guid,String> (BtlsId, typeof (Mono.Btls.MonoBtlsProvider).FullName);
providerRegistration.Add ("btls", btlsEntry);
}
#endif
#if MONO_FEATURE_APPLETLS
if (Platform.IsMacOS)
providerRegistration.Add ("default", appleTlsEntry);
else
#endif
#if MONO_FEATURE_BTLS
if (btlsEntry != null)
providerRegistration.Add ("default", btlsEntry);
else
#endif
providerRegistration.Add ("default", legacyEntry);
#if MONO_FEATURE_APPLETLS
providerRegistration.Add ("apple", appleTlsEntry);
#endif
}
#endif
#if MONO_FEATURE_BTLS
[MethodImpl (MethodImplOptions.InternalCall)]
internal extern static bool IsBtlsSupported ();
#endif
#if MONODROID
static MSI.MonoTlsProvider CreateDefaultProviderImpl ()
{
#if MONODROID
MSI.MonoTlsProvider provider = null;
var type = Environment.GetEnvironmentVariable ("XA_TLS_PROVIDER");
switch (type) {
@@ -281,24 +315,40 @@ namespace Mono.Net.Security
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 ()
{
var variable = Environment.GetEnvironmentVariable ("MONO_TLS_PROVIDER");
if (string.IsNullOrEmpty (variable))
variable = "default";
var type = Environment.GetEnvironmentVariable ("MONO_TLS_PROVIDER");
if (string.IsNullOrEmpty (type))
type = "default";
return LookupProvider (variable, true);
}
switch (type) {
case "default":
#if MONO_FEATURE_APPLETLS
if (Platform.IsMacOS)
goto case "apple";
#endif
#if MONO_FEATURE_BTLS
if (IsBtlsSupported ())
goto case "btls";
#endif
goto case "legacy";
#if MONO_FEATURE_APPLETLS
case "apple":
return new AppleTlsProvider ();
#endif
#if MONO_FEATURE_BTLS
case "btls":
return new MonoBtlsProvider ();
#endif
case "legacy":
return new Mono.Net.Security.LegacyTlsProvider ();
}
#endregion
return LookupProvider (type, true);
#endif
}
#region Mono.Security visible API

View File

@@ -52,7 +52,7 @@ namespace Mono.Net.Security
{
class MonoTlsStream
{
#if SECURITY_DEP
#if SECURITY_DEP
readonly MonoTlsProvider provider;
readonly NetworkStream networkStream;
readonly HttpWebRequest request;
@@ -99,9 +99,11 @@ namespace Mono.Net.Security
#endif
}
internal Stream CreateStream (byte[] buffer)
internal async Task<Stream> CreateStream (WebConnectionTunnel tunnel, CancellationToken cancellationToken)
{
#if SECURITY_DEP
var socket = networkStream.InternalSocket;
WebConnection.Debug ($"MONO TLS STREAM CREATE STREAM: {socket.ID}");
sslStream = provider.CreateSslStream (networkStream, false, settings);
try {
@@ -112,16 +114,21 @@ namespace Mono.Net.Security
host = host.Substring (0, pos);
}
sslStream.AuthenticateAsClient (
await sslStream.AuthenticateAsClientAsync (
host, request.ClientCertificates,
(SslProtocols)ServicePointManager.SecurityProtocol,
ServicePointManager.CheckCertificateRevocationList);
ServicePointManager.CheckCertificateRevocationList).ConfigureAwait (false);
status = WebExceptionStatus.Success;
} catch {
status = WebExceptionStatus.SecureChannelFailure;
} catch (Exception ex) {
WebConnection.Debug ($"MONO TLS STREAM ERROR: {socket.ID} {socket.CleanedUp} {ex.Message}");
if (socket.CleanedUp)
status = WebExceptionStatus.RequestCanceled;
else
status = WebExceptionStatus.SecureChannelFailure;
throw;
} finally {
WebConnection.Debug ($"MONO TLS STREAM CREATE STREAM DONE: {socket.ID} {socket.CleanedUp}");
if (CertificateValidationFailed)
status = WebExceptionStatus.TrustFailure;
@@ -134,8 +141,8 @@ namespace Mono.Net.Security
}
try {
if (buffer != null)
sslStream.Write (buffer, 0, buffer.Length);
if (tunnel?.Data != null)
await sslStream.WriteAsync (tunnel.Data, 0, tunnel.Data.Length, cancellationToken).ConfigureAwait (false);
} catch {
status = WebExceptionStatus.SendFailure;
sslStream = null;