Commit e910ff08 authored by ilushka85's avatar ilushka85

Change Fiddler Name to Titanium + Fix innovcation errors from resaving root cert as not exportable

parent fef05f52
......@@ -171,7 +171,7 @@ namespace Titanium.Web.Proxy.Network
this.typeX509Enrollment.InvokeMember("InitializeFromRequest", BindingFlags.InvokeMethod, null, obj15, subject);
if (IsRoot)
{
subject[0] = "DO_NOT_TRUST_FiddlerRoot-CE";
subject[0] = "DO_NOT_TRUST_TitaniumProxy-CE";
this.typeX509Enrollment.InvokeMember("CertificateFriendlyName", BindingFlags.PutDispProperty, null, obj15, subject);
}
subject[0] = 0;
......
......@@ -6,6 +6,7 @@ using System.Threading;
using System.Linq;
using System.Collections.Concurrent;
using System.IO;
using System.Diagnostics;
namespace Titanium.Web.Proxy.Network
{
......@@ -15,13 +16,13 @@ namespace Titanium.Web.Proxy.Network
internal class CertificateManager : IDisposable
{
private CertEnrollEngine certEngine = null;
/// <summary>
/// Cache dictionary
/// </summary>
private readonly IDictionary<string, CachedCertificate> certificateCache;
internal string Issuer { get; private set; }
internal string RootCertificateName { get; private set; }
......@@ -44,21 +45,23 @@ namespace Titanium.Web.Proxy.Network
/// <returns>true if succeeded, else false</returns>
internal bool CreateTrustedRootCertificate()
{
if(File.Exists("rootCert.pfx"))
if (File.Exists("rootCert.pfx"))
{
try
{
rootCertificate = new X509Certificate2("rootCert.pfx");
rootCertificate = new X509Certificate2("rootCert.pfx", string.Empty, X509KeyStorageFlags.Exportable);
if (rootCertificate != null)
{
return true;
}
}
catch
{
}
}
if (rootCertificate == null)
{
rootCertificate = CreateCertificate(RootCertificateName, true);
}
rootCertificate = CreateCertificate(RootCertificateName, true);
if (rootCertificate != null)
{
try
......@@ -67,7 +70,7 @@ namespace Titanium.Web.Proxy.Network
}
catch
{
}
}
return rootCertificate != null;
......@@ -94,15 +97,31 @@ namespace Titanium.Web.Proxy.Network
{
}
X509Certificate2 certificate = certEngine.CreateCert(certificateName, isRootCertificate,rootCertificate);
if (certificate != null && !certificateCache.ContainsKey(certificateName))
X509Certificate2 certificate = null;
lock (string.Intern(certificateName))
{
certificateCache.Add(certificateName, new CachedCertificate() { Certificate = certificate });
if (certificateCache.ContainsKey(certificateName) == false)
{
Debug.WriteLine(certificateName);
certificate = certEngine.CreateCert(certificateName, isRootCertificate, rootCertificate);
if (certificate != null && !certificateCache.ContainsKey(certificateName))
{
certificateCache.Add(certificateName, new CachedCertificate() { Certificate = certificate });
}
}
else
{
if (certificateCache.ContainsKey(certificateName))
{
var cached = certificateCache[certificateName];
cached.LastAccess = DateTime.Now;
return cached.Certificate;
}
}
}
return certificate;
}
......
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