Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #722 from justcoding121/master
Browse files Browse the repository at this point in the history
beta
  • Loading branch information
honfika authored Dec 27, 2019
2 parents 500cead + 6db82ba commit 6149ed6
Show file tree
Hide file tree
Showing 18 changed files with 341 additions and 68 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Kindly report only issues/bugs here. For programming help or questions use [Stac
* View/modify/redirect/block requests and responses
* Supports mutual SSL authentication, proxy authentication & automatic upstream proxy detection
* Kerberos/NTLM authentication over HTTP protocols for windows domain
* SOCKS4/5 Proxy support

### Installation
Install by [nuget](https://www.nuget.org/packages/Titanium.Web.Proxy)
Expand All @@ -29,21 +30,21 @@ For stable releases on [stable branch](https://github.com/justcoding121/Titanium

Supports

* .Net Standard 2.0 or above
* .Net Framework 4.6.1 or above
* .NET Standard 2.0 or above
* .NET Framework 4.5 or above

### Development environment

#### Windows
* Visual Studio Code as IDE for .NET core
* Visual Studio 2017/2019 as IDE for .NET framework/.NET core
* Visual Studio Code as IDE for .NET Core
* Visual Studio 2019 as IDE for .NET Framework/.NET Core

#### Mac OS
* Visual Studio Code as IDE for .NET core
* Visual Studio 2017 as IDE for Mono
* Visual Studio Code as IDE for .NET Core
* Visual Studio 2019 as IDE for Mono

#### Linux
* Visual Studio Code as IDE for .NET core
* Visual Studio Code as IDE for .NET Core
* Mono develop as IDE for Mono

### Usage
Expand Down Expand Up @@ -191,7 +192,7 @@ public async Task OnResponse(object sender, SessionEventArgs e)
{
if (e.HttpClient.Response.ResponseStatusCode == "200")
{
if (e.HttpClient.Response.ContentType!=null && e.HttpClient.Response.ContentType.Trim().ToLower().Contains("text/html"))
if (e.HttpClient.Response.ContentType != null && e.HttpClient.Response.ContentType.Trim().ToLower().Contains("text/html"))
{
byte[] bodyBytes = await e.GetResponseBody();
await e.SetResponseBody(bodyBytes);
Expand All @@ -202,7 +203,7 @@ public async Task OnResponse(object sender, SessionEventArgs e)
}
}

if (e.UserData!=null)
if (e.UserData != null)
{
// access request from UserData property where we stored it in RequestHandler
var request = (Request)e.UserData;
Expand All @@ -216,14 +217,14 @@ public Task OnCertificateValidation(object sender, CertificateValidationEventArg
if (e.SslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
e.IsValid = true;

return Task.FromResult(0);
return Task.CompletedTask;
}

// Allows overriding default client certificate selection logic during mutual authentication
public Task OnCertificateSelection(object sender, CertificateSelectionEventArgs e)
{
// set e.clientCertificate to override
return Task.FromResult(0);
return Task.CompletedTask;
}
```
### Note to contributors
Expand Down
4 changes: 4 additions & 0 deletions docs/api/Titanium.Web.Proxy.Network.CertificateEngine.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ <h3 id="fields">Fields
Default.</p>
</td>
</tr>
<tr>
<td id="Titanium_Web_Proxy_Network_CertificateEngine_BouncyCastleFast">BouncyCastleFast</td>
<td></td>
</tr>
<tr>
<td id="Titanium_Web_Proxy_Network_CertificateEngine_DefaultWindows">DefaultWindows</td>
<td><p>Uses Windows Certification Generation API and only valid in Windows OS.
Expand Down
52 changes: 26 additions & 26 deletions docs/api/Titanium.Web.Proxy.Network.CertificateManager.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
"api/Titanium.Web.Proxy.Network.CertificateEngine.html": {
"href": "api/Titanium.Web.Proxy.Network.CertificateEngine.html",
"title": "Enum CertificateEngine | Titanium Web Proxy",
"keywords": "Enum CertificateEngine Certificate Engine option. Namespace : Titanium.Web.Proxy.Network Assembly : Titanium.Web.Proxy.dll Syntax public enum CertificateEngine Fields Name Description BouncyCastle Uses BouncyCastle 3rd party library. Default. DefaultWindows Uses Windows Certification Generation API and only valid in Windows OS. Observed to be faster than BouncyCastle. Bug #468 Reported."
"keywords": "Enum CertificateEngine Certificate Engine option. Namespace : Titanium.Web.Proxy.Network Assembly : Titanium.Web.Proxy.dll Syntax public enum CertificateEngine Fields Name Description BouncyCastle Uses BouncyCastle 3rd party library. Default. BouncyCastleFast DefaultWindows Uses Windows Certification Generation API and only valid in Windows OS. Observed to be faster than BouncyCastle. Bug #468 Reported."
},
"api/Titanium.Web.Proxy.Network.CertificateManager.html": {
"href": "api/Titanium.Web.Proxy.Network.CertificateManager.html",
Expand Down
6 changes: 6 additions & 0 deletions docs/xrefmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2913,6 +2913,12 @@ references:
commentId: F:Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastle
fullName: Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastle
nameWithType: CertificateEngine.BouncyCastle
- uid: Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastleFast
name: BouncyCastleFast
href: api/Titanium.Web.Proxy.Network.CertificateEngine.html#Titanium_Web_Proxy_Network_CertificateEngine_BouncyCastleFast
commentId: F:Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastleFast
fullName: Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastleFast
nameWithType: CertificateEngine.BouncyCastleFast
- uid: Titanium.Web.Proxy.Network.CertificateEngine.DefaultWindows
name: DefaultWindows
href: api/Titanium.Web.Proxy.Network.CertificateEngine.html#Titanium_Web_Proxy_Network_CertificateEngine_DefaultWindows
Expand Down
23 changes: 18 additions & 5 deletions examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public ProxyTestController()
};
proxyServer.ForwardToUpstreamGateway = true;
proxyServer.CertificateManager.SaveFakeCertificates = true;
//proxyServer.ProxyBasicAuthenticateFunc = async (args, userName, password) =>
//{
// return true;
//};

// this is just to show the functionality, provided implementations use junk value
//proxyServer.GetCustomUpStreamProxyFunc = onGetCustomUpStreamProxyFunc;
Expand Down Expand Up @@ -94,8 +98,11 @@ public void StartProxy()
//proxyServer.UpStreamHttpsProxy = new ExternalProxy("localhost", 8888);

// SOCKS proxy
//proxyServer.UpStreamHttpProxy = new ExternalProxy("46.63.0.17", 4145) { ProxyType = ExternalProxyType.Socks4 };
//proxyServer.UpStreamHttpsProxy = new ExternalProxy("46.63.0.17", 4145) { ProxyType = ExternalProxyType.Socks4 };
//proxyServer.UpStreamHttpProxy = new ExternalProxy("127.0.0.1", 1080)
// { ProxyType = ExternalProxyType.Socks5, UserName = "User1", Password = "Pass" };
//proxyServer.UpStreamHttpsProxy = new ExternalProxy("127.0.0.1", 1080)
// { ProxyType = ExternalProxyType.Socks5, UserName = "User1", Password = "Pass" };


//var socksEndPoint = new SocksProxyEndPoint(IPAddress.Any, 1080, true)
//{
Expand Down Expand Up @@ -167,6 +174,12 @@ private async Task onBeforeTunnelConnectRequest(object sender, TunnelConnectSess
e.GetState().PipelineInfo.AppendLine(nameof(onBeforeTunnelConnectRequest) + ":" + hostname);
await writeToConsole("Tunnel to: " + hostname);

var clientLocalIp = e.ClientLocalEndPoint.Address;
if (!clientLocalIp.Equals(IPAddress.Loopback) && !clientLocalIp.Equals(IPAddress.IPv6Loopback))
{
e.HttpClient.UpStreamEndPoint = new IPEndPoint(clientLocalIp, 0);
}

if (hostname.Contains("dropbox.com"))
{
// Exclude Https addresses you don't want to proxy
Expand Down Expand Up @@ -212,7 +225,7 @@ private Task onBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEv
{
e.GetState().PipelineInfo.AppendLine(nameof(onBeforeTunnelConnectResponse) + ":" + e.HttpClient.Request.RequestUri);

return Task.FromResult(false);
return Task.CompletedTask;
}

// intercept & cancel redirect or update requests
Expand Down Expand Up @@ -356,7 +369,7 @@ public Task OnCertificateValidation(object sender, CertificateValidationEventArg
e.IsValid = true;
}

return Task.FromResult(0);
return Task.CompletedTask;
}

/// <summary>
Expand All @@ -370,7 +383,7 @@ public Task OnCertificateSelection(object sender, CertificateSelectionEventArgs

// set e.clientCertificate to override

return Task.FromResult(0);
return Task.CompletedTask;
}

private async Task writeToConsole(string message, ConsoleColor? consoleColor = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override void OnStart(string[] args)
{
// we do all this in here so we can reload settings with a simple restart

_proxyServerInstance = new ProxyServer();
_proxyServerInstance = new ProxyServer(false);

if (Properties.Settings.Default.ListeningPort <= 0 ||
Properties.Settings.Default.ListeningPort > 65535)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private protected SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoin
{
BufferPool = server.BufferPool;
ExceptionFunc = server.ExceptionFunc;
TimeLine["Session Created"] = DateTime.Now;
TimeLine["Session Created"] = DateTime.UtcNow;

CancellationTokenSource = cancellationTokenSource;

Expand Down
2 changes: 1 addition & 1 deletion src/Titanium.Web.Proxy/Http/HttpWebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal TcpServerConnection Connection
/// <param name="serverConnection">Instance of <see cref="TcpServerConnection" /></param>
internal void SetConnection(TcpServerConnection serverConnection)
{
serverConnection.LastAccess = DateTime.Now;
serverConnection.LastAccess = DateTime.UtcNow;
connection = serverConnection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ internal BCCertificateMaker(ExceptionHandler exceptionFunc)
/// Makes the certificate.
/// </summary>
/// <param name="sSubjectCn">The s subject cn.</param>
/// <param name="isRoot">if set to <c>true</c> [is root].</param>
/// <param name="signingCert">The signing cert.</param>
/// <returns>X509Certificate2 instance.</returns>
public X509Certificate2 MakeCertificate(string sSubjectCn, X509Certificate2? signingCert = null)
Expand Down
Loading

0 comments on commit 6149ed6

Please sign in to comment.