Commit 42e35359 authored by Honfika's avatar Honfika

allow to gt the dectypted data from a tunnel

parent 65357243
...@@ -231,7 +231,6 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -231,7 +231,6 @@ namespace Titanium.Web.Proxy.Examples.Wpf
}; };
//if (isTunnelConnect || e.HttpClient.Request.UpgradeToWebSocket) //if (isTunnelConnect || e.HttpClient.Request.UpgradeToWebSocket)
{
e.DataReceived += (sender, args) => e.DataReceived += (sender, args) =>
{ {
var session = (SessionEventArgsBase)sender; var session = (SessionEventArgsBase)sender;
...@@ -244,6 +243,9 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -244,6 +243,9 @@ namespace Titanium.Web.Proxy.Examples.Wpf
} }
li.ReceivedDataCount += args.Count; li.ReceivedDataCount += args.Count;
AppendTransferLog(session.GetHashCode() + (isTunnelConnect ? "_tunnel" : "") + "_received",
args.Buffer, args.Offset, args.Count);
} }
}; };
...@@ -259,14 +261,41 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -259,14 +261,41 @@ namespace Titanium.Web.Proxy.Examples.Wpf
} }
li.SentDataCount += args.Count; li.SentDataCount += args.Count;
AppendTransferLog(session.GetHashCode() + (isTunnelConnect ? "_tunnel" : "") + "_sent",
args.Buffer, args.Offset, args.Count);
} }
}; };
if (e is TunnelConnectSessionEventArgs te)
{
te.DecryptedDataReceived += (sender, args) =>
{
var session = (SessionEventArgsBase)sender;
AppendTransferLog(session.GetHashCode() + "_decrypted_received", args.Buffer, args.Offset,
args.Count);
};
te.DecryptedDataSent += (sender, args) =>
{
var session = (SessionEventArgsBase)sender;
AppendTransferLog(session.GetHashCode() + "_decrypted_sent", args.Buffer, args.Offset, args.Count);
};
} }
item.Update(); item.Update();
return item; return item;
} }
private void AppendTransferLog(string fileName, byte[] buffer, int offset, int count)
{
//string basePath = @"c:\!titanium\";
//using (var fs = new FileStream(basePath + fileName, FileMode.Append, FileAccess.Write, FileShare.Read))
//{
// fs.Write(buffer, offset, count);
//}
}
private string TunnelTypeToString(TunnelType tunnelType) private string TunnelTypeToString(TunnelType tunnelType)
{ {
switch (tunnelType) switch (tunnelType)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Threading; using System.Threading;
using Titanium.Web.Proxy.Http; using Titanium.Web.Proxy.Http;
using Titanium.Web.Proxy.Models; using Titanium.Web.Proxy.Models;
using Titanium.Web.Proxy.StreamExtended.Network;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
...@@ -40,5 +41,39 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -40,5 +41,39 @@ namespace Titanium.Web.Proxy.EventArguments
internal set => isHttpsConnect = value; internal set => isHttpsConnect = value;
} }
/// <summary>
/// Fired when decrypted data is sent within this session to server/client.
/// </summary>
public event EventHandler<DataEventArgs> DecryptedDataSent;
/// <summary>
/// Fired when decrypted data is received within this session from client/server.
/// </summary>
public event EventHandler<DataEventArgs> DecryptedDataReceived;
internal void OnDecryptedDataSent(byte[] buffer, int offset, int count)
{
try
{
DecryptedDataSent?.Invoke(this, new DataEventArgs(buffer, offset, count));
}
catch (Exception ex)
{
ExceptionFunc(new Exception("Exception thrown in user event", ex));
}
}
internal void OnDecryptedDataReceived(byte[] buffer, int offset, int count)
{
try
{
DecryptedDataReceived?.Invoke(this, new DataEventArgs(buffer, offset, count));
}
catch (Exception ex)
{
ExceptionFunc(new Exception("Exception thrown in user event", ex));
}
}
} }
} }
...@@ -216,6 +216,8 @@ namespace Titanium.Web.Proxy ...@@ -216,6 +216,8 @@ namespace Titanium.Web.Proxy
// HTTPS server created - we can now decrypt the client's traffic // HTTPS server created - we can now decrypt the client's traffic
clientStream = new CustomBufferedStream(sslStream, BufferPool); clientStream = new CustomBufferedStream(sslStream, BufferPool);
clientStream.DataRead += (o, args) => connectArgs.OnDecryptedDataSent(args.Buffer, args.Offset, args.Count);
clientStream.DataWrite += (o, args) => connectArgs.OnDecryptedDataReceived(args.Buffer, args.Offset, args.Count);
clientStreamWriter = new HttpResponseWriter(clientStream, BufferPool); clientStreamWriter = new HttpResponseWriter(clientStream, BufferPool);
} }
catch (Exception e) catch (Exception e)
...@@ -286,7 +288,8 @@ namespace Titanium.Web.Proxy ...@@ -286,7 +288,8 @@ namespace Titanium.Web.Proxy
if (!clientStream.IsClosed && !connection.Stream.IsClosed) if (!clientStream.IsClosed && !connection.Stream.IsClosed)
{ {
await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool, await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool,
null, null, connectArgs.CancellationTokenSource, ExceptionFunc); null, null,
connectArgs.CancellationTokenSource, ExceptionFunc);
} }
} }
finally finally
...@@ -336,8 +339,8 @@ namespace Titanium.Web.Proxy ...@@ -336,8 +339,8 @@ namespace Titanium.Web.Proxy
await connection.StreamWriter.WriteLineAsync(cancellationToken); await connection.StreamWriter.WriteLineAsync(cancellationToken);
#if NETCOREAPP2_1 #if NETCOREAPP2_1
await Http2Helper.SendHttp2(clientStream, connection.Stream, BufferPool.BufferSize, await Http2Helper.SendHttp2(clientStream, connection.Stream, BufferPool.BufferSize,
(buffer, offset, count) => { connectArgs.OnDataSent(buffer, offset, count); }, (buffer, offset, count) => { connectArgs.OnDecryptedDataSent(buffer, offset, count); },
(buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); }, (buffer, offset, count) => { connectArgs.OnDecryptedDataReceived(buffer, offset, count); },
() => new SessionEventArgs(this, endPoint, cancellationTokenSource) () => new SessionEventArgs(this, endPoint, cancellationTokenSource)
{ {
ProxyClient = { Connection = clientConnection }, ProxyClient = { Connection = clientConnection },
......
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