Commit 13dba195 authored by justcoding121's avatar justcoding121

cleanup certificate manager

parent 6a9e1839
...@@ -275,24 +275,6 @@ namespace Titanium.Web.Proxy.Network ...@@ -275,24 +275,6 @@ namespace Titanium.Web.Proxy.Network
} }
} }
private X509Certificate2 MakeCertificate(string certificateName, bool isRootCertificate)
{
if (!isRootCertificate && RootCertificate == null)
{
CreateRootCertificate();
}
var certificate = certEngine.MakeCertificate(certificateName, isRootCertificate, RootCertificate);
if (CertificateEngine == CertificateEngine.DefaultWindows)
{
//prevent certificates getting piled up in User\Personal store
Task.Run(() => UninstallCertificate(StoreName.My, StoreLocation.CurrentUser, certificate));
}
return certificate;
}
/// <summary> /// <summary>
/// Make current machine trust the Root Certificate used by this proxy /// Make current machine trust the Root Certificate used by this proxy
/// </summary> /// </summary>
...@@ -367,6 +349,24 @@ namespace Titanium.Web.Proxy.Network ...@@ -367,6 +349,24 @@ namespace Titanium.Web.Proxy.Network
} }
} }
private X509Certificate2 MakeCertificate(string certificateName, bool isRootCertificate)
{
if (!isRootCertificate && RootCertificate == null)
{
CreateRootCertificate();
}
var certificate = certEngine.MakeCertificate(certificateName, isRootCertificate, RootCertificate);
if (CertificateEngine == CertificateEngine.DefaultWindows)
{
//prevent certificates getting piled up in User\Personal store
Task.Run(() => UninstallCertificate(StoreName.My, StoreLocation.CurrentUser, certificate));
}
return certificate;
}
/// <summary> /// <summary>
/// Create an SSL certificate /// Create an SSL certificate
/// </summary> /// </summary>
...@@ -477,14 +477,6 @@ namespace Titanium.Web.Proxy.Network ...@@ -477,14 +477,6 @@ namespace Titanium.Web.Proxy.Network
} }
/// <summary>
/// Stops the certificate cache clear process
/// </summary>
internal void StopClearIdleCertificates()
{
clearCertificates = false;
}
/// <summary> /// <summary>
/// A method to clear outdated certificates /// A method to clear outdated certificates
/// </summary> /// </summary>
...@@ -507,6 +499,13 @@ namespace Titanium.Web.Proxy.Network ...@@ -507,6 +499,13 @@ namespace Titanium.Web.Proxy.Network
} }
/// <summary>
/// Stops the certificate cache clear process
/// </summary>
internal void StopClearIdleCertificates()
{
clearCertificates = false;
}
/// <summary> /// <summary>
/// Attempts to create a RootCertificate /// Attempts to create a RootCertificate
...@@ -567,7 +566,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -567,7 +566,7 @@ namespace Titanium.Web.Proxy.Network
} }
/// <summary> /// <summary>
/// Loads root certificate from current executing assembly location /// Loads root certificate from current executing assembly location with expected name rootCert.pfx
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public X509Certificate2 LoadRootCertificate() public X509Certificate2 LoadRootCertificate()
...@@ -591,7 +590,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -591,7 +590,7 @@ namespace Titanium.Web.Proxy.Network
} }
/// <summary> /// <summary>
/// Manually load a Root certificate file(.pfx file) /// Manually load a Root certificate file from give path (.pfx file)
/// </summary> /// </summary>
/// <param name="pfxFilePath">Set the name(path) of the .pfx file. If it is string.Empty Root certificate file will be named as "rootCert.pfx" (and will be saved in proxy dll directory)</param> /// <param name="pfxFilePath">Set the name(path) of the .pfx file. If it is string.Empty Root certificate file will be named as "rootCert.pfx" (and will be saved in proxy dll directory)</param>
/// <param name="password">Set a password for the .pfx file</param> /// <param name="password">Set a password for the .pfx file</param>
...@@ -614,7 +613,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -614,7 +613,7 @@ namespace Titanium.Web.Proxy.Network
/// <summary> /// <summary>
/// Trusts the root certificate in user store, optionally also in machine store /// Trusts the root certificate in user store, optionally also in machine store
/// Machine trust would require elevated permissions /// Machine trust would require elevated permissions (will silently fail otherwise)
/// </summary> /// </summary>
public void TrustRootCertificate(bool machineTrusted = false) public void TrustRootCertificate(bool machineTrusted = false)
{ {
...@@ -696,7 +695,8 @@ namespace Titanium.Web.Proxy.Network ...@@ -696,7 +695,8 @@ namespace Titanium.Web.Proxy.Network
} }
/// <summary> /// <summary>
/// Ensure certificates are setup (creates if required) & root certificate is trusted. /// Ensure certificates are setup (creates root if required)
/// Also makes root certificate trusted based on initial setup from proxy constructor for user/machine trust.
/// </summary> /// </summary>
public void EnsureRootCertificate(bool machineTrustRootCertificate = false) public void EnsureRootCertificate(bool machineTrustRootCertificate = false)
{ {
...@@ -717,7 +717,8 @@ namespace Titanium.Web.Proxy.Network ...@@ -717,7 +717,8 @@ namespace Titanium.Web.Proxy.Network
} }
/// <summary> /// <summary>
/// Ensure certificates are setup (creates if required) & root certificate is trusted. /// Ensure certificates are setup (creates root if required)
/// Also makes root certificate trusted based on provided parameters
/// </summary> /// </summary>
public void EnsureRootCertificate(bool userTrustRootCertificate, bool machineTrustRootCertificate, bool machineTrustRootCertificateAsAdmin) public void EnsureRootCertificate(bool userTrustRootCertificate, bool machineTrustRootCertificate, bool machineTrustRootCertificateAsAdmin)
{ {
...@@ -846,9 +847,6 @@ namespace Titanium.Web.Proxy.Network ...@@ -846,9 +847,6 @@ namespace Titanium.Web.Proxy.Network
} }
return success; return success;
return true;
} }
public void ClearRootCertificate() public void ClearRootCertificate()
...@@ -857,7 +855,6 @@ namespace Titanium.Web.Proxy.Network ...@@ -857,7 +855,6 @@ namespace Titanium.Web.Proxy.Network
rootCertificate = null; rootCertificate = null;
} }
/// <summary> /// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary> /// </summary>
......
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