Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
f870fad5
Commit
f870fad5
authored
Apr 14, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
order method signatures for readabilty
parent
59792b59
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
43 additions
and
39 deletions
+43
-39
AsyncEventHandler.cs
Titanium.Web.Proxy/EventArguments/AsyncEventHandler.cs
+1
-2
BeforeSslAuthenticateEventArgs.cs
...eb.Proxy/EventArguments/BeforeSslAuthenticateEventArgs.cs
+1
-1
DataEventArgs.cs
Titanium.Web.Proxy/EventArguments/DataEventArgs.cs
+1
-1
LimitedStream.cs
Titanium.Web.Proxy/EventArguments/LimitedStream.cs
+1
-1
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+6
-4
SessionEventArgsBase.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
+6
-4
TunnelConnectEventArgs.cs
Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
+1
-1
ExplicitClientHandler.cs
Titanium.Web.Proxy/ExplicitClientHandler.cs
+1
-1
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+15
-15
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+8
-7
TransparentClientHandler.cs
Titanium.Web.Proxy/TransparentClientHandler.cs
+2
-2
No files found.
Titanium.Web.Proxy/EventArguments/AsyncEventHandler.cs
View file @
f870fad5
using
System
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
namespace
Titanium.Web.Proxy.EventArguments
namespace
Titanium.Web.Proxy.EventArguments
{
{
...
...
Titanium.Web.Proxy/EventArguments/BeforeSslAuthenticateEventArgs.cs
View file @
f870fad5
...
@@ -9,7 +9,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -9,7 +9,7 @@ namespace Titanium.Web.Proxy.EventArguments
internal
BeforeSslAuthenticateEventArgs
(
CancellationTokenSource
taskCancellationSource
)
internal
BeforeSslAuthenticateEventArgs
(
CancellationTokenSource
taskCancellationSource
)
{
{
this
.
TaskCancellationSource
=
taskCancellationSource
;
TaskCancellationSource
=
taskCancellationSource
;
}
}
public
string
SniHostName
{
get
;
internal
set
;
}
public
string
SniHostName
{
get
;
internal
set
;
}
...
...
Titanium.Web.Proxy/EventArguments/DataEventArgs.cs
View file @
f870fad5
...
@@ -10,7 +10,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -10,7 +10,7 @@ namespace Titanium.Web.Proxy.EventArguments
public
int
Count
{
get
;
}
public
int
Count
{
get
;
}
public
DataEventArgs
(
byte
[]
buffer
,
int
offset
,
int
count
)
internal
DataEventArgs
(
byte
[]
buffer
,
int
offset
,
int
count
)
{
{
Buffer
=
buffer
;
Buffer
=
buffer
;
Offset
=
offset
;
Offset
=
offset
;
...
...
Titanium.Web.Proxy/EventArguments/LimitedStream.cs
View file @
f870fad5
...
@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.EventArguments
private
bool
readChunkTrail
;
private
bool
readChunkTrail
;
private
long
bytesRemaining
;
private
long
bytesRemaining
;
public
LimitedStream
(
CustomBufferedStream
baseStream
,
CustomBinaryReader
baseReader
,
bool
isChunked
,
long
contentLength
)
internal
LimitedStream
(
CustomBufferedStream
baseStream
,
CustomBinaryReader
baseReader
,
bool
isChunked
,
long
contentLength
)
{
{
this
.
baseStream
=
baseStream
;
this
.
baseStream
=
baseStream
;
this
.
baseReader
=
baseReader
;
this
.
baseReader
=
baseReader
;
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
f870fad5
...
@@ -57,13 +57,15 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -57,13 +57,15 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary>
/// <summary>
/// Constructor to initialize the proxy
/// Constructor to initialize the proxy
/// </summary>
/// </summary>
internal
SessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
ExceptionHandler
exceptionFunc
,
CancellationTokenSource
cancellationTokenSource
)
internal
SessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
:
this
(
bufferSize
,
endPoint
,
exceptionFunc
,
null
,
cancellationTokenSource
)
CancellationTokenSource
cancellationTokenSource
,
ExceptionHandler
exceptionFunc
)
:
this
(
bufferSize
,
endPoint
,
cancellationTokenSource
,
null
,
exceptionFunc
)
{
{
}
}
protected
SessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
ExceptionHandler
exceptionFunc
,
Request
request
,
CancellationTokenSource
cancellationTokenSource
)
protected
SessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
:
base
(
bufferSize
,
endPoint
,
exceptionFunc
,
request
,
cancellationTokenSource
)
CancellationTokenSource
cancellationTokenSource
,
Request
request
,
ExceptionHandler
exceptionFunc
)
:
base
(
bufferSize
,
endPoint
,
cancellationTokenSource
,
request
,
exceptionFunc
)
{
{
}
}
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
View file @
f870fad5
...
@@ -70,13 +70,15 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -70,13 +70,15 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary>
/// <summary>
/// Constructor to initialize the proxy
/// Constructor to initialize the proxy
/// </summary>
/// </summary>
internal
SessionEventArgsBase
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
ExceptionHandler
exceptionFunc
,
CancellationTokenSource
cancellationTokenSource
)
internal
SessionEventArgsBase
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
:
this
(
bufferSize
,
endPoint
,
exceptionFunc
,
null
,
cancellationTokenSource
)
CancellationTokenSource
cancellationTokenSource
,
ExceptionHandler
exceptionFunc
)
:
this
(
bufferSize
,
endPoint
,
cancellationTokenSource
,
null
,
exceptionFunc
)
{
{
}
}
protected
SessionEventArgsBase
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
ExceptionHandler
exceptionFunc
,
protected
SessionEventArgsBase
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
Request
request
,
CancellationTokenSource
cancellationTokenSource
)
CancellationTokenSource
cancellationTokenSource
,
Request
request
,
ExceptionHandler
exceptionFunc
)
{
{
this
.
BufferSize
=
bufferSize
;
this
.
BufferSize
=
bufferSize
;
this
.
ExceptionFunc
=
exceptionFunc
;
this
.
ExceptionFunc
=
exceptionFunc
;
...
...
Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
View file @
f870fad5
...
@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.EventArguments
public
bool
IsHttpsConnect
{
get
;
internal
set
;
}
public
bool
IsHttpsConnect
{
get
;
internal
set
;
}
internal
TunnelConnectSessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
ConnectRequest
connectRequest
,
ExceptionHandler
exceptionFunc
,
CancellationTokenSource
cancellationTokenSource
)
internal
TunnelConnectSessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
ConnectRequest
connectRequest
,
ExceptionHandler
exceptionFunc
,
CancellationTokenSource
cancellationTokenSource
)
:
base
(
bufferSize
,
endPoint
,
exceptionFunc
,
connectRequest
,
cancellationTokenSource
)
:
base
(
bufferSize
,
endPoint
,
cancellationTokenSource
,
connectRequest
,
exceptionFunc
)
{
{
}
}
}
}
...
...
Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
f870fad5
...
@@ -200,7 +200,7 @@ namespace Titanium.Web.Proxy
...
@@ -200,7 +200,7 @@ namespace Titanium.Web.Proxy
}
}
//Now create the request
//Now create the request
await
HandleHttpSessionRequest
(
tcpClient
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
connectHostname
,
endPoint
,
connectRequest
,
cancellationTokenSource
);
await
HandleHttpSessionRequest
(
endPoint
,
tcpClient
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
cancellationTokenSource
,
connectHostname
,
connectRequest
);
}
}
catch
(
ProxyHttpException
e
)
catch
(
ProxyHttpException
e
)
{
{
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
f870fad5
...
@@ -21,18 +21,18 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -21,18 +21,18 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <summary>
/// <summary>
/// Creates a TCP connection to server
/// Creates a TCP connection to server
/// </summary>
/// </summary>
/// <param name="server"></param>
/// <param name="remoteHostName"></param>
/// <param name="remoteHostName"></param>
/// <param name="remotePort"></param>
/// <param name="remotePort"></param>
/// <param name="httpVersion"></param>
/// <param name="httpVersion"></param>
/// <param name="isHttps"></param>
/// <param name="isHttps"></param>
/// <param name="isConnect"></param>
/// <param name="isConnect"></param>
/// <param name="proxyServer"></param>
/// <param name="upStreamEndPoint"></param>
/// <param name="upStreamEndPoint"></param>
/// <param name="externalProxy"></param>
/// <param name="externalProxy"></param>
/// <returns></returns>
/// <returns></returns>
internal
async
Task
<
TcpConnection
>
CreateClient
(
ProxyServer
server
,
internal
async
Task
<
TcpConnection
>
CreateClient
(
string
remoteHostName
,
string
remoteHostName
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
bool
isConnect
,
bool
isConnect
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
externalProxy
)
ProxyServer
proxyServer
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
externalProxy
)
{
{
bool
useUpstreamProxy
=
false
;
bool
useUpstreamProxy
=
false
;
...
@@ -65,11 +65,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -65,11 +65,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
await
client
.
ConnectAsync
(
remoteHostName
,
remotePort
);
await
client
.
ConnectAsync
(
remoteHostName
,
remotePort
);
}
}
stream
=
new
CustomBufferedStream
(
client
.
GetStream
(),
s
erver
.
BufferSize
);
stream
=
new
CustomBufferedStream
(
client
.
GetStream
(),
proxyS
erver
.
BufferSize
);
if
(
useUpstreamProxy
&&
(
isConnect
||
isHttps
))
if
(
useUpstreamProxy
&&
(
isConnect
||
isHttps
))
{
{
var
writer
=
new
HttpRequestWriter
(
stream
,
s
erver
.
BufferSize
);
var
writer
=
new
HttpRequestWriter
(
stream
,
proxyS
erver
.
BufferSize
);
await
writer
.
WriteLineAsync
(
$"CONNECT
{
remoteHostName
}
:
{
remotePort
}
HTTP/
{
httpVersion
}
"
);
await
writer
.
WriteLineAsync
(
$"CONNECT
{
remoteHostName
}
:
{
remotePort
}
HTTP/
{
httpVersion
}
"
);
await
writer
.
WriteLineAsync
(
$"Host:
{
remoteHostName
}
:
{
remotePort
}
"
);
await
writer
.
WriteLineAsync
(
$"Host:
{
remoteHostName
}
:
{
remotePort
}
"
);
await
writer
.
WriteLineAsync
(
$"
{
KnownHeaders
.
Connection
}
:
{
KnownHeaders
.
ConnectionKeepAlive
}
"
);
await
writer
.
WriteLineAsync
(
$"
{
KnownHeaders
.
Connection
}
:
{
KnownHeaders
.
ConnectionKeepAlive
}
"
);
...
@@ -84,7 +84,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -84,7 +84,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
await
writer
.
WriteLineAsync
();
await
writer
.
WriteLineAsync
();
using
(
var
reader
=
new
CustomBinaryReader
(
stream
,
s
erver
.
BufferSize
))
using
(
var
reader
=
new
CustomBinaryReader
(
stream
,
proxyS
erver
.
BufferSize
))
{
{
string
httpStatus
=
await
reader
.
ReadLineAsync
();
string
httpStatus
=
await
reader
.
ReadLineAsync
();
...
@@ -102,14 +102,14 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -102,14 +102,14 @@ namespace Titanium.Web.Proxy.Network.Tcp
if
(
isHttps
)
if
(
isHttps
)
{
{
var
sslStream
=
new
SslStream
(
stream
,
false
,
server
.
ValidateServerCertificate
,
s
erver
.
SelectClientCertificate
);
var
sslStream
=
new
SslStream
(
stream
,
false
,
proxyServer
.
ValidateServerCertificate
,
proxyS
erver
.
SelectClientCertificate
);
stream
=
new
CustomBufferedStream
(
sslStream
,
s
erver
.
BufferSize
);
stream
=
new
CustomBufferedStream
(
sslStream
,
proxyS
erver
.
BufferSize
);
await
sslStream
.
AuthenticateAsClientAsync
(
remoteHostName
,
null
,
server
.
SupportedSslProtocols
,
s
erver
.
CheckCertificateRevocation
);
await
sslStream
.
AuthenticateAsClientAsync
(
remoteHostName
,
null
,
proxyServer
.
SupportedSslProtocols
,
proxyS
erver
.
CheckCertificateRevocation
);
}
}
client
.
ReceiveTimeout
=
s
erver
.
ConnectionTimeOutSeconds
*
1000
;
client
.
ReceiveTimeout
=
proxyS
erver
.
ConnectionTimeOutSeconds
*
1000
;
client
.
SendTimeout
=
s
erver
.
ConnectionTimeOutSeconds
*
1000
;
client
.
SendTimeout
=
proxyS
erver
.
ConnectionTimeOutSeconds
*
1000
;
}
}
catch
(
Exception
)
catch
(
Exception
)
{
{
...
@@ -118,7 +118,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -118,7 +118,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
throw
;
throw
;
}
}
return
new
TcpConnection
(
s
erver
)
return
new
TcpConnection
(
proxyS
erver
)
{
{
UpStreamProxy
=
externalProxy
,
UpStreamProxy
=
externalProxy
,
UpStreamEndPoint
=
upStreamEndPoint
,
UpStreamEndPoint
=
upStreamEndPoint
,
...
@@ -127,8 +127,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -127,8 +127,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
IsHttps
=
isHttps
,
IsHttps
=
isHttps
,
UseUpstreamProxy
=
useUpstreamProxy
,
UseUpstreamProxy
=
useUpstreamProxy
,
TcpClient
=
client
,
TcpClient
=
client
,
StreamReader
=
new
CustomBinaryReader
(
stream
,
s
erver
.
BufferSize
),
StreamReader
=
new
CustomBinaryReader
(
stream
,
proxyS
erver
.
BufferSize
),
StreamWriter
=
new
HttpRequestWriter
(
stream
,
s
erver
.
BufferSize
),
StreamWriter
=
new
HttpRequestWriter
(
stream
,
proxyS
erver
.
BufferSize
),
Stream
=
stream
,
Stream
=
stream
,
Version
=
httpVersion
Version
=
httpVersion
};
};
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
f870fad5
...
@@ -33,14 +33,15 @@ namespace Titanium.Web.Proxy
...
@@ -33,14 +33,15 @@ namespace Titanium.Web.Proxy
/// <param name="clientStream"></param>
/// <param name="clientStream"></param>
/// <param name="clientStreamReader"></param>
/// <param name="clientStreamReader"></param>
/// <param name="clientStreamWriter"></param>
/// <param name="clientStreamWriter"></param>
/// <param name="cancellationTokenSource"></param>
/// <param name="httpsConnectHostname"></param>
/// <param name="httpsConnectHostname"></param>
/// <param name="endPoint"></param>
/// <param name="endPoint"></param>
/// <param name="connectRequest"></param>
/// <param name="connectRequest"></param>
/// <param name="isTransparentEndPoint"></param>
/// <param name="isTransparentEndPoint"></param>
/// <returns></returns>
/// <returns></returns>
private
async
Task
HandleHttpSessionRequest
(
TcpClient
client
,
CustomBufferedStream
clientStream
,
private
async
Task
HandleHttpSessionRequest
(
ProxyEndPoint
endPoint
,
TcpClient
client
,
CustomB
inaryReader
clientStreamReader
,
HttpResponseWriter
clientStreamWriter
,
string
httpsConnectHostname
,
CustomB
ufferedStream
clientStream
,
CustomBinaryReader
clientStreamReader
,
HttpResponseWriter
clientStreamWriter
,
ProxyEndPoint
endPoint
,
ConnectRequest
connectRequest
,
CancellationTokenSource
cancellationTokenSource
,
bool
isTransparentEndPoint
=
false
)
CancellationTokenSource
cancellationTokenSource
,
string
httpsConnectHostname
,
ConnectRequest
connectRequest
,
bool
isTransparentEndPoint
=
false
)
{
{
TcpConnection
connection
=
null
;
TcpConnection
connection
=
null
;
...
@@ -57,7 +58,7 @@ namespace Titanium.Web.Proxy
...
@@ -57,7 +58,7 @@ namespace Titanium.Web.Proxy
return
;
return
;
}
}
var
args
=
new
SessionEventArgs
(
BufferSize
,
endPoint
,
ExceptionFunc
,
cancellationTokenSource
)
var
args
=
new
SessionEventArgs
(
BufferSize
,
endPoint
,
cancellationTokenSource
,
ExceptionFunc
)
{
{
ProxyClient
=
{
TcpClient
=
client
},
ProxyClient
=
{
TcpClient
=
client
},
WebSession
=
{
ConnectRequest
=
connectRequest
}
WebSession
=
{
ConnectRequest
=
connectRequest
}
...
@@ -354,11 +355,11 @@ namespace Titanium.Web.Proxy
...
@@ -354,11 +355,11 @@ namespace Titanium.Web.Proxy
args
.
CustomUpStreamProxyUsed
=
customUpStreamProxy
;
args
.
CustomUpStreamProxyUsed
=
customUpStreamProxy
;
return
await
tcpConnectionFactory
.
CreateClient
(
this
,
return
await
tcpConnectionFactory
.
CreateClient
(
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
args
.
WebSession
.
Request
.
RequestUri
.
Port
,
args
.
WebSession
.
Request
.
RequestUri
.
Port
,
args
.
WebSession
.
Request
.
HttpVersion
,
args
.
WebSession
.
Request
.
HttpVersion
,
isHttps
,
isConnect
,
isHttps
,
isConnect
,
this
,
args
.
WebSession
.
UpStreamEndPoint
??
UpStreamEndPoint
,
args
.
WebSession
.
UpStreamEndPoint
??
UpStreamEndPoint
,
customUpStreamProxy
??
(
isHttps
?
UpStreamHttpsProxy
:
UpStreamHttpProxy
));
customUpStreamProxy
??
(
isHttps
?
UpStreamHttpsProxy
:
UpStreamHttpProxy
));
}
}
...
...
Titanium.Web.Proxy/TransparentClientHandler.cs
View file @
f870fad5
...
@@ -122,8 +122,8 @@ namespace Titanium.Web.Proxy
...
@@ -122,8 +122,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
//Now create the request
//Now create the request
await
HandleHttpSessionRequest
(
tcpClient
,
clientStream
,
clientStreamReader
,
clientStreamWrit
er
,
await
HandleHttpSessionRequest
(
endPoint
,
tcpClient
,
clientStream
,
clientStreamRead
er
,
isHttps
?
httpsHostName
:
null
,
endPoint
,
null
,
cancellationTokenSource
,
true
);
clientStreamWriter
,
cancellationTokenSource
,
isHttps
?
httpsHostName
:
null
,
null
,
true
);
}
}
finally
finally
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment