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

@ -22,6 +22,8 @@
<CompileItem Include="$(CommonPath)\System\Net\Http\HttpHandlerDefaults.cs" />
<CompileItem Include="$(CommonPath)\System\Net\Http\NoWriteNoSeekStreamContent.cs" />
<CompileItem Include="$(CommonPath)\System\Net\Http\WinHttpException.cs" />
<CompileItem Include="$(CommonPath)\System\Net\Security\CertificateHelper.cs" />
<CompileItem Include="$(CommonPath)\System\Net\Security\CertificateHelper.Windows.cs" />
<CompileItem Include="$(CommonPath)\System\Runtime\ExceptionServices\ExceptionStackTrace.cs" />
<CompileItem Include="$(CommonPath)\System\Threading\Tasks\RendezvousAwaitable.cs" />
<CompileItem Include="$(CommonPath)\System\Threading\Tasks\TaskToApm.cs" />

View File

@ -11,8 +11,7 @@ namespace System.Net.Http
{
internal static class WinHttpCertificateHelper
{
private const string ClientAuthenticationOID = "1.3.6.1.5.5.7.3.2";
private static readonly Oid s_serverAuthOid = new Oid("1.3.6.1.5.5.7.3.1");
private static readonly Oid s_serverAuthOid = new Oid("1.3.6.1.5.5.7.3.1", "1.3.6.1.5.5.7.3.1");
// TODO: Issue #2165. Merge with similar code used in System.Net.Security move to Common/src//System/Net.
public static void BuildChain(
@ -81,51 +80,7 @@ namespace System.Net.Http
}
}
public static X509Certificate2 GetEligibleClientCertificate()
{
// Get initial list of client certificates from the MY store.
X509Certificate2Collection candidateCerts;
using (var myStore = new X509Store(StoreName.My, StoreLocation.CurrentUser))
{
myStore.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
candidateCerts = myStore.Certificates;
}
return GetEligibleClientCertificate(candidateCerts);
}
// TODO: Issue #3891. Get the Trusted Issuers List from WinHTTP and use that to help narrow down
// the list of eligible client certificates.
public static X509Certificate2 GetEligibleClientCertificate(X509Certificate2Collection candidateCerts)
{
if (candidateCerts.Count == 0)
{
return null;
}
// Reduce the set of certificates to match the proper 'Client Authentication' criteria.
candidateCerts = candidateCerts.Find(X509FindType.FindByKeyUsage, X509KeyUsageFlags.DigitalSignature, false);
candidateCerts = candidateCerts.Find(X509FindType.FindByApplicationPolicy, ClientAuthenticationOID, false);
// Build a new collection with certs that have a private key. Need to do this
// manually because there is no X509FindType to match this criteria.
var eligibleCerts = new X509Certificate2Collection();
foreach (X509Certificate2 cert in candidateCerts)
{
if (cert.HasPrivateKey)
{
eligibleCerts.Add(cert);
}
}
if (eligibleCerts.Count > 0)
{
return eligibleCerts[0];
}
else
{
return null;
}
}
}
}

View File

@ -1125,11 +1125,11 @@ namespace System.Net.Http
X509Certificate2 clientCertificate = null;
if (_clientCertificateOption == ClientCertificateOption.Manual)
{
clientCertificate = WinHttpCertificateHelper.GetEligibleClientCertificate(ClientCertificates);
clientCertificate = CertificateHelper.GetEligibleClientCertificate(ClientCertificates);
}
else
{
clientCertificate = WinHttpCertificateHelper.GetEligibleClientCertificate();
clientCertificate = CertificateHelper.GetEligibleClientCertificate();
}
if (clientCertificate != null)
@ -1182,21 +1182,17 @@ namespace System.Net.Http
private void SetRequestHandleHttp2Options(SafeWinHttpHandle requestHandle, Version requestVersion)
{
Debug.Assert(requestHandle != null);
if (requestVersion == HttpVersion20)
uint optionData = (requestVersion == HttpVersion20) ? Interop.WinHttp.WINHTTP_PROTOCOL_FLAG_HTTP2 : 0;
if (Interop.WinHttp.WinHttpSetOption(
requestHandle,
Interop.WinHttp.WINHTTP_OPTION_ENABLE_HTTP_PROTOCOL,
ref optionData))
{
WinHttpTraceHelper.Trace("WinHttpHandler.SetRequestHandleHttp2Options: setting HTTP/2 option");
uint optionData = Interop.WinHttp.WINHTTP_PROTOCOL_FLAG_HTTP2;
if (Interop.WinHttp.WinHttpSetOption(
requestHandle,
Interop.WinHttp.WINHTTP_OPTION_ENABLE_HTTP_PROTOCOL,
ref optionData))
{
WinHttpTraceHelper.Trace("WinHttpHandler.SetRequestHandleHttp2Options: HTTP/2 option supported");
}
else
{
WinHttpTraceHelper.Trace("WinHttpHandler.SetRequestHandleHttp2Options: HTTP/2 option not supported");
}
WinHttpTraceHelper.Trace("WinHttpHandler.SetRequestHandleHttp2Options: HTTP/2 option supported, setting to {0}", optionData);
}
else
{
WinHttpTraceHelper.Trace("WinHttpHandler.SetRequestHandleHttp2Options: HTTP/2 option not supported");
}
}

View File

@ -350,7 +350,7 @@ namespace System.Net.Http
{
// TODO: Issue #2165. We need to pass in the cancellation token from the
// user's ReadAsync() call into the TrySetCanceled().
Debug.WriteLine("RequestCallback: QUERY_DATA_AVAILABLE - ERROR_WINHTTP_OPERATION_CANCELLED");
WinHttpTraceHelper.Trace("RequestCallback: QUERY_DATA_AVAILABLE - ERROR_WINHTTP_OPERATION_CANCELLED");
state.LifecycleAwaitable.SetCanceled();
}
else
@ -365,7 +365,7 @@ namespace System.Net.Http
{
// TODO: Issue #2165. We need to pass in the cancellation token from the
// user's ReadAsync() call into the TrySetCanceled().
Debug.WriteLine("RequestCallback: API_READ_DATA - ERROR_WINHTTP_OPERATION_CANCELLED");
WinHttpTraceHelper.Trace("RequestCallback: API_READ_DATA - ERROR_WINHTTP_OPERATION_CANCELLED");
state.LifecycleAwaitable.SetCanceled();
}
else
@ -379,7 +379,7 @@ namespace System.Net.Http
{
// TODO: Issue #2165. We need to pass in the cancellation token from the
// user's WriteAsync() call into the TrySetCanceled().
Debug.WriteLine("RequestCallback: API_WRITE_DATA - ERROR_WINHTTP_OPERATION_CANCELLED");
WinHttpTraceHelper.Trace("RequestCallback: API_WRITE_DATA - ERROR_WINHTTP_OPERATION_CANCELLED");
state.TcsInternalWriteDataToRequestStream.TrySetCanceled();
}
else

View File

@ -11,9 +11,6 @@ namespace System.Net.Http
/// </summary>
internal struct WinHttpResponseHeaderReader
{
private const string Gzip = "gzip";
private const string Deflate = "deflate";
private readonly char[] _buffer;
private readonly int _length;
private int _position;
@ -65,7 +62,7 @@ namespace System.Net.Http
int valueLength = startIndex + length - colonIndex - 1;
CharArrayHelpers.Trim(_buffer, ref valueStartIndex, ref valueLength);
value = GetHeaderValue(name, _buffer, valueStartIndex, valueLength);
value = HttpKnownHeaderNames.GetHeaderValue(name, _buffer, valueStartIndex, valueLength);
return true;
}
@ -127,35 +124,5 @@ namespace System.Net.Http
length = 0;
return false;
}
private static string GetHeaderValue(string name, char[] array, int startIndex, int length)
{
Debug.Assert(name != null);
CharArrayHelpers.DebugAssertArrayInputs(array, startIndex, length);
if (length == 0)
{
return string.Empty;
}
// If it's a known header value, use the known value instead of allocating a new string.
// Do a really quick reference equals check to see if name is the same object as
// HttpKnownHeaderNames.ContentEncoding, in which case the value is very likely to
// be either "gzip" or "deflate".
if (object.ReferenceEquals(name, HttpKnownHeaderNames.ContentEncoding))
{
if (CharArrayHelpers.EqualsOrdinalAsciiIgnoreCase(Gzip, array, startIndex, length))
{
return Gzip;
}
else if (CharArrayHelpers.EqualsOrdinalAsciiIgnoreCase(Deflate, array, startIndex, length))
{
return Deflate;
}
}
return new string(array, startIndex, length);
}
}
}

View File

@ -314,11 +314,8 @@ namespace System.Net.Http
{
if (_state.AsyncReadInProgress)
{
Debug.Assert(_requestHandle != null);
Debug.Assert(!_requestHandle.IsInvalid);
WinHttpTraceHelper.Trace("WinHttpResponseStream.CancelPendingResponseStreamReadOperation: before dispose");
_requestHandle.Dispose();
_requestHandle?.Dispose(); // null check necessary to handle race condition between stream disposal and cancellation
WinHttpTraceHelper.Trace("WinHttpResponseStream.CancelPendingResponseStreamReadOperation: after dispose");
}
}

View File

@ -17,6 +17,7 @@ using Xunit.Abstractions;
namespace System.Net.Http.WinHttpHandlerFunctional.Tests
{
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "WinHttpHandler not supported on UAP")]
public class ServerCertificateTest
{
private readonly ITestOutputHelper _output;

View File

@ -18,6 +18,7 @@ namespace System.Net.Http.WinHttpHandlerFunctional.Tests
{
// Note: Disposing the HttpClient object automatically disposes the handler within. So, it is not necessary
// to separately Dispose (or have a 'using' statement) for the handler.
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "WinHttpHandler not supported on UAP")]
public class WinHttpHandlerTest
{
// TODO: This is a placeholder until GitHub Issue #2383 gets resolved.

View File

@ -6,7 +6,7 @@ using System.Diagnostics;
using System.Net.Http.WinHttpHandlerUnitTests;
using System.Security.Cryptography.X509Certificates;
namespace System.Net.Http
namespace System.Security.Cryptography.X509Certificates
{
public class X509Store : IDisposable
{

View File

@ -3,6 +3,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{A2ECDEDB-12B7-402C-9230-152B7601179F}</ProjectGuid>
<NoWarn>$(NoWarn);0436</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<StringResourcesPath>../../src/Resources/Strings.resx</StringResourcesPath>
</PropertyGroup>
@ -66,6 +67,12 @@
<Compile Include="$(CommonPath)\System\Net\Http\WinHttpException.cs">
<Link>Common\System\Net\Http\WinHttpException.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Net\Security\CertificateHelper.cs">
<Link>Common\System\Net\Security\CertificateHelper.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Net\Security\CertificateHelper.Windows.cs">
<Link>Common\System\Net\Security\CertificateHelper.Windows.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Runtime\ExceptionServices\ExceptionStackTrace.cs">
<Link>Common\System\Runtime\ExceptionServices\ExceptionStackTrace.cs</Link>
</Compile>

View File

@ -193,7 +193,7 @@ namespace System.Net.Http.WinHttpHandlerUnitTests
{
Stream stream = MakeRequestStream();
Assert.Throws<ArgumentException>(() => stream.Write(new byte[1], 0, 3));
AssertExtensions.Throws<ArgumentException>("buffer", () => stream.Write(new byte[1], 0, 3));
}
[Fact]
@ -201,7 +201,7 @@ namespace System.Net.Http.WinHttpHandlerUnitTests
{
Stream stream = MakeRequestStream();
Assert.Throws<ArgumentException>(() => stream.Write(new byte[1], int.MaxValue, int.MaxValue));
AssertExtensions.Throws<ArgumentException>("buffer", () => stream.Write(new byte[1], int.MaxValue, int.MaxValue));
}
[Fact]

View File

@ -190,7 +190,7 @@ namespace System.Net.Http.WinHttpHandlerUnitTests
{
Stream stream = MakeResponseStream();
Assert.Throws<ArgumentException>(() => stream.Read(new byte[1], int.MaxValue, int.MaxValue));
AssertExtensions.Throws<ArgumentException>("buffer", () => stream.Read(new byte[1], int.MaxValue, int.MaxValue));
}
[Fact]