Skip to content

Commit

Permalink
process more TLS frames at one when available (#50815)
Browse files Browse the repository at this point in the history
* process more TLS frames when available

* add SslStream.Implementation.cs

* remove extra comment

* add back DefaultRequestHeaders_SentUnparsed

* feedback from review

* fix winhttp

* fix linker test

* feedback from review

* feedback from review

* feedback from review

* make EnsureFullTlsFrame async

* feedback from review
  • Loading branch information
wfurt committed Jun 24, 2021
1 parent 5c2ff17 commit 2ac023c
Show file tree
Hide file tree
Showing 17 changed files with 239 additions and 411 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private static unsafe extern PAL_SSLStreamStatus SSLStreamRead(
out int bytesRead);
internal static unsafe PAL_SSLStreamStatus SSLStreamRead(
SafeSslHandle sslHandle,
Span<byte> buffer,
ReadOnlySpan<byte> buffer,
out int bytesRead)
{
fixed (byte* bufferPtr = buffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Net.Security;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Authentication;
using System.Security.Authentication.ExtendedProtection;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Win32.SafeHandles;

internal static partial class Interop
Expand Down
127 changes: 0 additions & 127 deletions src/libraries/Common/tests/System/Net/Http/SchSendAuxRecordHttpTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ public sealed class PlatformHandler_HttpClientHandler_Proxy_Test : HttpClientHan
public PlatformHandler_HttpClientHandler_Proxy_Test(ITestOutputHelper output) : base(output) { }
}

public sealed class PlatformHandler_SchSendAuxRecordHttpTest : SchSendAuxRecordHttpTest
{
public PlatformHandler_SchSendAuxRecordHttpTest(ITestOutputHelper output) : base(output) { }
}

public sealed class PlatformHandler_HttpClientHandlerTest : HttpClientHandlerTest
{
public PlatformHandler_HttpClientHandlerTest(ITestOutputHelper output) : base(output) { }
Expand Down Expand Up @@ -299,13 +294,6 @@ public sealed class PlatformHandler_HttpClientHandler_Proxy_Http2_Test : HttpCli
public PlatformHandler_HttpClientHandler_Proxy_Http2_Test(ITestOutputHelper output) : base(output) { }
}

public sealed class PlatformHandler_SchSendAuxRecordHttp_Http2_Test : SchSendAuxRecordHttpTest
{
protected override Version UseVersion => HttpVersion20.Value;

public PlatformHandler_SchSendAuxRecordHttp_Http2_Test(ITestOutputHelper output) : base(output) { }
}

[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsWindows10Version1607OrGreater))]
public sealed class PlatformHandler_HttpClientHandler_Http2_Test : HttpClientHandlerTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@
Link="Common\System\Net\Http\RepeatedFlushContent.cs" />
<Compile Include="$(CommonTestPath)System\Net\Http\ResponseStreamTest.cs"
Link="Common\System\Net\Http\ResponseStreamTest.cs" />
<Compile Include="$(CommonTestPath)System\Net\Http\SchSendAuxRecordHttpTest.cs"
Link="Common\System\Net\Http\SchSendAuxRecordHttpTest.cs" />
<Compile Include="$(CommonTestPath)System\Net\Http\SyncBlockingContent.cs"
Link="Common\System\Net\Http\SyncBlockingContent.cs" />
<Compile Include="$(CommonTestPath)System\Net\Http\ThrowingContent.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,11 +985,6 @@ public async Task Http2GetAsync_TrailingHeaders_NoData_EmptyResponseObserved()
}
}

public sealed class SocketsHttpHandler_SchSendAuxRecordHttpTest : SchSendAuxRecordHttpTest
{
public SocketsHttpHandler_SchSendAuxRecordHttpTest(ITestOutputHelper output) : base(output) { }
}

public sealed class SocketsHttpHandler_HttpClientHandlerTest : HttpClientHandlerTest
{
public SocketsHttpHandler_HttpClientHandlerTest(ITestOutputHelper output) : base(output) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@
Link="Common\System\Net\Http\RepeatedFlushContent.cs" />
<Compile Include="$(CommonTestPath)System\Net\Http\ResponseStreamTest.cs"
Link="Common\System\Net\Http\ResponseStreamTest.cs" />
<Compile Include="$(CommonTestPath)System\Net\Http\SchSendAuxRecordHttpTest.cs"
Link="Common\System\Net\Http\SchSendAuxRecordHttpTest.cs" />
<Compile Include="SyncHttpHandlerTest.cs" />
<Compile Include="TelemetryTest.cs" />
<Compile Include="StreamContentTest.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal sealed partial class NetEventSource : EventSource
/// <param name="buffer">The buffer to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void DumpBuffer(object thisOrContextObject, ReadOnlyMemory<byte> buffer, [CallerMemberName] string? memberName = null)
public static void DumpBuffer(object thisOrContextObject, ReadOnlySpan<byte> buffer, [CallerMemberName] string? memberName = null)
{
if (Log.IsEnabled())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ is non-zero.
--*/
internal SecurityStatusPal Encrypt(ReadOnlyMemory<byte> buffer, ref byte[] output, out int resultSize)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.DumpBuffer(this, buffer);
if (NetEventSource.Log.IsEnabled()) NetEventSource.DumpBuffer(this, buffer.Span);

byte[] writeBuffer = output;

Expand All @@ -903,24 +903,12 @@ internal SecurityStatusPal Encrypt(ReadOnlyMemory<byte> buffer, ref byte[] outpu
return secStatus;
}

internal SecurityStatusPal Decrypt(byte[]? payload, ref int offset, ref int count)
internal SecurityStatusPal Decrypt(Span<byte> buffer, out int outputOffset, out int outputCount)
{
if ((uint)offset > (uint)(payload == null ? 0 : payload.Length))
{
Debug.Fail("Argument 'offset' out of range.");
throw new ArgumentOutOfRangeException(nameof(offset));
}

if ((uint)count > (uint)(payload == null ? 0 : payload.Length - offset))
{
Debug.Fail("Argument 'count' out of range.");
throw new ArgumentOutOfRangeException(nameof(count));
}

SecurityStatusPal status = SslStreamPal.DecryptMessage(_securityContext!, payload!, ref offset, ref count);
SecurityStatusPal status = SslStreamPal.DecryptMessage(_securityContext!, buffer, out outputOffset, out outputCount);
if (NetEventSource.Log.IsEnabled() && status.ErrorCode == SecurityStatusPalErrorCode.OK)
{
NetEventSource.DumpBuffer(this, payload!, offset, count);
NetEventSource.DumpBuffer(this, buffer.Slice(outputOffset, outputCount));
}

return status;
Expand Down
Loading

0 comments on commit 2ac023c

Please sign in to comment.