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
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 Exception Exception { get; internal set; }
......
using System.Net;
using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Extensions;
namespace Titanium.Web.Proxy.Models
{
......@@ -14,6 +17,11 @@ namespace Titanium.Web.Proxy.Models
/// </summary>
public string GenericCertificateName { get; set; }
/// <summary>
/// Before Ssl authentication
/// </summary>
public event AsyncEventHandler<BeforeSslAuthenticateEventArgs> BeforeSslAuthenticate;
/// <summary>
/// Constructor.
/// </summary>
......@@ -24,5 +32,13 @@ namespace Titanium.Web.Proxy.Models
{
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
}
}
if (connectArgs.TerminateSession)
{
throw new Exception("Session was terminated by user.");
}
//Hostname is excluded or it is not an HTTPS connect
if (!decryptSsl || !isClientHello)
{
......@@ -256,7 +261,15 @@ namespace Titanium.Web.Proxy
{
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;
......@@ -548,9 +561,15 @@ namespace Titanium.Web.Proxy
}
finally
{
if (args.TerminateSession)
{
throw new Exception("Session was terminated by user.");
}
await InvokeAfterResponse(args);
args.Dispose();
}
}
}
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