-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
Copy pathProgram.cs
60 lines (49 loc) · 1.9 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.HttpSys;
using Microsoft.Extensions.Hosting;
using TlsFeatureObserve;
using TlsFeaturesObserve.HttpSys;
HttpSysConfigurator.ConfigureCacheTlsClientHello();
CreateHostBuilder(args).Build().Run();
static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHost(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseHttpSys(options =>
{
// If you want to use https locally: https://stackoverflow.com/a/51841893
options.UrlPrefixes.Add("https://*:6000"); // HTTPS
options.Authentication.Schemes = AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
options.TlsClientHelloBytesCallback = ProcessTlsClientHello;
});
});
static void ProcessTlsClientHello(IFeatureCollection features, ReadOnlySpan<byte> tlsClientHelloBytes)
{
var httpConnectionFeature = features.Get<IHttpConnectionFeature>();
var myTlsFeature = new MyTlsFeature(
connectionId: httpConnectionFeature.ConnectionId,
tlsClientHelloLength: tlsClientHelloBytes.Length);
features.Set<IMyTlsFeature>(myTlsFeature);
}
public interface IMyTlsFeature
{
string ConnectionId { get; }
int TlsClientHelloLength { get; }
}
public class MyTlsFeature : IMyTlsFeature
{
public string ConnectionId { get; }
public int TlsClientHelloLength { get; }
public MyTlsFeature(string connectionId, int tlsClientHelloLength)
{
ConnectionId = connectionId;
TlsClientHelloLength = tlsClientHelloLength;
}
}