Commit 92fa402d authored by justcoding121's avatar justcoding121

move sslstream dispose to end to be safe

parent 0f910b1a
......@@ -41,11 +41,13 @@ namespace Titanium.Web.Proxy
bool closeServerConnection = false;
bool calledRequestHandler = false;
SslStream sslStream = null;
try
{
string connectHostname = null;
TunnelConnectSessionEventArgs connectArgs = null;
// Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
if (await HttpHelper.IsConnectMethod(clientStream) == 1)
......@@ -150,8 +152,6 @@ namespace Titanium.Web.Proxy
await tcpConnectionFactory.Release(connection, true);
}
SslStream sslStream = null;
if (EnableTcpServerConnectionPrefetch)
{
//don't pass cancellation token here
......@@ -201,10 +201,6 @@ namespace Titanium.Web.Proxy
throw new ProxyConnectException(
$"Couldn't authenticate host '{connectHostname}' with certificate '{certname}'.", e, connectArgs);
}
finally
{
sslStream?.Dispose();
}
if (await HttpHelper.IsConnectMethod(clientStream) == -1)
{
......@@ -354,6 +350,7 @@ namespace Titanium.Web.Proxy
await tcpConnectionFactory.Release(prefetchConnectionTask, closeServerConnection);
}
sslStream?.Dispose();
clientStream.Dispose();
if (!cancellationTokenSource.IsCancellationRequested)
......
......@@ -35,6 +35,8 @@ namespace Titanium.Web.Proxy
var clientStream = new CustomBufferedStream(clientConnection.GetStream(), BufferPool, BufferSize);
var clientStreamWriter = new HttpResponseWriter(clientStream, BufferPool, BufferSize);
SslStream sslStream = null;
try
{
var clientHelloInfo = await SslTools.PeekClientHello(clientStream, BufferPool, cancellationToken);
......@@ -61,8 +63,6 @@ namespace Titanium.Web.Proxy
if (endPoint.DecryptSsl && args.DecryptSsl)
{
SslStream sslStream = null;
//do client authentication using certificate
X509Certificate2 certificate = null;
try
......@@ -92,10 +92,7 @@ namespace Titanium.Web.Proxy
throw new ProxyConnectException(
$"Couldn't authenticate host '{httpsHostName}' with certificate '{certname}'.", e, session);
}
finally
{
sslStream?.Dispose();
}
}
else
{
......@@ -161,8 +158,9 @@ namespace Titanium.Web.Proxy
}
finally
{
sslStream?.Dispose();
clientStream.Dispose();
if (!cancellationTokenSource.IsCancellationRequested)
{
cancellationTokenSource.Cancel();
......
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