Skip to content

Commit

Permalink
增加80端口反代,以便自动跳转http访问到https请求上
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Jan 12, 2021
1 parent fc285cf commit bd7f9e7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packaging/package.net472.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
$result = 'Steam++'
$bin = '..\source\SteamTools\bin\x86\Release\'
# '*.exe.config'
$targetKeywords = '*.exe','*.dll','*.txt','*.VisualElementsManifest.xml','*.pak','*.bin','*.js'
$targetKeywords = '*.exe','*.dll','*.txt','*.VisualElementsManifest.xml','*.pak','*.bin','*.js','Log4net.config'
$ignoreKeywords = '*.vshost.*','Microsoft.*.resources.dll','ExPlugin.*.dll'

$exeSource = '\Steam++.exe'
Expand Down
25 changes: 18 additions & 7 deletions source/SteamTool.Proxy/HttpProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task OnRequest(object sender, SessionEventArgs e)
#endregion
Debug.WriteLine("OnRequest " + e.HttpClient.Request.RequestUri.AbsoluteUri);
Debug.WriteLine("OnRequest HTTP " + e.HttpClient.Request.HttpVersion);
Logger.Info("OnRequest" + e.HttpClient.Request.RequestUri.AbsoluteUri);
//Logger.Info("OnRequest" + e.HttpClient.Request.RequestUri.AbsoluteUri);
#endif
// Dns.GetHostAddressesAsync(e.HttpClient.Request.Host).ContinueWith(s =>
//{
Expand All @@ -87,6 +87,7 @@ public async Task OnRequest(object sender, SessionEventArgs e)
// return;
// }
//});
//Logger.Info("Steam++ OnRequest: " + e.HttpClient.Request.RequestUri.AbsoluteUri);
foreach (var item in ProxyDomains)
{
if (!item.IsEnable)
Expand All @@ -97,6 +98,10 @@ public async Task OnRequest(object sender, SessionEventArgs e)
{
if (e.HttpClient.Request.RequestUri.AbsoluteUri.Contains(host))
{
if (e.HttpClient.Request.RequestUri.Scheme == "http")
{
e.Redirect(e.HttpClient.Request.RequestUri.AbsoluteUri.Remove(0, 4).Insert(0, "https"));
}
IPAddress iP = null;
if (!string.IsNullOrEmpty(item.ProxyIPAddres))
{
Expand All @@ -106,13 +111,15 @@ public async Task OnRequest(object sender, SessionEventArgs e)
{
var iPs = await Dns.GetHostAddressesAsync(item.ToDomain);
iP = iPs.FirstOrDefault();
//Logger.Info("Proxy IP: " + iP);
}
if (iP != null)
{
e.HttpClient.UpStreamEndPoint = new IPEndPoint(IPAddress.Parse(iP.ToString()), item.Port);
}
if (e.HttpClient.ConnectRequest?.ClientHelloInfo != null)
{
//Logger.Info("ClientHelloInfo Info: " + e.HttpClient.ConnectRequest.ClientHelloInfo);
if (!string.IsNullOrEmpty(item.ServerName))
{
var sni = e.HttpClient.ConnectRequest.ClientHelloInfo.Extensions["server_name"];
Expand Down Expand Up @@ -255,11 +262,11 @@ public bool SetupCertificate()
//proxyServer.CertificateManager.CertificateEngine = Network.CertificateEngine.BouncyCastle;
//proxyServer.CertificateManager.SaveFakeCertificates = true;
var result = proxyServer.CertificateManager.CreateRootCertificate(true);
if (result)
{
proxyServer.CertificateManager.EnsureRootCertificate();
proxyServer.CertificateManager.RootCertificate.SaveCerCertificateFile(Path.Combine(AppContext.BaseDirectory, $@"{CertificateName}.Certificate.cer"));
}
//if (result)
//{
proxyServer.CertificateManager.EnsureRootCertificate();
proxyServer.CertificateManager.RootCertificate.SaveCerCertificateFile(Path.Combine(AppContext.BaseDirectory, $@"{CertificateName}.Certificate.cer"));
//}
return IsCertificateInstalled(proxyServer.CertificateManager.RootCertificate);
}

Expand Down Expand Up @@ -373,7 +380,11 @@ public bool StartProxy(bool IsProxyGOG = false)
//GenericCertificate = proxyServer.CertificateManager.RootCertificate
};
proxyServer.AddEndPoint(transparentEndPoint);

var transparentEndPoint80 = new TransparentProxyEndPoint(IPAddress.Any, 80, true)
{
//GenericCertificate = proxyServer.CertificateManager.RootCertificate
};
proxyServer.AddEndPoint(transparentEndPoint80);
proxyServer.ExceptionFunc = ((Exception exception) =>
{
Logger.Error(exception);
Expand Down
4 changes: 2 additions & 2 deletions source/SteamTools/Services/ProxyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public void Initialize()
new ProxyDomainModel{
Name=Resources.SteamImage,
Domains = new List<string>{"steamcdn-a.akamaihd.net" },
//ToDomain = "cdn.akamai.steamstatic.com",
ToDomain = "media.steampowered.com",
ToDomain = "cdn.akamai.steamstatic.com",
//ToDomain = "media.steampowered.com",
Hosts = new List<string>{ "steamcdn-a.akamaihd.net"},
DomainTag = DomainTag.SteamImage,
IsEnable= false,
Expand Down
2 changes: 1 addition & 1 deletion source/SteamTools/SteamTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<PackageId />

<Version>1.0.5</Version>
<Version>1.0.6</Version>

<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>
Expand Down

0 comments on commit bd7f9e7

Please sign in to comment.