Commit 348e1b37 authored by justcoding121's avatar justcoding121

Update documentation

parent fe9de696
...@@ -2,5 +2,12 @@ ...@@ -2,5 +2,12 @@
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary>
/// A generic asynchronous event handler used by this proxy.
/// </summary>
/// <typeparam name="TEventArgs"></typeparam>
/// <param name="sender">The proxy server instance.</param>
/// <param name="e">The event arguments.</param>
/// <returns></returns>
public delegate Task AsyncEventHandler<in TEventArgs>(object sender, TEventArgs e); public delegate Task AsyncEventHandler<in TEventArgs>(object sender, TEventArgs e);
} }
...@@ -3,6 +3,9 @@ using System.Threading; ...@@ -3,6 +3,9 @@ using System.Threading;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary>
/// This is used in transparent endpoint before authenticating client.
/// </summary>
public class BeforeSslAuthenticateEventArgs : EventArgs public class BeforeSslAuthenticateEventArgs : EventArgs
{ {
internal readonly CancellationTokenSource TaskCancellationSource; internal readonly CancellationTokenSource TaskCancellationSource;
...@@ -12,10 +15,21 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -12,10 +15,21 @@ namespace Titanium.Web.Proxy.EventArguments
TaskCancellationSource = taskCancellationSource; TaskCancellationSource = taskCancellationSource;
} }
/// <summary>
/// The server name indication hostname.
/// </summary>
public string SniHostName { get; internal set; } public string SniHostName { get; internal set; }
/// <summary>
/// Should we decrypt the SSL request?
/// If true we decrypt with fake certificate.
/// If false we relay the connection to the hostname mentioned in SniHostname.
/// </summary>
public bool DecryptSsl { get; set; } = true; public bool DecryptSsl { get; set; } = true;
/// <summary>
/// Terminate the request abruptly.
/// </summary>
public void TerminateSession() public void TerminateSession()
{ {
TaskCancellationSource.Cancel(); TaskCancellationSource.Cancel();
......
...@@ -4,37 +4,37 @@ using System.Security.Cryptography.X509Certificates; ...@@ -4,37 +4,37 @@ using System.Security.Cryptography.X509Certificates;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary> /// <summary>
/// An argument passed on to user for client certificate selection during mutual SSL authentication /// An argument passed on to user for client certificate selection during mutual SSL authentication.
/// </summary> /// </summary>
public class CertificateSelectionEventArgs : EventArgs public class CertificateSelectionEventArgs : EventArgs
{ {
/// <summary> /// <summary>
/// Sender object. /// The proxy server instance.
/// </summary> /// </summary>
public object Sender { get; internal set; } public object Sender { get; internal set; }
/// <summary> /// <summary>
/// Target host. /// The host to which we are authenticating against.
/// </summary> /// </summary>
public string TargetHost { get; internal set; } public string TargetHost { get; internal set; }
/// <summary> /// <summary>
/// Local certificates. /// Local certificates with matching issuers.
/// </summary> /// </summary>
public X509CertificateCollection LocalCertificates { get; internal set; } public X509CertificateCollection LocalCertificates { get; internal set; }
/// <summary> /// <summary>
/// Remote certificate. /// Remote certificate of the server.
/// </summary> /// </summary>
public X509Certificate RemoteCertificate { get; internal set; } public X509Certificate RemoteCertificate { get; internal set; }
/// <summary> /// <summary>
/// Acceptable issuers. /// Acceptable issuers mentioned by server.
/// </summary> /// </summary>
public string[] AcceptableIssuers { get; internal set; } public string[] AcceptableIssuers { get; internal set; }
/// <summary> /// <summary>
/// Client Certificate. /// Client Certificate we selected.
/// </summary> /// </summary>
public X509Certificate ClientCertificate { get; set; } public X509Certificate ClientCertificate { get; set; }
} }
......
...@@ -5,17 +5,18 @@ using System.Security.Cryptography.X509Certificates; ...@@ -5,17 +5,18 @@ using System.Security.Cryptography.X509Certificates;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary> /// <summary>
/// An argument passed on to the user for validating the server certificate during SSL authentication /// An argument passed on to the user for validating the server certificate
/// during SSL authentication.
/// </summary> /// </summary>
public class CertificateValidationEventArgs : EventArgs public class CertificateValidationEventArgs : EventArgs
{ {
/// <summary> /// <summary>
/// Certificate /// Server certificate.
/// </summary> /// </summary>
public X509Certificate Certificate { get; internal set; } public X509Certificate Certificate { get; internal set; }
/// <summary> /// <summary>
/// Certificate chain /// Certificate chain.
/// </summary> /// </summary>
public X509Chain Chain { get; internal set; } public X509Chain Chain { get; internal set; }
...@@ -25,7 +26,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -25,7 +26,7 @@ namespace Titanium.Web.Proxy.EventArguments
public SslPolicyErrors SslPolicyErrors { get; internal set; } public SslPolicyErrors SslPolicyErrors { get; internal set; }
/// <summary> /// <summary>
/// is a valid certificate? /// Is the given server certificate is valid?
/// </summary> /// </summary>
public bool IsValid { get; set; } public bool IsValid { get; set; }
} }
......
...@@ -2,6 +2,9 @@ using System; ...@@ -2,6 +2,9 @@ using System;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary>
/// Wraps the data sent/received by a proxy server instance.
/// </summary>
public class DataEventArgs : EventArgs public class DataEventArgs : EventArgs
{ {
internal DataEventArgs(byte[] buffer, int offset, int count) internal DataEventArgs(byte[] buffer, int offset, int count)
...@@ -11,10 +14,19 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -11,10 +14,19 @@ namespace Titanium.Web.Proxy.EventArguments
Count = count; Count = count;
} }
/// <summary>
/// The buffer with data.
/// </summary>
public byte[] Buffer { get; } public byte[] Buffer { get; }
/// <summary>
/// Offset in Buffer where valid data begins.
/// </summary>
public int Offset { get; } public int Offset { get; }
/// <summary>
/// Length from offset in Buffer with valid data.
/// </summary>
public int Count { get; } public int Count { get; }
} }
} }
...@@ -3,6 +3,9 @@ using Titanium.Web.Proxy.Http; ...@@ -3,6 +3,9 @@ using Titanium.Web.Proxy.Http;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary>
/// Class that wraps the multipart sent request arguments.
/// </summary>
public class MultipartRequestPartSentEventArgs : EventArgs public class MultipartRequestPartSentEventArgs : EventArgs
{ {
public MultipartRequestPartSentEventArgs(string boundary, HeaderCollection headers) public MultipartRequestPartSentEventArgs(string boundary, HeaderCollection headers)
...@@ -11,8 +14,14 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -11,8 +14,14 @@ namespace Titanium.Web.Proxy.EventArguments
Headers = headers; Headers = headers;
} }
/// <summary>
/// Boundary
/// </summary>
public string Boundary { get; } public string Boundary { get; }
/// <summary>
/// The header collection.
/// </summary>
public HeaderCollection Headers { get; } public HeaderCollection Headers { get; }
} }
} }
...@@ -15,10 +15,10 @@ using Titanium.Web.Proxy.Models; ...@@ -15,10 +15,10 @@ using Titanium.Web.Proxy.Models;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary> /// <summary>
/// Holds info related to a single proxy session (single request/response sequence) /// Holds info related to a single proxy session (single request/response sequence).
/// A proxy session is bounded to a single connection from client /// A proxy session is bounded to a single connection from client.
/// A proxy session ends when client terminates connection to proxy /// A proxy session ends when client terminates connection to proxy
/// or when server terminates connection from proxy /// or when server terminates connection from proxy.
/// </summary> /// </summary>
public class SessionEventArgs : SessionEventArgsBase public class SessionEventArgs : SessionEventArgsBase
{ {
...@@ -47,7 +47,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -47,7 +47,7 @@ namespace Titanium.Web.Proxy.EventArguments
private bool hasMulipartEventSubscribers => MultipartRequestPartSent != null; private bool hasMulipartEventSubscribers => MultipartRequestPartSent != null;
/// <summary> /// <summary>
/// Should we send the request again /// Should we send the request again ?
/// </summary> /// </summary>
public bool ReRequest public bool ReRequest
{ {
...@@ -346,9 +346,10 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -346,9 +346,10 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Gets the request body as bytes /// Gets the request body as bytes.
/// </summary> /// </summary>
/// <returns></returns> /// <param name="cancellationToken"></param>
/// <returns>The body as bytes.</returns>
public async Task<byte[]> GetRequestBody(CancellationToken cancellationToken = default) public async Task<byte[]> GetRequestBody(CancellationToken cancellationToken = default)
{ {
if (!WebSession.Request.IsBodyRead) if (!WebSession.Request.IsBodyRead)
...@@ -360,9 +361,10 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -360,9 +361,10 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Gets the request body as string /// Gets the request body as string.
/// </summary> /// </summary>
/// <returns></returns> /// <param name="cancellationToken">Cancellation token for this async task is optional.</param>
/// <returns>The body as string.</returns>
public async Task<string> GetRequestBodyAsString(CancellationToken cancellationToken = default) public async Task<string> GetRequestBodyAsString(CancellationToken cancellationToken = default)
{ {
if (!WebSession.Request.IsBodyRead) if (!WebSession.Request.IsBodyRead)
...@@ -374,9 +376,9 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -374,9 +376,9 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Sets the request body /// Sets the request body.
/// </summary> /// </summary>
/// <param name="body"></param> /// <param name="body">The request body bytes.</param>
public void SetRequestBody(byte[] body) public void SetRequestBody(byte[] body)
{ {
var request = WebSession.Request; var request = WebSession.Request;
...@@ -389,9 +391,9 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -389,9 +391,9 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Sets the body with the specified string /// Sets the body with the specified string.
/// </summary> /// </summary>
/// <param name="body"></param> /// <param name="body">The request body string to set.</param>
public void SetRequestBodyString(string body) public void SetRequestBodyString(string body)
{ {
if (WebSession.Request.Locked) if (WebSession.Request.Locked)
...@@ -403,7 +405,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -403,7 +405,7 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Gets the response body as byte array /// Gets the response body as bytes.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task<byte[]> GetResponseBody(CancellationToken cancellationToken = default) public async Task<byte[]> GetResponseBody(CancellationToken cancellationToken = default)
...@@ -417,9 +419,9 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -417,9 +419,9 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Gets the response body as string /// Gets the response body as string.
/// </summary> /// </summary>
/// <returns></returns> /// <returns>The string body.</returns>
public async Task<string> GetResponseBodyAsString(CancellationToken cancellationToken = default) public async Task<string> GetResponseBodyAsString(CancellationToken cancellationToken = default)
{ {
if (!WebSession.Response.IsBodyRead) if (!WebSession.Response.IsBodyRead)
...@@ -431,7 +433,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -431,7 +433,7 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Set the response body bytes /// Set the response body bytes.
/// </summary> /// </summary>
/// <param name="body"></param> /// <param name="body"></param>
public void SetResponseBody(byte[] body) public void SetResponseBody(byte[] body)
...@@ -446,7 +448,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -446,7 +448,7 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Replace the response body with the specified string /// Replace the response body with the specified string.
/// </summary> /// </summary>
/// <param name="body"></param> /// <param name="body"></param>
public void SetResponseBodyString(string body) public void SetResponseBodyString(string body)
...@@ -462,9 +464,8 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -462,9 +464,8 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Before request is made to server /// Before request is made to server respond with the specified HTML string to client
/// Respond with the specified HTML string to client /// and ignore the request.
/// and ignore the request
/// </summary> /// </summary>
/// <param name="html"></param> /// <param name="html"></param>
/// <param name="headers"></param> /// <param name="headers"></param>
...@@ -483,9 +484,8 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -483,9 +484,8 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Before request is made to server /// Before request is made to server respond with the specified byte[] to client
/// Respond with the specified byte[] to client /// and ignore the request.
/// and ignore the request
/// </summary> /// </summary>
/// <param name="result"></param> /// <param name="result"></param>
/// <param name="headers"></param> /// <param name="headers"></param>
...@@ -501,9 +501,8 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -501,9 +501,8 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary> /// <summary>
/// Before request is made to server  /// Before request is made to server 
/// Respond with the specified HTML string to client /// respond with the specified HTML string and the specified status to client.
/// and the specified status /// And then ignore the request. 
/// and ignore the request 
/// </summary> /// </summary>
/// <param name="html"></param> /// <param name="html"></param>
/// <param name="status"></param> /// <param name="status"></param>
...@@ -520,10 +519,8 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -520,10 +519,8 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Before request is made to server /// Before request is made to server respond with the specified byte[],
/// Respond with the specified byte[] to client /// the specified status to client. And then ignore the request.
/// and the specified status
/// and ignore the request
/// </summary> /// </summary>
/// <param name="result"></param> /// <param name="result"></param>
/// <param name="status"></param> /// <param name="status"></param>
...@@ -540,7 +537,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -540,7 +537,7 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Redirect to URL. /// Redirect to provided URL.
/// </summary> /// </summary>
/// <param name="url"></param> /// <param name="url"></param>
/// <returns></returns> /// <returns></returns>
......
...@@ -2,5 +2,9 @@ using System; ...@@ -2,5 +2,9 @@ using System;
namespace Titanium.Web.Proxy namespace Titanium.Web.Proxy
{ {
/// <summary>
/// A delegate to catch exceptions occuring in proxy.
/// </summary>
/// <param name="exception">The exception occurred in proxy.</param>
public delegate void ExceptionHandler(Exception exception); public delegate void ExceptionHandler(Exception exception);
} }
...@@ -19,47 +19,48 @@ using Titanium.Web.Proxy.Network.WinAuth.Security; ...@@ -19,47 +19,48 @@ using Titanium.Web.Proxy.Network.WinAuth.Security;
namespace Titanium.Web.Proxy namespace Titanium.Web.Proxy
{ {
/// <summary> /// <summary>
/// Proxy Server Main class /// This object is the backbone of proxy. One can create as many instances as needed.
/// However care should be taken to avoid using the same listening ports across multiple instances.
/// </summary> /// </summary>
public partial class ProxyServer : IDisposable public partial class ProxyServer : IDisposable
{ {
/// <summary>
/// HTTP & HTTPS scheme shorthands.
/// </summary>
internal static readonly string UriSchemeHttp = Uri.UriSchemeHttp; internal static readonly string UriSchemeHttp = Uri.UriSchemeHttp;
internal static readonly string UriSchemeHttps = Uri.UriSchemeHttps; internal static readonly string UriSchemeHttps = Uri.UriSchemeHttps;
/// <summary> /// <summary>
/// An default exception log func /// A default exception log func.
/// </summary> /// </summary>
private readonly ExceptionHandler defaultExceptionFunc = e => { }; private readonly ExceptionHandler defaultExceptionFunc = e => { };
/// <summary> /// <summary>
/// Backing field for corresponding public property /// Backing field for exposed public property.
/// </summary> /// </summary>
private int clientConnectionCount; private int clientConnectionCount;
/// <summary> /// <summary>
/// backing exception func for exposed public property /// Backing field for exposed public property.
/// </summary> /// </summary>
private ExceptionHandler exceptionFunc; private ExceptionHandler exceptionFunc;
/// <summary> /// <summary>
/// Backing field for corresponding public property /// Backing field for exposed public property.
/// </summary> /// </summary>
private int serverConnectionCount; private int serverConnectionCount;
/// <summary> /// <summary>
/// Manaage upstream proxy detection /// Upstream proxy manager.
/// </summary> /// </summary>
private WinHttpWebProxyFinder systemProxyResolver; private WinHttpWebProxyFinder systemProxyResolver;
/// <summary> /// <summary>
/// Constructor /// Initializes a new instance of ProxyServer class with provided parameters.
/// </summary> /// </summary>
/// <param name="userTrustRootCertificate"></param> /// <param name="userTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's user certificate store?</param>
/// <param name="machineTrustRootCertificate"> /// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param>
/// Note:setting machineTrustRootCertificate to true will force /// <param name="trustRootCertificateAsAdmin">Should we attempt to trust certificates with elevated permissions by prompting for UAC if required?</param>
/// userTrustRootCertificate to true
/// </param>
/// <param name="trustRootCertificateAsAdmin"></param>
public ProxyServer(bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false, public ProxyServer(bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false,
bool trustRootCertificateAsAdmin = false) : this(null, null, userTrustRootCertificate, bool trustRootCertificateAsAdmin = false) : this(null, null, userTrustRootCertificate,
machineTrustRootCertificate, trustRootCertificateAsAdmin) machineTrustRootCertificate, trustRootCertificateAsAdmin)
...@@ -67,16 +68,13 @@ namespace Titanium.Web.Proxy ...@@ -67,16 +68,13 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Constructor. /// Initializes a new instance of ProxyServer class with provided parameters.
/// </summary> /// </summary>
/// <param name="rootCertificateName">Name of root certificate.</param> /// <param name="rootCertificateName">Name of the root certificate.</param>
/// <param name="rootCertificateIssuerName">Name of root certificate issuer.</param> /// <param name="rootCertificateIssuerName">Name of the root certificate issuer.</param>
/// <param name="userTrustRootCertificate"></param> /// <param name="userTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's user certificate store?</param>
/// <param name="machineTrustRootCertificate"> /// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param>
/// Note:setting machineTrustRootCertificate to true will force /// <param name="trustRootCertificateAsAdmin">Should we attempt to trust certificates with elevated permissions by prompting for UAC if required?</param>
/// userTrustRootCertificate to true
/// </param>
/// <param name="trustRootCertificateAsAdmin"></param>
public ProxyServer(string rootCertificateName, string rootCertificateIssuerName, public ProxyServer(string rootCertificateName, string rootCertificateIssuerName,
bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false, bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false,
bool trustRootCertificateAsAdmin = false) bool trustRootCertificateAsAdmin = false)
...@@ -96,17 +94,17 @@ namespace Titanium.Web.Proxy ...@@ -96,17 +94,17 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// A object that creates tcp connection to server /// An object that creates tcp connection to server.
/// </summary> /// </summary>
private TcpConnectionFactory tcpConnectionFactory { get; } private TcpConnectionFactory tcpConnectionFactory { get; }
/// <summary> /// <summary>
/// Manage system proxy settings /// Manage system proxy settings.
/// </summary> /// </summary>
private SystemProxyManager systemProxySettingsManager { get; } private SystemProxyManager systemProxySettingsManager { get; }
/// <summary> /// <summary>
/// Is the proxy currently running /// Is the proxy currently running?
/// </summary> /// </summary>
public bool ProxyRunning { get; private set; } public bool ProxyRunning { get; private set; }
...@@ -118,52 +116,51 @@ namespace Titanium.Web.Proxy ...@@ -118,52 +116,51 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Enable disable Windows Authentication (NTLM/Kerberos) /// Enable disable Windows Authentication (NTLM/Kerberos)
/// Note: NTLM/Kerberos will always send local credentials of current user /// Note: NTLM/Kerberos will always send local credentials of current user
/// who is running the proxy process. This is because a man /// running the proxy process. This is because a man
/// in middle attack is not currently supported /// in middle attack with Windows domain authentication is not currently supported.
/// (which would require windows delegation enabled for this server process)
/// </summary> /// </summary>
public bool EnableWinAuth { get; set; } public bool EnableWinAuth { get; set; }
/// <summary> /// <summary>
/// Should we check for certificare revocation during SSL authentication to servers /// Should we check for certificare revocation during SSL authentication to servers
/// Note: If enabled can reduce performance (Default: NoCheck) /// Note: If enabled can reduce performance. Defaults to false.
/// </summary> /// </summary>
public X509RevocationMode CheckCertificateRevocation { get; set; } public X509RevocationMode CheckCertificateRevocation { get; set; }
/// <summary> /// <summary>
/// Does this proxy uses the HTTP protocol 100 continue behaviour strictly? /// Does this proxy uses the HTTP protocol 100 continue behaviour strictly?
/// Broken 100 contunue implementations on server/client may cause problems if enabled /// Broken 100 contunue implementations on server/client may cause problems if enabled.
/// </summary> /// </summary>
public bool Enable100ContinueBehaviour { get; set; } public bool Enable100ContinueBehaviour { get; set; }
/// <summary> /// <summary>
/// Buffer size used throughout this proxy /// Buffer size used throughout this proxy.
/// </summary> /// </summary>
public int BufferSize { get; set; } = 8192; public int BufferSize { get; set; } = 8192;
/// <summary> /// <summary>
/// Seconds client/server connection are to be kept alive when waiting for read/write to complete /// Seconds client/server connection are to be kept alive when waiting for read/write to complete.
/// </summary> /// </summary>
public int ConnectionTimeOutSeconds { get; set; } public int ConnectionTimeOutSeconds { get; set; }
/// <summary> /// <summary>
/// Total number of active client connections /// Total number of active client connections.
/// </summary> /// </summary>
public int ClientConnectionCount => clientConnectionCount; public int ClientConnectionCount => clientConnectionCount;
/// <summary> /// <summary>
/// Total number of active server connections /// Total number of active server connections.
/// </summary> /// </summary>
public int ServerConnectionCount => serverConnectionCount; public int ServerConnectionCount => serverConnectionCount;
/// <summary> /// <summary>
/// Realm used during Proxy Basic Authentication /// Realm used during Proxy Basic Authentication.
/// </summary> /// </summary>
public string ProxyRealm { get; set; } = "TitaniumProxy"; public string ProxyRealm { get; set; } = "TitaniumProxy";
/// <summary> /// <summary>
/// List of supported Ssl versions /// List of supported Ssl versions.
/// </summary> /// </summary>
public SslProtocols SupportedSslProtocols { get; set; } = public SslProtocols SupportedSslProtocols { get; set; } =
#if NET45 #if NET45
...@@ -173,39 +170,39 @@ namespace Titanium.Web.Proxy ...@@ -173,39 +170,39 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Manages certificates used by this proxy /// Manages certificates used by this proxy.
/// </summary> /// </summary>
public CertificateManager CertificateManager { get; } public CertificateManager CertificateManager { get; }
/// <summary> /// <summary>
/// External proxy for Http /// External proxy used for Http requests.
/// </summary> /// </summary>
public ExternalProxy UpStreamHttpProxy { get; set; } public ExternalProxy UpStreamHttpProxy { get; set; }
/// <summary> /// <summary>
/// External proxy for Http /// External proxy used for Https requests.
/// </summary> /// </summary>
public ExternalProxy UpStreamHttpsProxy { get; set; } public ExternalProxy UpStreamHttpsProxy { get; set; }
/// <summary> /// <summary>
/// Local adapter/NIC endpoint (where proxy makes request via) /// Local adapter/NIC endpoint where proxy makes request via.
/// default via any IP addresses of this machine /// Defaults via any IP addresses of this machine.
/// </summary> /// </summary>
public IPEndPoint UpStreamEndPoint { get; set; } = new IPEndPoint(IPAddress.Any, 0); public IPEndPoint UpStreamEndPoint { get; set; } = new IPEndPoint(IPAddress.Any, 0);
/// <summary> /// <summary>
/// A list of IpAddress and port this proxy is listening to /// A list of IpAddress and port this proxy is listening to.
/// </summary> /// </summary>
public List<ProxyEndPoint> ProxyEndPoints { get; set; } public List<ProxyEndPoint> ProxyEndPoints { get; set; }
/// <summary> /// <summary>
/// A callback to provide authentication credentials for up stream proxy this proxy is using for HTTP(S) requests /// A callback to provide authentication credentials for up stream proxy this proxy is using for HTTP(S) requests.
/// return the ExternalProxy object with valid credentials /// User should return the ExternalProxy object with valid credentials.
/// </summary> /// </summary>
public Func<SessionEventArgsBase, Task<ExternalProxy>> GetCustomUpStreamProxyFunc { get; set; } public Func<SessionEventArgsBase, Task<ExternalProxy>> GetCustomUpStreamProxyFunc { get; set; }
/// <summary> /// <summary>
/// Callback for error events in proxy /// Callback for error events in this proxy instance.
/// </summary> /// </summary>
public ExceptionHandler ExceptionFunc public ExceptionHandler ExceptionFunc
{ {
...@@ -214,9 +211,9 @@ namespace Titanium.Web.Proxy ...@@ -214,9 +211,9 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// A callback to authenticate clients /// A callback to authenticate clients.
/// Parameters are username, password provided by client /// Parameters are username & password as provided by client.
/// return true for successful authentication /// Return true for successful authentication.
/// </summary> /// </summary>
public Func<string, string, Task<bool>> AuthenticateUserFunc { get; set; } public Func<string, string, Task<bool>> AuthenticateUserFunc { get; set; }
...@@ -244,34 +241,34 @@ namespace Titanium.Web.Proxy ...@@ -244,34 +241,34 @@ namespace Titanium.Web.Proxy
public event EventHandler ServerConnectionCountChanged; public event EventHandler ServerConnectionCountChanged;
/// <summary> /// <summary>
/// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication /// Verifies the remote SSL certificate used for authentication.
/// </summary> /// </summary>
public event AsyncEventHandler<CertificateValidationEventArgs> ServerCertificateValidationCallback; public event AsyncEventHandler<CertificateValidationEventArgs> ServerCertificateValidationCallback;
/// <summary> /// <summary>
/// Callback tooverride client certificate during SSL mutual authentication /// Callback to override client certificate selection during mutual SSL authentication.
/// </summary> /// </summary>
public event AsyncEventHandler<CertificateSelectionEventArgs> ClientCertificateSelectionCallback; public event AsyncEventHandler<CertificateSelectionEventArgs> ClientCertificateSelectionCallback;
/// <summary> /// <summary>
/// Intercept request to server /// Intercept request to server.
/// </summary> /// </summary>
public event AsyncEventHandler<SessionEventArgs> BeforeRequest; public event AsyncEventHandler<SessionEventArgs> BeforeRequest;
/// <summary> /// <summary>
/// Intercept response from server /// Intercept response from server.
/// </summary> /// </summary>
public event AsyncEventHandler<SessionEventArgs> BeforeResponse; public event AsyncEventHandler<SessionEventArgs> BeforeResponse;
/// <summary> /// <summary>
/// Intercept after response from server /// Intercept after response from server.
/// </summary> /// </summary>
public event AsyncEventHandler<SessionEventArgs> AfterResponse; public event AsyncEventHandler<SessionEventArgs> AfterResponse;
/// <summary> /// <summary>
/// Add a proxy end point /// Add a proxy end point.
/// </summary> /// </summary>
/// <param name="endPoint"></param> /// <param name="endPoint">The proxy endpoint.</param>
public void AddEndPoint(ProxyEndPoint endPoint) public void AddEndPoint(ProxyEndPoint endPoint)
{ {
if (ProxyEndPoints.Any(x => if (ProxyEndPoints.Any(x =>
...@@ -289,10 +286,10 @@ namespace Titanium.Web.Proxy ...@@ -289,10 +286,10 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Remove a proxy end point /// Remove a proxy end point.
/// Will throw error if the end point does'nt exist /// Will throw error if the end point does'nt exist
/// </summary> /// </summary>
/// <param name="endPoint"></param> /// <param name="endPoint">The existing endpoint to remove.</param>
public void RemoveEndPoint(ProxyEndPoint endPoint) public void RemoveEndPoint(ProxyEndPoint endPoint)
{ {
if (ProxyEndPoints.Contains(endPoint) == false) if (ProxyEndPoints.Contains(endPoint) == false)
...@@ -309,7 +306,7 @@ namespace Titanium.Web.Proxy ...@@ -309,7 +306,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Set the given explicit end point as the default proxy server for current machine /// Set the given explicit end point as the default proxy server for current machine.
/// </summary> /// </summary>
/// <param name="endPoint"></param> /// <param name="endPoint"></param>
public void SetAsSystemHttpProxy(ExplicitProxyEndPoint endPoint) public void SetAsSystemHttpProxy(ExplicitProxyEndPoint endPoint)
...@@ -318,7 +315,7 @@ namespace Titanium.Web.Proxy ...@@ -318,7 +315,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Set the given explicit end point as the default proxy server for current machine /// Set the given explicit end point as the default proxy server for current machine.
/// </summary> /// </summary>
/// <param name="endPoint"></param> /// <param name="endPoint"></param>
public void SetAsSystemHttpsProxy(ExplicitProxyEndPoint endPoint) public void SetAsSystemHttpsProxy(ExplicitProxyEndPoint endPoint)
...@@ -327,7 +324,7 @@ namespace Titanium.Web.Proxy ...@@ -327,7 +324,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Set the given explicit end point as the default proxy server for current machine /// Set the given explicit end point as the default proxy server for current machine.
/// </summary> /// </summary>
/// <param name="endPoint"></param> /// <param name="endPoint"></param>
/// <param name="protocolType"></param> /// <param name="protocolType"></param>
...@@ -406,7 +403,7 @@ namespace Titanium.Web.Proxy ...@@ -406,7 +403,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Remove any HTTP proxy setting of current machien /// Clear HTTP proxy settings of current machine.
/// </summary> /// </summary>
public void DisableSystemHttpProxy() public void DisableSystemHttpProxy()
{ {
...@@ -414,7 +411,7 @@ namespace Titanium.Web.Proxy ...@@ -414,7 +411,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Remove any HTTPS proxy setting for current machine /// Clear HTTPS proxy settings of current machine.
/// </summary> /// </summary>
public void DisableSystemHttpsProxy() public void DisableSystemHttpsProxy()
{ {
...@@ -422,7 +419,7 @@ namespace Titanium.Web.Proxy ...@@ -422,7 +419,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Remove the specified proxy settings for current machine /// Clear the specified proxy setting for current machine.
/// </summary> /// </summary>
public void DisableSystemProxy(ProxyProtocolType protocolType) public void DisableSystemProxy(ProxyProtocolType protocolType)
{ {
...@@ -435,7 +432,7 @@ namespace Titanium.Web.Proxy ...@@ -435,7 +432,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Clear all proxy settings for current machine /// Clear all proxy settings for current machine.
/// </summary> /// </summary>
public void DisableAllSystemProxies() public void DisableAllSystemProxies()
{ {
...@@ -448,7 +445,7 @@ namespace Titanium.Web.Proxy ...@@ -448,7 +445,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Start this proxy server /// Start this proxy server instance.
/// </summary> /// </summary>
public void Start() public void Start()
{ {
...@@ -512,7 +509,7 @@ namespace Titanium.Web.Proxy ...@@ -512,7 +509,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Stop this proxy server /// Stop this proxy server instance.
/// </summary> /// </summary>
public void Stop() public void Stop()
{ {
...@@ -545,9 +542,9 @@ namespace Titanium.Web.Proxy ...@@ -545,9 +542,9 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Listen on the given end point on local machine /// Listen on given end point of local machine.
/// </summary> /// </summary>
/// <param name="endPoint"></param> /// <param name="endPoint">The end point to listen.</param>
private void Listen(ProxyEndPoint endPoint) private void Listen(ProxyEndPoint endPoint)
{ {
endPoint.Listener = new TcpListener(endPoint.IpAddress, endPoint.Port); endPoint.Listener = new TcpListener(endPoint.IpAddress, endPoint.Port);
...@@ -571,9 +568,9 @@ namespace Titanium.Web.Proxy ...@@ -571,9 +568,9 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Verifiy if its safe to set this end point as System proxy /// Verify if its safe to set this end point as system proxy.
/// </summary> /// </summary>
/// <param name="endPoint"></param> /// <param name="endPoint">The end point to validate.</param>
private void ValidateEndPointAsSystemProxy(ExplicitProxyEndPoint endPoint) private void ValidateEndPointAsSystemProxy(ExplicitProxyEndPoint endPoint)
{ {
if (endPoint == null) if (endPoint == null)
...@@ -593,13 +590,8 @@ namespace Titanium.Web.Proxy ...@@ -593,13 +590,8 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Gets the system up stream proxy. /// Gets the system up stream proxy.
/// </summary> /// </summary>
/// <param name="sessionEventArgs">The <see cref="SessionEventArgs" /> instance containing the event data.</param>
/// <returns>
/// <see cref="ExternalProxy" /> instance containing valid proxy configuration from PAC/WAPD scripts if any
/// exists.
/// </returns>
private Task<ExternalProxy> GetSystemUpStreamProxy(SessionEventArgsBase sessionEventArgs) private Task<ExternalProxy> GetSystemUpStreamProxy(SessionEventArgsBase sessionEventArgs)
{ {
var proxy = systemProxyResolver.GetProxy(sessionEventArgs.WebSession.Request.RequestUri); var proxy = systemProxyResolver.GetProxy(sessionEventArgs.WebSession.Request.RequestUri);
...@@ -607,9 +599,8 @@ namespace Titanium.Web.Proxy ...@@ -607,9 +599,8 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// When a connection is received from client act /// Act when a connection is received from client.
/// </summary> /// </summary>
/// <param name="asyn"></param>
private void OnAcceptConnection(IAsyncResult asyn) private void OnAcceptConnection(IAsyncResult asyn)
{ {
var endPoint = (ProxyEndPoint)asyn.AsyncState; var endPoint = (ProxyEndPoint)asyn.AsyncState;
...@@ -668,16 +659,14 @@ namespace Titanium.Web.Proxy ...@@ -668,16 +659,14 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Quit listening on the given end point /// Quit listening on the given end point.
/// </summary> /// </summary>
/// <param name="endPoint"></param>
private void QuitListen(ProxyEndPoint endPoint) private void QuitListen(ProxyEndPoint endPoint)
{ {
endPoint.Listener.Stop(); endPoint.Listener.Stop();
endPoint.Listener.Server.Dispose(); endPoint.Listener.Server.Dispose();
} }
internal void UpdateClientConnectionCount(bool increment) internal void UpdateClientConnectionCount(bool increment)
{ {
if (increment) if (increment)
......
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