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
c1f6c64e
Commit
c1f6c64e
authored
Mar 07, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move methods specific to transparent endpoint; Mark obsolete;
parent
29de4d43
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
63 deletions
+91
-63
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+36
-27
EndPoint.cs
Titanium.Web.Proxy/Models/EndPoint.cs
+49
-2
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+0
-18
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+6
-16
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
c1f6c64e
...
@@ -14,7 +14,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -14,7 +14,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
public
class
ProxyTestController
public
class
ProxyTestController
{
{
private
readonly
ProxyServer
proxyServer
;
private
readonly
ProxyServer
proxyServer
;
private
ExplicitProxyEndPoint
explicitEndPoint
;
//keep track of request headers
//keep track of request headers
private
readonly
IDictionary
<
Guid
,
HeaderCollection
>
requestHeaderHistory
=
new
ConcurrentDictionary
<
Guid
,
HeaderCollection
>();
private
readonly
IDictionary
<
Guid
,
HeaderCollection
>
requestHeaderHistory
=
new
ConcurrentDictionary
<
Guid
,
HeaderCollection
>();
...
@@ -52,38 +52,31 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -52,38 +52,31 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
{
proxyServer
.
BeforeRequest
+=
OnRequest
;
proxyServer
.
BeforeRequest
+=
OnRequest
;
proxyServer
.
BeforeResponse
+=
OnResponse
;
proxyServer
.
BeforeResponse
+=
OnResponse
;
proxyServer
.
TunnelConnectRequest
+=
OnTunnelConnectRequest
;
proxyServer
.
TunnelConnectResponse
+=
OnTunnelConnectResponse
;
proxyServer
.
ServerCertificateValidationCallback
+=
OnCertificateValidation
;
proxyServer
.
ServerCertificateValidationCallback
+=
OnCertificateValidation
;
proxyServer
.
ClientCertificateSelectionCallback
+=
OnCertificateSelection
;
proxyServer
.
ClientCertificateSelectionCallback
+=
OnCertificateSelection
;
//proxyServer.EnableWinAuth = true;
//proxyServer.EnableWinAuth = true;
var
explicitEndPoint
=
new
ExplicitProxyEndPoint
(
IPAddress
.
Any
,
8000
,
true
)
explicitEndPoint
=
new
ExplicitProxyEndPoint
(
IPAddress
.
Any
,
8000
,
true
)
{
{
//Exclude Https addresses you don't want to proxy
//You can set only one of the ExcludedHttpsHostNameRegex and IncludedHttpsHostNameRegex properties, otherwise ArgumentException will be thrown
//Useful for clients that use certificate pinning
//for example google.com and dropbox.com
//Use self-issued generic certificate on all https requests
ExcludedHttpsHostNameRegex
=
new
List
<
string
>
//Optimizes performance by not creating a certificate for each https-enabled domain
{
//Useful when certificate trust is not required by proxy clients
"dropbox.com"
//GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
},
//Include Https addresses you want to proxy (others will be excluded)
//for example github.com
//IncludedHttpsHostNameRegex = new List<string>
//{
// "github.com"
//},
//You can set only one of the ExcludedHttpsHostNameRegex and IncludedHttpsHostNameRegex properties, otherwise ArgumentException will be thrown
//Use self-issued generic certificate on all https requests
//Optimizes performance by not creating a certificate for each https-enabled domain
//Useful when certificate trust is not required by proxy clients
//GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
};
};
//Exclude Https addresses you don't want to proxy
//Useful for clients that use certificate pinning
//for example google.com and dropbox.com
explicitEndPoint
.
BeforeTunnelConnect
+=
OnBeforeTunnelConnect
;
explicitEndPoint
.
TunnelConnectRequest
+=
OnTunnelConnectRequest
;
explicitEndPoint
.
TunnelConnectResponse
+=
OnTunnelConnectResponse
;
//An explicit endpoint is where the client knows about the existence of a proxy
//An explicit endpoint is where the client knows about the existence of a proxy
//So client sends request in a proxy friendly manner
//So client sends request in a proxy friendly manner
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
...
@@ -120,8 +113,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -120,8 +113,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
public
void
Stop
()
public
void
Stop
()
{
{
proxyServer
.
TunnelConnectRequest
-=
OnTunnelConnectRequest
;
explicitEndPoint
.
BeforeTunnelConnect
-=
OnBeforeTunnelConnect
;
proxyServer
.
TunnelConnectResponse
-=
OnTunnelConnectResponse
;
explicitEndPoint
.
TunnelConnectRequest
-=
OnTunnelConnectRequest
;
explicitEndPoint
.
TunnelConnectResponse
-=
OnTunnelConnectResponse
;
proxyServer
.
BeforeRequest
-=
OnRequest
;
proxyServer
.
BeforeRequest
-=
OnRequest
;
proxyServer
.
BeforeResponse
-=
OnResponse
;
proxyServer
.
BeforeResponse
-=
OnResponse
;
proxyServer
.
ServerCertificateValidationCallback
-=
OnCertificateValidation
;
proxyServer
.
ServerCertificateValidationCallback
-=
OnCertificateValidation
;
...
@@ -133,6 +128,20 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -133,6 +128,20 @@ namespace Titanium.Web.Proxy.Examples.Basic
//proxyServer.CertificateManager.RemoveTrustedRootCertificates();
//proxyServer.CertificateManager.RemoveTrustedRootCertificates();
}
}
private
async
Task
<
bool
>
OnBeforeTunnelConnect
(
string
hostname
)
{
if
(
hostname
.
Contains
(
"google.com"
)
||
hostname
.
Contains
(
"bing.com"
))
{
//exclude bing.com and google.com from being decrypted
//instead it will be relayed via a secure TCP tunnel
return
await
Task
.
FromResult
(
true
);
}
else
{
return
await
Task
.
FromResult
(
false
);
}
}
private
async
Task
OnTunnelConnectRequest
(
object
sender
,
TunnelConnectSessionEventArgs
e
)
private
async
Task
OnTunnelConnectRequest
(
object
sender
,
TunnelConnectSessionEventArgs
e
)
{
{
Console
.
WriteLine
(
"Tunnel to: "
+
e
.
WebSession
.
Request
.
Host
);
Console
.
WriteLine
(
"Tunnel to: "
+
e
.
WebSession
.
Request
.
Host
);
...
...
Titanium.Web.Proxy/Models/EndPoint.cs
View file @
c1f6c64e
...
@@ -5,6 +5,9 @@ using System.Net;
...
@@ -5,6 +5,9 @@ using System.Net;
using
System.Net.Sockets
;
using
System.Net.Sockets
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Text.RegularExpressions
;
using
System.Text.RegularExpressions
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Extensions
;
namespace
Titanium.Web.Proxy.Models
namespace
Titanium.Web.Proxy.Models
{
{
...
@@ -67,9 +70,15 @@ namespace Titanium.Web.Proxy.Models
...
@@ -67,9 +70,15 @@ namespace Titanium.Web.Proxy.Models
internal
bool
IsSystemHttpsProxy
{
get
;
set
;
}
internal
bool
IsSystemHttpsProxy
{
get
;
set
;
}
/// <summary>
/// Generic certificate to use for SSL decryption.
/// </summary>
public
X509Certificate2
GenericCertificate
{
get
;
set
;
}
/// <summary>
/// <summary>
/// List of host names to exclude using Regular Expressions.
/// List of host names to exclude using Regular Expressions.
/// </summary>
/// </summary>
[
Obsolete
(
"ExcludedHttpsHostNameRegex is deprecated, please use ExcludeTunnelConnect instead."
)]
public
IEnumerable
<
string
>
ExcludedHttpsHostNameRegex
public
IEnumerable
<
string
>
ExcludedHttpsHostNameRegex
{
{
get
{
return
ExcludedHttpsHostNameRegexList
?.
Select
(
x
=>
x
.
ToString
()).
ToList
();
}
get
{
return
ExcludedHttpsHostNameRegexList
?.
Select
(
x
=>
x
.
ToString
()).
ToList
();
}
...
@@ -87,6 +96,7 @@ namespace Titanium.Web.Proxy.Models
...
@@ -87,6 +96,7 @@ namespace Titanium.Web.Proxy.Models
/// <summary>
/// <summary>
/// List of host names to exclude using Regular Expressions.
/// List of host names to exclude using Regular Expressions.
/// </summary>
/// </summary>
[
Obsolete
(
"IncludedHttpsHostNameRegex is deprecated, please use ExcludeTunnelConnect instead."
)]
public
IEnumerable
<
string
>
IncludedHttpsHostNameRegex
public
IEnumerable
<
string
>
IncludedHttpsHostNameRegex
{
{
get
{
return
IncludedHttpsHostNameRegexList
?.
Select
(
x
=>
x
.
ToString
()).
ToList
();
}
get
{
return
IncludedHttpsHostNameRegexList
?.
Select
(
x
=>
x
.
ToString
()).
ToList
();
}
...
@@ -102,10 +112,22 @@ namespace Titanium.Web.Proxy.Models
...
@@ -102,10 +112,22 @@ namespace Titanium.Web.Proxy.Models
}
}
/// <summary>
/// <summary>
/// Generic certificate to use for SSL decryption.
/// Return true if this HTTP connect request should'nt be decrypted and instead be relayed
/// Valid only for explicit endpoints
/// </summary>
/// </summary>
public
X509Certificate2
GenericCertificate
{
get
;
set
;
}
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>
/// <summary>
/// Constructor.
/// Constructor.
/// </summary>
/// </summary>
...
@@ -115,6 +137,31 @@ namespace Titanium.Web.Proxy.Models
...
@@ -115,6 +137,31 @@ namespace Titanium.Web.Proxy.Models
public
ExplicitProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
enableSsl
)
:
base
(
ipAddress
,
port
,
enableSsl
)
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>
/// <summary>
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
c1f6c64e
...
@@ -285,24 +285,6 @@ namespace Titanium.Web.Proxy
...
@@ -285,24 +285,6 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
public
event
EventHandler
ServerConnectionCountChanged
;
public
event
EventHandler
ServerConnectionCountChanged
;
/// <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
>>
ExcludeTunnelConnect
;
/// <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>
/// <summary>
/// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication
/// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication
/// </summary>
/// </summary>
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
c1f6c64e
...
@@ -77,9 +77,9 @@ namespace Titanium.Web.Proxy
...
@@ -77,9 +77,9 @@ namespace Titanium.Web.Proxy
excluded
=
!
endPoint
.
IncludedHttpsHostNameRegexList
.
Any
(
x
=>
x
.
IsMatch
(
connectHostname
));
excluded
=
!
endPoint
.
IncludedHttpsHostNameRegexList
.
Any
(
x
=>
x
.
IsMatch
(
connectHostname
));
}
}
if
(
Exclud
eTunnelConnect
!=
null
)
if
(
endPoint
.
Befor
eTunnelConnect
!=
null
)
{
{
excluded
=
await
Exclud
eTunnelConnect
(
connectHostname
);
excluded
=
await
endPoint
.
Befor
eTunnelConnect
(
connectHostname
);
}
}
connectRequest
=
new
ConnectRequest
connectRequest
=
new
ConnectRequest
...
@@ -95,18 +95,12 @@ namespace Titanium.Web.Proxy
...
@@ -95,18 +95,12 @@ namespace Titanium.Web.Proxy
connectArgs
.
ProxyClient
.
TcpClient
=
tcpClient
;
connectArgs
.
ProxyClient
.
TcpClient
=
tcpClient
;
connectArgs
.
ProxyClient
.
ClientStream
=
clientStream
;
connectArgs
.
ProxyClient
.
ClientStream
=
clientStream
;
if
(
TunnelConnectRequest
!=
null
)
await
endPoint
.
InvokeTunnectConnectRequest
(
this
,
connectArgs
,
ExceptionFunc
);
{
await
TunnelConnectRequest
.
InvokeAsync
(
this
,
connectArgs
,
ExceptionFunc
);
}
if
(
await
CheckAuthorization
(
clientStreamWriter
,
connectArgs
)
==
false
)
if
(
await
CheckAuthorization
(
clientStreamWriter
,
connectArgs
)
==
false
)
{
{
if
(
TunnelConnectResponse
!=
null
)
await
endPoint
.
InvokeTunnectConnectResponse
(
this
,
connectArgs
,
ExceptionFunc
);
{
await
TunnelConnectResponse
.
InvokeAsync
(
this
,
connectArgs
,
ExceptionFunc
);
}
return
;
return
;
}
}
...
@@ -124,11 +118,7 @@ namespace Titanium.Web.Proxy
...
@@ -124,11 +118,7 @@ namespace Titanium.Web.Proxy
connectRequest
.
ClientHelloInfo
=
clientHelloInfo
;
connectRequest
.
ClientHelloInfo
=
clientHelloInfo
;
}
}
if
(
TunnelConnectResponse
!=
null
)
await
endPoint
.
InvokeTunnectConnectResponse
(
this
,
connectArgs
,
ExceptionFunc
,
isClientHello
);
{
connectArgs
.
IsHttpsConnect
=
isClientHello
;
await
TunnelConnectResponse
.
InvokeAsync
(
this
,
connectArgs
,
ExceptionFunc
);
}
if
(!
excluded
&&
isClientHello
)
if
(!
excluded
&&
isClientHello
)
{
{
...
...
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