-
Notifications
You must be signed in to change notification settings - Fork 0
/
13_ClientCertificate.cs
42 lines (36 loc) · 1.47 KB
/
13_ClientCertificate.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
using System;
using System.IO;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace ProxyKit.Recipes
{
public class ClientCertificate : Recipe<ClientCertificate.Startup>
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// get your client-certificate from: https://badssl.com/download/
var certBytes = File.ReadAllBytes("./badssl.com-client.p12");
var clientCertificate = new X509Certificate2(certBytes, "badssl.com");
HttpMessageHandler CreatePrimaryHandler()
{
var clientHandler = new HttpClientHandler();
clientHandler.ClientCertificates.Add(clientCertificate);
clientHandler.ClientCertificateOptions = ClientCertificateOption.Manual;
return clientHandler;
}
services.AddProxy(httpClientBuilder => httpClientBuilder.ConfigurePrimaryHttpMessageHandler((Func<HttpMessageHandler>) CreatePrimaryHandler));
}
public void Configure(IApplicationBuilder app)
{
app.RunProxy(context => context
.ForwardTo("https://client.badssl.com/")
.AddXForwardedHeaders()
.Send());
}
}
}
}