diff --git a/Titanium.Web.Proxy/Helpers/Tcp.cs b/Titanium.Web.Proxy/Helpers/Tcp.cs index 5cac82141..226a26e00 100644 --- a/Titanium.Web.Proxy/Helpers/Tcp.cs +++ b/Titanium.Web.Proxy/Helpers/Tcp.cs @@ -229,7 +229,7 @@ internal static async Task SendRaw(ProxyServer server, finally { tcpConnection.Dispose(); - Interlocked.Decrement(ref server.ServerConnectionCountField); + Interlocked.Decrement(ref server.serverConnectionCount); } } } diff --git a/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs b/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs index 0471f0b73..4567dff61 100644 --- a/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs +++ b/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs @@ -95,12 +95,13 @@ internal async Task CreateClient(ProxyServer server, sslStream = new SslStream(stream, true, server.ValidateServerCertificate, 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); } catch { + sslStream?.Close(); sslStream?.Dispose(); throw; @@ -125,7 +126,7 @@ internal async Task CreateClient(ProxyServer server, client.ReceiveTimeout = server.ConnectionTimeOutSeconds * 1000; client.SendTimeout = server.ConnectionTimeOutSeconds * 1000; - Interlocked.Increment(ref server.ServerConnectionCountField); + Interlocked.Increment(ref server.serverConnectionCount); return new TcpConnection { diff --git a/Titanium.Web.Proxy/ProxyServer.cs b/Titanium.Web.Proxy/ProxyServer.cs index fefd59b4d..a9c3936ad 100644 --- a/Titanium.Web.Proxy/ProxyServer.cs +++ b/Titanium.Web.Proxy/ProxyServer.cs @@ -35,9 +35,20 @@ public partial class ProxyServer : IDisposable /// private Action exceptionFunc; + /// + /// Backing field for corresponding public property + /// private bool trustRootCertificate; - private int clientConnectionCountField; - internal int ServerConnectionCountField; + + /// + /// Backing field for corresponding public property + /// + private int clientConnectionCount; + + /// + /// Backing field for corresponding public property + /// + internal int serverConnectionCount; /// /// A object that creates tcp connection to server @@ -127,6 +138,12 @@ public CertificateEngine CertificateEngine set { CertificateManager.Engine = value; } } + /// + /// Should we check for certificare revocation during SSL authentication to servers + /// Note: If enabled can reduce performance (Default disabled) + /// + public bool CheckCertificateRevocation { get; set; } + /// /// Does this proxy uses the HTTP protocol 100 continue behaviour strictly? /// Broken 100 contunue implementations on server/client may cause problems if enabled @@ -231,13 +248,13 @@ public Action ExceptionFunc /// /// Total number of active client connections /// - public int ClientConnectionCount => clientConnectionCountField; + public int ClientConnectionCount => clientConnectionCount; /// /// Total number of active server connections /// - public int ServerConnectionCount => ServerConnectionCountField; + public int ServerConnectionCount => serverConnectionCount; /// /// Constructor @@ -597,7 +614,10 @@ private void OnAcceptConnection(IAsyncResult asyn) { Task.Run(async () => { - Interlocked.Increment(ref clientConnectionCountField); + Interlocked.Increment(ref clientConnectionCount); + + tcpClient.ReceiveTimeout = ConnectionTimeOutSeconds * 1000; + tcpClient.SendTimeout = ConnectionTimeOutSeconds * 1000; try { @@ -612,7 +632,7 @@ private void OnAcceptConnection(IAsyncResult asyn) } finally { - Interlocked.Decrement(ref clientConnectionCountField); + Interlocked.Decrement(ref clientConnectionCount); try { diff --git a/Titanium.Web.Proxy/RequestHandler.cs b/Titanium.Web.Proxy/RequestHandler.cs index d1a7a28d0..38ee110ed 100644 --- a/Titanium.Web.Proxy/RequestHandler.cs +++ b/Titanium.Web.Proxy/RequestHandler.cs @@ -36,9 +36,6 @@ private async Task HandleClient(ExplicitProxyEndPoint endPoint, TcpClient tcpCli var clientStream = new CustomBufferedStream(tcpClient.GetStream(), BufferSize); - clientStream.ReadTimeout = ConnectionTimeOutSeconds * 1000; - clientStream.WriteTimeout = ConnectionTimeOutSeconds * 1000; - var clientStreamReader = new CustomBinaryReader(clientStream, BufferSize); var clientStreamWriter = new StreamWriter(clientStream) { NewLine = ProxyConstants.NewLine }; @@ -187,9 +184,6 @@ private async Task HandleClient(TransparentProxyEndPoint endPoint, TcpClient tcp bool disposed = false; var clientStream = new CustomBufferedStream(tcpClient.GetStream(), BufferSize); - clientStream.ReadTimeout = ConnectionTimeOutSeconds * 1000; - clientStream.WriteTimeout = ConnectionTimeOutSeconds * 1000; - CustomBinaryReader clientStreamReader = null; StreamWriter clientStreamWriter = null; diff --git a/Titanium.Web.Proxy/ResponseHandler.cs b/Titanium.Web.Proxy/ResponseHandler.cs index 63275e69f..3a25aacb7 100644 --- a/Titanium.Web.Proxy/ResponseHandler.cs +++ b/Titanium.Web.Proxy/ResponseHandler.cs @@ -49,7 +49,7 @@ private async Task HandleHttpSessionResponse(SessionEventArgs args) if (args.WebSession.ServerConnection != null) { args.WebSession.ServerConnection.Dispose(); - Interlocked.Decrement(ref ServerConnectionCountField); + Interlocked.Decrement(ref serverConnectionCount); } var connection = await GetServerConnection(args); @@ -240,7 +240,7 @@ private void Dispose(Stream clientStream, if (serverConnection != null) { serverConnection.Dispose(); - Interlocked.Decrement(ref ServerConnectionCountField); + Interlocked.Decrement(ref serverConnectionCount); } } }