Commit 3b066c2e authored by justcoding121's avatar justcoding121

fix confusing namings

parent 9428e552
......@@ -43,7 +43,6 @@ namespace Titanium.Web.Proxy.UnitTests
}
//uncomment this to compare WinCert maker performance with BC (BC takes more time for same test above)
//cannot run this test in build server since trusting the certificate won't happen successfully
[TestMethod]
public async Task Simple_Create_Win_Certificate_Test()
{
......
......@@ -67,18 +67,21 @@ namespace Titanium.Web.Proxy.Network
internal bool CertValidated => RootCertificate != null;
/// <summary>
/// Trust the RootCertificate used by this proxy server
/// Note that this do not make the client trust the certificate!
/// This would import the root certificate to the certificate store of machine that runs this proxy server
/// Trust the RootCertificate used by this proxy server for current user
/// </summary>
internal bool UserTrustRoot { get; set; } = false;
/// <summary>
/// Needs elevated permission. Works only on Windows.
/// <para>Puts the certificate to the local machine's certificate store.</para>
/// <para>Certutil.exe is a command-line program that is installed as part of Certificate Services</para>
/// Trust the RootCertificate used by this proxy server for current machine
/// Needs elevated permission, otherwise will fail silently.
/// </summary>
internal bool MachineTrustRootAsAdministrator { get; set; } = false;
internal bool MachineTrustRoot { get; set; } = false;
/// <summary>
/// Whether trust operations should be done with elevated privillages
/// Will prompt with UAC if required. Works only on Windows.
/// </summary>
internal bool TrustRootAsAdministrator { get; set; } = false;
/// <summary>
/// Select Certificate Engine
......@@ -186,9 +189,36 @@ namespace Titanium.Web.Proxy.Network
public X509KeyStorageFlags StorageFlag { get; set; } = X509KeyStorageFlags.Exportable;
internal CertificateManager(Action<Exception> exceptionFunc)
/// <summary>
/// Constructor.
/// </summary>
/// <param name="rootCertificateName">Name of root certificate.</param>
/// <param name="rootCertificateIssuerName">Name of root certificate issuer.</param>
/// <param name="userTrustRootCertificate"></param>
/// <param name="machineTrustRootCertificate">Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true</param>
/// <param name="trustRootCertificateAsAdmin "></param>
/// <param name="exceptionFunc"></param>
internal CertificateManager(string rootCertificateName, string rootCertificateIssuerName, bool userTrustRootCertificate, bool machineTrustRootCertificate, bool trustRootCertificateAsAdmin, Action < Exception> exceptionFunc)
{
this.exceptionFunc = exceptionFunc;
UserTrustRoot = userTrustRootCertificate;
if (machineTrustRootCertificate)
{
MachineTrustRoot = machineTrustRootCertificate;
}
TrustRootAsAdministrator = trustRootCertificateAsAdmin;
if (rootCertificateName != null)
{
RootCertificateName = rootCertificateName;
}
if (rootCertificateIssuerName != null)
{
RootCertificateIssuerName = rootCertificateIssuerName;
}
if (RunTime.IsWindows)
{
//this is faster in Windows based on tests (see unit test project CertificateManagerTests.cs)
......@@ -617,6 +647,7 @@ namespace Titanium.Web.Proxy.Network
/// </summary>
public void TrustRootCertificate(bool machineTrusted = false)
{
//currentUser\personal
InstallCertificate(StoreName.My, StoreLocation.CurrentUser);
......@@ -698,21 +729,20 @@ namespace Titanium.Web.Proxy.Network
/// 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>
public void EnsureRootCertificate(bool machineTrustRootCertificate = false)
public void EnsureRootCertificate()
{
if (!CertValidated)
{
CreateRootCertificate();
}
if (UserTrustRoot)
if (TrustRootAsAdministrator)
{
TrustRootCertificate(machineTrustRootCertificate);
TrustRootCertificateAsAdmin(MachineTrustRoot);
}
if (MachineTrustRootAsAdministrator)
else if (UserTrustRoot)
{
TrustRootCertificateAsAdmin();
TrustRootCertificate(MachineTrustRoot);
}
}
......@@ -720,12 +750,20 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// Ensure certificates are setup (creates root if required)
/// Also makes root certificate trusted based on provided parameters
/// Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true
/// </summary>
public void EnsureRootCertificate(bool userTrustRootCertificate, bool machineTrustRootCertificate, bool machineTrustRootCertificateAsAdmin)
public void EnsureRootCertificate(bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false, bool trustRootCertificateAsAdmin = false)
{
if(machineTrustRootCertificate)
{
userTrustRootCertificate = true;
}
UserTrustRoot = userTrustRootCertificate;
MachineTrustRootAsAdministrator = machineTrustRootCertificateAsAdmin;
EnsureRootCertificate(machineTrustRootCertificate);
MachineTrustRoot = machineTrustRootCertificate;
TrustRootAsAdministrator = trustRootCertificateAsAdmin;
EnsureRootCertificate();
}
......
......@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Seconds client/server connection are to be kept alive when waiting for read/write to complete
/// </summary>
public int ConnectionTimeOutSeconds { get; set; }
public int ConnectionTimeOutSeconds { get; set; }
/// <summary>
/// Total number of active client connections
......@@ -208,31 +208,22 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Constructor
/// </summary>
public ProxyServer() : this(null, null, true, false)
/// <param name="userTrustRootCertificate"></param>
/// <param name="machineTrustRootCertificate">Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true</param>
/// <param name="trustRootCertificateAsAdmin "></param>
public ProxyServer(bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false, bool trustRootCertificateAsAdmin = false) : this(null, null, userTrustRootCertificate, machineTrustRootCertificate, trustRootCertificateAsAdmin)
{
}
/// <summary>
/// Constructor
/// </summary>
public ProxyServer(bool trustRoot) : this(null, null, trustRoot, false)
{
}
/// <summary>
/// Constructor
/// </summary>
public ProxyServer(bool trustRoot, bool trustRootAsAdmin) : this(null, null, trustRoot, trustRootAsAdmin)
{
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="rootCertificateName">Name of root certificate.</param>
/// <param name="rootCertificateIssuerName">Name of root certificate issuer.</param>
public ProxyServer(string rootCertificateName, string rootCertificateIssuerName, bool trustRootCertificate, bool trustRootCertificateAsAdmin)
/// <param name="userTrustRootCertificate"></param>
/// <param name="machineTrustRootCertificate">Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true</param>
/// <param name="trustRootCertificateAsAdmin "></param>
public ProxyServer(string rootCertificateName, string rootCertificateIssuerName, bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false, bool trustRootCertificateAsAdmin = false)
{
//default values
ConnectionTimeOutSeconds = 30;
......@@ -244,19 +235,7 @@ namespace Titanium.Web.Proxy
systemProxySettingsManager = new SystemProxyManager();
}
CertificateManager = new CertificateManager(ExceptionFunc);
CertificateManager.UserTrustRoot = trustRootCertificate;
CertificateManager.MachineTrustRootAsAdministrator = trustRootCertificateAsAdmin;
if (rootCertificateName != null)
{
CertificateManager.RootCertificateName = rootCertificateName;
}
if (rootCertificateIssuerName != null)
{
CertificateManager.RootCertificateIssuerName = rootCertificateIssuerName;
}
CertificateManager = new CertificateManager(rootCertificateName, rootCertificateIssuerName, userTrustRootCertificate, machineTrustRootCertificate, trustRootCertificateAsAdmin, ExceptionFunc);
}
/// <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