Commit 45c24ae2 authored by Honfika's avatar Honfika

fixes

parent b7ae26e2
...@@ -65,13 +65,13 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -65,13 +65,13 @@ namespace Titanium.Web.Proxy.Examples.Wpf
//proxyServer.CertificateEngine = CertificateEngine.DefaultWindows; //proxyServer.CertificateEngine = CertificateEngine.DefaultWindows;
////Set a password for the .pfx file ////Set a password for the .pfx file
//proxyServer.PasswordPFX = "PfxPassword"; //proxyServer.PfxPassword = "PfxPassword";
////Set Name(path) of the Root certificate file ////Set Name(path) of the Root certificate file
//proxyServer.NamePFXfile = @"C:\NameFolder\rootCert.pfx"; //proxyServer.PfxFilePath = @"C:\NameFolder\rootCert.pfx";
////do you want Replace an existing Root certificate file(.pfx) if password is incorrect(RootCertificate=null)? yes====>true ////do you want Replace an existing Root certificate file(.pfx) if password is incorrect(RootCertificate=null)? yes====>true
//proxyServer.OverwritePFXfile = true; //proxyServer.OverwritePfxFile = true;
////save all fake certificates in folder "crts"(will be created in proxy dll directory) ////save all fake certificates in folder "crts"(will be created in proxy dll directory)
////if create new Root certificate file(.pfx) ====> delete folder "crts" ////if create new Root certificate file(.pfx) ====> delete folder "crts"
...@@ -83,19 +83,18 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -83,19 +83,18 @@ namespace Titanium.Web.Proxy.Examples.Wpf
////if you need Load or Create Certificate now. ////// "true" if you need Enable===> Trust the RootCertificate used by this proxy server ////if you need Load or Create Certificate now. ////// "true" if you need Enable===> Trust the RootCertificate used by this proxy server
//proxyServer.EnsureRootCertificate(true); //proxyServer.EnsureRootCertificate(true);
//or load directly certificate(As Administrator if need this) ////or load directly certificate(As Administrator if need this)
//and At the same time chose path and password ////and At the same time chose path and password
//if password is incorrect and (overwriteRootCert=true)(RootCertificate=null) ====> replace an existing .pfx file ////if password is incorrect and (overwriteRootCert=true)(RootCertificate=null) ====> replace an existing .pfx file
//note : load now (if existed) ////note : load now (if existed)
//proxyServer.CertificateManager.LoadRootCertificate(@"C:\NameFolder\rootCert.pfx", "PfxPassword"); //proxyServer.CertificateManager.LoadRootCertificate(@"C:\NameFolder\rootCert.pfx", "PfxPassword");
//proxyServer.CertificateManager.TrustRootCertificateAsAdministrator(); proxyServer.CertificateManager.TrustRootCertificateAsAdministrator();
proxyServer.ForwardToUpstreamGateway = true;
//proxyServer.ForwardToUpstreamGateway = true;
var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true) var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true)
{ {
//ExcludedHttpsHostNameRegex = new[] { "ssllabs.com" }, ExcludedHttpsHostNameRegex = new[] { "ssllabs.com" },
//IncludedHttpsHostNameRegex = new string[0], //IncludedHttpsHostNameRegex = new string[0],
}; };
...@@ -114,7 +113,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -114,7 +113,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf
proxyServer.TunnelConnectResponse += ProxyServer_TunnelConnectResponse; proxyServer.TunnelConnectResponse += ProxyServer_TunnelConnectResponse;
proxyServer.ClientConnectionCountChanged += delegate { Dispatcher.Invoke(() => { ClientConnectionCount = proxyServer.ClientConnectionCount; }); }; proxyServer.ClientConnectionCountChanged += delegate { Dispatcher.Invoke(() => { ClientConnectionCount = proxyServer.ClientConnectionCount; }); };
proxyServer.ServerConnectionCountChanged += delegate { Dispatcher.Invoke(() => { ServerConnectionCount = proxyServer.ServerConnectionCount; }); }; proxyServer.ServerConnectionCountChanged += delegate { Dispatcher.Invoke(() => { ServerConnectionCount = proxyServer.ServerConnectionCount; }); };
proxyServer.Start(); proxyServer.Start();
proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp); proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);
InitializeComponent(); InitializeComponent();
......
using System; using System;
using System.IO; using System.IO;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Pkcs; using Org.BouncyCastle.Asn1.Pkcs;
...@@ -24,6 +25,8 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -24,6 +25,8 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// </summary> /// </summary>
internal class BCCertificateMaker : ICertificateMaker internal class BCCertificateMaker : ICertificateMaker
{ {
public static readonly Regex CNRemoverRegex = new Regex(@"^CN\s*=\s*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private const int certificateValidDays = 1825; private const int certificateValidDays = 1825;
private const int certificateGraceDays = 366; private const int certificateGraceDays = 366;
...@@ -146,7 +149,7 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -146,7 +149,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
{ {
try try
{ {
x509Certificate.FriendlyName = System.Text.RegularExpressions.Regex.Replace(subjectName, @"^CN\s*=\s*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); x509Certificate.FriendlyName = CNRemoverRegex.Replace(subjectName, string.Empty);
} }
catch (PlatformNotSupportedException) catch (PlatformNotSupportedException)
{ {
......
...@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <param name="tcpRows">TcpRow collection to initialize with.</param> /// <param name="tcpRows">TcpRow collection to initialize with.</param>
internal TcpTable(IEnumerable<TcpRow> tcpRows) internal TcpTable(IEnumerable<TcpRow> tcpRows)
{ {
this.TcpRows = tcpRows; TcpRows = tcpRows;
} }
/// <summary> /// <summary>
......
...@@ -47,24 +47,8 @@ namespace Titanium.Web.Proxy ...@@ -47,24 +47,8 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
private int serverConnectionCount; private int serverConnectionCount;
/// <summary>
/// Backing field for corresponding public property
/// </summary>
private bool trustRootCertificate = false;
private bool overwritePFXfile = true;
/// <summary>
/// Password for export and load rootCert.pfx
/// </summary>
private string passwordPFX = string.Empty;
private string namePFXfile = string.Empty;
private X509KeyStorageFlags storageFlag = X509KeyStorageFlags.Exportable; private X509KeyStorageFlags storageFlag = X509KeyStorageFlags.Exportable;
private bool saveFakeCertificates = false;
/// <summary> /// <summary>
/// A object that creates tcp connection to server /// A object that creates tcp connection to server
/// </summary> /// </summary>
...@@ -131,12 +115,8 @@ namespace Titanium.Web.Proxy ...@@ -131,12 +115,8 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
public bool TrustRootCertificate public bool TrustRootCertificate
{ {
get => trustRootCertificate; get => CertificateManager.trustRootCertificate;
set set => CertificateManager.trustRootCertificate = value;
{
trustRootCertificate = value;
CertificateManager.trustRootCertificate = trustRootCertificate;
}
} }
/// <summary> /// <summary>
...@@ -145,54 +125,38 @@ namespace Titanium.Web.Proxy ...@@ -145,54 +125,38 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
public bool SaveFakeCertificates public bool SaveFakeCertificates
{ {
get => saveFakeCertificates; get => CertificateManager.SaveFakeCertificates;
set set => CertificateManager.SaveFakeCertificates = value;
{
saveFakeCertificates = value;
CertificateManager.saveFakeCertificates = saveFakeCertificates;
}
} }
/// <summary> /// <summary>
/// Overwrite Root certificate file /// Overwrite Root certificate file
/// <para>true : replace an existing .pfx file if password is incorect or if RootCertificate = null</para> /// <para>true : replace an existing .pfx file if password is incorect or if RootCertificate = null</para>
/// </summary> /// </summary>
public bool OverwritePFXfile public bool OverwritePfxFile
{ {
get => overwritePFXfile; get => CertificateManager.OverwritePfXFile;
set set => CertificateManager.OverwritePfXFile = value;
{
overwritePFXfile = value;
CertificateManager.overwritePFXfile = this.overwritePFXfile;
}
} }
/// <summary> /// <summary>
/// Password of the Root certificate file /// Password of the Root certificate file
/// <para>Set a password for the .pfx file</para> /// <para>Set a password for the .pfx file</para>
/// </summary> /// </summary>
public string PasswordPFX public string PfxPassword
{ {
get => passwordPFX; get => CertificateManager.PfxPassword;
set set => CertificateManager.PfxPassword = value;
{
passwordPFX = value;
CertificateManager.passwordpfx = this.passwordPFX;
}
} }
/// <summary> /// <summary>
/// Name(path) of the Root certificate file /// Name(path) of the Root certificate file
/// <para>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)</para> /// <para>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)</para>
/// </summary> /// </summary>
public string NamePFXfile public string PfxFilePath
{ {
get => namePFXfile; get => CertificateManager.PfxFilePath;
set set => CertificateManager.PfxFilePath = value;
{
namePFXfile = value;
CertificateManager.namePFXfile = this.namePFXfile;
}
} }
public X509KeyStorageFlags StorageFlag public X509KeyStorageFlags StorageFlag
...@@ -201,7 +165,7 @@ namespace Titanium.Web.Proxy ...@@ -201,7 +165,7 @@ namespace Titanium.Web.Proxy
set set
{ {
storageFlag = value; storageFlag = value;
CertificateManager.storageFlag = this.storageFlag; CertificateManager.StorageFlag = storageFlag;
} }
} }
...@@ -480,7 +444,8 @@ namespace Titanium.Web.Proxy ...@@ -480,7 +444,8 @@ namespace Titanium.Web.Proxy
if (!endPoint.EnableSsl) if (!endPoint.EnableSsl)
{ {
throw new Exception("Endpoint do not support Https connections"); throw new Exception("Endpoint do not support Https connections");
} }
EnsureRootCertificate(); EnsureRootCertificate();
//If certificate was trusted by the machine //If certificate was trusted by the machine
...@@ -772,11 +737,11 @@ namespace Titanium.Web.Proxy ...@@ -772,11 +737,11 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Load or Create Certificate : after "Test Is the root certificate used by this proxy is valid?" /// Load or Create Certificate : after "Test Is the root certificate used by this proxy is valid?"
/// <param name="TrustRootCertificate">"Make current machine trust the Root Certificate used by this proxy" ==> True or False</param> /// <param name="trustRootCertificate">"Make current machine trust the Root Certificate used by this proxy" ==> True or False</param>
/// </summary> /// </summary>
public void EnsureRootCertificate(bool TrustRootCertificate) public void EnsureRootCertificate(bool trustRootCertificate)
{ {
this.TrustRootCertificate = TrustRootCertificate; TrustRootCertificate = trustRootCertificate;
EnsureRootCertificate(); EnsureRootCertificate();
} }
......
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