Description
Background and motivation
There is an effort to expose TLS client hello message in ASP.NET: see API Proposal: Expose TLS client hello message. We have already figured out the implementation for HTTP.SYS as underlying server (see feat: fetch TLS client hello message from HTTP.SYS.
The ask here is to have a similar API to fetch this data from SslStream in case ASP.NET uses Kestrel server.
API Proposal
Is should be a method / property to fetch the raw bytes of the tls client hello message.
public partial class SslStream
{
+ public ReadOnlySpan<byte> GetTlsClientHelloBytes();
}
or since we probably dont want to keep the data increasing the memory footprint, we can introduce a callback, which will be invoked during SslStream TLS client hello message processing:
+public delegate void TlsHelloMessageCallback(object sender, ReadOnlyMemory<buffer>);
public partial class SslClientAuthenticationOptions
{
+ TlsHelloMessageCallback ClientHelloBytesCallback { get; set; };
+ TlsHelloMessageCallback ServerHelloBytesCallback { get; set; };
}
public partial class SslServerAuthenticationOptions
{
+ TlsHelloMessageCallback ClientHelloBytesCallback { get; set; };
+ TlsHelloMessageCallback ServerHelloBytesCallback { get; set; };
}
API Usage
SslStream sslStream = ...;
var tlsClientHelloBytes = sslStream.GetTlsClientHelloBytes();
in case of callback:
void Configure(SslServerAuthenticationOptions options)
{
options.ClientHelloBytesCallback += bytes => ParseAndValidate(bytes);
}
Risks
there is no risk here - it is just an accessor to underlying data if needed for the user.
API probably will not be used by majority, and it will not be increasing costs of standard use cases, since users will not be passing a callback to invoke.