using FastGithub.ReverseProxy;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using System;
using System.Collections.Concurrent;
using System.Security.Cryptography.X509Certificates;
namespace FastGithub
{
public static class ListenOptionsHttpsExtensions
{
///
/// 应用fastGihub的https
///
///
///
///
///
public static ListenOptions UseGithubHttps(this ListenOptions listenOptions, string caPublicCerPath, string caPrivateKeyPath)
{
return listenOptions.UseHttps(https =>
{
var certs = new ConcurrentDictionary();
https.ServerCertificateSelector = (ctx, domain) =>
certs.GetOrAdd(domain, d =>
CertGenerator.Generate(
new[] { d },
2048,
DateTime.Today.AddYears(-1),
DateTime.Today.AddYears(1),
caPublicCerPath,
caPrivateKeyPath));
});
}
}
}