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
5c24d9cb
Commit
5c24d9cb
authored
Oct 31, 2018
by
Anton Ryzhov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding lock to CreateRootCertificate method
parent
f2b2ce52
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
39 deletions
+52
-39
CertificateManager.cs
src/Titanium.Web.Proxy/Network/CertificateManager.cs
+47
-38
DefaultCertificateDiskCache.cs
...Titanium.Web.Proxy/Network/DefaultCertificateDiskCache.cs
+5
-1
No files found.
src/Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
5c24d9cb
...
@@ -48,6 +48,8 @@ namespace Titanium.Web.Proxy.Network
...
@@ -48,6 +48,8 @@ namespace Titanium.Web.Proxy.Network
private
readonly
CancellationTokenSource
clearCertificatesTokenSource
;
private
readonly
CancellationTokenSource
clearCertificatesTokenSource
;
private
readonly
object
rootCertCreationLock
;
private
ICertificateMaker
certEngine
;
private
ICertificateMaker
certEngine
;
private
CertificateEngine
engine
;
private
CertificateEngine
engine
;
...
@@ -103,6 +105,8 @@ namespace Titanium.Web.Proxy.Network
...
@@ -103,6 +105,8 @@ namespace Titanium.Web.Proxy.Network
clearCertificatesTokenSource
=
new
CancellationTokenSource
();
clearCertificatesTokenSource
=
new
CancellationTokenSource
();
certificateCache
=
new
DefaultCertificateDiskCache
();
certificateCache
=
new
DefaultCertificateDiskCache
();
rootCertCreationLock
=
new
object
();
}
}
/// <summary>
/// <summary>
...
@@ -515,63 +519,68 @@ namespace Titanium.Web.Proxy.Network
...
@@ -515,63 +519,68 @@ namespace Titanium.Web.Proxy.Network
/// </returns>
/// </returns>
public
bool
CreateRootCertificate
(
bool
persistToFile
=
true
)
public
bool
CreateRootCertificate
(
bool
persistToFile
=
true
)
{
{
if
(
persistToFile
&&
RootCertificate
==
null
)
lock
(
rootCertCreationLock
)
{
RootCertificate
=
LoadRootCertificate
();
}
if
(
RootCertificate
!=
null
)
{
return
true
;
}
if
(!
OverwritePfxFile
)
{
{
try
if
(
persistToFile
&&
RootCertificate
==
null
)
{
{
var
rootCert
=
certificateCache
.
LoadRootCertificate
(
PfxFilePath
,
PfxPassword
,
X509KeyStorageFlags
.
Exportable
);
RootCertificate
=
LoadRootCertificate
();
if
(
rootCert
!=
null
)
{
return
false
;
}
}
}
catch
if
(
RootCertificate
!=
null
)
{
{
// root cert cannot be loaded
return
true
;
}
}
}
try
{
RootCertificate
=
CreateCertificate
(
RootCertificateName
,
true
);
}
catch
(
Exception
e
)
{
ExceptionFunc
(
e
);
}
if
(
persistToFile
&&
RootCertificate
!=
null
)
if
(!
OverwritePfxFile
)
{
try
{
{
try
try
{
{
certificateCache
.
Clear
();
var
rootCert
=
certificateCache
.
LoadRootCertificate
(
PfxFilePath
,
PfxPassword
,
X509KeyStorageFlags
.
Exportable
);
if
(
rootCert
!=
null
)
{
return
false
;
}
}
}
catch
catch
{
{
//
ignore
//
root cert cannot be loaded
}
}
}
certificateCache
.
SaveRootCertificate
(
PfxFilePath
,
PfxPassword
,
RootCertificate
);
try
{
RootCertificate
=
CreateCertificate
(
RootCertificateName
,
true
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
ExceptionFunc
(
e
);
ExceptionFunc
(
e
);
}
}
}
return
RootCertificate
!=
null
;
if
(
persistToFile
&&
RootCertificate
!=
null
)
{
try
{
try
{
certificateCache
.
Clear
();
}
catch
{
// ignore
}
certificateCache
.
SaveRootCertificate
(
PfxFilePath
,
PfxPassword
,
RootCertificate
);
}
catch
(
Exception
e
)
{
ExceptionFunc
(
e
);
}
}
return
RootCertificate
!=
null
;
}
}
}
/// <summary>
/// <summary>
...
@@ -600,7 +609,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -600,7 +609,7 @@ namespace Titanium.Web.Proxy.Network
/// </param>
/// </param>
/// <param name="password">Set a password for the .pfx file.</param>
/// <param name="password">Set a password for the .pfx file.</param>
/// <param name="overwritePfXFile">
/// <param name="overwritePfXFile">
/// true : replace an existing .pfx file if password is incorect or if
/// true : replace an existing .pfx file if password is incor
r
ect or if
/// RootCertificate==null.
/// RootCertificate==null.
/// </param>
/// </param>
/// <param name="storageFlag"></param>
/// <param name="storageFlag"></param>
...
...
src/Titanium.Web.Proxy/Network/DefaultCertificateDiskCache.cs
View file @
5c24d9cb
...
@@ -43,10 +43,14 @@ namespace Titanium.Web.Proxy.Network
...
@@ -43,10 +43,14 @@ namespace Titanium.Web.Proxy.Network
public
void
Clear
()
public
void
Clear
()
{
{
if
(
Directory
.
Exists
(
getCertificatePath
()))
try
{
{
Directory
.
Delete
(
getCertificatePath
(),
true
);
Directory
.
Delete
(
getCertificatePath
(),
true
);
}
}
catch
(
DirectoryNotFoundException
)
{
// do nothing
}
certificatePath
=
null
;
certificatePath
=
null
;
}
}
...
...
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