5

(I've posted this earlier to superuser)

I'd like to temporarily disable all trusted root certificates and wondering if there is a quicker way than going through every single one of them, right-click Properties and selecting "Disable all purposes for this certificate" (and then trying to find where I left off after the list in mmc scrolls back to the top)?

3
  • 1
    I suspect what you probably need to do is look in Powershell for a solution. The certs are in Cert:\LocalMachine\Root. There might be a way to disable the certs.
    – Zoredache
    Apr 30, 2014 at 22:30
  • I posted here because I was told SF may be better for the question.
    – zoli
    Apr 30, 2014 at 23:14
  • 1
    @zoli in the case someone thinks your question would be a better fit on another site, the original question should be migrated. The community will often do this by default for good questions that clearly fit on another site. You can also flag a question for a moderator and request a migration.
    – Zoredache
    Apr 30, 2014 at 23:27

2 Answers 2

4

Just as @Grant mentioned, Powershell can be used to remove (effectively disabling) the certificates from the store. An export can be done prior to the removal so you can re-import them back to the store.

To export & remove from the store:

Add-Type -AssemblyName System.Security

$exportPath = 'c:\temp\certexport'

$certStore = New-Object System.Security.Cryptography.X509Certificates.X509Store -ArgumentList 'Root', 'LocalMachine'

$certStore.Open('ReadWrite')

foreach ($cert in $certStore.Certificates) {

    # Export cert to a .cer file.
    $certPath = Join-Path -Path $exportPath -ChildPath "$($cert.Thumbprint).cer"
    [System.IO.File]::WriteAllBytes($certPath, $cert.Export('Cert'))

    # Remove the cert from the store.
    $certStore.Remove($cert)

}
$certStore.Close()

To re-import them back to the store:

Add-Type -AssemblyName System.Security

$exportPath = 'c:\temp\certexport'

$certStore = New-Object System.Security.Cryptography.X509Certificates.X509Store -ArgumentList 'Root', 'LocalMachine'

$certStore.Open('ReadWrite')

Get-ChildItem -Path $exportPath -Filter *.cer | ForEach-Object {

    $cert = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate($_.FullName)

    $certStore.Add($cert)
}
$certStore.Close()
1
  • +1 for actually writing the script I alluded to.
    – Grant
    May 3, 2014 at 23:47
2

Powershell doesn't appear to have any way of disabling the certificates. Which is kind of surprising, perhaps I missed them. But it does have commands to import, export, and delete them.

One could (and test this from a virtual machine with snapshots or something in case the first revision doesn't work out) write a powershell script to export all the certs, delete them all, pause while you do whatever you are doing, then import them again.

This doesn't quite give the same results as disabling them, but since you don't say why you are doing it, it might be close enough for your purposes.

I believe disabling a certificate does the same thing as marking it as untrusted. If that's the case you might be able to select them all and drag them to the untrusted certificates store. But check what is in there already - you wouldn't want to move any existing untrusted ones back when you are done.

2
  • 1
    Thanks! The purpose I wanted to do it was testing how some code behaves when it's making an SSL connection and it can't verify the server's certificates.
    – zoli
    May 1, 2014 at 19:49
  • 2
    @zoli Just beware that some applications behave differently for a missing certificate than for one explicitly marked as untrusted.
    – Grant
    May 1, 2014 at 19:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .