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
477a3d24
Commit
477a3d24
authored
May 22, 2017
by
justcoding121
Committed by
justcoding121
May 22, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#246 Create less certificates
parent
e261513c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
10 deletions
+50
-10
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+10
-7
HttpHelper.cs
Titanium.Web.Proxy/Helpers/HttpHelper.cs
+36
-1
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+3
-1
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+1
-1
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
477a3d24
...
@@ -13,7 +13,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -13,7 +13,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
private
readonly
ProxyServer
proxyServer
;
private
readonly
ProxyServer
proxyServer
;
//share requestBody outside handlers
//share requestBody outside handlers
private
readonly
Dictionary
<
Guid
,
string
>
requestBodyHistory
=
new
Dictionary
<
Guid
,
string
>();
//Using a dictionary is not a good idea since it can cause memory overflow
//ideally the data should be moved out of memory
//private readonly Dictionary<Guid, string> requestBodyHistory
// = new Dictionary<Guid, string>();
public
ProxyTestController
()
public
ProxyTestController
()
{
{
...
@@ -124,7 +127,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -124,7 +127,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
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
...
@@ -152,11 +155,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -152,11 +155,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
{
Console
.
WriteLine
(
"Active Server Connections:"
+
((
ProxyServer
)
sender
).
ServerConnectionCount
);
Console
.
WriteLine
(
"Active Server Connections:"
+
((
ProxyServer
)
sender
).
ServerConnectionCount
);
if
(
requestBodyHistory
.
ContainsKey
(
e
.
Id
))
//
if (requestBodyHistory.ContainsKey(e.Id))
{
//
{
//access request body by looking up the shared dictionary using requestId
//
//access request body by looking up the shared dictionary using requestId
var
requestBody
=
requestBodyHistory
[
e
.
Id
];
//
var requestBody = requestBodyHistory[e.Id];
}
//
}
//read response headers
//read response headers
var
responseHeaders
=
e
.
WebSession
.
Response
.
ResponseHeaders
;
var
responseHeaders
=
e
.
WebSession
.
Response
.
ResponseHeaders
;
...
...
Titanium.Web.Proxy/Helpers/H
eader
Helper.cs
→
Titanium.Web.Proxy/Helpers/H
ttp
Helper.cs
View file @
477a3d24
...
@@ -4,7 +4,7 @@ using Titanium.Web.Proxy.Shared;
...
@@ -4,7 +4,7 @@ using Titanium.Web.Proxy.Shared;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
{
{
internal
static
class
H
eader
Helper
internal
static
class
H
ttp
Helper
{
{
private
static
readonly
Encoding
defaultEncoding
=
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
private
static
readonly
Encoding
defaultEncoding
=
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
...
@@ -50,5 +50,40 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -50,5 +50,40 @@ namespace Titanium.Web.Proxy.Helpers
//return default if not specified
//return default if not specified
return
defaultEncoding
;
return
defaultEncoding
;
}
}
/// <summary>
/// Tries to get root domain from a given hostname
/// Adapted from below answer
/// https://stackoverflow.com/questions/16473838/get-domain-name-of-a-url-in-c-sharp-net
/// </summary>
/// <param name="hostname"></param>
/// <returns></returns>
internal
static
string
GetWildCardDomainName
(
string
hostname
)
{
/*all needed domain in lower case*/
/*for now just hard code most common ones */
string
[]
col
=
{
".com"
,
".net"
,
".org"
,
".cn"
,
".co.uk"
,
".co.in"
,
".co.us"
};
foreach
(
string
name
in
col
)
{
if
(
hostname
.
EndsWith
(
name
))
{
int
idx
=
hostname
.
LastIndexOf
(
name
);
int
sec
=
hostname
.
Substring
(
0
,
idx
-
1
).
LastIndexOf
(
'.'
);
if
(
hostname
.
Substring
(
0
,
sec
+
1
).
Contains
(
"."
))
{
var
rootDomain
=
hostname
.
Substring
(
sec
+
1
);
return
"*."
+
rootDomain
;
}
break
;
}
}
//return as it is
return
hostname
;
}
}
}
}
}
Titanium.Web.Proxy/RequestHandler.cs
View file @
477a3d24
...
@@ -113,8 +113,10 @@ namespace Titanium.Web.Proxy
...
@@ -113,8 +113,10 @@ namespace Titanium.Web.Proxy
{
{
sslStream
=
new
SslStream
(
clientStream
);
sslStream
=
new
SslStream
(
clientStream
);
var
certName
=
HttpHelper
.
GetWildCardDomainName
(
httpRemoteUri
.
Host
);
var
certificate
=
endPoint
.
GenericCertificate
??
var
certificate
=
endPoint
.
GenericCertificate
??
CertificateManager
.
CreateCertificate
(
httpRemoteUri
.
Host
,
false
);
CertificateManager
.
CreateCertificate
(
certName
,
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
,
...
...
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
477a3d24
...
@@ -74,7 +74,7 @@
...
@@ -74,7 +74,7 @@
<Compile
Include=
"EventArguments\CertificateValidationEventArgs.cs"
/>
<Compile
Include=
"EventArguments\CertificateValidationEventArgs.cs"
/>
<Compile
Include=
"Extensions\ByteArrayExtensions.cs"
/>
<Compile
Include=
"Extensions\ByteArrayExtensions.cs"
/>
<Compile
Include=
"Extensions\FuncExtensions.cs"
/>
<Compile
Include=
"Extensions\FuncExtensions.cs"
/>
<Compile
Include=
"Helpers\H
eader
Helper.cs"
/>
<Compile
Include=
"Helpers\H
ttp
Helper.cs"
/>
<Compile
Include=
"Extensions\StringExtensions.cs"
/>
<Compile
Include=
"Extensions\StringExtensions.cs"
/>
<Compile
Include=
"Helpers\BufferPool.cs"
/>
<Compile
Include=
"Helpers\BufferPool.cs"
/>
<Compile
Include=
"Helpers\CustomBufferedStream.cs"
/>
<Compile
Include=
"Helpers\CustomBufferedStream.cs"
/>
...
...
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