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
347adaab
Commit
347adaab
authored
Mar 12, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into beta
parents
1405c3ab
3b066c2e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
89 deletions
+105
-89
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+40
-40
CertificateManagerTests.cs
...s/Titanium.Web.Proxy.UnitTests/CertificateManagerTests.cs
+0
-1
CertificateManager.cs
Titanium.Web.Proxy/Network/CertificateManager.cs
+55
-17
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+10
-31
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
347adaab
...
@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
proxyServer
.
ExceptionFunc
=
exception
=>
Console
.
WriteLine
(
exception
.
Message
);
proxyServer
.
ExceptionFunc
=
exception
=>
Console
.
WriteLine
(
exception
.
Message
);
proxyServer
.
ForwardToUpstreamGateway
=
true
;
proxyServer
.
ForwardToUpstreamGateway
=
true
;
proxyServer
.
CertificateManager
.
SaveFakeCertificates
=
true
;
//optionally set the Certificate Engine
//optionally set the Certificate Engine
//Under Mono or Non-Windows runtimes only BouncyCastle will be supported
//Under Mono or Non-Windows runtimes only BouncyCastle will be supported
//proxyServer.CertificateManager.CertificateEngine = Network.CertificateEngine.BouncyCastle;
//proxyServer.CertificateManager.CertificateEngine = Network.CertificateEngine.BouncyCastle;
...
@@ -165,31 +165,31 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -165,31 +165,31 @@ namespace Titanium.Web.Proxy.Examples.Basic
// e.MultipartRequestPartSent += MultipartRequestPartSent;
// e.MultipartRequestPartSent += MultipartRequestPartSent;
//}
//}
if
(
e
.
WebSession
.
Request
.
HasBody
)
//
if (e.WebSession.Request.HasBody)
{
//
{
//Get/Set request body bytes
//
//Get/Set request body bytes
var
bodyBytes
=
await
e
.
GetRequestBody
();
//
var bodyBytes = await e.GetRequestBody();
await
e
.
SetRequestBody
(
bodyBytes
);
//
await e.SetRequestBody(bodyBytes);
//Get/Set request body as string
//
//Get/Set request body as string
string
bodyString
=
await
e
.
GetRequestBodyAsString
();
//
string bodyString = await e.GetRequestBodyAsString();
await
e
.
SetRequestBodyString
(
bodyString
);
//
await e.SetRequestBodyString(bodyString);
//requestBodyHistory[e.Id] = bodyString;
//
//requestBodyHistory[e.Id] = bodyString;
}
//
}
//To cancel a request with a custom HTML content
//To cancel a request with a custom HTML content
//Filter URL
//Filter URL
if
(
e
.
WebSession
.
Request
.
RequestUri
.
AbsoluteUri
.
Contains
(
"yahoo.com"
))
//
if (e.WebSession.Request.RequestUri.AbsoluteUri.Contains("yahoo.com"))
{
//
{
e
.
Ok
(
"<!DOCTYPE html>"
+
//
e.Ok("<!DOCTYPE html>" +
"<html><body><h1>"
+
//
"<html><body><h1>" +
"Website Blocked"
+
//
"Website Blocked" +
"</h1>"
+
//
"</h1>" +
"<p>Blocked by titanium web proxy.</p>"
+
//
"<p>Blocked by titanium web proxy.</p>" +
"</body>"
+
//
"</body>" +
"</html>"
);
//
"</html>");
}
//
}
////Redirect example
////Redirect example
//if (e.WebSession.Request.RequestUri.AbsoluteUri.Contains("wikipedia.org"))
//if (e.WebSession.Request.RequestUri.AbsoluteUri.Contains("wikipedia.org"))
...
@@ -219,27 +219,27 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -219,27 +219,27 @@ namespace Titanium.Web.Proxy.Examples.Basic
// var requestBody = requestBodyHistory[e.Id];
// var requestBody = requestBodyHistory[e.Id];
//}
//}
//read response headers
//
//
read response headers
responseHeaderHistory
[
e
.
Id
]
=
e
.
WebSession
.
Response
.
Headers
;
//
responseHeaderHistory[e.Id] = e.WebSession.Response.Headers;
// print out process id of current session
//
//
print out process id of current session
//Console.WriteLine($"PID: {e.WebSession.ProcessId.Value}");
//
//
Console.WriteLine($"PID: {e.WebSession.ProcessId.Value}");
//if (!e.ProxySession.Request.Host.Equals("medeczane.sgk.gov.tr")) return;
//
//
if (!e.ProxySession.Request.Host.Equals("medeczane.sgk.gov.tr")) return;
if
(
e
.
WebSession
.
Request
.
Method
==
"GET"
||
e
.
WebSession
.
Request
.
Method
==
"POST"
)
//
if (e.WebSession.Request.Method == "GET" || e.WebSession.Request.Method == "POST")
{
//
{
if
(
e
.
WebSession
.
Response
.
StatusCode
==
(
int
)
HttpStatusCode
.
OK
)
//
if (e.WebSession.Response.StatusCode == (int)HttpStatusCode.OK)
{
//
{
if
(
e
.
WebSession
.
Response
.
ContentType
!=
null
&&
e
.
WebSession
.
Response
.
ContentType
.
Trim
().
ToLower
().
Contains
(
"text/html"
))
//
if (e.WebSession.Response.ContentType != null && e.WebSession.Response.ContentType.Trim().ToLower().Contains("text/html"))
{
//
{
var
bodyBytes
=
await
e
.
GetResponseBody
();
//
var bodyBytes = await e.GetResponseBody();
await
e
.
SetResponseBody
(
bodyBytes
);
//
await e.SetResponseBody(bodyBytes);
string
body
=
await
e
.
GetResponseBodyAsString
();
//
string body = await e.GetResponseBodyAsString();
await
e
.
SetResponseBodyString
(
body
);
//
await e.SetResponseBodyString(body);
}
//
}
}
//
}
}
//
}
}
}
/// <summary>
/// <summary>
...
...
Tests/Titanium.Web.Proxy.UnitTests/CertificateManagerTests.cs
View file @
347adaab
...
@@ -43,7 +43,6 @@ namespace Titanium.Web.Proxy.UnitTests
...
@@ -43,7 +43,6 @@ namespace Titanium.Web.Proxy.UnitTests
}
}
//uncomment this to compare WinCert maker performance with BC (BC takes more time for same test above)
//uncomment this to compare WinCert maker performance with BC (BC takes more time for same test above)
//cannot run this test in build server since trusting the certificate won't happen successfully
[
TestMethod
]
[
TestMethod
]
public
async
Task
Simple_Create_Win_Certificate_Test
()
public
async
Task
Simple_Create_Win_Certificate_Test
()
{
{
...
...
Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
347adaab
...
@@ -67,18 +67,21 @@ namespace Titanium.Web.Proxy.Network
...
@@ -67,18 +67,21 @@ namespace Titanium.Web.Proxy.Network
internal
bool
CertValidated
=>
RootCertificate
!=
null
;
internal
bool
CertValidated
=>
RootCertificate
!=
null
;
/// <summary>
/// <summary>
/// Trust the RootCertificate used by this proxy server
/// Trust the RootCertificate used by this proxy server for current user
/// Note that this do not make the client trust the certificate!
/// This would import the root certificate to the certificate store of machine that runs this proxy server
/// </summary>
/// </summary>
internal
bool
UserTrustRoot
{
get
;
set
;
}
=
false
;
internal
bool
UserTrustRoot
{
get
;
set
;
}
=
false
;
/// <summary>
/// <summary>
/// Needs elevated permission. Works only on Windows.
/// Trust the RootCertificate used by this proxy server for current machine
/// <para>Puts the certificate to the local machine's certificate store.</para>
/// Needs elevated permission, otherwise will fail silently.
/// <para>Certutil.exe is a command-line program that is installed as part of Certificate Services</para>
/// </summary>
/// </summary>
internal
bool
MachineTrustRootAsAdministrator
{
get
;
set
;
}
=
false
;
internal
bool
MachineTrustRoot
{
get
;
set
;
}
=
false
;
/// <summary>
/// Whether trust operations should be done with elevated privillages
/// Will prompt with UAC if required. Works only on Windows.
/// </summary>
internal
bool
TrustRootAsAdministrator
{
get
;
set
;
}
=
false
;
/// <summary>
/// <summary>
/// Select Certificate Engine
/// Select Certificate Engine
...
@@ -186,9 +189,36 @@ namespace Titanium.Web.Proxy.Network
...
@@ -186,9 +189,36 @@ namespace Titanium.Web.Proxy.Network
public
X509KeyStorageFlags
StorageFlag
{
get
;
set
;
}
=
X509KeyStorageFlags
.
Exportable
;
public
X509KeyStorageFlags
StorageFlag
{
get
;
set
;
}
=
X509KeyStorageFlags
.
Exportable
;
internal
CertificateManager
(
Action
<
Exception
>
exceptionFunc
)
/// <summary>
/// Constructor.
/// </summary>
/// <param name="rootCertificateName">Name of root certificate.</param>
/// <param name="rootCertificateIssuerName">Name of root certificate issuer.</param>
/// <param name="userTrustRootCertificate"></param>
/// <param name="machineTrustRootCertificate">Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true</param>
/// <param name="trustRootCertificateAsAdmin "></param>
/// <param name="exceptionFunc"></param>
internal
CertificateManager
(
string
rootCertificateName
,
string
rootCertificateIssuerName
,
bool
userTrustRootCertificate
,
bool
machineTrustRootCertificate
,
bool
trustRootCertificateAsAdmin
,
Action
<
Exception
>
exceptionFunc
)
{
{
this
.
exceptionFunc
=
exceptionFunc
;
this
.
exceptionFunc
=
exceptionFunc
;
UserTrustRoot
=
userTrustRootCertificate
;
if
(
machineTrustRootCertificate
)
{
MachineTrustRoot
=
machineTrustRootCertificate
;
}
TrustRootAsAdministrator
=
trustRootCertificateAsAdmin
;
if
(
rootCertificateName
!=
null
)
{
RootCertificateName
=
rootCertificateName
;
}
if
(
rootCertificateIssuerName
!=
null
)
{
RootCertificateIssuerName
=
rootCertificateIssuerName
;
}
if
(
RunTime
.
IsWindows
)
if
(
RunTime
.
IsWindows
)
{
{
//this is faster in Windows based on tests (see unit test project CertificateManagerTests.cs)
//this is faster in Windows based on tests (see unit test project CertificateManagerTests.cs)
...
@@ -617,6 +647,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -617,6 +647,7 @@ namespace Titanium.Web.Proxy.Network
/// </summary>
/// </summary>
public
void
TrustRootCertificate
(
bool
machineTrusted
=
false
)
public
void
TrustRootCertificate
(
bool
machineTrusted
=
false
)
{
{
//currentUser\personal
//currentUser\personal
InstallCertificate
(
StoreName
.
My
,
StoreLocation
.
CurrentUser
);
InstallCertificate
(
StoreName
.
My
,
StoreLocation
.
CurrentUser
);
...
@@ -698,21 +729,20 @@ namespace Titanium.Web.Proxy.Network
...
@@ -698,21 +729,20 @@ namespace Titanium.Web.Proxy.Network
/// Ensure certificates are setup (creates root if required)
/// Ensure certificates are setup (creates root if required)
/// Also makes root certificate trusted based on initial setup from proxy constructor for user/machine trust.
/// Also makes root certificate trusted based on initial setup from proxy constructor for user/machine trust.
/// </summary>
/// </summary>
public
void
EnsureRootCertificate
(
bool
machineTrustRootCertificate
=
false
)
public
void
EnsureRootCertificate
()
{
{
if
(!
CertValidated
)
if
(!
CertValidated
)
{
{
CreateRootCertificate
();
CreateRootCertificate
();
}
}
if
(
UserTrustRoot
)
if
(
TrustRootAsAdministrator
)
{
{
TrustRootCertificate
(
machineTrustRootCertificate
);
TrustRootCertificate
AsAdmin
(
MachineTrustRoot
);
}
}
else
if
(
UserTrustRoot
)
if
(
MachineTrustRootAsAdministrator
)
{
{
TrustRootCertificate
AsAdmin
(
);
TrustRootCertificate
(
MachineTrustRoot
);
}
}
}
}
...
@@ -720,12 +750,20 @@ namespace Titanium.Web.Proxy.Network
...
@@ -720,12 +750,20 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// <summary>
/// Ensure certificates are setup (creates root if required)
/// Ensure certificates are setup (creates root if required)
/// Also makes root certificate trusted based on provided parameters
/// Also makes root certificate trusted based on provided parameters
/// Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true
/// </summary>
/// </summary>
public
void
EnsureRootCertificate
(
bool
userTrustRootCertificate
,
bool
machineTrustRootCertificate
,
bool
machineTrustRootCertificateAsAdmin
)
public
void
EnsureRootCertificate
(
bool
userTrustRootCertificate
=
true
,
bool
machineTrustRootCertificate
=
false
,
bool
trustRootCertificateAsAdmin
=
false
)
{
{
if
(
machineTrustRootCertificate
)
{
userTrustRootCertificate
=
true
;
}
UserTrustRoot
=
userTrustRootCertificate
;
UserTrustRoot
=
userTrustRootCertificate
;
MachineTrustRootAsAdministrator
=
machineTrustRootCertificateAsAdmin
;
MachineTrustRoot
=
machineTrustRootCertificate
;
EnsureRootCertificate
(
machineTrustRootCertificate
);
TrustRootAsAdministrator
=
trustRootCertificateAsAdmin
;
EnsureRootCertificate
();
}
}
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
347adaab
...
@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy
...
@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Seconds client/server connection are to be kept alive when waiting for read/write to complete
/// Seconds client/server connection are to be kept alive when waiting for read/write to complete
/// </summary>
/// </summary>
public
int
ConnectionTimeOutSeconds
{
get
;
set
;
}
public
int
ConnectionTimeOutSeconds
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Total number of active client connections
/// Total number of active client connections
...
@@ -208,31 +208,22 @@ namespace Titanium.Web.Proxy
...
@@ -208,31 +208,22 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Constructor
/// Constructor
/// </summary>
/// </summary>
public
ProxyServer
()
:
this
(
null
,
null
,
true
,
false
)
/// <param name="userTrustRootCertificate"></param>
/// <param name="machineTrustRootCertificate">Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true</param>
/// <param name="trustRootCertificateAsAdmin "></param>
public
ProxyServer
(
bool
userTrustRootCertificate
=
true
,
bool
machineTrustRootCertificate
=
false
,
bool
trustRootCertificateAsAdmin
=
false
)
:
this
(
null
,
null
,
userTrustRootCertificate
,
machineTrustRootCertificate
,
trustRootCertificateAsAdmin
)
{
{
}
}
/// <summary>
/// Constructor
/// </summary>
public
ProxyServer
(
bool
trustRoot
)
:
this
(
null
,
null
,
trustRoot
,
false
)
{
}
/// <summary>
/// Constructor
/// </summary>
public
ProxyServer
(
bool
trustRoot
,
bool
trustRootAsAdmin
)
:
this
(
null
,
null
,
trustRoot
,
trustRootAsAdmin
)
{
}
/// <summary>
/// <summary>
/// Constructor.
/// Constructor.
/// </summary>
/// </summary>
/// <param name="rootCertificateName">Name of root certificate.</param>
/// <param name="rootCertificateName">Name of root certificate.</param>
/// <param name="rootCertificateIssuerName">Name of root certificate issuer.</param>
/// <param name="rootCertificateIssuerName">Name of root certificate issuer.</param>
public
ProxyServer
(
string
rootCertificateName
,
string
rootCertificateIssuerName
,
bool
trustRootCertificate
,
bool
trustRootCertificateAsAdmin
)
/// <param name="userTrustRootCertificate"></param>
/// <param name="machineTrustRootCertificate">Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true</param>
/// <param name="trustRootCertificateAsAdmin "></param>
public
ProxyServer
(
string
rootCertificateName
,
string
rootCertificateIssuerName
,
bool
userTrustRootCertificate
=
true
,
bool
machineTrustRootCertificate
=
false
,
bool
trustRootCertificateAsAdmin
=
false
)
{
{
//default values
//default values
ConnectionTimeOutSeconds
=
30
;
ConnectionTimeOutSeconds
=
30
;
...
@@ -244,19 +235,7 @@ namespace Titanium.Web.Proxy
...
@@ -244,19 +235,7 @@ namespace Titanium.Web.Proxy
systemProxySettingsManager
=
new
SystemProxyManager
();
systemProxySettingsManager
=
new
SystemProxyManager
();
}
}
CertificateManager
=
new
CertificateManager
(
ExceptionFunc
);
CertificateManager
=
new
CertificateManager
(
rootCertificateName
,
rootCertificateIssuerName
,
userTrustRootCertificate
,
machineTrustRootCertificate
,
trustRootCertificateAsAdmin
,
ExceptionFunc
);
CertificateManager
.
UserTrustRoot
=
trustRootCertificate
;
CertificateManager
.
MachineTrustRootAsAdministrator
=
trustRootCertificateAsAdmin
;
if
(
rootCertificateName
!=
null
)
{
CertificateManager
.
RootCertificateName
=
rootCertificateName
;
}
if
(
rootCertificateIssuerName
!=
null
)
{
CertificateManager
.
RootCertificateIssuerName
=
rootCertificateIssuerName
;
}
}
}
/// <summary>
/// <summary>
...
...
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