Commit a4210640 authored by Jehonathan's avatar Jehonathan Committed by GitHub

Merge pull request #160 from justcoding121/develop

Beta release
parents 813fe750 4a235365
...@@ -6,7 +6,7 @@ A light weight http(s) proxy server written in C# ...@@ -6,7 +6,7 @@ A light weight http(s) proxy server written in C#
Kindly report only issues/bugs here . For programming help or questions use [StackOverflow](http://stackoverflow.com/questions/tagged/titanium-web-proxy) with the tag Titanium-Web-Proxy. Kindly report only issues/bugs here . For programming help or questions use [StackOverflow](http://stackoverflow.com/questions/tagged/titanium-web-proxy) with the tag Titanium-Web-Proxy.
![alt tag](https://raw.githubusercontent.com/justcoding121/Titanium-Web-Proxy/release/Examples/Titanium.Web.Proxy.Examples.Basic/Capture.PNG) ![alt tag](https://raw.githubusercontent.com/justcoding121/Titanium-Web-Proxy/develop/Examples/Titanium.Web.Proxy.Examples.Basic/Capture.PNG)
Features Features
======== ========
...@@ -27,11 +27,11 @@ Refer the HTTP Proxy Server library in your project, look up Test project to lea ...@@ -27,11 +27,11 @@ Refer the HTTP Proxy Server library in your project, look up Test project to lea
Install by nuget: Install by nuget:
For beta releases on [release branch](https://github.com/justcoding121/Titanium-Web-Proxy/tree/release) For beta releases on [beta branch](https://github.com/justcoding121/Titanium-Web-Proxy/tree/release)
Install-Package Titanium.Web.Proxy -Pre Install-Package Titanium.Web.Proxy -Pre
For stable releases on [master branch](https://github.com/justcoding121/Titanium-Web-Proxy/tree/master) For stable releases on [stable branch](https://github.com/justcoding121/Titanium-Web-Proxy/tree/master)
Install-Package Titanium.Web.Proxy Install-Package Titanium.Web.Proxy
......
...@@ -15,6 +15,8 @@ using Titanium.Web.Proxy.Shared; ...@@ -15,6 +15,8 @@ using Titanium.Web.Proxy.Shared;
namespace Titanium.Web.Proxy.Helpers namespace Titanium.Web.Proxy.Helpers
{ {
using System.Net;
internal enum IpVersion internal enum IpVersion
{ {
Ipv4 = 1, Ipv4 = 1,
...@@ -143,7 +145,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -143,7 +145,7 @@ namespace Titanium.Web.Proxy.Helpers
string remoteHostName, int remotePort, string httpCmd, Version httpVersion, Dictionary<string, HttpHeader> requestHeaders, string remoteHostName, int remotePort, string httpCmd, Version httpVersion, Dictionary<string, HttpHeader> requestHeaders,
bool isHttps, SslProtocols supportedProtocols, bool isHttps, SslProtocols supportedProtocols,
RemoteCertificateValidationCallback remoteCertificateValidationCallback, LocalCertificateSelectionCallback localCertificateSelectionCallback, RemoteCertificateValidationCallback remoteCertificateValidationCallback, LocalCertificateSelectionCallback localCertificateSelectionCallback,
Stream clientStream, TcpConnectionFactory tcpConnectionFactory) Stream clientStream, TcpConnectionFactory tcpConnectionFactory, IPEndPoint upStreamEndPoint)
{ {
//prepare the prefix content //prepare the prefix content
StringBuilder sb = null; StringBuilder sb = null;
...@@ -173,7 +175,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -173,7 +175,7 @@ namespace Titanium.Web.Proxy.Helpers
remoteHostName, remotePort, remoteHostName, remotePort,
httpVersion, isHttps, httpVersion, isHttps,
supportedProtocols, remoteCertificateValidationCallback, localCertificateSelectionCallback, supportedProtocols, remoteCertificateValidationCallback, localCertificateSelectionCallback,
null, null, clientStream); null, null, clientStream, upStreamEndPoint);
try try
{ {
......
...@@ -91,7 +91,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -91,7 +91,7 @@ namespace Titanium.Web.Proxy.Http
var header = headerItem.Value; var header = headerItem.Value;
if (headerItem.Key != "Proxy-Authorization") if (headerItem.Key != "Proxy-Authorization")
{ {
requestLines.AppendLine(header.Name + ":" + header.Value); requestLines.AppendLine(header.Name + ": " + header.Value);
} }
} }
...@@ -103,7 +103,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -103,7 +103,7 @@ namespace Titanium.Web.Proxy.Http
{ {
if (headerItem.Key != "Proxy-Authorization") if (headerItem.Key != "Proxy-Authorization")
{ {
requestLines.AppendLine(header.Name + ":" + header.Value); requestLines.AppendLine(header.Name + ": " + header.Value);
} }
} }
} }
......
...@@ -12,6 +12,8 @@ using Titanium.Web.Proxy.Shared; ...@@ -12,6 +12,8 @@ using Titanium.Web.Proxy.Shared;
namespace Titanium.Web.Proxy.Network.Tcp namespace Titanium.Web.Proxy.Network.Tcp
{ {
using System.Net;
/// <summary> /// <summary>
/// A class that manages Tcp Connection to server used by this proxy server /// A class that manages Tcp Connection to server used by this proxy server
/// </summary> /// </summary>
...@@ -34,13 +36,14 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -34,13 +36,14 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <param name="externalHttpProxy"></param> /// <param name="externalHttpProxy"></param>
/// <param name="externalHttpsProxy"></param> /// <param name="externalHttpsProxy"></param>
/// <param name="clientStream"></param> /// <param name="clientStream"></param>
/// <param name="upStreamEndPoint"></param>
/// <returns></returns> /// <returns></returns>
internal async Task<TcpConnection> CreateClient(int bufferSize, int connectionTimeOutSeconds, internal async Task<TcpConnection> CreateClient(int bufferSize, int connectionTimeOutSeconds,
string remoteHostName, int remotePort, Version httpVersion, string remoteHostName, int remotePort, Version httpVersion,
bool isHttps, SslProtocols supportedSslProtocols, bool isHttps, SslProtocols supportedSslProtocols,
RemoteCertificateValidationCallback remoteCertificateValidationCallback, LocalCertificateSelectionCallback localCertificateSelectionCallback, RemoteCertificateValidationCallback remoteCertificateValidationCallback, LocalCertificateSelectionCallback localCertificateSelectionCallback,
ExternalProxy externalHttpProxy, ExternalProxy externalHttpsProxy, ExternalProxy externalHttpProxy, ExternalProxy externalHttpsProxy,
Stream clientStream) Stream clientStream, EndPoint upStreamEndPoint)
{ {
TcpClient client; TcpClient client;
Stream stream; Stream stream;
...@@ -52,7 +55,9 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -52,7 +55,9 @@ namespace Titanium.Web.Proxy.Network.Tcp
//If this proxy uses another external proxy then create a tunnel request for HTTPS connections //If this proxy uses another external proxy then create a tunnel request for HTTPS connections
if (externalHttpsProxy != null && externalHttpsProxy.HostName != remoteHostName) if (externalHttpsProxy != null && externalHttpsProxy.HostName != remoteHostName)
{ {
client = new TcpClient(externalHttpsProxy.HostName, externalHttpsProxy.Port); client = new TcpClient();
client.Client.Bind(upStreamEndPoint);
client.Client.Connect(externalHttpsProxy.HostName, externalHttpsProxy.Port);
stream = client.GetStream(); stream = client.GetStream();
using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize, true) { NewLine = ProxyConstants.NewLine }) using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize, true) { NewLine = ProxyConstants.NewLine })
...@@ -76,7 +81,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -76,7 +81,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
var result = await reader.ReadLineAsync(); var result = await reader.ReadLineAsync();
if (!new string[] { "200 OK", "connection established" }.Any(s=> result.ToLower().Contains(s.ToLower()))) if (!new string[] { "200 OK", "connection established" }.Any(s => result.ToLower().Contains(s.ToLower())))
{ {
throw new Exception("Upstream proxy failed to create a secure tunnel"); throw new Exception("Upstream proxy failed to create a secure tunnel");
} }
...@@ -86,7 +91,9 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -86,7 +91,9 @@ namespace Titanium.Web.Proxy.Network.Tcp
} }
else else
{ {
client = new TcpClient(remoteHostName, remotePort); client = new TcpClient();
client.Client.Bind(upStreamEndPoint);
client.Client.Connect(remoteHostName, remotePort);
stream = client.GetStream(); stream = client.GetStream();
} }
...@@ -110,12 +117,16 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -110,12 +117,16 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
if (externalHttpProxy != null && externalHttpProxy.HostName != remoteHostName) if (externalHttpProxy != null && externalHttpProxy.HostName != remoteHostName)
{ {
client = new TcpClient(externalHttpProxy.HostName, externalHttpProxy.Port); client = new TcpClient();
client.Client.Bind(upStreamEndPoint);
client.Client.Connect(externalHttpProxy.HostName, externalHttpProxy.Port);
stream = client.GetStream(); stream = client.GetStream();
} }
else else
{ {
client = new TcpClient(remoteHostName, remotePort); client = new TcpClient();
client.Client.Bind(upStreamEndPoint);
client.Client.Connect(remoteHostName, remotePort);
stream = client.GetStream(); stream = client.GetStream();
} }
} }
...@@ -126,6 +137,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -126,6 +137,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
stream.ReadTimeout = connectionTimeOutSeconds * 1000; stream.ReadTimeout = connectionTimeOutSeconds * 1000;
stream.WriteTimeout = connectionTimeOutSeconds * 1000; stream.WriteTimeout = connectionTimeOutSeconds * 1000;
return new TcpConnection() return new TcpConnection()
{ {
UpStreamHttpProxy = externalHttpProxy, UpStreamHttpProxy = externalHttpProxy,
...@@ -140,4 +152,4 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -140,4 +152,4 @@ namespace Titanium.Web.Proxy.Network.Tcp
}; };
} }
} }
} }
\ No newline at end of file
...@@ -117,6 +117,12 @@ namespace Titanium.Web.Proxy ...@@ -117,6 +117,12 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
public ExternalProxy UpStreamHttpsProxy { get; set; } public ExternalProxy UpStreamHttpsProxy { get; set; }
/// <summary>
/// Local adapter/NIC endpoint (where proxy makes request via)
/// default via any IP addresses of this machine
/// </summary>
public IPEndPoint UpStreamEndPoint { get; set; } = new IPEndPoint(IPAddress.Any, 0);
/// <summary> /// <summary>
/// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication /// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication
/// </summary> /// </summary>
......
...@@ -152,7 +152,7 @@ namespace Titanium.Web.Proxy ...@@ -152,7 +152,7 @@ namespace Titanium.Web.Proxy
false, SupportedSslProtocols, false, SupportedSslProtocols,
new RemoteCertificateValidationCallback(ValidateServerCertificate), new RemoteCertificateValidationCallback(ValidateServerCertificate),
new LocalCertificateSelectionCallback(SelectClientCertificate), new LocalCertificateSelectionCallback(SelectClientCertificate),
clientStream, tcpConnectionFactory); clientStream, tcpConnectionFactory, UpStreamEndPoint);
Dispose(clientStream, clientStreamReader, clientStreamWriter, null); Dispose(clientStream, clientStreamReader, clientStreamWriter, null);
return; return;
...@@ -251,7 +251,7 @@ namespace Titanium.Web.Proxy ...@@ -251,7 +251,7 @@ namespace Titanium.Web.Proxy
args.IsHttps, SupportedSslProtocols, args.IsHttps, SupportedSslProtocols,
new RemoteCertificateValidationCallback(ValidateServerCertificate), new RemoteCertificateValidationCallback(ValidateServerCertificate),
new LocalCertificateSelectionCallback(SelectClientCertificate), new LocalCertificateSelectionCallback(SelectClientCertificate),
customUpStreamHttpProxy ?? UpStreamHttpProxy, customUpStreamHttpsProxy ?? UpStreamHttpsProxy, args.ProxyClient.ClientStream); customUpStreamHttpProxy ?? UpStreamHttpProxy, customUpStreamHttpsProxy ?? UpStreamHttpsProxy, args.ProxyClient.ClientStream, UpStreamEndPoint);
} }
args.WebSession.Request.RequestLocked = true; args.WebSession.Request.RequestLocked = true;
...@@ -487,7 +487,7 @@ namespace Titanium.Web.Proxy ...@@ -487,7 +487,7 @@ namespace Titanium.Web.Proxy
httpCmd, httpVersion, args.WebSession.Request.RequestHeaders, args.IsHttps, httpCmd, httpVersion, args.WebSession.Request.RequestHeaders, args.IsHttps,
SupportedSslProtocols, new RemoteCertificateValidationCallback(ValidateServerCertificate), SupportedSslProtocols, new RemoteCertificateValidationCallback(ValidateServerCertificate),
new LocalCertificateSelectionCallback(SelectClientCertificate), new LocalCertificateSelectionCallback(SelectClientCertificate),
clientStream, tcpConnectionFactory); clientStream, tcpConnectionFactory, UpStreamEndPoint);
Dispose(clientStream, clientStreamReader, clientStreamWriter, args); Dispose(clientStream, clientStreamReader, clientStreamWriter, args);
break; break;
......
...@@ -56,9 +56,9 @@ deploy: ...@@ -56,9 +56,9 @@ deploy:
auth_token: auth_token:
secure: ItVm+50ASpDXx1w+FCe2NTpZxqCbjRWfugLjk/bqBIi00DvPnSGOV1rIQ5hnwBW3 secure: ItVm+50ASpDXx1w+FCe2NTpZxqCbjRWfugLjk/bqBIi00DvPnSGOV1rIQ5hnwBW3
on: on:
branch: /(master|release)/ branch: /(stable|beta)/
- provider: NuGet - provider: NuGet
api_key: api_key:
secure: ZbRmjOcp+TDllRV1wxqLZjdRV7hld388rXlWVJuGGiQleomP9Ku+Nsy3a75E7/9k secure: ZbRmjOcp+TDllRV1wxqLZjdRV7hld388rXlWVJuGGiQleomP9Ku+Nsy3a75E7/9k
on: on:
branch: /(master|release)/ branch: /(stable|beta)/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment