Certificate is not Valid, even though proxy is set.

1 Answer 40 Views
FiddlerCore Windows
Ryan
Top achievements
Rank 1
Iron
Ryan asked on 25 Feb 2024, 01:57 AM

In my program; I use Fiddler Core. When ran on a pc; it set's the proxy as it should but when trying to browse the network with the proxy on; i'm getting "Your connection is Not private"; error message on all browsers. Please see attached photos for reference. Here is my running code:

 


private void stopfiddler()
{
    if (!FiddlerApplication.IsStarted())
    {
    }
    else
    {
        FiddlerApplication.Shutdown();
    }
}

public static void SavePreferences()
{

    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    string cert = ConfigurationManager.AppSettings["fiddler.certmaker.bc.cert"];
    string key = ConfigurationManager.AppSettings["fiddler.certmaker.bc.key"];
    if (cert == null || key == null)
    {
        config.AppSettings.Settings.Add("fiddler.certmaker.bc.cert", FiddlerApplication.Prefs.GetStringPref("fiddler.certmaker.bc.cert", null));
        config.AppSettings.Settings.Add("fiddler.certmaker.bc.key", FiddlerApplication.Prefs.GetStringPref("fiddler.certmaker.bc.key", null));
        config.Save(ConfigurationSaveMode.Modified);
        ConfigurationManager.RefreshSection("appSettings");
    }
    else
    {
        config.AppSettings.Settings["fiddler.certmaker.bc.cert"].Value = FiddlerApplication.Prefs.GetStringPref("fiddler.certmaker.bc.cert", null);
        config.AppSettings.Settings["fiddler.certmaker.bc.key"].Value = FiddlerApplication.Prefs.GetStringPref("fiddler.certmaker.bc.key", null);
        config.Save(ConfigurationSaveMode.Modified);
        ConfigurationManager.RefreshSection("appSettings");
    }
}

public static bool IsCertCreated()
{

    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    string cert = ConfigurationManager.AppSettings["fiddler.certmaker.bc.cert"];
    string key = ConfigurationManager.AppSettings["fiddler.certmaker.bc.key"];
    if (cert != null && key != null)
    {
        return true;
    }
    else
    {
        return false;
    }
}

public static void RemoveFiddlerPreferences()
{
    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

    config.AppSettings.Settings.Remove("fiddler.certmaker.bc.cert");
    config.AppSettings.Settings.Remove("fiddler.certmaker.bc.key");

    config.Save(ConfigurationSaveMode.Modified);
    ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
}

public static void LoadPreferences()
{
    string cert = ConfigurationManager.AppSettings["fiddler.certmaker.bc.cert"];
    string key = ConfigurationManager.AppSettings["fiddler.certmaker.bc.key"];

    if (!string.IsNullOrEmpty(cert) && !string.IsNullOrEmpty(key))
    {
        FiddlerApplication.Prefs.SetStringPref("fiddler.certmaker.bc.cert", cert);
        FiddlerApplication.Prefs.SetStringPref("fiddler.certmaker.bc.key", key);
    }

}
private void Installcert()
{

    if (IsCertCreated())
    {
        
    }
    else
    {
        BCCertMaker.BCCertMaker certProvider = new BCCertMaker.BCCertMaker();
        certProvider.CreateRootCertificate();
        X509Certificate2 rootCert = certProvider.GetRootCertificate();
        // Create a certificate store and add the root certificate to it
        X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
        store.Open(OpenFlags.ReadWrite);
        store.Add(rootCert);
        SavePreferences();
    }
}

private void Remove()
{
    using (var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine))
    {
        store.Open(OpenFlags.ReadWrite);

        var certificatesToRemove = store.Certificates
            .Cast<X509Certificate2>()
            .Where(c => c.SubjectName.Name.ToLower().Contains("DO_NOT_TRUST_FiddlerRoot"))
            .ToList();

        foreach (var cert in certificatesToRemove)
        {
            string certPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, cert.Thumbprint + ".cer");
            if (File.Exists(certPath))
            {
                File.Delete(certPath);
            }

            store.Remove(cert);
        }
        RemoveFiddlerPreferences();
        store.Close();
        MessageBox.Show("Deleted");
    }
}

private void appentext(string value)
{
    if (InvokeRequired)
    {
        return;
    }
}

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Nick Iliev
Telerik team
answered on 26 Feb 2024, 08:00 AM

Hello Ryan,

 

The error message indicates that the Fiddler certificate authority is not installed and trusted, and as a result, the secure connection fails. The first thing to do and check is the custom logic where you are checking if the CA is installed and trusted.

You can try the demo application provided in this GitHub repository and use it as a reference (no custom logic related to configuration manager).

 

Regards,
Nick Iliev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
FiddlerCore Windows
Asked by
Ryan
Top achievements
Rank 1
Iron
Answers by
Nick Iliev
Telerik team
Share this question
or