Commit 341c29ec authored by Jehonathan Thomas's avatar Jehonathan Thomas Committed by GitHub

Merge pull request #241 from justcoding121/develop

add TLS cert revocation check flag; cleanup
parents 6a66e7b1 83cca8a5
...@@ -229,7 +229,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -229,7 +229,7 @@ namespace Titanium.Web.Proxy.Helpers
finally finally
{ {
tcpConnection.Dispose(); tcpConnection.Dispose();
Interlocked.Decrement(ref server.ServerConnectionCountField); Interlocked.Decrement(ref server.serverConnectionCount);
} }
} }
} }
......
...@@ -95,12 +95,13 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -95,12 +95,13 @@ namespace Titanium.Web.Proxy.Network.Tcp
sslStream = new SslStream(stream, true, server.ValidateServerCertificate, sslStream = new SslStream(stream, true, server.ValidateServerCertificate,
server.SelectClientCertificate); server.SelectClientCertificate);
await sslStream.AuthenticateAsClientAsync(remoteHostName, null, server.SupportedSslProtocols, false); await sslStream.AuthenticateAsClientAsync(remoteHostName, null, server.SupportedSslProtocols, server.CheckCertificateRevocation);
stream = new CustomBufferedStream(sslStream, server.BufferSize); stream = new CustomBufferedStream(sslStream, server.BufferSize);
} }
catch catch
{ {
sslStream?.Close();
sslStream?.Dispose(); sslStream?.Dispose();
throw; throw;
...@@ -125,7 +126,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -125,7 +126,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
client.ReceiveTimeout = server.ConnectionTimeOutSeconds * 1000; client.ReceiveTimeout = server.ConnectionTimeOutSeconds * 1000;
client.SendTimeout = server.ConnectionTimeOutSeconds * 1000; client.SendTimeout = server.ConnectionTimeOutSeconds * 1000;
Interlocked.Increment(ref server.ServerConnectionCountField); Interlocked.Increment(ref server.serverConnectionCount);
return new TcpConnection return new TcpConnection
{ {
......
...@@ -35,9 +35,20 @@ namespace Titanium.Web.Proxy ...@@ -35,9 +35,20 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
private Action<Exception> exceptionFunc; private Action<Exception> exceptionFunc;
/// <summary>
/// Backing field for corresponding public property
/// </summary>
private bool trustRootCertificate; private bool trustRootCertificate;
private int clientConnectionCountField;
internal int ServerConnectionCountField; /// <summary>
/// Backing field for corresponding public property
/// </summary>
private int clientConnectionCount;
/// <summary>
/// Backing field for corresponding public property
/// </summary>
internal int serverConnectionCount;
/// <summary> /// <summary>
/// A object that creates tcp connection to server /// A object that creates tcp connection to server
...@@ -127,6 +138,12 @@ namespace Titanium.Web.Proxy ...@@ -127,6 +138,12 @@ namespace Titanium.Web.Proxy
set { CertificateManager.Engine = value; } set { CertificateManager.Engine = value; }
} }
/// <summary>
/// Should we check for certificare revocation during SSL authentication to servers
/// Note: If enabled can reduce performance (Default disabled)
/// </summary>
public bool 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
...@@ -231,13 +248,13 @@ namespace Titanium.Web.Proxy ...@@ -231,13 +248,13 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Total number of active client connections /// Total number of active client connections
/// </summary> /// </summary>
public int ClientConnectionCount => clientConnectionCountField; public int ClientConnectionCount => clientConnectionCount;
/// <summary> /// <summary>
/// Total number of active server connections /// Total number of active server connections
/// </summary> /// </summary>
public int ServerConnectionCount => ServerConnectionCountField; public int ServerConnectionCount => serverConnectionCount;
/// <summary> /// <summary>
/// Constructor /// Constructor
...@@ -597,7 +614,10 @@ namespace Titanium.Web.Proxy ...@@ -597,7 +614,10 @@ namespace Titanium.Web.Proxy
{ {
Task.Run(async () => Task.Run(async () =>
{ {
Interlocked.Increment(ref clientConnectionCountField); Interlocked.Increment(ref clientConnectionCount);
tcpClient.ReceiveTimeout = ConnectionTimeOutSeconds * 1000;
tcpClient.SendTimeout = ConnectionTimeOutSeconds * 1000;
try try
{ {
...@@ -612,7 +632,7 @@ namespace Titanium.Web.Proxy ...@@ -612,7 +632,7 @@ namespace Titanium.Web.Proxy
} }
finally finally
{ {
Interlocked.Decrement(ref clientConnectionCountField); Interlocked.Decrement(ref clientConnectionCount);
try try
{ {
......
...@@ -36,9 +36,6 @@ namespace Titanium.Web.Proxy ...@@ -36,9 +36,6 @@ namespace Titanium.Web.Proxy
var clientStream = new CustomBufferedStream(tcpClient.GetStream(), BufferSize); var clientStream = new CustomBufferedStream(tcpClient.GetStream(), BufferSize);
clientStream.ReadTimeout = ConnectionTimeOutSeconds * 1000;
clientStream.WriteTimeout = ConnectionTimeOutSeconds * 1000;
var clientStreamReader = new CustomBinaryReader(clientStream, BufferSize); var clientStreamReader = new CustomBinaryReader(clientStream, BufferSize);
var clientStreamWriter = new StreamWriter(clientStream) { NewLine = ProxyConstants.NewLine }; var clientStreamWriter = new StreamWriter(clientStream) { NewLine = ProxyConstants.NewLine };
...@@ -187,9 +184,6 @@ namespace Titanium.Web.Proxy ...@@ -187,9 +184,6 @@ namespace Titanium.Web.Proxy
bool disposed = false; bool disposed = false;
var clientStream = new CustomBufferedStream(tcpClient.GetStream(), BufferSize); var clientStream = new CustomBufferedStream(tcpClient.GetStream(), BufferSize);
clientStream.ReadTimeout = ConnectionTimeOutSeconds * 1000;
clientStream.WriteTimeout = ConnectionTimeOutSeconds * 1000;
CustomBinaryReader clientStreamReader = null; CustomBinaryReader clientStreamReader = null;
StreamWriter clientStreamWriter = null; StreamWriter clientStreamWriter = null;
......
...@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy ...@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy
if (args.WebSession.ServerConnection != null) if (args.WebSession.ServerConnection != null)
{ {
args.WebSession.ServerConnection.Dispose(); args.WebSession.ServerConnection.Dispose();
Interlocked.Decrement(ref ServerConnectionCountField); Interlocked.Decrement(ref serverConnectionCount);
} }
var connection = await GetServerConnection(args); var connection = await GetServerConnection(args);
...@@ -240,7 +240,7 @@ namespace Titanium.Web.Proxy ...@@ -240,7 +240,7 @@ namespace Titanium.Web.Proxy
if (serverConnection != null) if (serverConnection != null)
{ {
serverConnection.Dispose(); serverConnection.Dispose();
Interlocked.Decrement(ref ServerConnectionCountField); Interlocked.Decrement(ref serverConnectionCount);
} }
} }
} }
......
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