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
6d1a583b
Unverified
Commit
6d1a583b
authored
Nov 05, 2018
by
Jehonathan Thomas
Committed by
GitHub
Nov 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #520 from justcoding121/master
Beta
parents
26e77586
2a57f752
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
346 additions
and
166 deletions
+346
-166
Titanium.Web.Proxy.Network.CertificateManager.html
docs/api/Titanium.Web.Proxy.Network.CertificateManager.html
+60
-27
index.json
docs/index.json
+1
-1
xrefmap.yml
docs/xrefmap.yml
+13
-0
CachedCertificate.cs
src/Titanium.Web.Proxy/Network/CachedCertificate.cs
+4
-8
CertificateManager.cs
src/Titanium.Web.Proxy/Network/CertificateManager.cs
+113
-130
DefaultCertificateDiskCache.cs
...Titanium.Web.Proxy/Network/DefaultCertificateDiskCache.cs
+123
-0
ICertificateCache.cs
src/Titanium.Web.Proxy/Network/ICertificateCache.cs
+32
-0
No files found.
docs/api/Titanium.Web.Proxy.Network.CertificateManager.html
View file @
6d1a583b
This diff is collapsed.
Click to expand it.
docs/index.json
View file @
6d1a583b
This diff is collapsed.
Click to expand it.
docs/xrefmap.yml
View file @
6d1a583b
...
...
@@ -2970,6 +2970,19 @@ references:
isSpec
:
"
True"
fullName
:
Titanium.Web.Proxy.Network.CertificateManager.CertificateEngine
nameWithType
:
CertificateManager.CertificateEngine
-
uid
:
Titanium.Web.Proxy.Network.CertificateManager.CertificateStorage
name
:
CertificateStorage
href
:
api/Titanium.Web.Proxy.Network.CertificateManager.html#Titanium_Web_Proxy_Network_CertificateManager_CertificateStorage
commentId
:
P:Titanium.Web.Proxy.Network.CertificateManager.CertificateStorage
fullName
:
Titanium.Web.Proxy.Network.CertificateManager.CertificateStorage
nameWithType
:
CertificateManager.CertificateStorage
-
uid
:
Titanium.Web.Proxy.Network.CertificateManager.CertificateStorage*
name
:
CertificateStorage
href
:
api/Titanium.Web.Proxy.Network.CertificateManager.html#Titanium_Web_Proxy_Network_CertificateManager_CertificateStorage_
commentId
:
Overload:Titanium.Web.Proxy.Network.CertificateManager.CertificateStorage
isSpec
:
"
True"
fullName
:
Titanium.Web.Proxy.Network.CertificateManager.CertificateStorage
nameWithType
:
CertificateManager.CertificateStorage
-
uid
:
Titanium.Web.Proxy.Network.CertificateManager.ClearRootCertificate
name
:
ClearRootCertificate()
href
:
api/Titanium.Web.Proxy.Network.CertificateManager.html#Titanium_Web_Proxy_Network_CertificateManager_ClearRootCertificate
...
...
src/Titanium.Web.Proxy/Network/CachedCertificate.cs
View file @
6d1a583b
using
System
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Threading.Tasks
;
namespace
Titanium.Web.Proxy.Network
{
/// <summary>
/// An object that holds the cached certificate
/// </summary>
internal
class
CachedCertificate
internal
sealed
class
CachedCertificate
{
internal
CachedCertificate
()
{
LastAccess
=
DateTime
.
Now
;
}
internal
X509Certificate2
Certificate
{
get
;
set
;
}
/// <summary>
///
last time this certificate was used
/// Useful
l in determining its cache lifetime
///
Last time this certificate was used.
/// Useful
in determining its cache lifetime.
/// </summary>
internal
DateTime
LastAccess
{
get
;
set
;
}
}
...
...
src/Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
6d1a583b
This diff is collapsed.
Click to expand it.
src/Titanium.Web.Proxy/Network/DefaultCertificateDiskCache.cs
0 → 100644
View file @
6d1a583b
using
System
;
using
System.IO
;
using
System.Reflection
;
using
System.Security.Cryptography.X509Certificates
;
namespace
Titanium.Web.Proxy.Network
{
internal
sealed
class
DefaultCertificateDiskCache
:
ICertificateCache
{
private
const
string
defaultCertificateDirectoryName
=
"crts"
;
private
const
string
defaultCertificateFileExtension
=
".pfx"
;
private
const
string
defaultRootCertificateFileName
=
"rootCert"
+
defaultCertificateFileExtension
;
private
string
rootCertificatePath
;
private
string
certificatePath
;
public
X509Certificate2
LoadRootCertificate
(
string
name
,
string
password
,
X509KeyStorageFlags
storageFlags
)
{
string
filePath
=
getRootCertificatePath
(
name
);
return
loadCertificate
(
filePath
,
password
,
storageFlags
);
}
public
void
SaveRootCertificate
(
string
name
,
string
password
,
X509Certificate2
certificate
)
{
string
filePath
=
getRootCertificatePath
(
name
);
byte
[]
exported
=
certificate
.
Export
(
X509ContentType
.
Pkcs12
,
password
);
File
.
WriteAllBytes
(
filePath
,
exported
);
}
/// <inheritdoc />
public
X509Certificate2
LoadCertificate
(
string
subjectName
,
X509KeyStorageFlags
storageFlags
)
{
string
filePath
=
Path
.
Combine
(
getCertificatePath
(),
subjectName
+
defaultCertificateFileExtension
);
return
loadCertificate
(
filePath
,
string
.
Empty
,
storageFlags
);
}
/// <inheritdoc />
public
void
SaveCertificate
(
string
subjectName
,
X509Certificate2
certificate
)
{
string
filePath
=
Path
.
Combine
(
getCertificatePath
(),
subjectName
+
defaultCertificateFileExtension
);
byte
[]
exported
=
certificate
.
Export
(
X509ContentType
.
Pkcs12
);
File
.
WriteAllBytes
(
filePath
,
exported
);
}
public
void
Clear
()
{
try
{
Directory
.
Delete
(
getCertificatePath
(),
true
);
}
catch
(
DirectoryNotFoundException
)
{
// do nothing
}
certificatePath
=
null
;
}
private
X509Certificate2
loadCertificate
(
string
filePath
,
string
password
,
X509KeyStorageFlags
storageFlags
)
{
byte
[]
exported
;
try
{
exported
=
File
.
ReadAllBytes
(
filePath
);
}
catch
(
IOException
)
{
// file or directory not found
return
null
;
}
return
new
X509Certificate2
(
exported
,
password
,
storageFlags
);
}
private
string
getRootCertificatePath
(
string
filePath
)
{
if
(
Path
.
IsPathRooted
(
filePath
))
{
return
filePath
;
}
return
Path
.
Combine
(
getRootCertificateDirectory
(),
string
.
IsNullOrEmpty
(
filePath
)
?
defaultRootCertificateFileName
:
filePath
);
}
private
string
getCertificatePath
()
{
if
(
certificatePath
==
null
)
{
string
path
=
getRootCertificateDirectory
();
string
certPath
=
Path
.
Combine
(
path
,
defaultCertificateDirectoryName
);
if
(!
Directory
.
Exists
(
certPath
))
{
Directory
.
CreateDirectory
(
certPath
);
}
certificatePath
=
certPath
;
}
return
certificatePath
;
}
private
string
getRootCertificateDirectory
()
{
if
(
rootCertificatePath
==
null
)
{
string
assemblyLocation
=
GetType
().
Assembly
.
Location
;
// dynamically loaded assemblies returns string.Empty location
if
(
assemblyLocation
==
string
.
Empty
)
{
assemblyLocation
=
Assembly
.
GetEntryAssembly
().
Location
;
}
string
path
=
Path
.
GetDirectoryName
(
assemblyLocation
);
rootCertificatePath
=
path
??
throw
new
NullReferenceException
();
}
return
rootCertificatePath
;
}
}
}
src/Titanium.Web.Proxy/Network/ICertificateCache.cs
0 → 100644
View file @
6d1a583b
using
System.Security.Cryptography.X509Certificates
;
namespace
Titanium.Web.Proxy.Network
{
public
interface
ICertificateCache
{
/// <summary>
/// Loads the root certificate from the storage.
/// </summary>
X509Certificate2
LoadRootCertificate
(
string
name
,
string
password
,
X509KeyStorageFlags
storageFlags
);
/// <summary>
/// Saves the root certificate to the storage.
/// </summary>
void
SaveRootCertificate
(
string
name
,
string
password
,
X509Certificate2
certificate
);
/// <summary>
/// Loads certificate from the storage. Returns true if certificate does not exist.
/// </summary>
X509Certificate2
LoadCertificate
(
string
subjectName
,
X509KeyStorageFlags
storageFlags
);
/// <summary>
/// Stores certificate into the storage.
/// </summary>
void
SaveCertificate
(
string
subjectName
,
X509Certificate2
certificate
);
/// <summary>
/// Clears the storage.
/// </summary>
void
Clear
();
}
}
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