Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
setup sample
  • Loading branch information
DeagleGross committed Jun 10, 2025
commit d1315f0dc4f6683e2032ea490de27ccd21f4f9b8
14 changes: 9 additions & 5 deletions src/Servers/HttpSys/samples/TlsFeaturesObserve/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ static IHostBuilder CreateHostBuilder(string[] args) =>
options.Authentication.Schemes = AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;

var property = typeof(HttpSysOptions).GetProperty("TlsClientHelloBytesCallback", BindingFlags.NonPublic | BindingFlags.Instance);
var delegateType = property.PropertyType; // Get the exact delegate type
// If you want to resolve a callback API, uncomment.
// Recommended approach is to use the on-demand API to fetch TLS client hello bytes,
// look into Startup.cs for details.

// Create a delegate of the correct type
var callbackDelegate = Delegate.CreateDelegate(delegateType, typeof(Holder).GetMethod(nameof(Holder.ProcessTlsClientHello), BindingFlags.Static | BindingFlags.Public));
//var property = typeof(HttpSysOptions).GetProperty("TlsClientHelloBytesCallback", BindingFlags.NonPublic | BindingFlags.Instance);
//var delegateType = property.PropertyType; // Get the exact delegate type

property?.SetValue(options, callbackDelegate);
//// Create a delegate of the correct type
//var callbackDelegate = Delegate.CreateDelegate(delegateType, typeof(Holder).GetMethod(nameof(Holder.ProcessTlsClientHello), BindingFlags.Static | BindingFlags.Public));

//property?.SetValue(options, callbackDelegate);
});
});

Expand Down
18 changes: 16 additions & 2 deletions src/Servers/HttpSys/samples/TlsFeaturesObserve/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ public class Startup
{
public void Configure(IApplicationBuilder app)
{
// recommended approach to fetch TLS client hello bytes
// is via on-demand API per request or by building own connection-lifecycle manager
app.Run(async (HttpContext context) =>
{
context.Response.ContentType = "text/plain";

var tlsFeature = context.Features.Get<IMyTlsFeature>();
await context.Response.WriteAsync("TlsClientHello data: " + $"connectionId={tlsFeature?.ConnectionId}; length={tlsFeature?.TlsClientHelloLength}");
var httpSysAssembly = typeof(Microsoft.AspNetCore.Server.HttpSys.HttpSysOptions).Assembly;
var httpSysPropertyFeatureType = httpSysAssembly.GetType("Microsoft.AspNetCore.Server.HttpSys.IHttpSysRequestPropertyFeature");
var httpSysPropertyFeature = context.Features[httpSysPropertyFeatureType]!;

await context.Response.WriteAsync("");
});

// middleware compatible with callback API
//app.Run(async (HttpContext context) =>
//{
// context.Response.ContentType = "text/plain";

// var tlsFeature = context.Features.Get<IMyTlsFeature>();
// await context.Response.WriteAsync("TlsClientHello` data: " + $"connectionId={tlsFeature?.ConnectionId}; length={tlsFeature?.TlsClientHelloLength}");
//});
}
}
4 changes: 3 additions & 1 deletion src/Servers/HttpSys/src/IHttpSysRequestPropertyFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace Microsoft.AspNetCore.Server.HttpSys;
/// <summary>
/// Provides API to read HTTP_REQUEST_PROPERTY value from the HTTP.SYS request.
/// <see href="https://learn.microsoft.com/windows/win32/api/http/ne-http-http_request_property"/>
/// <br/>
/// internal for backport
/// </summary>
public interface IHttpSysRequestPropertyFeature
internal interface IHttpSysRequestPropertyFeature
{
/// <summary>
/// Reads the TLS client hello from HTTP.SYS
Expand Down
Loading