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
1405c3ab
Commit
1405c3ab
authored
Mar 12, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into beta
parents
a988e27d
5d22fe00
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
308 additions
and
250 deletions
+308
-250
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+3
-1
MainWindow.xaml.cs
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
+2
-5
CertificateManagerTests.cs
...s/Titanium.Web.Proxy.UnitTests/CertificateManagerTests.cs
+33
-27
EndPoint.cs
Titanium.Web.Proxy/Models/EndPoint.cs
+0
-36
BCCertificateMaker.cs
Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs
+2
-3
WinCertificateMaker.cs
...nium.Web.Proxy/Network/Certificate/WinCertificateMaker.cs
+2
-11
CertificateManager.cs
Titanium.Web.Proxy/Network/CertificateManager.cs
+259
-154
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+2
-2
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+0
-10
ProxyConstants.cs
Titanium.Web.Proxy/Shared/ProxyConstants.cs
+5
-1
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
1405c3ab
...
@@ -32,8 +32,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -32,8 +32,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
proxyServer
=
new
ProxyServer
();
proxyServer
=
new
ProxyServer
();
//generate root certificate without storing it in file system
//generate root certificate without storing it in file system
//proxyServer.CertificateManager.CreateTrustedRootCertificate(false);
//proxyServer.CertificateManager.CreateRootCertificate(false);
//proxyServer.CertificateManager.TrustRootCertificate();
//proxyServer.CertificateManager.TrustRootCertificate();
//proxyServer.CertificateManager.TrustRootCertificateAsAdmin();
proxyServer
.
ExceptionFunc
=
exception
=>
Console
.
WriteLine
(
exception
.
Message
);
proxyServer
.
ExceptionFunc
=
exception
=>
Console
.
WriteLine
(
exception
.
Message
);
proxyServer
.
ForwardToUpstreamGateway
=
true
;
proxyServer
.
ForwardToUpstreamGateway
=
true
;
...
...
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
View file @
1405c3ab
...
@@ -88,11 +88,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -88,11 +88,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf
////note : load now (if existed)
////note : load now (if existed)
//proxyServer.CertificateManager.LoadRootCertificate(@"C:\NameFolder\rootCert.pfx", "PfxPassword");
//proxyServer.CertificateManager.LoadRootCertificate(@"C:\NameFolder\rootCert.pfx", "PfxPassword");
var
explicitEndPoint
=
new
ExplicitProxyEndPoint
(
IPAddress
.
Any
,
8000
,
true
)
var
explicitEndPoint
=
new
ExplicitProxyEndPoint
(
IPAddress
.
Any
,
8000
,
true
);
{
ExcludedHttpsHostNameRegex
=
new
[]
{
"ssllabs.com"
},
//IncludedHttpsHostNameRegex = new string[0],
};
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
//proxyServer.UpStreamHttpProxy = new ExternalProxy
//proxyServer.UpStreamHttpProxy = new ExternalProxy
...
...
Tests/Titanium.Web.Proxy.UnitTests/CertificateManagerTests.cs
View file @
1405c3ab
...
@@ -15,25 +15,27 @@ namespace Titanium.Web.Proxy.UnitTests
...
@@ -15,25 +15,27 @@ namespace Titanium.Web.Proxy.UnitTests
private
readonly
Random
random
=
new
Random
();
private
readonly
Random
random
=
new
Random
();
[
TestMethod
]
[
TestMethod
]
public
async
Task
Simple_Create_Certificate_Test
()
public
async
Task
Simple_
BC_
Create_Certificate_Test
()
{
{
var
tasks
=
new
List
<
Task
>();
var
tasks
=
new
List
<
Task
>();
var
mgr
=
new
CertificateManager
(
new
Lazy
<
Action
<
Exception
>>(()
=>
(
e
=>
{
})).
Value
);
var
mgr
=
new
CertificateManager
(
new
Lazy
<
Action
<
Exception
>>(()
=>
(
e
=>
{
//Console.WriteLine(e.ToString() + e.InnerException != null ? e.InnerException.ToString() : string.Empty);
})).
Value
);
mgr
.
CertificateEngine
=
CertificateEngine
.
BouncyCastle
;
mgr
.
ClearIdleCertificates
();
mgr
.
ClearIdleCertificates
();
for
(
int
i
=
0
;
i
<
5
;
i
++)
foreach
(
string
host
in
hostNames
)
foreach
(
string
host
in
hostNames
)
{
tasks
.
Add
(
Task
.
Run
(
async
()
=>
{
{
tasks
.
Add
(
Task
.
Run
(()
=>
//get the connection
{
var
certificate
=
await
mgr
.
CreateCertificateAsync
(
host
);
//get the connection
var
certificate
=
mgr
.
CreateCertificate
(
host
,
false
);
Assert
.
IsNotNull
(
certificate
);
Assert
.
IsNotNull
(
certificate
);
}));
}));
}
}
await
Task
.
WhenAll
(
tasks
.
ToArray
());
await
Task
.
WhenAll
(
tasks
.
ToArray
());
...
@@ -42,30 +44,34 @@ namespace Titanium.Web.Proxy.UnitTests
...
@@ -42,30 +44,34 @@ 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
//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
()
{
{
var
tasks
=
new
List
<
Task
>();
var
tasks
=
new
List
<
Task
>();
var
mgr
=
new
CertificateManager
(
new
Lazy
<
Action
<
Exception
>>(()
=>
(
e
=>
{
})).
Value
);
var
mgr
=
new
CertificateManager
(
new
Lazy
<
Action
<
Exception
>>(()
=>
(
e
=>
{
//Console.WriteLine(e.ToString() + e.InnerException != null ? e.InnerException.ToString() : string.Empty);
})).
Value
);
mgr
.
CertificateEngine
=
CertificateEngine
.
DefaultWindows
;
mgr
.
CreateRootCertificate
(
true
);
mgr
.
CreateRootCertificate
(
true
);
mgr
.
TrustRootCertificate
();
mgr
.
TrustRootCertificate
(
true
);
mgr
.
ClearIdleCertificates
();
mgr
.
ClearIdleCertificates
();
mgr
.
CertificateEngine
=
CertificateEngine
.
DefaultWindows
;
foreach
(
string
host
in
hostNames
)
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
foreach
(
string
host
in
hostNames
)
tasks
.
Add
(
Task
.
Run
(
async
()
=>
{
{
//get the connection
tasks
.
Add
(
Task
.
Run
(()
=>
var
certificate
=
await
mgr
.
CreateCertificateAsync
(
host
);
{
//get the connection
Assert
.
IsNotNull
(
certificate
);
var
certificate
=
mgr
.
CreateCertificate
(
host
,
false
);
}));
Assert
.
IsNotNull
(
certificate
);
}
}));
}
await
Task
.
WhenAll
(
tasks
.
ToArray
());
await
Task
.
WhenAll
(
tasks
.
ToArray
());
mgr
.
RemoveTrustedRootCertificate
(
true
);
mgr
.
StopClearIdleCertificates
();
mgr
.
StopClearIdleCertificates
();
}
}
}
}
...
...
Titanium.Web.Proxy/Models/EndPoint.cs
View file @
1405c3ab
...
@@ -75,42 +75,6 @@ namespace Titanium.Web.Proxy.Models
...
@@ -75,42 +75,6 @@ namespace Titanium.Web.Proxy.Models
/// </summary>
/// </summary>
public
X509Certificate2
GenericCertificate
{
get
;
set
;
}
public
X509Certificate2
GenericCertificate
{
get
;
set
;
}
/// <summary>
/// List of host names to exclude using Regular Expressions.
/// </summary>
[
Obsolete
(
"ExcludedHttpsHostNameRegex is deprecated, please use BeforeTunnelConnect event instead."
)]
public
IEnumerable
<
string
>
ExcludedHttpsHostNameRegex
{
get
{
return
ExcludedHttpsHostNameRegexList
?.
Select
(
x
=>
x
.
ToString
()).
ToList
();
}
set
{
if
(
IncludedHttpsHostNameRegex
!=
null
)
{
throw
new
ArgumentException
(
"Cannot set excluded when included is set"
);
}
ExcludedHttpsHostNameRegexList
=
value
?.
Select
(
x
=>
new
Regex
(
x
,
RegexOptions
.
Compiled
)).
ToList
();
}
}
/// <summary>
/// List of host names to exclude using Regular Expressions.
/// </summary>
[
Obsolete
(
"IncludedHttpsHostNameRegex is deprecated, please use BeforeTunnelConnect event instead."
)]
public
IEnumerable
<
string
>
IncludedHttpsHostNameRegex
{
get
{
return
IncludedHttpsHostNameRegexList
?.
Select
(
x
=>
x
.
ToString
()).
ToList
();
}
set
{
if
(
ExcludedHttpsHostNameRegex
!=
null
)
{
throw
new
ArgumentException
(
"Cannot set included when excluded is set"
);
}
IncludedHttpsHostNameRegexList
=
value
?.
Select
(
x
=>
new
Regex
(
x
,
RegexOptions
.
Compiled
)).
ToList
();
}
}
/// <summary>
/// <summary>
/// Return true if this HTTP connect request should'nt be decrypted and instead be relayed
/// Return true if this HTTP connect request should'nt be decrypted and instead be relayed
/// Valid only for explicit endpoints
/// Valid only for explicit endpoints
...
...
Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs
View file @
1405c3ab
...
@@ -17,6 +17,7 @@ using Org.BouncyCastle.Pkcs;
...
@@ -17,6 +17,7 @@ using Org.BouncyCastle.Pkcs;
using
Org.BouncyCastle.Security
;
using
Org.BouncyCastle.Security
;
using
Org.BouncyCastle.Utilities
;
using
Org.BouncyCastle.Utilities
;
using
Org.BouncyCastle.X509
;
using
Org.BouncyCastle.X509
;
using
Titanium.Web.Proxy.Shared
;
namespace
Titanium.Web.Proxy.Network.Certificate
namespace
Titanium.Web.Proxy.Network.Certificate
{
{
...
@@ -25,8 +26,6 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -25,8 +26,6 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// </summary>
/// </summary>
internal
class
BCCertificateMaker
:
ICertificateMaker
internal
class
BCCertificateMaker
:
ICertificateMaker
{
{
public
static
readonly
Regex
CNRemoverRegex
=
new
Regex
(
@"^CN\s*=\s*"
,
RegexOptions
.
IgnoreCase
|
RegexOptions
.
Compiled
);
private
const
int
certificateValidDays
=
1825
;
private
const
int
certificateValidDays
=
1825
;
private
const
int
certificateGraceDays
=
366
;
private
const
int
certificateGraceDays
=
366
;
...
@@ -149,7 +148,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -149,7 +148,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
{
{
try
try
{
{
x509Certificate
.
FriendlyName
=
CNRemoverRegex
.
Replace
(
subjectName
,
string
.
Empty
);
x509Certificate
.
FriendlyName
=
ProxyConstants
.
CNRemoverRegex
.
Replace
(
subjectName
,
string
.
Empty
);
}
}
catch
(
PlatformNotSupportedException
)
catch
(
PlatformNotSupportedException
)
{
{
...
...
Titanium.Web.Proxy/Network/Certificate/WinCertificateMaker.cs
View file @
1405c3ab
...
@@ -250,17 +250,8 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -250,17 +250,8 @@ namespace Titanium.Web.Proxy.Network.Certificate
typeX509Enrollment
.
InvokeMember
(
"InstallResponse"
,
BindingFlags
.
InvokeMethod
,
null
,
x509Enrollment
,
typeValue
);
typeX509Enrollment
.
InvokeMember
(
"InstallResponse"
,
BindingFlags
.
InvokeMethod
,
null
,
x509Enrollment
,
typeValue
);
typeValue
=
new
object
[]
{
null
,
0
,
1
};
typeValue
=
new
object
[]
{
null
,
0
,
1
};
try
string
empty
=
(
string
)
typeX509Enrollment
.
InvokeMember
(
"CreatePFX"
,
BindingFlags
.
InvokeMethod
,
null
,
x509Enrollment
,
typeValue
);
{
return
new
X509Certificate2
(
Convert
.
FromBase64String
(
empty
),
string
.
Empty
,
X509KeyStorageFlags
.
Exportable
);
string
empty
=
(
string
)
typeX509Enrollment
.
InvokeMember
(
"CreatePFX"
,
BindingFlags
.
InvokeMethod
,
null
,
x509Enrollment
,
typeValue
);
return
new
X509Certificate2
(
Convert
.
FromBase64String
(
empty
),
string
.
Empty
,
X509KeyStorageFlags
.
Exportable
);
}
catch
(
Exception
)
{
// ignored
}
return
null
;
}
}
private
X509Certificate2
MakeCertificateInternal
(
string
sSubjectCN
,
bool
isRoot
,
private
X509Certificate2
MakeCertificateInternal
(
string
sSubjectCN
,
bool
isRoot
,
...
...
Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
1405c3ab
This diff is collapsed.
Click to expand it.
Titanium.Web.Proxy/ProxyServer.cs
View file @
1405c3ab
...
@@ -245,8 +245,8 @@ namespace Titanium.Web.Proxy
...
@@ -245,8 +245,8 @@ namespace Titanium.Web.Proxy
}
}
CertificateManager
=
new
CertificateManager
(
ExceptionFunc
);
CertificateManager
=
new
CertificateManager
(
ExceptionFunc
);
CertificateManager
.
TrustRoot
=
trustRootCertificate
;
CertificateManager
.
User
TrustRoot
=
trustRootCertificate
;
CertificateManager
.
TrustRootAsAdministrator
=
trustRootCertificateAsAdmin
;
CertificateManager
.
Machine
TrustRootAsAdministrator
=
trustRootCertificateAsAdmin
;
if
(
rootCertificateName
!=
null
)
if
(
rootCertificateName
!=
null
)
{
{
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
1405c3ab
...
@@ -67,16 +67,6 @@ namespace Titanium.Web.Proxy
...
@@ -67,16 +67,6 @@ namespace Titanium.Web.Proxy
//filter out excluded host names
//filter out excluded host names
bool
excluded
=
false
;
bool
excluded
=
false
;
if
(
endPoint
.
ExcludedHttpsHostNameRegex
!=
null
)
{
excluded
=
endPoint
.
ExcludedHttpsHostNameRegexList
.
Any
(
x
=>
x
.
IsMatch
(
connectHostname
));
}
if
(
endPoint
.
IncludedHttpsHostNameRegex
!=
null
)
{
excluded
=
!
endPoint
.
IncludedHttpsHostNameRegexList
.
Any
(
x
=>
x
.
IsMatch
(
connectHostname
));
}
if
(
endPoint
.
BeforeTunnelConnect
!=
null
)
if
(
endPoint
.
BeforeTunnelConnect
!=
null
)
{
{
excluded
=
await
endPoint
.
BeforeTunnelConnect
(
connectHostname
);
excluded
=
await
endPoint
.
BeforeTunnelConnect
(
connectHostname
);
...
...
Titanium.Web.Proxy/Shared/ProxyConstants.cs
View file @
1405c3ab
namespace
Titanium.Web.Proxy.Shared
using
System.Text.RegularExpressions
;
namespace
Titanium.Web.Proxy.Shared
{
{
/// <summary>
/// <summary>
/// Literals shared by Proxy Server
/// Literals shared by Proxy Server
...
@@ -13,5 +15,7 @@
...
@@ -13,5 +15,7 @@
internal
static
readonly
char
[]
EqualSplit
=
{
'='
};
internal
static
readonly
char
[]
EqualSplit
=
{
'='
};
internal
static
readonly
byte
[]
NewLine
=
{(
byte
)
'\r'
,
(
byte
)
'\n'
};
internal
static
readonly
byte
[]
NewLine
=
{(
byte
)
'\r'
,
(
byte
)
'\n'
};
public
static
readonly
Regex
CNRemoverRegex
=
new
Regex
(
@"^CN\s*=\s*"
,
RegexOptions
.
IgnoreCase
|
RegexOptions
.
Compiled
);
}
}
}
}
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