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
a863fd15
Commit
a863fd15
authored
Oct 11, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix lock issues causing memory violation
parent
3b8ae98b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
35 deletions
+37
-35
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+24
-21
CertificateManager.cs
src/Titanium.Web.Proxy/Network/CertificateManager.cs
+13
-14
No files found.
examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
a863fd15
...
@@ -16,9 +16,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -16,9 +16,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
public
class
ProxyTestController
public
class
ProxyTestController
{
{
private
readonly
SemaphoreSlim
@lock
=
new
SemaphoreSlim
(
1
);
private
readonly
SemaphoreSlim
@lock
=
new
SemaphoreSlim
(
1
);
private
readonly
ProxyServer
proxyServer
;
private
readonly
ProxyServer
proxyServer
;
private
ExplicitProxyEndPoint
explicitEndPoint
;
private
ExplicitProxyEndPoint
explicitEndPoint
;
public
ProxyTestController
()
public
ProxyTestController
()
...
@@ -32,27 +30,13 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -32,27 +30,13 @@ namespace Titanium.Web.Proxy.Examples.Basic
proxyServer
.
ExceptionFunc
=
async
exception
=>
proxyServer
.
ExceptionFunc
=
async
exception
=>
{
{
await
@lock
.
WaitAsync
();
if
(
exception
is
ProxyHttpException
phex
)
try
{
{
var
color
=
Console
.
ForegroundColor
;
await
WriteToConsole
(
exception
.
Message
+
": "
+
phex
.
InnerException
?.
Message
,
ConsoleColor
.
Red
);
Console
.
ForegroundColor
=
ConsoleColor
.
Red
;
if
(
exception
is
ProxyHttpException
phex
)
{
Console
.
WriteLine
(
exception
.
Message
+
": "
+
phex
.
InnerException
?.
Message
);
}
else
{
Console
.
WriteLine
(
exception
.
Message
);
}
Console
.
ForegroundColor
=
color
;
}
}
finally
else
{
{
@lock
.
Release
(
);
await
WriteToConsole
(
exception
.
Message
,
ConsoleColor
.
Red
);
}
}
};
};
proxyServer
.
ForwardToUpstreamGateway
=
true
;
proxyServer
.
ForwardToUpstreamGateway
=
true
;
...
@@ -110,7 +94,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -110,7 +94,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
// Only explicit proxies can be set as system proxy!
// Only explicit proxies can be set as system proxy!
//proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
//proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
//proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
//proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
if
(
RunTime
.
IsWindows
)
if
(
RunTime
.
IsWindows
)
{
{
proxyServer
.
SetAsSystemProxy
(
explicitEndPoint
,
ProxyProtocolType
.
AllHttp
);
proxyServer
.
SetAsSystemProxy
(
explicitEndPoint
,
ProxyProtocolType
.
AllHttp
);
}
}
...
@@ -281,6 +265,24 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -281,6 +265,24 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
{
await
@lock
.
WaitAsync
();
await
@lock
.
WaitAsync
();
ConsoleColor
color
;
try
{
color
=
Console
.
ForegroundColor
;
}
finally
{
@lock
.
Release
();
}
await
WriteToConsole
(
message
,
color
);
}
private
async
Task
WriteToConsole
(
string
message
,
ConsoleColor
color
)
{
await
@lock
.
WaitAsync
();
try
try
{
{
Console
.
WriteLine
(
message
);
Console
.
WriteLine
(
message
);
...
@@ -289,6 +291,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -289,6 +291,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
{
@lock
.
Release
();
@lock
.
Release
();
}
}
}
}
///// <summary>
///// <summary>
...
...
src/Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
a863fd15
...
@@ -60,7 +60,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -60,7 +60,7 @@ namespace Titanium.Web.Proxy.Network
private
X509Certificate2
rootCertificate
;
private
X509Certificate2
rootCertificate
;
private
string
rootCertificateName
;
private
string
rootCertificateName
;
/// <summary>
/// <summary>
/// Initializes a new instance of the <see cref="CertificateManager"/> class.
/// Initializes a new instance of the <see cref="CertificateManager"/> class.
/// </summary>
/// </summary>
...
@@ -242,7 +242,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -242,7 +242,7 @@ namespace Titanium.Web.Proxy.Network
public
void
Dispose
()
public
void
Dispose
()
{
{
}
}
private
string
getRootCertificateDirectory
()
private
string
getRootCertificateDirectory
()
{
{
string
assemblyLocation
=
Assembly
.
GetExecutingAssembly
().
Location
;
string
assemblyLocation
=
Assembly
.
GetExecutingAssembly
().
Location
;
...
@@ -427,17 +427,16 @@ namespace Titanium.Web.Proxy.Network
...
@@ -427,17 +427,16 @@ namespace Titanium.Web.Proxy.Network
certificate
=
makeCertificate
(
certificateName
,
false
);
certificate
=
makeCertificate
(
certificateName
,
false
);
// store as cache
// store as cache
Task
.
Run
(()
=>
try
{
var
exported
=
certificate
.
Export
(
X509ContentType
.
Pkcs12
);
File
.
WriteAllBytes
(
certificatePath
,
exported
);
}
catch
(
Exception
e
)
{
{
try
ExceptionFunc
(
new
Exception
(
"Failed to save fake certificate."
,
e
));
{
}
File
.
WriteAllBytes
(
certificatePath
,
certificate
.
Export
(
X509ContentType
.
Pkcs12
));
}
catch
(
Exception
e
)
{
ExceptionFunc
(
new
Exception
(
"Failed to save fake certificate."
,
e
));
}
});
}
}
else
else
{
{
...
@@ -530,7 +529,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -530,7 +529,7 @@ namespace Titanium.Web.Proxy.Network
await
Task
.
Delay
(
1000
*
60
);
await
Task
.
Delay
(
1000
*
60
);
}
}
}
}
/// <summary>
/// <summary>
/// Stops the certificate cache clear process
/// Stops the certificate cache clear process
/// </summary>
/// </summary>
...
@@ -776,7 +775,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -776,7 +775,7 @@ namespace Titanium.Web.Proxy.Network
EnsureRootCertificate
();
EnsureRootCertificate
();
}
}
/// <summary>
/// <summary>
/// Determines whether the root certificate is trusted.
/// Determines whether the root certificate is trusted.
/// </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