-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Use handshake timeout for Tls listener callback #62177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Use handshake timeout for Tls listener callback #62177
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
@@ -21,7 +21,7 @@ | |||
|
|||
namespace InMemory.FunctionalTests; | |||
|
|||
public class TlsListenerMiddlewareTests : TestApplicationErrorLoggerLoggedTest | |||
public class TlsListenerTests : TestApplicationErrorLoggerLoggedTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably add a cancellation test here as well. Set the handshake timeout to something small like 1 millisecond and check that the request was canceled.
@@ -50,6 +50,57 @@ public Task OnTlsClientHelloAsync_ValidData_MultipleSegments(int id, List<byte[] | |||
public Task OnTlsClientHelloAsync_InvalidData_MultipleSegments(int id, List<byte[]> packets) | |||
=> RunTlsClientHelloCallbackTest_WithMultipleSegments(id, packets, tlsClientHelloCallbackExpected: false); | |||
|
|||
[Fact] | |||
public async Task RunTlsClientHelloCallbackTest_WithPreCancelledToken() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public async Task RunTlsClientHelloCallbackTest_WithPreCancelledToken() | |
public async Task RunTlsClientHelloCallbackTest_WithPreCanceledToken() |
{ | ||
clientHelloBytes = default; | ||
|
||
// in case bad actor will be sending a TLS client hello one byte at a time | ||
// and we know the expected length of TLS client hello, | ||
// we can check and fail fastly here instead of re-parsing the TLS client hello "header" on each iteration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// we can check and fail fastly here instead of re-parsing the TLS client hello "header" on each iteration | |
// we can check and fail quickly here instead of re-parsing the TLS client hello "header" on each iteration |
Problem
HttpsConnectionMiddleware carefully considers a handshake timeout.
New TlsListenerMiddleware does not use it, and in case of a configured timeout request will not be cancelled.
Solution
I renamed
TlsListenerMiddleware
toTlsListener
to be used as part ofHttpsConnectionMiddleware
. It will use the same cancellation token as the latter. We can move the code directly intoHttpsConnectionMiddleware
but IMOTlsListener
has a bit different purpose and can be living in a separate instance.TlsListener
now does not invoke next middleware delegate.Also changed the parsing code to remember the TLS client hello record length, and if that is known re-parsing of TLS client hello "header" will not be happening on each iteration.
Closes #62172