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
cfdcaee9
Commit
cfdcaee9
authored
May 15, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to generate root certificate with Titanium without storing it in file system
parent
b6d18a61
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
30 deletions
+39
-30
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+6
-0
CertificateManager.cs
Titanium.Web.Proxy/Network/CertificateManager.cs
+10
-7
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+21
-21
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+2
-2
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
cfdcaee9
...
@@ -17,6 +17,12 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -17,6 +17,12 @@ namespace Titanium.Web.Proxy.Examples.Basic
public
ProxyTestController
()
public
ProxyTestController
()
{
{
proxyServer
=
new
ProxyServer
();
proxyServer
=
new
ProxyServer
();
//generate root certificate without storing it in file system
//proxyServer.CertificateEngine = Network.CertificateEngine.BouncyCastle;
//proxyServer.CertificateManager.CreateTrustedRootCertificate(false);
//proxyServer.CertificateManager.TrustRootCertificate();
proxyServer
.
ExceptionFunc
=
exception
=>
Console
.
WriteLine
(
exception
.
Message
);
proxyServer
.
ExceptionFunc
=
exception
=>
Console
.
WriteLine
(
exception
.
Message
);
proxyServer
.
TrustRootCertificate
=
true
;
proxyServer
.
TrustRootCertificate
=
true
;
...
...
Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
cfdcaee9
...
@@ -29,9 +29,9 @@ namespace Titanium.Web.Proxy.Network
...
@@ -29,9 +29,9 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// <summary>
/// A class to manage SSL certificates used by this proxy server
/// A class to manage SSL certificates used by this proxy server
/// </summary>
/// </summary>
internal
class
CertificateManager
:
IDisposable
public
class
CertificateManager
:
IDisposable
{
{
public
CertificateEngine
Engine
internal
CertificateEngine
Engine
{
{
get
{
return
engine
;
}
get
{
return
engine
;
}
set
set
...
@@ -164,10 +164,13 @@ namespace Titanium.Web.Proxy.Network
...
@@ -164,10 +164,13 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// <summary>
/// Attempts to create a RootCertificate
/// Attempts to create a RootCertificate
/// </summary>
/// </summary>
/// <returns>true if succeeded, else false</returns>
/// <param name="persistToFile">if set to <c>true</c> try to load/save the certificate from rootCert.pfx.</param>
internal
bool
CreateTrustedRootCertificate
()
/// <returns>
/// true if succeeded, else false
/// </returns>
public
bool
CreateTrustedRootCertificate
(
bool
persistToFile
=
true
)
{
{
if
(
RootCertificate
==
null
)
if
(
persistToFile
&&
RootCertificate
==
null
)
{
{
RootCertificate
=
LoadRootCertificate
();
RootCertificate
=
LoadRootCertificate
();
}
}
...
@@ -186,7 +189,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -186,7 +189,7 @@ namespace Titanium.Web.Proxy.Network
exceptionFunc
(
e
);
exceptionFunc
(
e
);
}
}
if
(
RootCertificate
!=
null
)
if
(
persistToFile
&&
RootCertificate
!=
null
)
{
{
try
try
{
{
...
@@ -205,7 +208,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -205,7 +208,7 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// <summary>
/// Trusts the root certificate.
/// Trusts the root certificate.
/// </summary>
/// </summary>
internal
void
TrustRootCertificate
()
public
void
TrustRootCertificate
()
{
{
//current user
//current user
TrustRootCertificate
(
StoreLocation
.
CurrentUser
);
TrustRootCertificate
(
StoreLocation
.
CurrentUser
);
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
cfdcaee9
...
@@ -24,11 +24,6 @@ namespace Titanium.Web.Proxy
...
@@ -24,11 +24,6 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
private
bool
proxyRunning
{
get
;
set
;
}
private
bool
proxyRunning
{
get
;
set
;
}
/// <summary>
/// Manages certificates used by this proxy
/// </summary>
private
CertificateManager
certificateManager
{
get
;
set
;
}
/// <summary>
/// <summary>
/// An default exception log func
/// An default exception log func
/// </summary>
/// </summary>
...
@@ -64,13 +59,18 @@ namespace Titanium.Web.Proxy
...
@@ -64,13 +59,18 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
public
int
BufferSize
{
get
;
set
;
}
=
8192
;
public
int
BufferSize
{
get
;
set
;
}
=
8192
;
/// <summary>
/// Manages certificates used by this proxy
/// </summary>
public
CertificateManager
CertificateManager
{
get
;
}
/// <summary>
/// <summary>
/// The root certificate
/// The root certificate
/// </summary>
/// </summary>
public
X509Certificate2
RootCertificate
public
X509Certificate2
RootCertificate
{
{
get
{
return
c
ertificateManager
.
RootCertificate
;
}
get
{
return
C
ertificateManager
.
RootCertificate
;
}
set
{
c
ertificateManager
.
RootCertificate
=
value
;
}
set
{
C
ertificateManager
.
RootCertificate
=
value
;
}
}
}
/// <summary>
/// <summary>
...
@@ -79,8 +79,8 @@ namespace Titanium.Web.Proxy
...
@@ -79,8 +79,8 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
public
string
RootCertificateIssuerName
public
string
RootCertificateIssuerName
{
{
get
{
return
c
ertificateManager
.
Issuer
;
}
get
{
return
C
ertificateManager
.
Issuer
;
}
set
{
c
ertificateManager
.
RootCertificateName
=
value
;
}
set
{
C
ertificateManager
.
RootCertificateName
=
value
;
}
}
}
/// <summary>
/// <summary>
...
@@ -92,8 +92,8 @@ namespace Titanium.Web.Proxy
...
@@ -92,8 +92,8 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
public
string
RootCertificateName
public
string
RootCertificateName
{
{
get
{
return
c
ertificateManager
.
RootCertificateName
;
}
get
{
return
C
ertificateManager
.
RootCertificateName
;
}
set
{
c
ertificateManager
.
Issuer
=
value
;
}
set
{
C
ertificateManager
.
Issuer
=
value
;
}
}
}
/// <summary>
/// <summary>
...
@@ -121,8 +121,8 @@ namespace Titanium.Web.Proxy
...
@@ -121,8 +121,8 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
public
CertificateEngine
CertificateEngine
public
CertificateEngine
CertificateEngine
{
{
get
{
return
c
ertificateManager
.
Engine
;
}
get
{
return
C
ertificateManager
.
Engine
;
}
set
{
c
ertificateManager
.
Engine
=
value
;
}
set
{
C
ertificateManager
.
Engine
=
value
;
}
}
}
/// <summary>
/// <summary>
...
@@ -251,7 +251,7 @@ namespace Titanium.Web.Proxy
...
@@ -251,7 +251,7 @@ namespace Titanium.Web.Proxy
new
FireFoxProxySettingsManager
();
new
FireFoxProxySettingsManager
();
#endif
#endif
c
ertificateManager
=
new
CertificateManager
(
ExceptionFunc
);
C
ertificateManager
=
new
CertificateManager
(
ExceptionFunc
);
if
(
rootCertificateName
!=
null
)
if
(
rootCertificateName
!=
null
)
{
{
RootCertificateName
=
rootCertificateName
;
RootCertificateName
=
rootCertificateName
;
...
@@ -356,7 +356,7 @@ namespace Titanium.Web.Proxy
...
@@ -356,7 +356,7 @@ namespace Titanium.Web.Proxy
EnsureRootCertificate
();
EnsureRootCertificate
();
//If certificate was trusted by the machine
//If certificate was trusted by the machine
if
(
c
ertificateManager
.
CertValidated
)
if
(
C
ertificateManager
.
CertValidated
)
{
{
systemProxySettingsManager
.
SetHttpsProxy
(
systemProxySettingsManager
.
SetHttpsProxy
(
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Any
)
|
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Any
)
|
...
@@ -435,7 +435,7 @@ namespace Titanium.Web.Proxy
...
@@ -435,7 +435,7 @@ namespace Titanium.Web.Proxy
Listen
(
endPoint
);
Listen
(
endPoint
);
}
}
c
ertificateManager
.
ClearIdleCertificates
(
CertificateCacheTimeOutMinutes
);
C
ertificateManager
.
ClearIdleCertificates
(
CertificateCacheTimeOutMinutes
);
proxyRunning
=
true
;
proxyRunning
=
true
;
}
}
...
@@ -468,7 +468,7 @@ namespace Titanium.Web.Proxy
...
@@ -468,7 +468,7 @@ namespace Titanium.Web.Proxy
ProxyEndPoints
.
Clear
();
ProxyEndPoints
.
Clear
();
c
ertificateManager
?.
StopClearIdleCertificates
();
C
ertificateManager
?.
StopClearIdleCertificates
();
proxyRunning
=
false
;
proxyRunning
=
false
;
}
}
...
@@ -483,7 +483,7 @@ namespace Titanium.Web.Proxy
...
@@ -483,7 +483,7 @@ namespace Titanium.Web.Proxy
Stop
();
Stop
();
}
}
c
ertificateManager
?.
Dispose
();
C
ertificateManager
?.
Dispose
();
}
}
/// <summary>
/// <summary>
...
@@ -543,13 +543,13 @@ namespace Titanium.Web.Proxy
...
@@ -543,13 +543,13 @@ namespace Titanium.Web.Proxy
private
void
EnsureRootCertificate
()
private
void
EnsureRootCertificate
()
{
{
if
(!
c
ertificateManager
.
CertValidated
)
if
(!
C
ertificateManager
.
CertValidated
)
{
{
c
ertificateManager
.
CreateTrustedRootCertificate
();
C
ertificateManager
.
CreateTrustedRootCertificate
();
if
(
TrustRootCertificate
)
if
(
TrustRootCertificate
)
{
{
c
ertificateManager
.
TrustRootCertificate
();
C
ertificateManager
.
TrustRootCertificate
();
}
}
}
}
}
}
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
cfdcaee9
...
@@ -110,7 +110,7 @@ namespace Titanium.Web.Proxy
...
@@ -110,7 +110,7 @@ namespace Titanium.Web.Proxy
{
{
sslStream
=
new
SslStream
(
clientStream
,
true
);
sslStream
=
new
SslStream
(
clientStream
,
true
);
var
certificate
=
endPoint
.
GenericCertificate
??
c
ertificateManager
.
CreateCertificate
(
httpRemoteUri
.
Host
,
false
);
var
certificate
=
endPoint
.
GenericCertificate
??
C
ertificateManager
.
CreateCertificate
(
httpRemoteUri
.
Host
,
false
);
//Successfully managed to authenticate the client using the fake certificate
//Successfully managed to authenticate the client using the fake certificate
await
sslStream
.
AuthenticateAsServerAsync
(
certificate
,
false
,
await
sslStream
.
AuthenticateAsServerAsync
(
certificate
,
false
,
...
@@ -177,7 +177,7 @@ namespace Titanium.Web.Proxy
...
@@ -177,7 +177,7 @@ namespace Titanium.Web.Proxy
var
sslStream
=
new
SslStream
(
clientStream
,
true
);
var
sslStream
=
new
SslStream
(
clientStream
,
true
);
//implement in future once SNI supported by SSL stream, for now use the same certificate
//implement in future once SNI supported by SSL stream, for now use the same certificate
var
certificate
=
c
ertificateManager
.
CreateCertificate
(
endPoint
.
GenericCertificateName
,
false
);
var
certificate
=
C
ertificateManager
.
CreateCertificate
(
endPoint
.
GenericCertificateName
,
false
);
try
try
{
{
...
...
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