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
fd2d0cb7
Commit
fd2d0cb7
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
b1db949f
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 @
fd2d0cb7
...
...
@@ -17,6 +17,12 @@ namespace Titanium.Web.Proxy.Examples.Basic
public
ProxyTestController
()
{
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
.
TrustRootCertificate
=
true
;
...
...
Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
fd2d0cb7
...
...
@@ -29,9 +29,9 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// A class to manage SSL certificates used by this proxy server
/// </summary>
internal
class
CertificateManager
:
IDisposable
public
class
CertificateManager
:
IDisposable
{
public
CertificateEngine
Engine
internal
CertificateEngine
Engine
{
get
{
return
engine
;
}
set
...
...
@@ -164,10 +164,13 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// Attempts to create a RootCertificate
/// </summary>
/// <returns>true if succeeded, else false</returns>
internal
bool
CreateTrustedRootCertificate
()
/// <param name="persistToFile">if set to <c>true</c> try to load/save the certificate from rootCert.pfx.</param>
/// <returns>
/// true if succeeded, else false
/// </returns>
public
bool
CreateTrustedRootCertificate
(
bool
persistToFile
=
true
)
{
if
(
RootCertificate
==
null
)
if
(
persistToFile
&&
RootCertificate
==
null
)
{
RootCertificate
=
LoadRootCertificate
();
}
...
...
@@ -186,7 +189,7 @@ namespace Titanium.Web.Proxy.Network
exceptionFunc
(
e
);
}
if
(
RootCertificate
!=
null
)
if
(
persistToFile
&&
RootCertificate
!=
null
)
{
try
{
...
...
@@ -205,7 +208,7 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// Trusts the root certificate.
/// </summary>
internal
void
TrustRootCertificate
()
public
void
TrustRootCertificate
()
{
//current user
TrustRootCertificate
(
StoreLocation
.
CurrentUser
);
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
fd2d0cb7
...
...
@@ -24,11 +24,6 @@ namespace Titanium.Web.Proxy
/// </summary>
private
bool
proxyRunning
{
get
;
set
;
}
/// <summary>
/// Manages certificates used by this proxy
/// </summary>
private
CertificateManager
certificateManager
{
get
;
set
;
}
/// <summary>
/// An default exception log func
/// </summary>
...
...
@@ -64,13 +59,18 @@ namespace Titanium.Web.Proxy
/// </summary>
public
int
BufferSize
{
get
;
set
;
}
=
8192
;
/// <summary>
/// Manages certificates used by this proxy
/// </summary>
public
CertificateManager
CertificateManager
{
get
;
}
/// <summary>
/// The root certificate
/// </summary>
public
X509Certificate2
RootCertificate
{
get
{
return
c
ertificateManager
.
RootCertificate
;
}
set
{
c
ertificateManager
.
RootCertificate
=
value
;
}
get
{
return
C
ertificateManager
.
RootCertificate
;
}
set
{
C
ertificateManager
.
RootCertificate
=
value
;
}
}
/// <summary>
...
...
@@ -79,8 +79,8 @@ namespace Titanium.Web.Proxy
/// </summary>
public
string
RootCertificateIssuerName
{
get
{
return
c
ertificateManager
.
Issuer
;
}
set
{
c
ertificateManager
.
RootCertificateName
=
value
;
}
get
{
return
C
ertificateManager
.
Issuer
;
}
set
{
C
ertificateManager
.
RootCertificateName
=
value
;
}
}
/// <summary>
...
...
@@ -92,8 +92,8 @@ namespace Titanium.Web.Proxy
/// </summary>
public
string
RootCertificateName
{
get
{
return
c
ertificateManager
.
RootCertificateName
;
}
set
{
c
ertificateManager
.
Issuer
=
value
;
}
get
{
return
C
ertificateManager
.
RootCertificateName
;
}
set
{
C
ertificateManager
.
Issuer
=
value
;
}
}
/// <summary>
...
...
@@ -121,8 +121,8 @@ namespace Titanium.Web.Proxy
/// </summary>
public
CertificateEngine
CertificateEngine
{
get
{
return
c
ertificateManager
.
Engine
;
}
set
{
c
ertificateManager
.
Engine
=
value
;
}
get
{
return
C
ertificateManager
.
Engine
;
}
set
{
C
ertificateManager
.
Engine
=
value
;
}
}
/// <summary>
...
...
@@ -251,7 +251,7 @@ namespace Titanium.Web.Proxy
new
FireFoxProxySettingsManager
();
#endif
c
ertificateManager
=
new
CertificateManager
(
ExceptionFunc
);
C
ertificateManager
=
new
CertificateManager
(
ExceptionFunc
);
if
(
rootCertificateName
!=
null
)
{
RootCertificateName
=
rootCertificateName
;
...
...
@@ -356,7 +356,7 @@ namespace Titanium.Web.Proxy
EnsureRootCertificate
();
//If certificate was trusted by the machine
if
(
c
ertificateManager
.
CertValidated
)
if
(
C
ertificateManager
.
CertValidated
)
{
systemProxySettingsManager
.
SetHttpsProxy
(
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Any
)
|
...
...
@@ -435,7 +435,7 @@ namespace Titanium.Web.Proxy
Listen
(
endPoint
);
}
c
ertificateManager
.
ClearIdleCertificates
(
CertificateCacheTimeOutMinutes
);
C
ertificateManager
.
ClearIdleCertificates
(
CertificateCacheTimeOutMinutes
);
proxyRunning
=
true
;
}
...
...
@@ -468,7 +468,7 @@ namespace Titanium.Web.Proxy
ProxyEndPoints
.
Clear
();
c
ertificateManager
?.
StopClearIdleCertificates
();
C
ertificateManager
?.
StopClearIdleCertificates
();
proxyRunning
=
false
;
}
...
...
@@ -483,7 +483,7 @@ namespace Titanium.Web.Proxy
Stop
();
}
c
ertificateManager
?.
Dispose
();
C
ertificateManager
?.
Dispose
();
}
/// <summary>
...
...
@@ -543,13 +543,13 @@ namespace Titanium.Web.Proxy
private
void
EnsureRootCertificate
()
{
if
(!
c
ertificateManager
.
CertValidated
)
if
(!
C
ertificateManager
.
CertValidated
)
{
c
ertificateManager
.
CreateTrustedRootCertificate
();
C
ertificateManager
.
CreateTrustedRootCertificate
();
if
(
TrustRootCertificate
)
{
c
ertificateManager
.
TrustRootCertificate
();
C
ertificateManager
.
TrustRootCertificate
();
}
}
}
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
fd2d0cb7
...
...
@@ -110,7 +110,7 @@ namespace Titanium.Web.Proxy
{
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
await
sslStream
.
AuthenticateAsServerAsync
(
certificate
,
false
,
...
...
@@ -177,7 +177,7 @@ namespace Titanium.Web.Proxy
var
sslStream
=
new
SslStream
(
clientStream
,
true
);
//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
{
...
...
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