Skip to content

Commit 0c2dc96

Browse files
committed
init
1 parent a710517 commit 0c2dc96

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/Servers/Kestrel/Core/src/Middleware/TlsListener.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ private static ClientHelloParseState TryParseClientHello(ReadOnlySequence<byte>
9494
return ClientHelloParseState.NotEnoughData;
9595
}
9696

97+
// this means we finally got a full tls record, so we can return without parsing again
98+
if (recordLength != -1)
99+
{
100+
clientHelloBytes = buffer.Slice(0, 5 + recordLength);
101+
return ClientHelloParseState.ValidTlsClientHello;
102+
}
103+
97104
if (buffer.Length < 6)
98105
{
99106
return ClientHelloParseState.NotEnoughData;

src/Servers/Kestrel/Core/test/TlsListenerMiddlewareTests.cs renamed to src/Servers/Kestrel/Core/test/TlsListenerTests.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests;
3030

31-
public class TlsListenerMiddlewareTests
31+
public class TlsListenerTests
3232
{
3333
[Theory]
3434
[MemberData(nameof(ValidClientHelloData))]
@@ -50,6 +50,29 @@ public Task OnTlsClientHelloAsync_ValidData_MultipleSegments(int id, List<byte[]
5050
public Task OnTlsClientHelloAsync_InvalidData_MultipleSegments(int id, List<byte[]> packets)
5151
=> RunTlsClientHelloCallbackTest_WithMultipleSegments(id, packets, tlsClientHelloCallbackExpected: false);
5252

53+
[Fact]
54+
public async Task RunTlsClientHelloCallbackTest_WithPreCancelledToken()
55+
{
56+
var serviceContext = new TestServiceContext();
57+
58+
var pipe = new Pipe();
59+
var writer = pipe.Writer;
60+
var reader = new ObservablePipeReader(pipe.Reader);
61+
62+
var transport = new DuplexPipe(reader, writer);
63+
var transportConnection = new DefaultConnectionContext("test", transport, transport);
64+
65+
var tlsClientHelloCallbackInvoked = false;
66+
var middleware = new TlsListener((ctx, data) => { tlsClientHelloCallbackInvoked = true; });
67+
68+
var cts = new CancellationTokenSource();
69+
cts.Cancel();
70+
71+
await writer.WriteAsync(new byte[1] { 0x16 });
72+
await middleware.OnTlsClientHelloAsync(transportConnection, cts.Token);
73+
Assert.False(tlsClientHelloCallbackInvoked);
74+
}
75+
5376
[Fact]
5477
public async Task RunTlsClientHelloCallbackTest_DeterministicallyReads()
5578
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace InMemory.FunctionalTests;
2323

24-
public class TlsListenerMiddlewareTests : TestApplicationErrorLoggerLoggedTest
24+
public class TlsListenerTests : TestApplicationErrorLoggerLoggedTest
2525
{
2626
private static readonly X509Certificate2 _x509Certificate2 = TestResources.GetTestCertificate();
2727

0 commit comments

Comments
 (0)