Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@@ -158,7 +158,7 @@ namespace Mono.Net.Security
RunSynchronously = sync;
}
[SD.Conditional ("MARTIN_DEBUG")]
[SD.Conditional ("MONO_TLS_DEBUG")]
protected void Debug (string message, params object[] args)
{
Parent.Debug ("{0}({1}:{2}): {3}", Name, Parent.ID, ID, string.Format (message, args));
@@ -226,6 +226,7 @@ namespace Mono.Net.Security
if (Interlocked.Exchange (ref WriteRequested, 0) != 0) {
// Flush the write queue.
Debug ("ProcessOperation - flushing write queue");
await Parent.InnerWrite (RunSynchronously, cancellationToken);
}

View File

@@ -68,6 +68,10 @@ namespace Mono.Net.Security
get { return false; }
}
internal override bool SupportsCleanShutdown {
get { return false; }
}
public override SslProtocols SupportedProtocols {
get { return SslProtocols.Tls; }
}

View File

@@ -384,10 +384,10 @@ namespace Mono.Net.Security
static int nextId;
internal readonly int ID = ++nextId;
[SD.Conditional ("MARTIN_DEBUG")]
[SD.Conditional ("MONO_TLS_DEBUG")]
protected internal void Debug (string message, params object[] args)
{
Console.Error.WriteLine ("MobileAuthenticatedStream({0}): {1}", ID, string.Format (message, args));
MonoTlsProviderFactory.Debug ("MobileAuthenticatedStream({0}): {1}", ID, string.Format (message, args));
}
#region Called back from native code via SslConnection
@@ -531,7 +531,7 @@ namespace Mono.Net.Security
internal async Task<int> InnerRead (bool sync, int requestedSize, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested ();
Debug ("InnerRead: {0} {1} {2} {3}", readBuffer.Offset, readBuffer.Size, readBuffer.Remaining, requestedSize);
Debug ("InnerRead: {0} {1} {2} {3} {4}", sync, readBuffer.Offset, readBuffer.Size, readBuffer.Remaining, requestedSize);
var len = System.Math.Min (readBuffer.Remaining, requestedSize);
if (len == 0)
@@ -612,11 +612,16 @@ namespace Mono.Net.Security
* SSLHandshake() will return repeatedly with 'SslStatus.WouldBlock', we then need
* to take care of I/O and call it again.
*/
var newStatus = AsyncOperationStatus.Continue;
if (xobileTlsContext.ProcessHandshake ()) {
xobileTlsContext.FinishHandshake ();
return AsyncOperationStatus.Complete;
newStatus = AsyncOperationStatus.Complete;
}
return AsyncOperationStatus.Continue;
if (lastException != null)
lastException.Throw ();
return newStatus;
}
}
@@ -624,8 +629,10 @@ namespace Mono.Net.Security
{
lock (ioLock) {
// This operates on the internal buffer and will never block.
var ret = xobileTlsContext.Read (userBuffer.Buffer, userBuffer.Offset, userBuffer.Size, out bool wantMore);
return (ret, wantMore);
var ret = xobileTlsContext.Read (userBuffer.Buffer, userBuffer.Offset, userBuffer.Size);
if (lastException != null)
lastException.Throw ();
return ret;
}
}
@@ -633,8 +640,10 @@ namespace Mono.Net.Security
{
lock (ioLock) {
// This operates on the internal buffer and will never block.
var ret = xobileTlsContext.Write (userBuffer.Buffer, userBuffer.Offset, userBuffer.Size, out bool wantMore);
return (ret, wantMore);
var ret = xobileTlsContext.Write (userBuffer.Buffer, userBuffer.Offset, userBuffer.Size);
if (lastException != null)
lastException.Throw ();
return ret;
}
}
@@ -698,7 +707,7 @@ namespace Mono.Net.Security
public override void Flush ()
{
// Write() automatically flushes the underlying stream.
InnerStream.Flush ();
}
public SslProtocols SslProtocol {

View File

@@ -78,10 +78,10 @@ namespace Mono.Net.Security
get { return parent.Provider; }
}
[SD.Conditional ("MARTIN_DEBUG")]
[SD.Conditional ("MONO_TLS_DEBUG")]
protected void Debug (string message, params object[] args)
{
Console.Error.WriteLine ("{0}: {1}", GetType ().Name, string.Format (message, args));
parent.Debug ("{0}: {1}", GetType ().Name, string.Format (message, args));
}
public abstract bool HasContext {
@@ -165,9 +165,9 @@ namespace Mono.Net.Security
public abstract void Flush ();
public abstract int Read (byte[] buffer, int offset, int count, out bool wantMore);
public abstract (int ret, bool wantMore) Read (byte[] buffer, int offset, int count);
public abstract int Write (byte[] buffer, int offset, int count, out bool wantMore);
public abstract (int ret, bool wantMore) Write (byte[] buffer, int offset, int count);
public abstract void Shutdown ();

View File

@@ -38,6 +38,7 @@ using System.Security.Cryptography.X509Certificates;
using System;
using System.Net;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
@@ -192,6 +193,22 @@ namespace Mono.Net.Security
}
}
static bool enableDebug;
[Conditional ("MONO_TLS_DEBUG")]
static void InitializeDebug ()
{
if (Environment.GetEnvironmentVariable ("MONO_TLS_DEBUG") != null)
enableDebug = true;
}
[Conditional ("MONO_TLS_DEBUG")]
internal static void Debug (string message, params object[] args)
{
if (enableDebug)
Console.Error.WriteLine (message, args);
}
#endregion
internal static readonly Guid AppleTlsId = new Guid ("981af8af-a3a3-419a-9f01-a518e3a17c1c");
@@ -203,6 +220,9 @@ namespace Mono.Net.Security
lock (locker) {
if (providerRegistration != null)
return;
InitializeDebug ();
providerRegistration = new Dictionary<string,Tuple<Guid,string>> ();
providerCache = new Dictionary<Guid,MSI.MonoTlsProvider> ();

View File

@@ -41,6 +41,7 @@ using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Net.Security;
using System.Threading;
using System.Threading.Tasks;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
@@ -56,6 +57,8 @@ namespace Mono.Net.Security
readonly NetworkStream networkStream;
readonly HttpWebRequest request;
readonly MonoTlsSettings settings;
internal HttpWebRequest Request {
get { return request; }
}
@@ -65,6 +68,8 @@ namespace Mono.Net.Security
internal IMonoSslStream SslStream {
get { return sslStream; }
}
#else
const string EXCEPTION_MESSAGE = "System.Net.Security.SslStream is not supported on the current platform.";
#endif
WebExceptionStatus status;
@@ -77,12 +82,9 @@ namespace Mono.Net.Security
get; set;
}
#if SECURITY_DEP
// readonly ChainValidationHelper validationHelper;
readonly MonoTlsSettings settings;
public MonoTlsStream (HttpWebRequest request, NetworkStream networkStream)
{
#if SECURITY_DEP
this.request = request;
this.networkStream = networkStream;
@@ -90,11 +92,16 @@ namespace Mono.Net.Security
provider = request.TlsProvider ?? MonoTlsProviderFactory.GetProviderInternal ();
status = WebExceptionStatus.SecureChannelFailure;
/*validationHelper =*/ ChainValidationHelper.Create (provider, ref settings, this);
ChainValidationHelper.Create (provider, ref settings, this);
#else
status = WebExceptionStatus.SecureChannelFailure;
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
#endif
}
internal Stream CreateStream (byte[] buffer)
{
#if SECURITY_DEP
sslStream = provider.CreateSslStream (networkStream, false, settings);
try {
@@ -111,7 +118,7 @@ namespace Mono.Net.Security
ServicePointManager.CheckCertificateRevocationList);
status = WebExceptionStatus.Success;
} catch (Exception) {
} catch {
status = WebExceptionStatus.SecureChannelFailure;
throw;
} finally {
@@ -136,7 +143,9 @@ namespace Mono.Net.Security
}
return sslStream.AuthenticatedStream;
}
#else
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
#endif
}
}
}