Commit 9142ed3d authored by justcoding121's avatar justcoding121

Fix build failure

parent 7d16af35
...@@ -11,11 +11,11 @@ namespace Titanium.Web.Proxy ...@@ -11,11 +11,11 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Call back to override server certificate validation /// Call back to override server certificate validation
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender">The sender object.</param>
/// <param name="certificate"></param> /// <param name="certificate">The remote certificate.</param>
/// <param name="chain"></param> /// <param name="chain">The certificate chain.</param>
/// <param name="sslPolicyErrors"></param> /// <param name="sslPolicyErrors">Ssl policy errors</param>
/// <returns></returns> /// <returns>Return true if valid certificate.</returns>
internal bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, internal bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors) SslPolicyErrors sslPolicyErrors)
{ {
...@@ -47,11 +47,11 @@ namespace Titanium.Web.Proxy ...@@ -47,11 +47,11 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Call back to select client certificate used for mutual authentication /// Call back to select client certificate used for mutual authentication
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender">The sender.</param>
/// <param name="targetHost"></param> /// <param name="targetHost">The remote hostname.</param>
/// <param name="localCertificates"></param> /// <param name="localCertificates">Selected local certificates by SslStream.</param>
/// <param name="remoteCertificate"></param> /// <param name="remoteCertificate">The remote certificate of server.</param>
/// <param name="acceptableIssuers"></param> /// <param name="acceptableIssuers">The acceptable issues for client certificate as listed by server.</param>
/// <returns></returns> /// <returns></returns>
internal X509Certificate SelectClientCertificate(object sender, string targetHost, internal X509Certificate SelectClientCertificate(object sender, string targetHost,
X509CertificateCollection localCertificates, X509CertificateCollection localCertificates,
......
...@@ -24,9 +24,9 @@ namespace Titanium.Web.Proxy ...@@ -24,9 +24,9 @@ namespace Titanium.Web.Proxy
/// This is called when client is aware of proxy /// This is called when client is aware of proxy
/// So for HTTPS requests client would send CONNECT header to negotiate a secure tcp tunnel via proxy /// So for HTTPS requests client would send CONNECT header to negotiate a secure tcp tunnel via proxy
/// </summary> /// </summary>
/// <param name="endPoint"></param> /// <param name="endPoint">The explicit endpoint.</param>
/// <param name="tcpClient"></param> /// <param name="tcpClient">The client.</param>
/// <returns></returns> /// <returns>The task.</returns>
private async Task HandleClient(ExplicitProxyEndPoint endPoint, TcpClient tcpClient) private async Task HandleClient(ExplicitProxyEndPoint endPoint, TcpClient tcpClient)
{ {
var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenSource = new CancellationTokenSource();
......
using System; using System;
#if NETSTANDARD2_0
using System.Runtime.InteropServices;
#endif
namespace Titanium.Web.Proxy.Helpers namespace Titanium.Web.Proxy.Helpers
{ {
/// <summary> /// <summary>
...@@ -18,9 +21,8 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -18,9 +21,8 @@ namespace Titanium.Web.Proxy.Helpers
/// cache for Windows platform check /// cache for Windows platform check
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private static readonly Lazy<bool> isRunningOnWindows = private static readonly Lazy<bool> isRunningOnWindows
new Lazy<bool>(() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); = new Lazy<bool>(() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
#endif #endif
/// <summary> /// <summary>
......
...@@ -13,8 +13,14 @@ namespace Titanium.Web.Proxy ...@@ -13,8 +13,14 @@ namespace Titanium.Web.Proxy
{ {
public partial class ProxyServer public partial class ProxyServer
{ {
/// <summary>
/// Callback to authorize clients of this proxy instance.
/// </summary>
/// <param name="session">The session event arguments.</param>
/// <returns>True if authorized.</returns>
private async Task<bool> CheckAuthorization(SessionEventArgsBase session) private async Task<bool> CheckAuthorization(SessionEventArgsBase session)
{ {
//If we are not authorizing clients return true
if (AuthenticateUserFunc == null) if (AuthenticateUserFunc == null)
{ {
return true; return true;
...@@ -70,6 +76,11 @@ namespace Titanium.Web.Proxy ...@@ -70,6 +76,11 @@ namespace Titanium.Web.Proxy
} }
} }
/// <summary>
/// Create an authentication required response.
/// </summary>
/// <param name="description">Response description.</param>
/// <returns></returns>
private Response CreateAuthentication407Response(string description) private Response CreateAuthentication407Response(string description)
{ {
var response = new Response var response = new Response
......
...@@ -27,19 +27,22 @@ namespace Titanium.Web.Proxy ...@@ -27,19 +27,22 @@ namespace Titanium.Web.Proxy
EnableWinAuth && RunTime.IsWindows && !RunTime.IsRunningOnMono; EnableWinAuth && RunTime.IsWindows && !RunTime.IsRunningOnMono;
/// <summary> /// <summary>
/// This is the core request handler method for a particular connection from client /// This is the core request handler method for a particular connection from client.
/// Will create new session (request/response) sequence until /// Will create new session (request/response) sequence until
/// client/server abruptly terminates connection or by normal HTTP termination /// client/server abruptly terminates connection or by normal HTTP termination.
/// </summary> /// </summary>
/// <param name="client"></param> /// <param name="endPoint">The proxy endpoint.</param>
/// <param name="clientStream"></param> /// <param name="client">The client.</param>
/// <param name="clientStreamReader"></param> /// <param name="clientStream">The client stream.</param>
/// <param name="clientStreamWriter"></param> /// <param name="clientStreamReader">The client stream reader.</param>
/// <param name="cancellationTokenSource"></param> /// <param name="clientStreamWriter">The client stream writer.</param>
/// <param name="httpsConnectHostname"></param> /// <param name="cancellationTokenSource">The cancellation token source for this async task.</param>
/// <param name="endPoint"></param> /// <param name="httpsConnectHostname">
/// <param name="connectRequest"></param> /// The https hostname as appeared in CONNECT request if this is a HTTPS request from
/// <param name="isTransparentEndPoint"></param> /// explicit endpoint.
/// </param>
/// <param name="connectRequest">The Connect request if this is a HTTPS request from explicit endpoint.</param>
/// <param name="isTransparentEndPoint">Is this a request from transparent endpoint?</param>
/// <returns></returns> /// <returns></returns>
private async Task HandleHttpSessionRequest(ProxyEndPoint endPoint, TcpClient client, private async Task HandleHttpSessionRequest(ProxyEndPoint endPoint, TcpClient client,
CustomBufferedStream clientStream, CustomBinaryReader clientStreamReader, CustomBufferedStream clientStream, CustomBinaryReader clientStreamReader,
...@@ -272,9 +275,9 @@ namespace Titanium.Web.Proxy ...@@ -272,9 +275,9 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Handle a specific session (request/response sequence) /// Handle a specific session (request/response sequence)
/// </summary> /// </summary>
/// <param name="connection"></param> /// <param name="connection">The tcp connection.</param>
/// <param name="args"></param> /// <param name="args">The session event arguments.</param>
/// <returns>True if close the connection</returns> /// <returns></returns>
private async Task HandleHttpSessionRequestInternal(TcpConnection connection, SessionEventArgs args) private async Task HandleHttpSessionRequestInternal(TcpConnection connection, SessionEventArgs args)
{ {
try try
...@@ -355,11 +358,11 @@ namespace Titanium.Web.Proxy ...@@ -355,11 +358,11 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Create a Server Connection /// Create a server connection.
/// </summary> /// </summary>
/// <param name="args"></param> /// <param name="args">The session event arguments.</param>
/// <param name="isConnect"></param> /// <param name="isConnect">Is this a CONNECT request.</param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken">The cancellation token for this async task.</param>
/// <returns></returns> /// <returns></returns>
private async Task<TcpConnection> GetServerConnection(SessionEventArgsBase args, bool isConnect, private async Task<TcpConnection> GetServerConnection(SessionEventArgsBase args, bool isConnect,
CancellationToken cancellationToken) CancellationToken cancellationToken)
...@@ -385,7 +388,7 @@ namespace Titanium.Web.Proxy ...@@ -385,7 +388,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// prepare the request headers so that we can avoid encodings not parsable by this proxy /// Prepare the request headers so that we can avoid encodings not parsable by this proxy
/// </summary> /// </summary>
/// <param name="requestHeaders"></param> /// <param name="requestHeaders"></param>
private void PrepareRequestHeaders(HeaderCollection requestHeaders) private void PrepareRequestHeaders(HeaderCollection requestHeaders)
...@@ -398,6 +401,11 @@ namespace Titanium.Web.Proxy ...@@ -398,6 +401,11 @@ namespace Titanium.Web.Proxy
requestHeaders.FixProxyHeaders(); requestHeaders.FixProxyHeaders();
} }
/// <summary>
/// Invoke before request handler if it is set.
/// </summary>
/// <param name="args">The session event arguments.</param>
/// <returns></returns>
private async Task InvokeBeforeRequest(SessionEventArgs args) private async Task InvokeBeforeRequest(SessionEventArgs args)
{ {
if (BeforeRequest != null) if (BeforeRequest != null)
......
...@@ -9,15 +9,15 @@ using Titanium.Web.Proxy.Network.WinAuth.Security; ...@@ -9,15 +9,15 @@ using Titanium.Web.Proxy.Network.WinAuth.Security;
namespace Titanium.Web.Proxy namespace Titanium.Web.Proxy
{ {
/// <summary> /// <summary>
/// Handle the response from server /// Handle the response from server.
/// </summary> /// </summary>
partial class ProxyServer partial class ProxyServer
{ {
/// <summary> /// <summary>
/// Called asynchronously when a request was successfully and we received the response /// Called asynchronously when a request was successfully and we received the response.
/// </summary> /// </summary>
/// <param name="args"></param> /// <param name="args">The session event arguments.</param>
/// <returns>true if client/server connection was terminated (and disposed) </returns> /// <returns> The task.</returns>
private async Task HandleHttpSessionResponse(SessionEventArgs args) private async Task HandleHttpSessionResponse(SessionEventArgs args)
{ {
try try
...@@ -129,6 +129,11 @@ namespace Titanium.Web.Proxy ...@@ -129,6 +129,11 @@ namespace Titanium.Web.Proxy
} }
} }
/// <summary>
/// Invoke before response if it is set.
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
private async Task InvokeBeforeResponse(SessionEventArgs args) private async Task InvokeBeforeResponse(SessionEventArgs args)
{ {
if (BeforeResponse != null) if (BeforeResponse != null)
...@@ -137,6 +142,11 @@ namespace Titanium.Web.Proxy ...@@ -137,6 +142,11 @@ namespace Titanium.Web.Proxy
} }
} }
/// <summary>
/// Invoke after response if it is set.
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
private async Task InvokeAfterResponse(SessionEventArgs args) private async Task InvokeAfterResponse(SessionEventArgs args)
{ {
if (AfterResponse != null) if (AfterResponse != null)
......
...@@ -17,11 +17,11 @@ namespace Titanium.Web.Proxy ...@@ -17,11 +17,11 @@ namespace Titanium.Web.Proxy
partial class ProxyServer partial class ProxyServer
{ {
/// <summary> /// <summary>
/// This is called when this proxy acts as a reverse proxy (like a real http server) /// This is called when this proxy acts as a reverse proxy (like a real http server).
/// So for HTTPS requests we would start SSL negotiation right away without expecting a CONNECT request from client /// So for HTTPS requests we would start SSL negotiation right away without expecting a CONNECT request from client
/// </summary> /// </summary>
/// <param name="endPoint"></param> /// <param name="endPoint">The transparent endpoint.</param>
/// <param name="tcpClient"></param> /// <param name="tcpClient">The client.</param>
/// <returns></returns> /// <returns></returns>
private async Task HandleClient(TransparentProxyEndPoint endPoint, TcpClient tcpClient) private async Task HandleClient(TransparentProxyEndPoint endPoint, TcpClient tcpClient)
{ {
...@@ -44,8 +44,11 @@ namespace Titanium.Web.Proxy ...@@ -44,8 +44,11 @@ namespace Titanium.Web.Proxy
{ {
httpsHostName = clientHelloInfo.GetServerName() ?? endPoint.GenericCertificateName; httpsHostName = clientHelloInfo.GetServerName() ?? endPoint.GenericCertificateName;
var args = new BeforeSslAuthenticateEventArgs(cancellationTokenSource); var args = new BeforeSslAuthenticateEventArgs(cancellationTokenSource)
args.SniHostName = httpsHostName; {
SniHostName = httpsHostName
};
await endPoint.InvokeBeforeSslAuthenticate(this, args, ExceptionFunc); await endPoint.InvokeBeforeSslAuthenticate(this, args, ExceptionFunc);
if (cancellationTokenSource.IsCancellationRequested) if (cancellationTokenSource.IsCancellationRequested)
......
...@@ -13,7 +13,9 @@ namespace Titanium.Web.Proxy ...@@ -13,7 +13,9 @@ namespace Titanium.Web.Proxy
{ {
public partial class ProxyServer public partial class ProxyServer
{ {
//possible header names /// <summary>
/// possible header names.
/// </summary>
private static readonly HashSet<string> authHeaderNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase) private static readonly HashSet<string> authHeaderNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{ {
"WWW-Authenticate", "WWW-Authenticate",
...@@ -24,6 +26,9 @@ namespace Titanium.Web.Proxy ...@@ -24,6 +26,9 @@ namespace Titanium.Web.Proxy
"KerberosAuthorization" "KerberosAuthorization"
}; };
/// <summary>
/// supported authentication schemes.
/// </summary>
private static readonly HashSet<string> authSchemes = new HashSet<string>(StringComparer.OrdinalIgnoreCase) private static readonly HashSet<string> authSchemes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{ {
"NTLM", "NTLM",
...@@ -32,13 +37,12 @@ namespace Titanium.Web.Proxy ...@@ -32,13 +37,12 @@ namespace Titanium.Web.Proxy
}; };
/// <summary> /// <summary>
/// Handle windows NTLM authentication /// Handle windows NTLM/Kerberos authentication.
/// Can expand this for Kerberos in future
/// Note: NTLM/Kerberos cannot do a man in middle operation /// Note: NTLM/Kerberos cannot do a man in middle operation
/// we do for HTTPS requests. /// we do for HTTPS requests.
/// As such we will be sending local credentials of current /// As such we will be sending local credentials of current
/// User to server to authenticate requests. /// User to server to authenticate requests.
/// To disable this set ProxyServer.EnableWinAuth to false /// To disable this set ProxyServer.EnableWinAuth to false.
/// </summary> /// </summary>
internal async Task Handle401UnAuthorized(SessionEventArgs args) internal async Task Handle401UnAuthorized(SessionEventArgs args)
{ {
......
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