mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-29 07:27:36 +08:00
fixed proxy cert
This commit is contained in:
+3
-2
@@ -46,7 +46,7 @@
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Spacing="15" HorizontalAlignment="Right" VerticalAlignment="Center">
|
||||
<TextBox Watermark="{ReflectionBinding Path=Res.Search,Mode=OneWay,Source={x:Static resx:R.Current}}" Text="{CompiledBinding SearchText,Mode=TwoWay}" VerticalAlignment="Center"
|
||||
<TextBox Watermark="{ReflectionBinding Path=Res.Search,Mode=OneWay,Source={x:Static resx:R.Current}}" Text="{CompiledBinding SearchText,Mode=TwoWay}" VerticalAlignment="Center"
|
||||
Width="300"
|
||||
MinWidth="200">
|
||||
<TextBox.InnerLeftContent>
|
||||
@@ -162,7 +162,8 @@
|
||||
Command="{ReflectionBinding #u.DataContext.DownloadScriptItemButton}"
|
||||
CommandParameter="{Binding}"
|
||||
Content="{Binding NewVersion,StringFormat={}v{0}}"
|
||||
FontSize="{DynamicResource FontSizeH8}"
|
||||
FontSize="{DynamicResource FontSizeH7}"
|
||||
VerticalContentAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource HighlightForegroundBrushKey}"/>
|
||||
<Ellipse VerticalAlignment="Center"
|
||||
|
||||
+10
-2
@@ -612,8 +612,7 @@ namespace System.Application.UI.Resx {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 启动加速服务失败,请检查443端口是否被占用或者证书安装失败。
|
||||
///或者尝试使用Windows代理模式。 的本地化字符串。
|
||||
/// 查找类似 启动加速服务失败,证书安装失败。 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string CommunityFix_StartProxyFaild {
|
||||
get {
|
||||
@@ -621,6 +620,15 @@ namespace System.Application.UI.Resx {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 加速服务启动失败,443端口被占用。请检查您的443端口或者尝试使用Windows代理模式。 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string CommunityFix_StartProxyFaild443 {
|
||||
get {
|
||||
return ResourceManager.GetString("CommunityFix_StartProxyFaild443", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 加速已启动成功 的本地化字符串。
|
||||
/// </summary>
|
||||
|
||||
@@ -304,8 +304,10 @@
|
||||
<value>一键加速</value>
|
||||
</data>
|
||||
<data name="CommunityFix_StartProxyFaild" xml:space="preserve">
|
||||
<value>启动加速服务失败,请检查443端口是否被占用或者证书安装失败。
|
||||
或者尝试使用Windows代理模式。</value>
|
||||
<value>启动加速服务失败,证书安装失败。</value>
|
||||
</data>
|
||||
<data name="CommunityFix_StartProxyFaild443" xml:space="preserve">
|
||||
<value>加速服务启动失败,443端口被占用。请检查您的443端口或者尝试使用Windows代理模式。</value>
|
||||
</data>
|
||||
<data name="CommunityFix_StartProxySuccess" xml:space="preserve">
|
||||
<value>加速已启动成功</value>
|
||||
|
||||
@@ -40,21 +40,24 @@ namespace System.Application.Services.Implementation
|
||||
public int ProxyPort { get; set; } = 26501;
|
||||
|
||||
public bool ProxyRunning => proxyServer.ProxyRunning;
|
||||
public IList<HttpHeader> JsHeader =>new List<HttpHeader>() { new HttpHeader("Content-Type", "text/javascript;charset=UTF-8") };
|
||||
public IList<HttpHeader> JsHeader => new List<HttpHeader>() { new HttpHeader("Content-Type", "text/javascript;charset=UTF-8") };
|
||||
|
||||
public HttpProxyServiceImpl()
|
||||
{
|
||||
//proxyServer.CertificateManager.PfxPassword = $"{CertificateName}";
|
||||
//proxyServer.ThreadPoolWorkerThread = Environment.ProcessorCount * 8;
|
||||
proxyServer.ThreadPoolWorkerThread = Environment.ProcessorCount * 8;
|
||||
proxyServer.CertificateManager.PfxFilePath = Path.Combine(IOPath.AppDataDirectory, $@"{CertificateName}.Certificate.pfx");
|
||||
proxyServer.CertificateManager.RootCertificateIssuerName = $"{CertificateName} Certificate Authority";
|
||||
proxyServer.CertificateManager.RootCertificateName = $"{CertificateName} Certificate";
|
||||
proxyServer.CertificateManager.CertificateValidDays = 300;
|
||||
// 可选地设置证书引擎
|
||||
//proxyServer.CertificateManager.SaveFakeCertificates = true;
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
proxyServer.CertificateManager.CertificateEngine = CertificateEngine.DefaultWindows;
|
||||
else
|
||||
proxyServer.CertificateManager.CertificateEngine = CertificateEngine.BouncyCastle;
|
||||
|
||||
//if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
// proxyServer.CertificateManager.CertificateEngine = CertificateEngine.DefaultWindows;
|
||||
//else
|
||||
proxyServer.EnableConnectionPool = true;
|
||||
proxyServer.CertificateManager.CertificateEngine = CertificateEngine.BouncyCastleFast;
|
||||
}
|
||||
|
||||
public async Task OnRequest(object sender, SessionEventArgs e)
|
||||
@@ -67,8 +70,9 @@ namespace System.Application.Services.Implementation
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (e.HttpClient.Request.Host == "local.steampp.net") {
|
||||
e.Ok(Scripts.FirstOrDefault(x=>x.JsPathUrl == e.HttpClient.Request.RequestUri.LocalPath)?.Content??"404", JsHeader);
|
||||
if (e.HttpClient.Request.Host == "local.steampp.net")
|
||||
{
|
||||
e.Ok(Scripts.FirstOrDefault(x => x.JsPathUrl == e.HttpClient.Request.RequestUri.LocalPath)?.Content ?? "404", JsHeader);
|
||||
return;
|
||||
}
|
||||
foreach (var item in ProxyDomains)
|
||||
@@ -125,22 +129,19 @@ namespace System.Application.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
//await Dns.GetHostAddressesAsync(e.HttpClient.Request.Host).ContinueWith(s =>
|
||||
//{
|
||||
// //部分运营商将奇怪的域名解析到127.0.0.1 再此排除这些不支持的代理域名
|
||||
// if (IPAddress.IsLoopback(s.Result.FirstOrDefault())
|
||||
// && ProxyDomains.Count(w => w.Enable && w.Hosts.Contains(e.HttpClient.Request.Host)) == 0)
|
||||
// {
|
||||
// e.Ok($"IsLoopback URL : {e.HttpClient.Request.RequestUri.AbsoluteUri} \r\n not support proxy");
|
||||
// return;
|
||||
// }
|
||||
// Log.Info("Proxy", "IsLoopback OnRequest: " + e.HttpClient.Request.RequestUri.AbsoluteUri);
|
||||
//});
|
||||
var s = await Dns.GetHostAddressesAsync(e.HttpClient.Request.Host);
|
||||
//部分运营商将奇怪的域名解析到127.0.0.1 再此排除这些不支持的代理域名
|
||||
if (IPAddress.IsLoopback(s.FirstOrDefault()) && ProxyDomains.Count(w => w.Enable && w.Hosts.Contains(e.HttpClient.Request.Host)) == 0)
|
||||
{
|
||||
e.TerminateSession();
|
||||
return;
|
||||
}
|
||||
Log.Info("Proxy", "IsLoopback OnRequest: " + e.HttpClient.Request.RequestUri.AbsoluteUri);
|
||||
|
||||
////没有匹配到的结果直接返回不支持,避免出现Loopback死循环内存溢出
|
||||
//e.Ok($"URL : {e.HttpClient.Request.RequestUri.AbsoluteUri} {Environment.NewLine}not support proxy");
|
||||
return;
|
||||
}
|
||||
////没有匹配到的结果直接返回不支持,避免出现Loopback死循环内存溢出
|
||||
//e.Ok($"URL : {e.HttpClient.Request.RequestUri.AbsoluteUri} {Environment.NewLine}not support proxy");
|
||||
return;
|
||||
}
|
||||
|
||||
public async Task OnResponse(object sender, SessionEventArgs e)
|
||||
{
|
||||
@@ -175,17 +176,17 @@ namespace System.Application.Services.Implementation
|
||||
}
|
||||
foreach (var script in Scripts)
|
||||
{
|
||||
if(script.ExcludeDomainNamesArray!=null)
|
||||
foreach (var host in script.ExcludeDomainNamesArray)
|
||||
{
|
||||
if (e.HttpClient.Request.RequestUri.AbsoluteUri.IsWildcard(host))
|
||||
goto close;
|
||||
}
|
||||
if (script.ExcludeDomainNamesArray != null)
|
||||
foreach (var host in script.ExcludeDomainNamesArray)
|
||||
{
|
||||
if (e.HttpClient.Request.RequestUri.AbsoluteUri.IsWildcard(host))
|
||||
goto close;
|
||||
}
|
||||
foreach (var host in script.MatchDomainNamesArray)
|
||||
{
|
||||
var state = host.IndexOf("/") == 0;
|
||||
if (state)
|
||||
state = Regex.IsMatch(e.HttpClient.Request.RequestUri.AbsoluteUri, host.Substring(1),RegexOptions.Compiled);
|
||||
state = Regex.IsMatch(e.HttpClient.Request.RequestUri.AbsoluteUri, host.Substring(1), RegexOptions.Compiled);
|
||||
else
|
||||
state = e.HttpClient.Request.RequestUri.AbsoluteUri.IsWildcard(host);
|
||||
if (state)
|
||||
@@ -197,7 +198,7 @@ namespace System.Application.Services.Implementation
|
||||
}
|
||||
var doc = await e.GetResponseBodyAsString();
|
||||
var index = doc.LastIndexOf("</body>", StringComparison.OrdinalIgnoreCase);
|
||||
if(index==-1)
|
||||
if (index == -1)
|
||||
index = doc.LastIndexOf("</head>", StringComparison.OrdinalIgnoreCase);
|
||||
if (script.JsPathUrl == null)
|
||||
script.JsPathUrl = $"/{Guid.NewGuid()}";
|
||||
@@ -314,6 +315,7 @@ namespace System.Application.Services.Implementation
|
||||
{
|
||||
if (!IsCertificateInstalled(proxyServer.CertificateManager.RootCertificate))
|
||||
{
|
||||
DeleteCertificate();
|
||||
var isOk = SetupCertificate();
|
||||
if (!isOk)
|
||||
{
|
||||
@@ -442,6 +444,8 @@ namespace System.Application.Services.Implementation
|
||||
{
|
||||
if (certificate2 == null)
|
||||
return false;
|
||||
if (certificate2.NotAfter <= DateTime.Now)
|
||||
return false;
|
||||
using var store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
|
||||
store.Open(OpenFlags.MaxAllowed);
|
||||
return store.Certificates.Contains(certificate2);
|
||||
|
||||
Reference in New Issue
Block a user