Certutil Examples for Managing Active Directory Certificate Services (AD CS) from the Command Line

Certutil Examples for Managing Active Directory Certificate Services (AD CS) from the Command Line

Applies to: Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012



Certutil.exe is a command-line program that is installed as part of Active Directory Certificate Services (AD CS). You can use Certutil.exe to dump and display certification authority (CA) configuration information, configure Certificate Services, back up and restore CA components, and verify certificates, key pairs, and certificate chains. This article was created to show examples of certutil commands. Sections in this article include:

View CA Configuration

If you want to view the configuration settings for the CA, which includes the type of information that is set by the CAPolicy.inf or afterward installation by running post configuration scripts, you can issue the following commands:

certutil -dump

certutil -getreg

certutil -getreg CA

Publish expired certificates in the CRL

If you want to maintain a revoked certificate in the CRL beyond the certificate’s expiration date, you can enable the publication of expired certificates to the CRL by running the following command at a command-line prompt and then restarting Certificate Services.

certutil –setreg ca\CRLFlags +CRLF_PUBLISH_EXPIRED_CERT_CR

Dump certificate templates and settings from the CA

certutil -v -template

Variations of that command

certutil -v -template > templatelist.txt

certutil -v -template clientauth > clientauthsettings.txt

Copy a CRL to a file

If you want to copy a certificate revocation list and name it corprootca.crl to removable media (like a floppy drive of a:), then you can run the following command:

certutil -getcrl a:\corprootca.crl

View Certificate Templates

If you want to dump a list of certificate templates and their settings to a text file (MyTemplates.txt), you can run the following command:

    certutil -v -template > MyTemplates.txt

View AIA container

To view the contents of the AIA container in Active Directory Domain Services (AD DS) for a domain named contoso.com, run the following command:

certutil -viewstore "ldap:///CN=AIA,CN=Public Key Services,CN=Services,CN=Configuration,DC=contoso,DC=com?

cACertificate?base?objectclass=certificationAuthority"

View Intermediate CA certificate store

To view the content of the client computer’s Intermediate Certification Authorities certificate store, type the following command at a command-line prompt.

certutil -enterprise -viewstore CA

View NTAuth Container

To view the content of the NTAuth container in AD DS for a domain named Corp.contoso.com, you would type the following command on a single line and press ENTER:

certutil -viewstore "ldap:///CN=NTAuthCertificates,CN=Public Key Services,CN=Services,CN=Configuration,DC=corp,DC=contoso,DC=com"

View Trusted Root CAs

To view the content of the client computer’s Trusted Root Certification Authorities Enterprise certificate store, type the following command at a command-line prompt.

certutil -enterprise -viewstore Root

Purge policy cache

When you are working with Certificate Enrollment Policy Web Services servers, there is a cache located on the local computer of cached policies. You may want to clear when the resulting certificate policies are not what you expect. You can clear this certificate policy cache by running the following command:

certutil -f -policyserver * -policycache delete

Check the certificate revocation chain

certutil -verify -urlfetch <certificatename>

certutil -URL <certificatename>

For more information on these commands, see the end of the Step by Step Guide - Two Tier PKI Hierarchy Deployment

Certutil Q & A

This could become a Frequently Asked Questions (FAQ) about Certutil at some point. For now, we will just keep it here:

When do you use ‘certutil –addstore’ versus ‘certutil –importcert?

  • Use Certutil -addstore to add a .cer file to anystore. Adds a raw certificate to a certificate store. A .cer file does not contain the private key, .pfx file usually contains the private key.
  • Use Certutil –importpfx to import a .pfx, usually to personal store (My store). Certutil –importcert is meant to import a cert into a CA’s database. This is useful when using the CA to archive certs and keys that were not issued by the CA, or to be able to manage CRLs for a cert lost from the CA’s database for some reason.
  • Certutil -repairstore can be used to associate a certificate with the matching private key. This could be useful if someone deleted a certificate from the store and lost the CERT_KEY_PROV_INFO_PROP_ID that points at the private key.
  • Certreq -accept installs an issued certificate when there is an pending certificate request in the Request store)
    • The command should be used if there is a pending request as it will pick up the CERT_KEY_PROV_INFO_PROP_ID property, friendly name, and other properties from the pending (also known as dummy) certificate. Then, it attaches to the new certificate and removes the pending (dummy) certificate.
    • The sequence of this flow follows this command order:
      • Certreq -new (creates a new request and dummy certificate)
      • Certreq -submit (or using some manual submission method via a Web page)
      • Certreq -retrieve (if there is a pending request that is later issued)
      • Certreq -accept (installs the certificate)

Additional references for CertUtil Examples

Certificate Revocation and Status Checking - A link to the whitepaper in the TechNet Library; the appendices (Appendixes) have many examples

Basic CRL checking with certutil - A link to an entry in the PKI blog

Additional details about certificate status codes

CERT_TRUST_STATUS Structure - provides certificate status code meanings

Command line references for CertUtil

Certutil on MSDN - A task oriented reference for the Certutil command, with great details.

Certutil Certificates - A link to TekWeb.dk, which is very much like a command reference

Certutil - The Windows Server 2008 command line reference in the TechNet Library

Certutil tasks for managing certificates - Windows Server 2003 Whitepaper that has command reference like information

Certutil tasks for key archival and recovery - Windows Server 2003 document



Leave a Comment
  • Please add 5 and 7 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Kurt L Hudson MSFT edited Revision 15. Comment: Added command variations as requested in the comments section

  • Kurt L Hudson MSFT edited Revision 14. Comment: Added an example about viewing certificate templates

  • Kurt L Hudson MSFT edited Revision 13. Comment: Updated based on feedback from Senior developer

  • Kurt L Hudson MSFT edited Revision 12. Comment: Added a Q & A section

  • Kurt L Hudson MSFT edited Revision 11. Comment: Added a new example

  • Kurt L Hudson edited Revision 9. Comment: Updated with a new good reference

  • Kurt L Hudson edited Revision 8. Comment: added more examples

  • Kurt L Hudson edited Revision 6. Comment: added anchor link

  • Kurt L Hudson edited Revision 5. Comment: Added command to clear policycache

  • Kurt L Hudson edited Revision 4. Comment: updated with certutil -getcert

Page 1 of 2 (14 items) 12
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Kurt L Hudson edited Original. Comment: Added more examples

  • Kurt L Hudson edited Revision 1. Comment: added an additional reference

  • Kurt L Hudson edited Revision 2. Comment: Added an example and did some reformatting

  • Kurt L Hudson edited Revision 3. Comment: Updated further to show additional commands

  • Kurt L Hudson edited Revision 4. Comment: updated with certutil -getcert

  • Kurt L Hudson edited Revision 5. Comment: Added command to clear policycache

  • Kurt L Hudson edited Revision 6. Comment: added anchor link

  • Kurt L Hudson edited Revision 8. Comment: added more examples

  • Kurt L Hudson edited Revision 9. Comment: Updated with a new good reference

  • Kurt L Hudson MSFT edited Revision 11. Comment: Added a new example

  • Kurt L Hudson MSFT edited Revision 12. Comment: Added a Q & A section

  • Kurt L Hudson MSFT edited Revision 13. Comment: Updated based on feedback from Senior developer

  • how exactly you use "CertUtil -deleteEnrollmentServer" as I want to delete a invalid address

    -----------------------

    Kurt Hudson's response

    First, run certutil -deleteEnrollmentServer -? (notice that you have three authentication options) Kerberos | UserName | ClientCertificate

    certutil -deleteEnrollmentServer Kerberos

    is one example. That should remove the CEP URL, if you are using Kerberos authentication. If using a different authentication method, then select the one that is appropriate.

  • Kurt L Hudson MSFT edited Revision 14. Comment: Added an example about viewing certificate templates

  • Is there any way to find out the details of certificate template ? for.eg. I wan to find Key Usage or Extended Key usage of given template name.

    Thanks !

    ------------------------------

    Kurt Hudson's response:

    I have added that example to the article along with another about dumping all the certificates to a text file. You must have the certificate template name that you want to dump. For example, if you wanted the settings for a certificate template with a name of CEPEncryption sent to a .txt file, then you would run:

    certutil > -v -template CEPEncryption > CEPEncryptionSettings.txt

    notepad CEPEncryptionSettings.txt

    Notepad would display the settings you want. If you just want the output on the screen, remove the > CEPEncryptionSettings.txt part of the command and it will output to the screen.

Page 1 of 2 (19 items) 12