Commit db39e8e7 authored by Honfika's avatar Honfika

do not create cert path when not needed

parent 6f57a319
...@@ -30,14 +30,14 @@ namespace Titanium.Web.Proxy.Network ...@@ -30,14 +30,14 @@ namespace Titanium.Web.Proxy.Network
/// <inheritdoc /> /// <inheritdoc />
public X509Certificate2? LoadCertificate(string subjectName, X509KeyStorageFlags storageFlags) public X509Certificate2? LoadCertificate(string subjectName, X509KeyStorageFlags storageFlags)
{ {
string path = Path.Combine(getCertificatePath(), subjectName + defaultCertificateFileExtension); string filePath = Path.Combine(getCertificatePath(false), subjectName + defaultCertificateFileExtension);
return loadCertificate(path, string.Empty, storageFlags); return loadCertificate(filePath, string.Empty, storageFlags);
} }
/// <inheritdoc /> /// <inheritdoc />
public void SaveCertificate(string subjectName, X509Certificate2 certificate) public void SaveCertificate(string subjectName, X509Certificate2 certificate)
{ {
string filePath = Path.Combine(getCertificatePath(), subjectName + defaultCertificateFileExtension); string filePath = Path.Combine(getCertificatePath(true), subjectName + defaultCertificateFileExtension);
byte[] exported = certificate.Export(X509ContentType.Pkcs12); byte[] exported = certificate.Export(X509ContentType.Pkcs12);
File.WriteAllBytes(filePath, exported); File.WriteAllBytes(filePath, exported);
} }
...@@ -46,9 +46,13 @@ namespace Titanium.Web.Proxy.Network ...@@ -46,9 +46,13 @@ namespace Titanium.Web.Proxy.Network
{ {
try try
{ {
Directory.Delete(getCertificatePath(), true); string path = getCertificatePath(false);
if (Directory.Exists(path))
{
Directory.Delete(path, true);
}
} }
catch (DirectoryNotFoundException) catch (Exception)
{ {
// do nothing // do nothing
} }
...@@ -89,14 +93,14 @@ namespace Titanium.Web.Proxy.Network ...@@ -89,14 +93,14 @@ namespace Titanium.Web.Proxy.Network
string.IsNullOrEmpty(pathOrName) ? defaultRootCertificateFileName : pathOrName); string.IsNullOrEmpty(pathOrName) ? defaultRootCertificateFileName : pathOrName);
} }
private string getCertificatePath() private string getCertificatePath(bool create)
{ {
if (certificatePath == null) if (certificatePath == null)
{ {
string path = getRootCertificateDirectory(); string path = getRootCertificateDirectory();
string certPath = Path.Combine(path, defaultCertificateDirectoryName); string certPath = Path.Combine(path, defaultCertificateDirectoryName);
if (!Directory.Exists(certPath)) if (create && !Directory.Exists(certPath))
{ {
Directory.CreateDirectory(certPath); Directory.CreateDirectory(certPath);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment