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
9c6b022c
Commit
9c6b022c
authored
Feb 06, 2016
by
titanium007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
option to specifi certificate name for transparent endpoint
parent
534ea740
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
10 deletions
+28
-10
EndPoint.cs
Titanium.Web.Proxy/Models/EndPoint.cs
+9
-1
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+19
-9
No files found.
Titanium.Web.Proxy/Models/EndPoint.cs
View file @
9c6b022c
...
@@ -37,10 +37,18 @@ namespace Titanium.Web.Proxy.Models
...
@@ -37,10 +37,18 @@ namespace Titanium.Web.Proxy.Models
public
class
TransparentProxyEndPoint
:
ProxyEndPoint
public
class
TransparentProxyEndPoint
:
ProxyEndPoint
{
{
//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
public
string
GenericCertificateName
{
get
;
set
;
}
// public bool UseServerNameIndication { get; set; }
public
TransparentProxyEndPoint
(
IPAddress
IpAddress
,
int
Port
,
bool
EnableSsl
)
public
TransparentProxyEndPoint
(
IPAddress
IpAddress
,
int
Port
,
bool
EnableSsl
)
:
base
(
IpAddress
,
Port
,
EnableSsl
)
:
base
(
IpAddress
,
Port
,
EnableSsl
)
{
{
this
.
GenericCertificateName
=
"localhost"
;
}
}
}
}
}
}
Titanium.Web.Proxy/RequestHandler.cs
View file @
9c6b022c
...
@@ -15,11 +15,13 @@ using Titanium.Web.Proxy.Extensions;
...
@@ -15,11 +15,13 @@ using Titanium.Web.Proxy.Extensions;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Network
;
using
Titanium.Web.Proxy.Network
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
using
System.Security.Cryptography.X509Certificates
;
namespace
Titanium.Web.Proxy
namespace
Titanium.Web.Proxy
{
{
partial
class
ProxyServer
partial
class
ProxyServer
{
{
//This is called when client is aware of proxy
private
static
void
HandleClient
(
ExplicitProxyEndPoint
endPoint
,
TcpClient
client
)
private
static
void
HandleClient
(
ExplicitProxyEndPoint
endPoint
,
TcpClient
client
)
{
{
Stream
clientStream
=
client
.
GetStream
();
Stream
clientStream
=
client
.
GetStream
();
...
@@ -54,7 +56,7 @@ namespace Titanium.Web.Proxy
...
@@ -54,7 +56,7 @@ namespace Titanium.Web.Proxy
var
excluded
=
endPoint
.
ExcludedHostNameRegex
!=
null
?
endPoint
.
ExcludedHostNameRegex
.
Any
(
x
=>
Regex
.
IsMatch
(
httpRemoteUri
.
Host
,
x
))
:
false
;
var
excluded
=
endPoint
.
ExcludedHostNameRegex
!=
null
?
endPoint
.
ExcludedHostNameRegex
.
Any
(
x
=>
Regex
.
IsMatch
(
httpRemoteUri
.
Host
,
x
))
:
false
;
//Client wants to create a secure tcp tunnel (its a HTTPS request)
//Client wants to create a secure tcp tunnel (its a HTTPS request)
if
(
httpVerb
.
ToUpper
()
==
"CONNECT"
&&
!
excluded
&&
httpRemoteUri
.
Port
!=
80
)
if
(
httpVerb
.
ToUpper
()
==
"CONNECT"
&&
!
excluded
&&
httpRemoteUri
.
Port
!=
80
)
{
{
httpRemoteUri
=
new
Uri
(
"https://"
+
httpCmdSplit
[
1
]);
httpRemoteUri
=
new
Uri
(
"https://"
+
httpCmdSplit
[
1
]);
clientStreamReader
.
ReadAllLines
();
clientStreamReader
.
ReadAllLines
();
...
@@ -115,12 +117,21 @@ namespace Titanium.Web.Proxy
...
@@ -115,12 +117,21 @@ namespace Titanium.Web.Proxy
}
}
}
}
private
static
void
HandleClient
(
TransparentProxyEndPoint
endPoint
,
TcpClient
client
)
//This is called when requests are routed through router to this endpoint
private
static
void
HandleClient
(
TransparentProxyEndPoint
endPoint
,
TcpClient
tcpClient
)
{
{
var
sslStream
=
new
SslStream
(
c
lient
.
GetStream
(),
true
);
var
sslStream
=
new
SslStream
(
tcpC
lient
.
GetStream
(),
true
);
CustomBinaryReader
clientStreamReader
=
null
;
CustomBinaryReader
clientStreamReader
=
null
;
StreamWriter
clientStreamWriter
=
null
;
StreamWriter
clientStreamWriter
=
null
;
var
certificate
=
CertManager
.
CreateCertificate
(
"127.0.0.1"
);
X509Certificate2
certificate
=
null
;
//if(endPoint.UseServerNameIndication)
//{
// //implement in future once SNI supported by SSL stream
// certificate = CertManager.CreateCertificate(endPoint.GenericCertificateName);
//}
//else
certificate
=
CertManager
.
CreateCertificate
(
endPoint
.
GenericCertificateName
);
try
try
{
{
...
@@ -133,20 +144,19 @@ namespace Titanium.Web.Proxy
...
@@ -133,20 +144,19 @@ 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
}
}
catch
(
Exception
)
catch
(
Exception
e
)
{
{
if
(
sslStream
!=
null
)
if
(
sslStream
!=
null
)
sslStream
.
Dispose
();
sslStream
.
Dispose
();
Dispose
(
c
lient
,
sslStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
Dispose
(
tcpC
lient
,
sslStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
return
;
}
}
var
httpCmd
=
clientStreamReader
.
ReadLine
();
var
httpCmd
=
clientStreamReader
.
ReadLine
();
//Now create the request
//Now create the request
HandleHttpSessionRequest
(
c
lient
,
httpCmd
,
sslStream
,
clientStreamReader
,
clientStreamWriter
,
HandleHttpSessionRequest
(
tcpC
lient
,
httpCmd
,
sslStream
,
clientStreamReader
,
clientStreamWriter
,
true
);
true
);
}
}
...
...
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