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
6e5e683e
Commit
6e5e683e
authored
Mar 13, 2018
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the Excluded property to the TunnelConnectRequest event
parent
80b8cc37
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
158 additions
and
25 deletions
+158
-25
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+5
-15
TunnelConnectEventArgs.cs
Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
+3
-1
ExplicitProxyEndPoint.cs
Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs
+65
-0
ProxyEndPoint.cs
Titanium.Web.Proxy/Models/ProxyEndPoint.cs
+54
-0
TransparentProxyEndPoint.cs
Titanium.Web.Proxy/Models/TransparentProxyEndPoint.cs
+28
-0
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+3
-9
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
6e5e683e
...
...
@@ -69,9 +69,6 @@ namespace Titanium.Web.Proxy.Examples.Basic
};
//Fired when a CONNECT request is received
explicitEndPoint
.
BeforeTunnelConnect
+=
OnBeforeTunnelConnect
;
explicitEndPoint
.
TunnelConnectRequest
+=
OnTunnelConnectRequest
;
explicitEndPoint
.
TunnelConnectResponse
+=
OnTunnelConnectResponse
;
...
...
@@ -111,7 +108,6 @@ namespace Titanium.Web.Proxy.Examples.Basic
public
void
Stop
()
{
explicitEndPoint
.
BeforeTunnelConnect
-=
OnBeforeTunnelConnect
;
explicitEndPoint
.
TunnelConnectRequest
-=
OnTunnelConnectRequest
;
explicitEndPoint
.
TunnelConnectResponse
-=
OnTunnelConnectResponse
;
...
...
@@ -126,26 +122,20 @@ namespace Titanium.Web.Proxy.Examples.Basic
//proxyServer.CertificateManager.RemoveTrustedRootCertificates();
}
private
async
Task
<
bool
>
OnBeforeTunnelConnect
(
string
hostnam
e
)
private
async
Task
OnTunnelConnectRequest
(
object
sender
,
TunnelConnectSessionEventArgs
e
)
{
string
hostname
=
e
.
WebSession
.
Request
.
Host
;
Console
.
WriteLine
(
"Tunnel to: "
+
hostname
);
if
(
hostname
.
Contains
(
"dropbox.com"
))
{
//Exclude Https addresses you don't want to proxy
//Useful for clients that use certificate pinning
//for example dropbox.com
return
await
Task
.
FromResult
(
true
);
}
else
{
return
await
Task
.
FromResult
(
false
);
e
.
Excluded
=
true
;
}
}
private
async
Task
OnTunnelConnectRequest
(
object
sender
,
TunnelConnectSessionEventArgs
e
)
{
Console
.
WriteLine
(
"Tunnel to: "
+
e
.
WebSession
.
Request
.
Host
);
}
private
async
Task
OnTunnelConnectResponse
(
object
sender
,
TunnelConnectSessionEventArgs
e
)
{
}
...
...
Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
View file @
6e5e683e
...
...
@@ -6,7 +6,9 @@ namespace Titanium.Web.Proxy.EventArguments
{
public
class
TunnelConnectSessionEventArgs
:
SessionEventArgs
{
public
bool
IsHttpsConnect
{
get
;
set
;
}
public
bool
Excluded
{
get
;
set
;
}
public
bool
IsHttpsConnect
{
get
;
internal
set
;
}
internal
TunnelConnectSessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
ConnectRequest
connectRequest
,
Action
<
Exception
>
exceptionFunc
)
:
base
(
bufferSize
,
endPoint
,
exceptionFunc
)
...
...
Titanium.Web.Proxy/Models/EndPoint.cs
→
Titanium.Web.Proxy/Models/E
xplicitProxyE
ndPoint.cs
View file @
6e5e683e
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Text.RegularExpressions
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Extensions
;
namespace
Titanium.Web.Proxy.Models
{
/// <summary>
/// An abstract endpoint where the proxy listens
/// </summary>
public
abstract
class
ProxyEndPoint
{
/// <summary>
/// Constructor.
/// </summary>
/// <param name="ipAddress"></param>
/// <param name="port"></param>
/// <param name="enableSsl"></param>
protected
ProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
enableSsl
)
{
IpAddress
=
ipAddress
;
Port
=
port
;
EnableSsl
=
enableSsl
;
}
/// <summary>
/// underlying TCP Listener object
/// </summary>
internal
TcpListener
Listener
{
get
;
set
;
}
/// <summary>
/// Ip Address we are listening.
/// </summary>
public
IPAddress
IpAddress
{
get
;
internal
set
;
}
/// <summary>
/// Port we are listening.
/// </summary>
public
int
Port
{
get
;
internal
set
;
}
/// <summary>
/// Enable SSL?
/// </summary>
public
bool
EnableSsl
{
get
;
internal
set
;
}
/// <summary>
/// Is IPv6 enabled?
/// </summary>
public
bool
IpV6Enabled
=>
Equals
(
IpAddress
,
IPAddress
.
IPv6Any
)
||
Equals
(
IpAddress
,
IPAddress
.
IPv6Loopback
)
||
Equals
(
IpAddress
,
IPAddress
.
IPv6None
);
}
/// <summary>
/// A proxy endpoint that the client is aware of
/// So client application know that it is communicating with a proxy server
/// </summary>
public
class
ExplicitProxyEndPoint
:
ProxyEndPoint
{
internal
List
<
Regex
>
ExcludedHttpsHostNameRegexList
;
internal
List
<
Regex
>
IncludedHttpsHostNameRegexList
;
internal
bool
IsSystemHttpProxy
{
get
;
set
;
}
internal
bool
IsSystemHttpsProxy
{
get
;
set
;
}
/// <summary>
/// Generic certificate to use for SSL decryption.
/// </summary>
public
X509Certificate2
GenericCertificate
{
get
;
set
;
}
/// <summary>
/// Return true if this HTTP connect request should'nt be decrypted and instead be relayed
/// Valid only for explicit endpoints
/// </summary>
public
Func
<
string
,
Task
<
bool
>>
BeforeTunnelConnect
;
/// <summary>
/// Intercept tunnel connect request
/// Valid only for explicit endpoints
/// </summary>
public
event
AsyncEventHandler
<
TunnelConnectSessionEventArgs
>
TunnelConnectRequest
;
/// <summary>
/// Intercept tunnel connect response
/// Valid only for explicit endpoints
/// </summary>
public
event
AsyncEventHandler
<
TunnelConnectSessionEventArgs
>
TunnelConnectResponse
;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="ipAddress"></param>
/// <param name="port"></param>
/// <param name="enableSsl"></param>
public
ExplicitProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
enableSsl
)
:
base
(
ipAddress
,
port
,
enableSsl
)
{
}
internal
async
Task
InvokeTunnectConnectRequest
(
ProxyServer
proxyServer
,
TunnelConnectSessionEventArgs
connectArgs
,
Action
<
Exception
>
exceptionFunc
)
{
if
(
TunnelConnectRequest
!=
null
)
{
await
TunnelConnectRequest
.
InvokeAsync
(
proxyServer
,
connectArgs
,
exceptionFunc
);
}
}
internal
async
Task
InvokeTunnectConnectResponse
(
ProxyServer
proxyServer
,
TunnelConnectSessionEventArgs
connectArgs
,
Action
<
Exception
>
exceptionFunc
)
{
if
(
TunnelConnectResponse
!=
null
)
{
await
TunnelConnectResponse
.
InvokeAsync
(
proxyServer
,
connectArgs
,
exceptionFunc
);
}
}
internal
async
Task
InvokeTunnectConnectResponse
(
ProxyServer
proxyServer
,
TunnelConnectSessionEventArgs
connectArgs
,
Action
<
Exception
>
exceptionFunc
,
bool
isClientHello
)
{
if
(
TunnelConnectResponse
!=
null
)
{
connectArgs
.
IsHttpsConnect
=
isClientHello
;
await
TunnelConnectResponse
.
InvokeAsync
(
proxyServer
,
connectArgs
,
exceptionFunc
);
}
}
}
/// <summary>
/// A proxy end point client is not aware of
/// Usefull when requests are redirected to this proxy end point through port forwarding
/// </summary>
public
class
TransparentProxyEndPoint
:
ProxyEndPoint
{
/// <summary>
/// Name of the Certificate need to be sent (same as the hostname we want to proxy)
/// This is valid only when UseServerNameIndication is set to false
/// </summary>
public
string
GenericCertificateName
{
get
;
set
;
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="ipAddress"></param>
/// <param name="port"></param>
/// <param name="enableSsl"></param>
public
TransparentProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
enableSsl
)
:
base
(
ipAddress
,
port
,
enableSsl
)
{
GenericCertificateName
=
"localhost"
;
}
}
}
using
System
;
using
System.Net
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Extensions
;
namespace
Titanium.Web.Proxy.Models
{
/// <summary>
/// A proxy endpoint that the client is aware of
/// So client application know that it is communicating with a proxy server
/// </summary>
public
class
ExplicitProxyEndPoint
:
ProxyEndPoint
{
internal
bool
IsSystemHttpProxy
{
get
;
set
;
}
internal
bool
IsSystemHttpsProxy
{
get
;
set
;
}
/// <summary>
/// Generic certificate to use for SSL decryption.
/// </summary>
public
X509Certificate2
GenericCertificate
{
get
;
set
;
}
/// <summary>
/// Intercept tunnel connect request
/// Valid only for explicit endpoints
/// Set the <see cref="TunnelConnectSessionEventArgs.Excluded"/> property to true if this HTTP connect request should'nt be decrypted and instead be relayed
/// </summary>
public
event
AsyncEventHandler
<
TunnelConnectSessionEventArgs
>
TunnelConnectRequest
;
/// <summary>
/// Intercept tunnel connect response
/// Valid only for explicit endpoints
/// </summary>
public
event
AsyncEventHandler
<
TunnelConnectSessionEventArgs
>
TunnelConnectResponse
;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="ipAddress"></param>
/// <param name="port"></param>
/// <param name="enableSsl"></param>
public
ExplicitProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
enableSsl
)
:
base
(
ipAddress
,
port
,
enableSsl
)
{
}
internal
async
Task
InvokeTunnectConnectRequest
(
ProxyServer
proxyServer
,
TunnelConnectSessionEventArgs
connectArgs
,
Action
<
Exception
>
exceptionFunc
)
{
if
(
TunnelConnectRequest
!=
null
)
{
await
TunnelConnectRequest
.
InvokeAsync
(
proxyServer
,
connectArgs
,
exceptionFunc
);
}
}
internal
async
Task
InvokeTunnectConnectResponse
(
ProxyServer
proxyServer
,
TunnelConnectSessionEventArgs
connectArgs
,
Action
<
Exception
>
exceptionFunc
,
bool
isClientHello
=
false
)
{
if
(
TunnelConnectResponse
!=
null
)
{
connectArgs
.
IsHttpsConnect
=
isClientHello
;
await
TunnelConnectResponse
.
InvokeAsync
(
proxyServer
,
connectArgs
,
exceptionFunc
);
}
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/Models/ProxyEndPoint.cs
0 → 100644
View file @
6e5e683e
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.Text.RegularExpressions
;
namespace
Titanium.Web.Proxy.Models
{
/// <summary>
/// An abstract endpoint where the proxy listens
/// </summary>
public
abstract
class
ProxyEndPoint
{
/// <summary>
/// Constructor.
/// </summary>
/// <param name="ipAddress"></param>
/// <param name="port"></param>
/// <param name="enableSsl"></param>
protected
ProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
enableSsl
)
{
IpAddress
=
ipAddress
;
Port
=
port
;
EnableSsl
=
enableSsl
;
}
/// <summary>
/// underlying TCP Listener object
/// </summary>
internal
TcpListener
Listener
{
get
;
set
;
}
/// <summary>
/// Ip Address we are listening.
/// </summary>
public
IPAddress
IpAddress
{
get
;
}
/// <summary>
/// Port we are listening.
/// </summary>
public
int
Port
{
get
;
internal
set
;
}
/// <summary>
/// Enable SSL?
/// </summary>
public
bool
EnableSsl
{
get
;
}
/// <summary>
/// Is IPv6 enabled?
/// </summary>
public
bool
IpV6Enabled
=>
Equals
(
IpAddress
,
IPAddress
.
IPv6Any
)
||
Equals
(
IpAddress
,
IPAddress
.
IPv6Loopback
)
||
Equals
(
IpAddress
,
IPAddress
.
IPv6None
);
}
}
Titanium.Web.Proxy/Models/TransparentProxyEndPoint.cs
0 → 100644
View file @
6e5e683e
using
System.Net
;
namespace
Titanium.Web.Proxy.Models
{
/// <summary>
/// A proxy end point client is not aware of
/// Usefull when requests are redirected to this proxy end point through port forwarding
/// </summary>
public
class
TransparentProxyEndPoint
:
ProxyEndPoint
{
/// <summary>
/// Name of the Certificate need to be sent (same as the hostname we want to proxy)
/// This is valid only when UseServerNameIndication is set to false
/// </summary>
public
string
GenericCertificateName
{
get
;
set
;
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="ipAddress"></param>
/// <param name="port"></param>
/// <param name="enableSsl"></param>
public
TransparentProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
enableSsl
)
:
base
(
ipAddress
,
port
,
enableSsl
)
{
GenericCertificateName
=
"localhost"
;
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/RequestHandler.cs
View file @
6e5e683e
...
...
@@ -64,14 +64,6 @@ namespace Titanium.Web.Proxy
var
httpRemoteUri
=
new
Uri
(
"http://"
+
httpUrl
);
connectHostname
=
httpRemoteUri
.
Host
;
//filter out excluded host names
bool
excluded
=
false
;
if
(
endPoint
.
BeforeTunnelConnect
!=
null
)
{
excluded
=
await
endPoint
.
BeforeTunnelConnect
(
connectHostname
);
}
connectRequest
=
new
ConnectRequest
{
RequestUri
=
httpRemoteUri
,
...
...
@@ -86,7 +78,9 @@ namespace Titanium.Web.Proxy
connectArgs
.
ProxyClient
.
ClientStream
=
clientStream
;
await
endPoint
.
InvokeTunnectConnectRequest
(
this
,
connectArgs
,
ExceptionFunc
);
//filter out excluded host names
bool
excluded
=
connectArgs
.
Excluded
;
if
(
await
CheckAuthorization
(
clientStreamWriter
,
connectArgs
)
==
false
)
{
...
...
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