From f508c531edf79bed6769d47aa81ea7dc0dde8de7 Mon Sep 17 00:00:00 2001
From: xljiulang <366193849@qq.com>
Date: Tue, 13 Jul 2021 22:37:34 +0800
Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=89=E8=A3=85=E6=A0=B9=E8=AF=81?=
=?UTF-8?q?=E4=B9=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ListenOptionsHttpsExtensions.cs | 23 +++++++++++++++++++
FastGithub/FastGithub.csproj | 9 ++++----
FastGithub/Program.cs | 2 +-
FastGithub/README.MD | 4 ++++
4 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/FastGithub.ReverseProxy/ListenOptionsHttpsExtensions.cs b/FastGithub.ReverseProxy/ListenOptionsHttpsExtensions.cs
index 39cfd8f..e1dd115 100644
--- a/FastGithub.ReverseProxy/ListenOptionsHttpsExtensions.cs
+++ b/FastGithub.ReverseProxy/ListenOptionsHttpsExtensions.cs
@@ -1,6 +1,8 @@
using FastGithub.ReverseProxy;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
using System.Security.Cryptography.X509Certificates;
@@ -21,6 +23,27 @@ namespace FastGithub
///
public static ListenOptions UseGithubHttps(this ListenOptions listenOptions, string caPublicCerPath, string caPrivateKeyPath)
{
+ if (OperatingSystem.IsWindows())
+ {
+ try
+ {
+ var caCert = new X509Certificate2(caPublicCerPath);
+ using var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
+ store.Open(OpenFlags.ReadWrite);
+ if (store.Certificates.Find(X509FindType.FindByThumbprint, caCert.Thumbprint, true).Count == 0)
+ {
+ store.Add(caCert);
+ store.Close();
+ }
+ }
+ catch (Exception ex)
+ {
+ var loggerFactory = listenOptions.ApplicationServices.GetRequiredService();
+ var logger = loggerFactory.CreateLogger($"{nameof(FastGithub)}{nameof(ReverseProxy)}");
+ logger.LogError($"安装根证书{caPublicCerPath}失败:{ex.Message}");
+ }
+ }
+
return listenOptions.UseHttps(https =>
{
var certs = new ConcurrentDictionary();
diff --git a/FastGithub/FastGithub.csproj b/FastGithub/FastGithub.csproj
index 3594d20..5ba4faf 100644
--- a/FastGithub/FastGithub.csproj
+++ b/FastGithub/FastGithub.csproj
@@ -5,6 +5,7 @@
net5.0;net6.0
MIT
app.ico
+ true
@@ -25,19 +26,19 @@
- PreserveNewest
+ PreserveNewest
- PreserveNewest
+ PreserveNewest
PreserveNewest
- PreserveNewest
+ PreserveNewest
- PreserveNewest
+ PreserveNewest
PreserveNewest
diff --git a/FastGithub/Program.cs b/FastGithub/Program.cs
index 44e844a..3d5197b 100644
--- a/FastGithub/Program.cs
+++ b/FastGithub/Program.cs
@@ -49,7 +49,7 @@ namespace FastGithub
});
web.UseKestrel(kestrel =>
- {
+ {
kestrel.ListenAnyIP(443, listen => listen.UseGithubHttps("FastGithub_CA.cer", "FastGithub_CA.key"));
});
});
diff --git a/FastGithub/README.MD b/FastGithub/README.MD
index 05fbef7..29a7938 100644
--- a/FastGithub/README.MD
+++ b/FastGithub/README.MD
@@ -1,6 +1,10 @@
# FastGithub
github定制版的dns服务,解析github最优的ip
+### 安装根证书
+默认开启github反向代理功能,开启之后dns返回github的ip指向FastGithub自身。
+需要在浏览器所在的设备安装FastGithub_CA.cer到`将所有的证书都放入下载存储\受信任的根证书颁发机构`
+
### 本机使用
* 运行FastGithub程序,本机的网络适配器的dns会自动变成127.0.0.1
* 如果网络适配器的dns没有变成127.0.0.1,请手工修改网络适配器的dns