Commit 3b066c2e authored by justcoding121's avatar justcoding121

fix confusing namings

parent 9428e552
...@@ -43,7 +43,6 @@ namespace Titanium.Web.Proxy.UnitTests ...@@ -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) //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] [TestMethod]
public async Task Simple_Create_Win_Certificate_Test() public async Task Simple_Create_Win_Certificate_Test()
{ {
......
...@@ -67,18 +67,21 @@ namespace Titanium.Web.Proxy.Network ...@@ -67,18 +67,21 @@ namespace Titanium.Web.Proxy.Network
internal bool CertValidated => RootCertificate != null; internal bool CertValidated => RootCertificate != null;
/// <summary> /// <summary>
/// Trust the RootCertificate used by this proxy server /// Trust the RootCertificate used by this proxy server for current user
/// 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
/// </summary> /// </summary>
internal bool UserTrustRoot { get; set; } = false; internal bool UserTrustRoot { get; set; } = false;
/// <summary> /// <summary>
/// Needs elevated permission. Works only on Windows. /// Trust the RootCertificate used by this proxy server for current machine
/// <para>Puts the certificate to the local machine's certificate store.</para> /// Needs elevated permission, otherwise will fail silently.
/// <para>Certutil.exe is a command-line program that is installed as part of Certificate Services</para>
/// </summary> /// </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> /// <summary>
/// Select Certificate Engine /// Select Certificate Engine
...@@ -186,9 +189,36 @@ namespace Titanium.Web.Proxy.Network ...@@ -186,9 +189,36 @@ namespace Titanium.Web.Proxy.Network
public X509KeyStorageFlags StorageFlag { get; set; } = X509KeyStorageFlags.Exportable; 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; this.exceptionFunc = exceptionFunc;
UserTrustRoot = userTrustRootCertificate;
if (machineTrustRootCertificate)
{
MachineTrustRoot = machineTrustRootCertificate;
}
TrustRootAsAdministrator = trustRootCertificateAsAdmin;
if (rootCertificateName != null)
{
RootCertificateName = rootCertificateName;
}
if (rootCertificateIssuerName != null)
{
RootCertificateIssuerName = rootCertificateIssuerName;
}
if (RunTime.IsWindows) if (RunTime.IsWindows)
{ {
//this is faster in Windows based on tests (see unit test project CertificateManagerTests.cs) //this is faster in Windows based on tests (see unit test project CertificateManagerTests.cs)
...@@ -617,6 +647,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -617,6 +647,7 @@ namespace Titanium.Web.Proxy.Network
/// </summary> /// </summary>
public void TrustRootCertificate(bool machineTrusted = false) public void TrustRootCertificate(bool machineTrusted = false)
{ {
//currentUser\personal //currentUser\personal
InstallCertificate(StoreName.My, StoreLocation.CurrentUser); InstallCertificate(StoreName.My, StoreLocation.CurrentUser);
...@@ -698,21 +729,20 @@ namespace Titanium.Web.Proxy.Network ...@@ -698,21 +729,20 @@ namespace Titanium.Web.Proxy.Network
/// Ensure certificates are setup (creates root if required) /// Ensure certificates are setup (creates root if required)
/// Also makes root certificate trusted based on initial setup from proxy constructor for user/machine trust. /// 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()
{ {
if (!CertValidated) if (!CertValidated)
{ {
CreateRootCertificate(); CreateRootCertificate();
} }
if (UserTrustRoot) if (TrustRootAsAdministrator)
{ {
TrustRootCertificate(machineTrustRootCertificate); TrustRootCertificateAsAdmin(MachineTrustRoot);
} }
else if (UserTrustRoot)
if (MachineTrustRootAsAdministrator)
{ {
TrustRootCertificateAsAdmin(); TrustRootCertificate(MachineTrustRoot);
} }
} }
...@@ -720,12 +750,20 @@ namespace Titanium.Web.Proxy.Network ...@@ -720,12 +750,20 @@ namespace Titanium.Web.Proxy.Network
/// <summary> /// <summary>
/// Ensure certificates are setup (creates root if required) /// Ensure certificates are setup (creates root if required)
/// Also makes root certificate trusted based on provided parameters /// Also makes root certificate trusted based on provided parameters
/// Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true
/// </summary> /// </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; UserTrustRoot = userTrustRootCertificate;
MachineTrustRootAsAdministrator = machineTrustRootCertificateAsAdmin; MachineTrustRoot = machineTrustRootCertificate;
EnsureRootCertificate(machineTrustRootCertificate); TrustRootAsAdministrator = trustRootCertificateAsAdmin;
EnsureRootCertificate();
} }
......
...@@ -208,31 +208,22 @@ namespace Titanium.Web.Proxy ...@@ -208,31 +208,22 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </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> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
/// <param name="rootCertificateName">Name of root certificate.</param> /// <param name="rootCertificateName">Name of root certificate.</param>
/// <param name="rootCertificateIssuerName">Name of root certificate issuer.</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 //default values
ConnectionTimeOutSeconds = 30; ConnectionTimeOutSeconds = 30;
...@@ -244,19 +235,7 @@ namespace Titanium.Web.Proxy ...@@ -244,19 +235,7 @@ namespace Titanium.Web.Proxy
systemProxySettingsManager = new SystemProxyManager(); systemProxySettingsManager = new SystemProxyManager();
} }
CertificateManager = new CertificateManager(ExceptionFunc); CertificateManager = new CertificateManager(rootCertificateName, rootCertificateIssuerName, userTrustRootCertificate, machineTrustRootCertificate, trustRootCertificateAsAdmin, ExceptionFunc);
CertificateManager.UserTrustRoot = trustRootCertificate;
CertificateManager.MachineTrustRootAsAdministrator = trustRootCertificateAsAdmin;
if (rootCertificateName != null)
{
CertificateManager.RootCertificateName = rootCertificateName;
}
if (rootCertificateIssuerName != null)
{
CertificateManager.RootCertificateIssuerName = rootCertificateIssuerName;
}
} }
/// <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