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
f2b2ce52
Commit
f2b2ce52
authored
Oct 31, 2018
by
Anton Ryzhov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename ICertificateStorage to ICertificateCache
parent
46926db7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
19 deletions
+19
-19
CertificateManager.cs
src/Titanium.Web.Proxy/Network/CertificateManager.cs
+17
-17
DefaultCertificateDiskCache.cs
...Titanium.Web.Proxy/Network/DefaultCertificateDiskCache.cs
+1
-1
ICertificateCache.cs
src/Titanium.Web.Proxy/Network/ICertificateCache.cs
+1
-1
No files found.
src/Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
f2b2ce52
...
@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// <summary>
/// Cache dictionary
/// Cache dictionary
/// </summary>
/// </summary>
private
readonly
ConcurrentDictionary
<
string
,
CachedCertificate
>
c
ertificateCache
;
private
readonly
ConcurrentDictionary
<
string
,
CachedCertificate
>
c
achedCertificates
;
private
readonly
CancellationTokenSource
clearCertificatesTokenSource
;
private
readonly
CancellationTokenSource
clearCertificatesTokenSource
;
...
@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy.Network
private
string
rootCertificateName
;
private
string
rootCertificateName
;
private
ICertificate
Storage
certificateStorag
e
;
private
ICertificate
Cache
certificateCach
e
;
/// <summary>
/// <summary>
/// Initializes a new instance of the <see cref="CertificateManager"/> class.
/// Initializes a new instance of the <see cref="CertificateManager"/> class.
...
@@ -98,11 +98,11 @@ namespace Titanium.Web.Proxy.Network
...
@@ -98,11 +98,11 @@ namespace Titanium.Web.Proxy.Network
CertificateEngine
=
CertificateEngine
.
BouncyCastle
;
CertificateEngine
=
CertificateEngine
.
BouncyCastle
;
c
ertificateCache
=
new
ConcurrentDictionary
<
string
,
CachedCertificate
>();
c
achedCertificates
=
new
ConcurrentDictionary
<
string
,
CachedCertificate
>();
clearCertificatesTokenSource
=
new
CancellationTokenSource
();
clearCertificatesTokenSource
=
new
CancellationTokenSource
();
certificate
Storage
=
new
DefaultCertificateStorag
e
();
certificate
Cache
=
new
DefaultCertificateDiskCach
e
();
}
}
/// <summary>
/// <summary>
...
@@ -224,10 +224,10 @@ namespace Titanium.Web.Proxy.Network
...
@@ -224,10 +224,10 @@ namespace Titanium.Web.Proxy.Network
/// The service to save fake certificates.
/// The service to save fake certificates.
/// The default storage saves certificates in folder "crts" (will be created in proxy dll directory).
/// The default storage saves certificates in folder "crts" (will be created in proxy dll directory).
/// </summary>
/// </summary>
public
ICertificate
Storag
e
CertificateStorage
public
ICertificate
Cach
e
CertificateStorage
{
{
get
=>
certificate
Storag
e
;
get
=>
certificate
Cach
e
;
set
=>
certificate
Storage
=
value
??
new
DefaultCertificateStorag
e
();
set
=>
certificate
Cache
=
value
??
new
DefaultCertificateDiskCach
e
();
}
}
/// <summary>
/// <summary>
...
@@ -388,7 +388,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -388,7 +388,7 @@ namespace Titanium.Web.Proxy.Network
try
try
{
{
certificate
=
certificate
Storag
e
.
LoadCertificate
(
subjectName
,
StorageFlag
);
certificate
=
certificate
Cach
e
.
LoadCertificate
(
subjectName
,
StorageFlag
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
...
@@ -402,7 +402,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -402,7 +402,7 @@ namespace Titanium.Web.Proxy.Network
try
try
{
{
certificate
Storag
e
.
SaveCertificate
(
subjectName
,
certificate
);
certificate
Cach
e
.
SaveCertificate
(
subjectName
,
certificate
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
...
@@ -432,7 +432,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -432,7 +432,7 @@ namespace Titanium.Web.Proxy.Network
internal
async
Task
<
X509Certificate2
>
CreateCertificateAsync
(
string
certificateName
)
internal
async
Task
<
X509Certificate2
>
CreateCertificateAsync
(
string
certificateName
)
{
{
// check in cache first
// check in cache first
var
item
=
c
ertificateCache
.
GetOrAdd
(
certificateName
,
_
=>
var
item
=
c
achedCertificates
.
GetOrAdd
(
certificateName
,
_
=>
{
{
var
cached
=
new
CachedCertificate
();
var
cached
=
new
CachedCertificate
();
cached
.
CreationTask
=
Task
.
Run
(()
=>
cached
.
CreationTask
=
Task
.
Run
(()
=>
...
@@ -479,11 +479,11 @@ namespace Titanium.Web.Proxy.Network
...
@@ -479,11 +479,11 @@ namespace Titanium.Web.Proxy.Network
{
{
var
cutOff
=
DateTime
.
Now
.
AddMinutes
(-
1
*
CertificateCacheTimeOutMinutes
);
var
cutOff
=
DateTime
.
Now
.
AddMinutes
(-
1
*
CertificateCacheTimeOutMinutes
);
var
outdated
=
c
ertificateCache
.
Where
(
x
=>
x
.
Value
.
LastAccess
<
cutOff
).
ToList
();
var
outdated
=
c
achedCertificates
.
Where
(
x
=>
x
.
Value
.
LastAccess
<
cutOff
).
ToList
();
foreach
(
var
cache
in
outdated
)
foreach
(
var
cache
in
outdated
)
{
{
c
ertificateCache
.
TryRemove
(
cache
.
Key
,
out
_
);
c
achedCertificates
.
TryRemove
(
cache
.
Key
,
out
_
);
}
}
// after a minute come back to check for outdated certificates in cache
// after a minute come back to check for outdated certificates in cache
...
@@ -529,7 +529,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -529,7 +529,7 @@ namespace Titanium.Web.Proxy.Network
{
{
try
try
{
{
var
rootCert
=
certificate
Storag
e
.
LoadRootCertificate
(
PfxFilePath
,
PfxPassword
,
X509KeyStorageFlags
.
Exportable
);
var
rootCert
=
certificate
Cach
e
.
LoadRootCertificate
(
PfxFilePath
,
PfxPassword
,
X509KeyStorageFlags
.
Exportable
);
if
(
rootCert
!=
null
)
if
(
rootCert
!=
null
)
{
{
return
false
;
return
false
;
...
@@ -556,14 +556,14 @@ namespace Titanium.Web.Proxy.Network
...
@@ -556,14 +556,14 @@ namespace Titanium.Web.Proxy.Network
{
{
try
try
{
{
certificate
Storag
e
.
Clear
();
certificate
Cach
e
.
Clear
();
}
}
catch
catch
{
{
// ignore
// ignore
}
}
certificate
Storag
e
.
SaveRootCertificate
(
PfxFilePath
,
PfxPassword
,
RootCertificate
);
certificate
Cach
e
.
SaveRootCertificate
(
PfxFilePath
,
PfxPassword
,
RootCertificate
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
...
@@ -582,7 +582,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -582,7 +582,7 @@ namespace Titanium.Web.Proxy.Network
{
{
try
try
{
{
return
certificate
Storag
e
.
LoadRootCertificate
(
PfxFilePath
,
PfxPassword
,
X509KeyStorageFlags
.
Exportable
);
return
certificate
Cach
e
.
LoadRootCertificate
(
PfxFilePath
,
PfxPassword
,
X509KeyStorageFlags
.
Exportable
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
...
@@ -875,8 +875,8 @@ namespace Titanium.Web.Proxy.Network
...
@@ -875,8 +875,8 @@ namespace Titanium.Web.Proxy.Network
/// </summary>
/// </summary>
public
void
ClearRootCertificate
()
public
void
ClearRootCertificate
()
{
{
certificateStorage
.
Clear
();
certificateCache
.
Clear
();
certificateCache
.
Clear
();
cachedCertificates
.
Clear
();
rootCertificate
=
null
;
rootCertificate
=
null
;
}
}
}
}
...
...
src/Titanium.Web.Proxy/Network/DefaultCertificate
Storag
e.cs
→
src/Titanium.Web.Proxy/Network/DefaultCertificate
DiskCach
e.cs
View file @
f2b2ce52
...
@@ -5,7 +5,7 @@ using System.Security.Cryptography.X509Certificates;
...
@@ -5,7 +5,7 @@ using System.Security.Cryptography.X509Certificates;
namespace
Titanium.Web.Proxy.Network
namespace
Titanium.Web.Proxy.Network
{
{
internal
sealed
class
DefaultCertificate
Storage
:
ICertificateStorag
e
internal
sealed
class
DefaultCertificate
DiskCache
:
ICertificateCach
e
{
{
private
const
string
defaultCertificateDirectoryName
=
"crts"
;
private
const
string
defaultCertificateDirectoryName
=
"crts"
;
private
const
string
defaultCertificateFileExtension
=
".pfx"
;
private
const
string
defaultCertificateFileExtension
=
".pfx"
;
...
...
src/Titanium.Web.Proxy/Network/ICertificate
Storag
e.cs
→
src/Titanium.Web.Proxy/Network/ICertificate
Cach
e.cs
View file @
f2b2ce52
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
namespace
Titanium.Web.Proxy.Network
namespace
Titanium.Web.Proxy.Network
{
{
public
interface
ICertificate
Storag
e
public
interface
ICertificate
Cach
e
{
{
/// <summary>
/// <summary>
/// Loads the root certificate from the storage.
/// Loads the root certificate from the storage.
...
...
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