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

Commit 6149ed6

Browse files
authored
Merge pull request #722 from justcoding121/master
beta
2 parents 500cead + 6db82ba commit 6149ed6

File tree

18 files changed

+341
-68
lines changed

18 files changed

+341
-68
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Kindly report only issues/bugs here. For programming help or questions use [Stac
1515
* View/modify/redirect/block requests and responses
1616
* Supports mutual SSL authentication, proxy authentication & automatic upstream proxy detection
1717
* Kerberos/NTLM authentication over HTTP protocols for windows domain
18+
* SOCKS4/5 Proxy support
1819

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

3031
Supports
3132

32-
* .Net Standard 2.0 or above
33-
* .Net Framework 4.6.1 or above
33+
* .NET Standard 2.0 or above
34+
* .NET Framework 4.5 or above
3435

3536
### Development environment
3637

3738
#### Windows
38-
* Visual Studio Code as IDE for .NET core
39-
* Visual Studio 2017/2019 as IDE for .NET framework/.NET core
39+
* Visual Studio Code as IDE for .NET Core
40+
* Visual Studio 2019 as IDE for .NET Framework/.NET Core
4041

4142
#### Mac OS
42-
* Visual Studio Code as IDE for .NET core
43-
* Visual Studio 2017 as IDE for Mono
43+
* Visual Studio Code as IDE for .NET Core
44+
* Visual Studio 2019 as IDE for Mono
4445

4546
#### Linux
46-
* Visual Studio Code as IDE for .NET core
47+
* Visual Studio Code as IDE for .NET Core
4748
* Mono develop as IDE for Mono
4849

4950
### Usage
@@ -191,7 +192,7 @@ public async Task OnResponse(object sender, SessionEventArgs e)
191192
{
192193
if (e.HttpClient.Response.ResponseStatusCode == "200")
193194
{
194-
if (e.HttpClient.Response.ContentType!=null && e.HttpClient.Response.ContentType.Trim().ToLower().Contains("text/html"))
195+
if (e.HttpClient.Response.ContentType != null && e.HttpClient.Response.ContentType.Trim().ToLower().Contains("text/html"))
195196
{
196197
byte[] bodyBytes = await e.GetResponseBody();
197198
await e.SetResponseBody(bodyBytes);
@@ -202,7 +203,7 @@ public async Task OnResponse(object sender, SessionEventArgs e)
202203
}
203204
}
204205

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

219-
return Task.FromResult(0);
220+
return Task.CompletedTask;
220221
}
221222

222223
// Allows overriding default client certificate selection logic during mutual authentication
223224
public Task OnCertificateSelection(object sender, CertificateSelectionEventArgs e)
224225
{
225226
// set e.clientCertificate to override
226-
return Task.FromResult(0);
227+
return Task.CompletedTask;
227228
}
228229
```
229230
### Note to contributors

docs/api/Titanium.Web.Proxy.Network.CertificateEngine.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ <h3 id="fields">Fields
108108
Default.</p>
109109
</td>
110110
</tr>
111+
<tr>
112+
<td id="Titanium_Web_Proxy_Network_CertificateEngine_BouncyCastleFast">BouncyCastleFast</td>
113+
<td></td>
114+
</tr>
111115
<tr>
112116
<td id="Titanium_Web_Proxy_Network_CertificateEngine_DefaultWindows">DefaultWindows</td>
113117
<td><p>Uses Windows Certification Generation API and only valid in Windows OS.

docs/api/Titanium.Web.Proxy.Network.CertificateManager.html

Lines changed: 26 additions & 26 deletions
Large diffs are not rendered by default.

docs/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
"api/Titanium.Web.Proxy.Network.CertificateEngine.html": {
243243
"href": "api/Titanium.Web.Proxy.Network.CertificateEngine.html",
244244
"title": "Enum CertificateEngine | Titanium Web Proxy",
245-
"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."
245+
"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."
246246
},
247247
"api/Titanium.Web.Proxy.Network.CertificateManager.html": {
248248
"href": "api/Titanium.Web.Proxy.Network.CertificateManager.html",

docs/xrefmap.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,6 +2913,12 @@ references:
29132913
commentId: F:Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastle
29142914
fullName: Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastle
29152915
nameWithType: CertificateEngine.BouncyCastle
2916+
- uid: Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastleFast
2917+
name: BouncyCastleFast
2918+
href: api/Titanium.Web.Proxy.Network.CertificateEngine.html#Titanium_Web_Proxy_Network_CertificateEngine_BouncyCastleFast
2919+
commentId: F:Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastleFast
2920+
fullName: Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastleFast
2921+
nameWithType: CertificateEngine.BouncyCastleFast
29162922
- uid: Titanium.Web.Proxy.Network.CertificateEngine.DefaultWindows
29172923
name: DefaultWindows
29182924
href: api/Titanium.Web.Proxy.Network.CertificateEngine.html#Titanium_Web_Proxy_Network_CertificateEngine_DefaultWindows

examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public ProxyTestController()
4444
};
4545
proxyServer.ForwardToUpstreamGateway = true;
4646
proxyServer.CertificateManager.SaveFakeCertificates = true;
47+
//proxyServer.ProxyBasicAuthenticateFunc = async (args, userName, password) =>
48+
//{
49+
// return true;
50+
//};
4751

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

96100
// SOCKS proxy
97-
//proxyServer.UpStreamHttpProxy = new ExternalProxy("46.63.0.17", 4145) { ProxyType = ExternalProxyType.Socks4 };
98-
//proxyServer.UpStreamHttpsProxy = new ExternalProxy("46.63.0.17", 4145) { ProxyType = ExternalProxyType.Socks4 };
101+
//proxyServer.UpStreamHttpProxy = new ExternalProxy("127.0.0.1", 1080)
102+
// { ProxyType = ExternalProxyType.Socks5, UserName = "User1", Password = "Pass" };
103+
//proxyServer.UpStreamHttpsProxy = new ExternalProxy("127.0.0.1", 1080)
104+
// { ProxyType = ExternalProxyType.Socks5, UserName = "User1", Password = "Pass" };
105+
99106

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

177+
var clientLocalIp = e.ClientLocalEndPoint.Address;
178+
if (!clientLocalIp.Equals(IPAddress.Loopback) && !clientLocalIp.Equals(IPAddress.IPv6Loopback))
179+
{
180+
e.HttpClient.UpStreamEndPoint = new IPEndPoint(clientLocalIp, 0);
181+
}
182+
170183
if (hostname.Contains("dropbox.com"))
171184
{
172185
// Exclude Https addresses you don't want to proxy
@@ -212,7 +225,7 @@ private Task onBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEv
212225
{
213226
e.GetState().PipelineInfo.AppendLine(nameof(onBeforeTunnelConnectResponse) + ":" + e.HttpClient.Request.RequestUri);
214227

215-
return Task.FromResult(false);
228+
return Task.CompletedTask;
216229
}
217230

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

359-
return Task.FromResult(0);
372+
return Task.CompletedTask;
360373
}
361374

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

371384
// set e.clientCertificate to override
372385

373-
return Task.FromResult(0);
386+
return Task.CompletedTask;
374387
}
375388

376389
private async Task writeToConsole(string message, ConsoleColor? consoleColor = null)

examples/Titanium.Web.Proxy.Examples.WindowsService/ProxyService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected override void OnStart(string[] args)
2121
{
2222
// we do all this in here so we can reload settings with a simple restart
2323

24-
_proxyServerInstance = new ProxyServer();
24+
_proxyServerInstance = new ProxyServer(false);
2525

2626
if (Properties.Settings.Default.ListeningPort <= 0 ||
2727
Properties.Settings.Default.ListeningPort > 65535)

src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private protected SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoin
5353
{
5454
BufferPool = server.BufferPool;
5555
ExceptionFunc = server.ExceptionFunc;
56-
TimeLine["Session Created"] = DateTime.Now;
56+
TimeLine["Session Created"] = DateTime.UtcNow;
5757

5858
CancellationTokenSource = cancellationTokenSource;
5959

src/Titanium.Web.Proxy/Http/HttpWebClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ internal TcpServerConnection Connection
9292
/// <param name="serverConnection">Instance of <see cref="TcpServerConnection" /></param>
9393
internal void SetConnection(TcpServerConnection serverConnection)
9494
{
95-
serverConnection.LastAccess = DateTime.Now;
95+
serverConnection.LastAccess = DateTime.UtcNow;
9696
connection = serverConnection;
9797
}
9898

src/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ internal BCCertificateMaker(ExceptionHandler exceptionFunc)
4444
/// Makes the certificate.
4545
/// </summary>
4646
/// <param name="sSubjectCn">The s subject cn.</param>
47-
/// <param name="isRoot">if set to <c>true</c> [is root].</param>
4847
/// <param name="signingCert">The signing cert.</param>
4948
/// <returns>X509Certificate2 instance.</returns>
5049
public X509Certificate2 MakeCertificate(string sSubjectCn, X509Certificate2? signingCert = null)

0 commit comments

Comments
 (0)