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
cbda4ca6
Commit
cbda4ca6
authored
May 08, 2017
by
Jehonathan Thomas
Committed by
GitHub
May 08, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #210 from honfika/develop
#205 IncludedHttpsHostNameRegex and #207 Inconsistent naming fixes
parents
196bf663
f2988f4a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
97 additions
and
47 deletions
+97
-47
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+7
-1
EndPoint.cs
Titanium.Web.Proxy/Models/EndPoint.cs
+54
-20
CertificateManager.cs
Titanium.Web.Proxy/Network/CertificateManager.cs
+12
-11
ProxyAuthorizationHandler.cs
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
+2
-2
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+9
-9
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+13
-4
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
cbda4ca6
...
...
@@ -37,9 +37,15 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
//Exclude Https addresses you don't want to proxy
//Useful for clients that use certificate pinning
//for example dropbox.com
//for example
google.com and
dropbox.com
// ExcludedHttpsHostNameRegex = new List<string>() { "google.com", "dropbox.com" }
//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
...
...
Titanium.Web.Proxy/Models/EndPoint.cs
View file @
cbda4ca6
using
System.Collections.Generic
;
using
System
;
using
System.Collections.Generic
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.Security.Cryptography.X509Certificates
;
...
...
@@ -13,14 +14,14 @@ namespace Titanium.Web.Proxy.Models
/// <summary>
/// Constructor.
/// </summary>
/// <param name="
I
pAddress"></param>
/// <param name="
P
ort"></param>
/// <param name="
E
nableSsl"></param>
protected
ProxyEndPoint
(
IPAddress
IpAddress
,
int
Port
,
bool
E
nableSsl
)
/// <param name="
i
pAddress"></param>
/// <param name="
p
ort"></param>
/// <param name="
e
nableSsl"></param>
protected
ProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
e
nableSsl
)
{
this
.
IpAddress
=
I
pAddress
;
this
.
Port
=
P
ort
;
this
.
EnableSsl
=
E
nableSsl
;
this
.
IpAddress
=
i
pAddress
;
this
.
Port
=
p
ort
;
this
.
EnableSsl
=
e
nableSsl
;
}
/// <summary>
...
...
@@ -43,7 +44,7 @@ namespace Titanium.Web.Proxy.Models
||
Equals
(
IpAddress
,
IPAddress
.
IPv6Loopback
)
||
Equals
(
IpAddress
,
IPAddress
.
IPv6None
);
internal
TcpListener
l
istener
{
get
;
set
;
}
internal
TcpListener
L
istener
{
get
;
set
;
}
}
/// <summary>
...
...
@@ -52,13 +53,46 @@ namespace Titanium.Web.Proxy.Models
/// </summary>
public
class
ExplicitProxyEndPoint
:
ProxyEndPoint
{
private
List
<
string
>
_excludedHttpsHostNameRegex
;
private
List
<
string
>
_includedHttpsHostNameRegex
;
internal
bool
IsSystemHttpProxy
{
get
;
set
;
}
internal
bool
IsSystemHttpsProxy
{
get
;
set
;
}
/// <summary>
/// List of host names to exclude using Regular Expressions.
/// </summary>
public
List
<
string
>
ExcludedHttpsHostNameRegex
{
get
;
set
;
}
public
List
<
string
>
ExcludedHttpsHostNameRegex
{
get
{
return
_excludedHttpsHostNameRegex
;
}
set
{
if
(
IncludedHttpsHostNameRegex
!=
null
)
{
throw
new
ArgumentException
(
"Cannot set excluded when included is set"
);
}
_excludedHttpsHostNameRegex
=
value
;
}
}
/// <summary>
/// List of host names to exclude using Regular Expressions.
/// </summary>
public
List
<
string
>
IncludedHttpsHostNameRegex
{
get
{
return
_includedHttpsHostNameRegex
;
}
set
{
if
(
ExcludedHttpsHostNameRegex
!=
null
)
{
throw
new
ArgumentException
(
"Cannot set included when excluded is set"
);
}
_includedHttpsHostNameRegex
=
value
;
}
}
/// <summary>
/// Generic certificate to use for SSL decryption.
...
...
@@ -68,11 +102,11 @@ namespace Titanium.Web.Proxy.Models
/// <summary>
/// Constructor.
/// </summary>
/// <param name="
I
pAddress"></param>
/// <param name="
P
ort"></param>
/// <param name="
E
nableSsl"></param>
public
ExplicitProxyEndPoint
(
IPAddress
IpAddress
,
int
Port
,
bool
E
nableSsl
)
:
base
(
IpAddress
,
Port
,
E
nableSsl
)
/// <param name="
i
pAddress"></param>
/// <param name="
p
ort"></param>
/// <param name="
e
nableSsl"></param>
public
ExplicitProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
e
nableSsl
)
:
base
(
ipAddress
,
port
,
e
nableSsl
)
{
}
...
...
@@ -94,11 +128,11 @@ namespace Titanium.Web.Proxy.Models
/// <summary>
/// Constructor.
/// </summary>
/// <param name="
I
pAddress"></param>
/// <param name="
P
ort"></param>
/// <param name="
E
nableSsl"></param>
public
TransparentProxyEndPoint
(
IPAddress
IpAddress
,
int
Port
,
bool
E
nableSsl
)
:
base
(
IpAddress
,
Port
,
E
nableSsl
)
/// <param name="
i
pAddress"></param>
/// <param name="
p
ort"></param>
/// <param name="
e
nableSsl"></param>
public
TransparentProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
e
nableSsl
)
:
base
(
ipAddress
,
port
,
e
nableSsl
)
{
this
.
GenericCertificateName
=
"localhost"
;
}
...
...
Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
cbda4ca6
...
...
@@ -43,9 +43,10 @@ namespace Titanium.Web.Proxy.Network
private
readonly
Action
<
Exception
>
exceptionFunc
;
internal
string
Issuer
{
get
;
}
internal
string
RootCertificateName
{
get
;
}
internal
X509Certificate2
r
ootCertificate
{
get
;
set
;
}
internal
X509Certificate2
R
ootCertificate
{
get
;
set
;
}
internal
CertificateManager
(
CertificateEngine
engine
,
string
issuer
,
...
...
@@ -107,32 +108,32 @@ namespace Titanium.Web.Proxy.Network
/// <returns>true if succeeded, else false</returns>
internal
bool
CreateTrustedRootCertificate
()
{
r
ootCertificate
=
GetRootCertificate
();
if
(
r
ootCertificate
!=
null
)
R
ootCertificate
=
GetRootCertificate
();
if
(
R
ootCertificate
!=
null
)
{
return
true
;
}
try
{
r
ootCertificate
=
CreateCertificate
(
RootCertificateName
,
true
);
R
ootCertificate
=
CreateCertificate
(
RootCertificateName
,
true
);
}
catch
(
Exception
e
)
{
exceptionFunc
(
e
);
}
if
(
r
ootCertificate
!=
null
)
if
(
R
ootCertificate
!=
null
)
{
try
{
var
fileName
=
GetRootCertificatePath
();
File
.
WriteAllBytes
(
fileName
,
r
ootCertificate
.
Export
(
X509ContentType
.
Pkcs12
));
File
.
WriteAllBytes
(
fileName
,
R
ootCertificate
.
Export
(
X509ContentType
.
Pkcs12
));
}
catch
(
Exception
e
)
{
exceptionFunc
(
e
);
}
}
return
r
ootCertificate
!=
null
;
return
R
ootCertificate
!=
null
;
}
/// <summary>
...
...
@@ -159,7 +160,7 @@ namespace Titanium.Web.Proxy.Network
{
try
{
certificate
=
certEngine
.
MakeCertificate
(
certificateName
,
isRootCertificate
,
r
ootCertificate
);
certificate
=
certEngine
.
MakeCertificate
(
certificateName
,
isRootCertificate
,
R
ootCertificate
);
}
catch
(
Exception
e
)
{
...
...
@@ -226,7 +227,7 @@ namespace Titanium.Web.Proxy.Network
internal
void
TrustRootCertificate
(
StoreLocation
storeLocation
,
Action
<
Exception
>
exceptionFunc
)
{
if
(
r
ootCertificate
==
null
)
if
(
R
ootCertificate
==
null
)
{
exceptionFunc
(
new
Exception
(
"Could not set root certificate"
...
...
@@ -243,8 +244,8 @@ namespace Titanium.Web.Proxy.Network
x509RootStore
.
Open
(
OpenFlags
.
ReadWrite
);
x509PersonalStore
.
Open
(
OpenFlags
.
ReadWrite
);
x509RootStore
.
Add
(
r
ootCertificate
);
x509PersonalStore
.
Add
(
r
ootCertificate
);
x509RootStore
.
Add
(
R
ootCertificate
);
x509PersonalStore
.
Add
(
R
ootCertificate
);
}
catch
(
Exception
e
)
{
...
...
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
View file @
cbda4ca6
...
...
@@ -13,14 +13,14 @@ namespace Titanium.Web.Proxy
public
partial
class
ProxyServer
{
private
async
Task
<
bool
>
CheckAuthorization
(
StreamWriter
clientStreamWriter
,
IEnumerable
<
HttpHeader
>
H
eaders
)
private
async
Task
<
bool
>
CheckAuthorization
(
StreamWriter
clientStreamWriter
,
IEnumerable
<
HttpHeader
>
h
eaders
)
{
if
(
AuthenticateUserFunc
==
null
)
{
return
true
;
}
var
httpHeaders
=
Headers
as
HttpHeader
[]
??
H
eaders
.
ToArray
();
var
httpHeaders
=
headers
as
HttpHeader
[]
??
h
eaders
.
ToArray
();
try
{
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
cbda4ca6
...
...
@@ -491,12 +491,12 @@ namespace Titanium.Web.Proxy
/// <param name="endPoint"></param>
private
void
Listen
(
ProxyEndPoint
endPoint
)
{
endPoint
.
l
istener
=
new
TcpListener
(
endPoint
.
IpAddress
,
endPoint
.
Port
);
endPoint
.
l
istener
.
Start
();
endPoint
.
L
istener
=
new
TcpListener
(
endPoint
.
IpAddress
,
endPoint
.
Port
);
endPoint
.
L
istener
.
Start
();
endPoint
.
Port
=
((
IPEndPoint
)
endPoint
.
l
istener
.
LocalEndpoint
).
Port
;
endPoint
.
Port
=
((
IPEndPoint
)
endPoint
.
L
istener
.
LocalEndpoint
).
Port
;
// accept clients asynchronously
endPoint
.
l
istener
.
BeginAcceptTcpClient
(
OnAcceptConnection
,
endPoint
);
endPoint
.
L
istener
.
BeginAcceptTcpClient
(
OnAcceptConnection
,
endPoint
);
}
/// <summary>
...
...
@@ -505,9 +505,9 @@ namespace Titanium.Web.Proxy
/// <param name="endPoint"></param>
private
void
QuitListen
(
ProxyEndPoint
endPoint
)
{
endPoint
.
l
istener
.
Stop
();
endPoint
.
l
istener
.
Server
.
Close
();
endPoint
.
l
istener
.
Server
.
Dispose
();
endPoint
.
L
istener
.
Stop
();
endPoint
.
L
istener
.
Server
.
Close
();
endPoint
.
L
istener
.
Server
.
Dispose
();
}
/// <summary>
...
...
@@ -541,7 +541,7 @@ namespace Titanium.Web.Proxy
try
{
//based on end point type call appropriate request handlers
tcpClient
=
endPoint
.
l
istener
.
EndAcceptTcpClient
(
asyn
);
tcpClient
=
endPoint
.
L
istener
.
EndAcceptTcpClient
(
asyn
);
}
catch
(
ObjectDisposedException
)
{
...
...
@@ -595,7 +595,7 @@ namespace Titanium.Web.Proxy
}
// Get the listener that handles the client request.
endPoint
.
l
istener
.
BeginAcceptTcpClient
(
OnAcceptConnection
,
endPoint
);
endPoint
.
L
istener
.
BeginAcceptTcpClient
(
OnAcceptConnection
,
endPoint
);
}
/// <summary>
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
cbda4ca6
...
...
@@ -72,8 +72,17 @@ namespace Titanium.Web.Proxy
}
//filter out excluded host names
var
excluded
=
endPoint
.
ExcludedHttpsHostNameRegex
!=
null
&&
endPoint
.
ExcludedHttpsHostNameRegex
.
Any
(
x
=>
Regex
.
IsMatch
(
httpRemoteUri
.
Host
,
x
));
bool
excluded
=
false
;
if
(
endPoint
.
ExcludedHttpsHostNameRegex
!=
null
)
{
excluded
=
endPoint
.
ExcludedHttpsHostNameRegex
.
Any
(
x
=>
Regex
.
IsMatch
(
httpRemoteUri
.
Host
,
x
));
}
if
(
endPoint
.
IncludedHttpsHostNameRegex
!=
null
)
{
excluded
=
!
endPoint
.
IncludedHttpsHostNameRegex
.
Any
(
x
=>
Regex
.
IsMatch
(
httpRemoteUri
.
Host
,
x
));
}
List
<
HttpHeader
>
connectRequestHeaders
=
null
;
...
...
@@ -212,7 +221,7 @@ namespace Titanium.Web.Proxy
endPoint
.
EnableSsl
?
endPoint
.
GenericCertificateName
:
null
,
endPoint
,
null
);
}
private
async
Task
HandleHttpSessionRequestInternal
(
TcpConnection
connection
,
SessionEventArgs
args
,
ExternalProxy
customUpStreamHttpProxy
,
ExternalProxy
customUpStreamHttpsProxy
,
bool
C
loseConnection
)
private
async
Task
HandleHttpSessionRequestInternal
(
TcpConnection
connection
,
SessionEventArgs
args
,
ExternalProxy
customUpStreamHttpProxy
,
ExternalProxy
customUpStreamHttpsProxy
,
bool
c
loseConnection
)
{
try
{
...
...
@@ -331,7 +340,7 @@ namespace Titanium.Web.Proxy
return
;
}
if
(
C
loseConnection
)
if
(
c
loseConnection
)
{
//dispose
connection
?.
Dispose
();
...
...
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