Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / C#
Tip/Trick

Windows SSL Certificate Cleaner

Rate me:
Please Sign up or sign in to vote.
4.83/5 (4 votes)
20 Jul 2015CPOL3 min read 12.7K   491   4   1
Displays Windows SSL certifiacte in a tree-view and allows you to delete some certificates

Introduction

The Windows management console and security snap-in makes it hard to see just what is going on in Windows as more and more central authority root SSL certificates are added to your machine so this program hopes to simplify matters by presenting the certificates in a tree view and uses colour coded warnings to help make cleaning out suspect certificates easier.

This little Windows application was built using Visual Studio 2010 and you can download all the source code for the full project by clicking the 'CertChecker' link at the top of the screen or just click the 'Windows App' link to download the program ready to run as a Windows .EXE file.

Image 1

Background

I decided to write this program because I know that my ISP is hijacking DNS requests made to outside servers and redirecting them back to IP-Address owned by my ISP since this allows ISPs to lower upstream costs and improves performance but this means that any SSL traffic also gets diverted to the ISP's servers so I suspect that they are somehow using Man-in-the-middle (MITM) to achieve this and that would involve using a none to trust worthy CA certificate on my machine.

My first step was to clean out the Windows certificate store and this resulted in myself writing this program because the tools used by Windows are not very helpful and have hardly changed over the past twenty years.

Using the Code

I added a form to the project as can be seen in the image at the top of this screen that uses a class 'CertStore' to retrieve a collection of machine/user certificates with a tree structure using 'CertItem' so that CA Certificates contain a collection of child certificates that are better known as intermediate certificates that are authorized by the CAs.

Add the files CertStore.cs and Helper.cs to your own project if you want a list of Windows certificates in your project using the code below.

C#
using System;
using System.Collections.Generic;
using CertCheck;

Dictionary<string, CertItem> Certificates =CertStore.LoadCertificates();
foreach (CertItem I in Certificates.Values)
    {
        //Do your thing here or call I.Delete(); to delete the CA certificate and any children
    }   //See I.ErrorMessage for any warnings about the certificate

Reading Windows certificates in .NET is easy using a X509Certificate2 and X509Store from the 'System.Security.Cryptography.X509Certificates' namespace as shown in the code snippet below:

C#
using System;
using System.Collections.Generic;
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

Dictionary<string,CertItem> DicCA=new Dictionary<string, CertItem>(StringComparer.OrdinalIgnoreCase);
Dictionary<string, CertItem> DicCASorted = new Dictionary<string, CertItem>();
X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 Cert in store.Certificates)
     {//Load up the CA Certificates for this user
       CertItem I = new CertItem(Cert,store, "CAUser",true);
       DicCA.Add(I.Name  + I.Thumbprint , I);
     }
//you could use I.Delete() to delete the certificate but the app must run with admin rights to do this

The store location here is 'CurrentUser' but you might also like to use 'LocalMachine' to get the rest of the certificates and also change the StoreName to access personal certificates or other stores.

Windows certificates also contain thumb prints and you should not delete any certificates using the thumb prints shown below as it might stop your machine from working and the frontend I have put on this program prevents you from making this mistakes but you can find out more detail about these certificates here.

Do not delete certificates with these thumb prints.

00c1008b3c3c8811d13ef663ecdf40            4a19d2388c82591ca55d735f155ddca3,

03c78f37db9228df3cbb1aad82fa6710,         79ad16a14aa0a5ad4c7358f407132e65,

03c78f37db9228df3cbb1aad82fa6710

If you have Windows updates turned on, then Microsoft will often add new certificates to your certificate store automatically without warning and some of the certificate encryption keys Microsoft uses are hardcoded into Windows, but I see it as the fox is guarding the chicken house and keep my updates turned off.

How Safe is SSL?

When Alice wants to talk to Bob, she sets up a SSL Connection and Bob sends her back a very expensive key with 256 teeth and she then builds a lock for the key and puts her cheap session key into a steel box and locks it with the padlock she built around Bob's key and she then sends it back to Bob who has the master key for the expensive padlock.

Bob opens the box using his master key and once the handshake is over, they send love letters to each other but they don't use Bob's lock, they use Alice's cheap lock and key!

This guy says it better than me Youtube HTTPS.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
Old dog that is tired of learning new tricks when the new dish they are cooking never tastes quite so good as the old one.

Comments and Discussions

 
QuestionDoes not work at all on Windows 10 Pin
Philippe Verdy19-Jun-18 6:54
Philippe Verdy19-Jun-18 6:54 
This app internally tries to index the same objects multiple times in a dictionnary (a collection of objects with unique key constraints), and this fails indefinitely. There's a serious bug...

System.ArgumentException: Un élément avec la même clé a déjà été ajouté.
   à System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   à System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   à CertCheck.CertStore.LoadCertificates()
   à CertCheck.CertStore.FillTreeView(TreeView Tree)
   à CertCheck.Form1.timer1_Tick(Object sender, EventArgs e)
   à System.Windows.Forms.Timer.OnTick(EventArgs e)
   à System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   à System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Assemblys chargés **************
mscorlib
    Version de l'assembly : 4.0.0.0
    Version Win32 : 4.7.3062.0 built by: NET472REL1
    CodeBase : file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
CertCheck
    Version de l'assembly : 1.0.0.2
    Version Win32 : 1.0.0.2
    CodeBase : file:///D:/verdy/Downloads/CertCheck.exe
----------------------------------------
System.Windows.Forms
    Version de l'assembly : 4.0.0.0
    Version Win32 : 4.7.3062.0 built by: NET472REL1
    CodeBase : file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Version de l'assembly : 4.0.0.0
    Version Win32 : 4.7.3062.0 built by: NET472REL1
    CodeBase : file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Version de l'assembly : 4.0.0.0
    Version Win32 : 4.7.3062.0 built by: NET472REL1
    CodeBase : file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Version de l'assembly : 4.0.0.0
    Version Win32 : 4.7.3062.0 built by: NET472REL1
    CodeBase : file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Version de l'assembly : 4.0.0.0
    Version Win32 : 4.7.3062.0 built by: NET472REL1
    CodeBase : file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Accessibility
    Version de l'assembly : 4.0.0.0
    Version Win32 : 4.7.3062.0 built by: NET472REL1
    CodeBase : file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Core
    Version de l'assembly : 4.0.0.0
    Version Win32 : 4.7.3062.0 built by: NET472REL1
    CodeBase : file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.resources
    Version de l'assembly : 4.0.0.0
    Version Win32 : 4.7.3062.0 built by: NET472REL1
    CodeBase : file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.resources/v4.0_4.0.0.0_fr_b77a5c561934e089/System.resources.dll
----------------------------------------
mscorlib.resources
    Version de l'assembly : 4.0.0.0
    Version Win32 : 4.7.3062.0 built by: NET472REL1
    CodeBase : file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_fr_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.Windows.Forms.resources
    Version de l'assembly : 4.0.0.0
    Version Win32 : 4.7.3062.0 built by: NET472REL1
    CodeBase : file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_fr_b77a5c561934e089/System.Windows.Forms.resources.dll

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.