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
6f1c42df
Commit
6f1c42df
authored
Mar 09, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update sample code
parent
68eec168
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
13 deletions
+28
-13
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+5
-6
README.md
README.md
+23
-7
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
6f1c42df
...
@@ -68,9 +68,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -68,9 +68,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
//GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
//GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
};
};
//Exclude Https addresses you don't want to proxy
//Fired when a CONNECT request is received
//Useful for clients that use certificate pinning
//for example google.com and dropbox.com
explicitEndPoint
.
BeforeTunnelConnect
+=
OnBeforeTunnelConnect
;
explicitEndPoint
.
BeforeTunnelConnect
+=
OnBeforeTunnelConnect
;
...
@@ -130,10 +128,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -130,10 +128,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
private
async
Task
<
bool
>
OnBeforeTunnelConnect
(
string
hostname
)
private
async
Task
<
bool
>
OnBeforeTunnelConnect
(
string
hostname
)
{
{
if
(
hostname
.
Contains
(
"
amazon.com"
)
||
hostname
.
Contains
(
"paypal
.com"
))
if
(
hostname
.
Contains
(
"
dropbox
.com"
))
{
{
//exclude bing.com and google.com from being decrypted
//Exclude Https addresses you don't want to proxy
//instead it will be relayed via a secure TCP tunnel
//Useful for clients that use certificate pinning
//for example dropbox.com
return
await
Task
.
FromResult
(
true
);
return
await
Task
.
FromResult
(
true
);
}
}
else
else
...
...
README.md
View file @
6f1c42df
...
@@ -66,17 +66,17 @@ proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection;
...
@@ -66,17 +66,17 @@ proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection;
var
explicitEndPoint
=
new
ExplicitProxyEndPoint
(
IPAddress
.
Any
,
8000
,
true
)
var
explicitEndPoint
=
new
ExplicitProxyEndPoint
(
IPAddress
.
Any
,
8000
,
true
)
{
{
//Exclude HTTPS addresses you don't want to proxy
//You can set only one of the ExcludedHttpsHostNameRegex and IncludedHttpsHostNameRegex properties, otherwise ArgumentException will be thrown
//Useful for clients that use certificate pinning
//for example dropbox.com
// ExcludedHttpsHostNameRegex = new List<string>() { "google.com", "dropbox.com" }
//Use self-issued generic certificate on all
HTTPS
requests
//Use self-issued generic certificate on all
https
requests
//Optimizes performance by not creating a certificate for each
HTTPS
-enabled domain
//Optimizes performance by not creating a certificate for each
https
-enabled domain
//Useful when certificate trust is not required by proxy clients
//Useful when certificate trust is not required by proxy clients
//
GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
//GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
};
};
//Fired when a CONNECT request is received
explicitEndPoint
.
BeforeTunnelConnect
+=
OnBeforeTunnelConnect
;
//An explicit endpoint is where the client knows about the existence of a proxy
//An explicit endpoint is where the client knows about the existence of a proxy
//So client sends request in a proxy friendly manner
//So client sends request in a proxy friendly manner
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
...
@@ -109,6 +109,7 @@ proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
...
@@ -109,6 +109,7 @@ proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
Console
.
Read
();
Console
.
Read
();
//Unsubscribe & Quit
//Unsubscribe & Quit
explicitEndPoint
.
BeforeTunnelConnect
-=
OnBeforeTunnelConnect
;
proxyServer
.
BeforeRequest
-=
OnRequest
;
proxyServer
.
BeforeRequest
-=
OnRequest
;
proxyServer
.
BeforeResponse
-=
OnResponse
;
proxyServer
.
BeforeResponse
-=
OnResponse
;
proxyServer
.
ServerCertificateValidationCallback
-=
OnCertificateValidation
;
proxyServer
.
ServerCertificateValidationCallback
-=
OnCertificateValidation
;
...
@@ -125,6 +126,21 @@ Sample request and response event handlers
...
@@ -125,6 +126,21 @@ Sample request and response event handlers
private
IDictionary
<
Guid
,
string
>
requestBodyHistory
private
IDictionary
<
Guid
,
string
>
requestBodyHistory
=
new
ConcurrentDictionary
<
Guid
,
string
>();
=
new
ConcurrentDictionary
<
Guid
,
string
>();
private
async
Task
<
bool
>
OnBeforeTunnelConnect
(
string
hostname
)
{
if
(
hostname
.
Contains
(
"dropbox.com"
))
{
//Exclude Https addresses you don't want to proxy
//Useful for clients that use certificate pinning
//for example dropbox.com
return
await
Task
.
FromResult
(
true
);
}
else
{
return
await
Task
.
FromResult
(
false
);
}
}
public
async
Task
OnRequest
(
object
sender
,
SessionEventArgs
e
)
public
async
Task
OnRequest
(
object
sender
,
SessionEventArgs
e
)
{
{
Console
.
WriteLine
(
e
.
WebSession
.
Request
.
Url
);
Console
.
WriteLine
(
e
.
WebSession
.
Request
.
Url
);
...
...
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