Commit e7093f93 authored by justcoding121's avatar justcoding121

Support terminate session anytime

parent 7eea65ab
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Titanium.Web.Proxy.EventArguments
{
public class BeforeSslAuthenticateEventArgs : EventArgs
{
public string SniHostName { get; internal set; }
public bool DecryptSsl { get; set; } = true;
public bool TerminateSession { get; set; }
}
}
...@@ -69,6 +69,11 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -69,6 +69,11 @@ namespace Titanium.Web.Proxy.EventArguments
public ProxyEndPoint LocalEndPoint { get; } public ProxyEndPoint LocalEndPoint { get; }
/// <summary>
/// Terminates the session abruptly by terminating client/server connections
/// </summary>
public bool TerminateSession { get; set; }
public bool IsTransparent => LocalEndPoint is TransparentProxyEndPoint; public bool IsTransparent => LocalEndPoint is TransparentProxyEndPoint;
public Exception Exception { get; internal set; } public Exception Exception { get; internal set; }
......
using System.Net; using System.Net;
using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Extensions;
namespace Titanium.Web.Proxy.Models namespace Titanium.Web.Proxy.Models
{ {
...@@ -14,6 +17,11 @@ namespace Titanium.Web.Proxy.Models ...@@ -14,6 +17,11 @@ namespace Titanium.Web.Proxy.Models
/// </summary> /// </summary>
public string GenericCertificateName { get; set; } public string GenericCertificateName { get; set; }
/// <summary>
/// Before Ssl authentication
/// </summary>
public event AsyncEventHandler<BeforeSslAuthenticateEventArgs> BeforeSslAuthenticate;
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
...@@ -24,5 +32,13 @@ namespace Titanium.Web.Proxy.Models ...@@ -24,5 +32,13 @@ namespace Titanium.Web.Proxy.Models
{ {
GenericCertificateName = "localhost"; GenericCertificateName = "localhost";
} }
internal async Task InvokeBeforeSslAuthenticate(ProxyServer proxyServer, BeforeSslAuthenticateEventArgs connectArgs, ExceptionHandler exceptionFunc)
{
if (BeforeSslAuthenticate != null)
{
await BeforeSslAuthenticate.InvokeAsync(proxyServer, connectArgs, exceptionFunc);
}
}
} }
} }
\ No newline at end of file
...@@ -164,6 +164,11 @@ namespace Titanium.Web.Proxy ...@@ -164,6 +164,11 @@ namespace Titanium.Web.Proxy
} }
} }
if (connectArgs.TerminateSession)
{
throw new Exception("Session was terminated by user.");
}
//Hostname is excluded or it is not an HTTPS connect //Hostname is excluded or it is not an HTTPS connect
if (!decryptSsl || !isClientHello) if (!decryptSsl || !isClientHello)
{ {
...@@ -256,7 +261,15 @@ namespace Titanium.Web.Proxy ...@@ -256,7 +261,15 @@ namespace Titanium.Web.Proxy
{ {
httpsHostName = clientHelloInfo.GetServerName() ?? endPoint.GenericCertificateName; httpsHostName = clientHelloInfo.GetServerName() ?? endPoint.GenericCertificateName;
if (endPoint.DecryptSsl) var args = new BeforeSslAuthenticateEventArgs();
await endPoint.InvokeBeforeSslAuthenticate(this, args, ExceptionFunc);
if(args.TerminateSession)
{
throw new Exception("Session was terminated by user.");
}
if (endPoint.DecryptSsl && args.DecryptSsl)
{ {
SslStream sslStream = null; SslStream sslStream = null;
...@@ -548,9 +561,15 @@ namespace Titanium.Web.Proxy ...@@ -548,9 +561,15 @@ namespace Titanium.Web.Proxy
} }
finally finally
{ {
if (args.TerminateSession)
{
throw new Exception("Session was terminated by user.");
}
await InvokeAfterResponse(args); await InvokeAfterResponse(args);
args.Dispose(); args.Dispose();
} }
} }
} }
finally finally
......
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