Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Titanium.Web.Proxy/Helpers/Tcp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ internal static async Task SendRaw(ProxyServer server,
finally
{
tcpConnection.Dispose();
Interlocked.Decrement(ref server.ServerConnectionCountField);
Interlocked.Decrement(ref server.serverConnectionCount);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ internal async Task<TcpConnection> 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;
Expand All @@ -125,7 +126,7 @@ internal async Task<TcpConnection> 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
{
Expand Down
32 changes: 26 additions & 6 deletions Titanium.Web.Proxy/ProxyServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,20 @@ public partial class ProxyServer : IDisposable
/// </summary>
private Action<Exception> exceptionFunc;

/// <summary>
/// Backing field for corresponding public property
/// </summary>
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>
/// A object that creates tcp connection to server
Expand Down Expand Up @@ -127,6 +138,12 @@ public CertificateEngine CertificateEngine
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>
/// Does this proxy uses the HTTP protocol 100 continue behaviour strictly?
/// Broken 100 contunue implementations on server/client may cause problems if enabled
Expand Down Expand Up @@ -231,13 +248,13 @@ public Action<Exception> ExceptionFunc
/// <summary>
/// Total number of active client connections
/// </summary>
public int ClientConnectionCount => clientConnectionCountField;
public int ClientConnectionCount => clientConnectionCount;


/// <summary>
/// Total number of active server connections
/// </summary>
public int ServerConnectionCount => ServerConnectionCountField;
public int ServerConnectionCount => serverConnectionCount;

/// <summary>
/// Constructor
Expand Down Expand Up @@ -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
{
Expand All @@ -612,7 +632,7 @@ private void OnAcceptConnection(IAsyncResult asyn)
}
finally
{
Interlocked.Decrement(ref clientConnectionCountField);
Interlocked.Decrement(ref clientConnectionCount);

try
{
Expand Down
6 changes: 0 additions & 6 deletions Titanium.Web.Proxy/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions Titanium.Web.Proxy/ResponseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private async Task<bool> 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);
Expand Down Expand Up @@ -240,7 +240,7 @@ private void Dispose(Stream clientStream,
if (serverConnection != null)
{
serverConnection.Dispose();
Interlocked.Decrement(ref ServerConnectionCountField);
Interlocked.Decrement(ref serverConnectionCount);
}
}
}
Expand Down