-
Notifications
You must be signed in to change notification settings - Fork 10.3k
API Proposal: Expose TLS client hello message #60805
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
Comments
What about adding a property with a default implementation to |
@halter73 I have no problem adding it to the I dont think it should be a property though, because we want it to be "on-demand" API (basically we do not fetch and save it if it is not requested) |
API Review Notes:
|
updated the proposal with a purely aspnetcore change (no SslStream / dotnet-runtime changes required): @halter73 @BrennanConroy let me know if you have comments, or we can go through the review |
@DeagleGross Have you figured this part out yet? |
@halter73 yep, proposed |
API Approved! namespace Microsoft.AspNetCore.Server.Kestrel.Https;
public class HttpsConnectionAdapterOptions
{
+ Action<ConnectionContext, ReadOnlySequence<byte>> TlsClientHelloBytesCallback { get; set; }
} namespace Microsoft.AspNetCore.Server.HttpSys;
public class HttpSysOptions
{
+ Action<IFeatureCollection, ReadOnlySpan<byte>> TlsClientHelloBytesCallback { get; set; }
} |
Update: After implementing this, we discovered we need to make the callbacks nullable. The final approved API is: namespace Microsoft.AspNetCore.Server.Kestrel.Https;
public class HttpsConnectionAdapterOptions
{
+ Action<ConnectionContext, ReadOnlySequence<byte>>? TlsClientHelloBytesCallback { get; set; }
} namespace Microsoft.AspNetCore.Server.HttpSys;
public class HttpSysOptions
{
+ Action<IFeatureCollection, ReadOnlySpan<byte>>? TlsClientHelloBytesCallback { get; set; }
} |
Is there an existing issue for this?
Intro
We need to add implementation at least for HTTP.SYS / Kestrel servers. Based on SslStream API Proposal for Kestrel support (dotnet/runtime proposal), it seems more likely that a callback will be introduced there (something like
SslServerAuthenticationOptions.ClientHelloBytesCallback
).Or we can just support it in aspnetcore directly similarly to how YARP has already done it (see TlsFilter middleware).
Proposed API
Kestrel
Exposing a separate extension on
ListenOptionsHttpsExtensions
or on a new typeListenOptionsTlsExtensions
works for KestrelKestrel Usage:
Implementation of such a kind would be reading every packet, then if it appears to start with TLS client hello header, then we would try to identify the length of it, read needed data, and then invoke a callback. Later we would be able to even add an overload to provide a parsed TLS client hello message in a strictly typed way (like TlsFrameInfo)
This also helps user to associate the tls client hello with a specific connection (
ConnectionContext
parameter).ReadOnlySequence<byte>
should be chosen instead ofReadOnlySpan<byte>
because tls info can come in different segments, and it will not be a contiguous memory then (see TlsFilter'sif (!buffer.IsSingleSegment)
)Http.Sys
In order to align the implementation for different servers, I am proposing to add a similar callback to
HttpSysOptions
namespace Microsoft.AspNetCore.Server.HttpSys; public class HttpSysOptions { + Action<IFeatureCollection, ReadOnlySpan<byte>> ClientHelloBytesCallback { get; set; } }
Http.sys Usage:
HTTP.SYS API would have same idea, but different implementation: a) having a callback in a different options class and b) having an
IFeatureCollection
instead ofConnectionContext
(there is none yet for HTTP.SYS). That would also give full control to the user to lookup to any feature collection or even set their own feature for future call rejection for instance.Other considered designs (and why they are not chosen)
Middleware
Adding a separate middleware on top of
IApplicationBuilder.Run()
will not fulfil the need, since such a middleware is terminal (runs after the internal ASP.NET middleware chain including SslStream one):Exposing bytes field on the
ITlsHandshakeFeature
(or similar)This is considered a non-performant API for both servers due to increasing a memory footprint significantly (see dotnet/runtime#113729 (comment)):
Is your feature request related to a problem? Please describe the problem.
The intention here is to have an API to access a TLS client hello message in a format of raw bytes (in example
byte[]
). In such a way users can analyze it and make whatever decision they want to.The text was updated successfully, but these errors were encountered: