Restoration of a Certification Authority Certificate with Hardware Security Module (HSM)

The following describes how to restore a CA certificate with a hardware security module (HSM).

Restoring the certification authority certificate may be necessary for the following reasons:

Restoration of a CA certificate with a software key is fundamentally different and is described in this article .

For the following procedure, it is necessary as preparation that the key storage provider belonging to the hardware security module is already installed and set up. Access to the key material from the target computer must therefore already be guaranteed. Since this procedure differs depending on the HSM manufacturer, it is not described here. The documentation of the respective HSM manufacturer must be used for this.

If multiple CA certificates are to be restored, the following steps must be repeated accordingly for each certificate.

Implementation

Do you know TameMyCerts? TameMyCerts is an add-on for the Microsoft certification authority (Active Directory Certificate Services). It extends the function of the certification authority and enables the application of rule sets to realize the secure automation of certificate issuance. TameMyCerts is unique in the Microsoft ecosystem, has already proven itself in countless companies around the world and is available under a free license. It can be downloaded via GitHub and used free of charge. Professional maintenance is also offered.

To restore the CA certificates, their version without the private key is required - i.e., for example, the version stored in the Authority Information Access (AIA) store. The certificates are located on the source system under C:\Windows\System32\CertSrv\CertEnroll.

Explorer, folder C:\Windows\System32\CertSrv\CertEnroll: six CA certificate files (.crt) of "ADCS Labor Issuing CA 2" highlighted, plus CRL files (.crl)

On the target computer, open the computer account certificate management console (certlm.msc). Right-click on "Personal", then "All Tasks" - "Import...".

certlm: context menu "All Tasks", "Import..." on the "Personal" folder of "Certificates - Local Computer"

In the next screen, "Next" is clicked.

Welcome page of the "Certificate Import Wizard", store location "Local Machine" selected

With "Browse..." the backup file is now selected.

Certificate Import Wizard, "File to Import": empty "File name" field, "Browse..." button highlighted

Now the CA certificate to be restored is selected.

Dialog "Open" in the folder C:\LabFiles with several certificate files CA03.intra.adcslabor.de_ADCS Labor Issuing CA, file type "X.509 Certificate"

Now the next dialog can be called with "Next".

Certificate Import Wizard, "File to Import": file name C:\LabFiles\CA03.intra.adcslabor.de_ADCS Labor Issuing CA 2.crt

The default selection ("Personal") for saving the certificate can be kept.

Certificate Import Wizard, "Certificate Store": "Place all certificates in the following store", certificate store "Personal"

Click on "Finish" to restore the CA certificate.

Certificate Import Wizard, summary: store "Personal", content "Certificate", file name C:\LabFiles\CA03.intra.adcslabor.de_ADCS Labor Iss...

If the import was successful, a corresponding message is generated.

"Certificate Import Wizard" message: "The import was successful."

It should be noted that, as expected, the certification authority certificate cannot yet access its private key. This must now be connected in the next step.

certlm, Personal\Certificates folder: certificate "ADCS Labor Issuing CA 2" (highlighted)

First, the SHA1 fingerprint (thumbprint) of the certificate is required. This can be identified via the certificate properties dialog or by the following Windows PowerShell command:

Get-ChildItem -Path Cert:\LocalMachine\My\

PowerShell: dir Cert:\LocalMachine\My\ shows thumbprint BD5DDD4F2DD772E6F0E461B3765393CB1329A6A1 with subject CN=ADCS Labor Issuing CA 2

Now the private key must be linked to the certificate identified by the fingerprint. This must be done in the NT AUTHORITY\SYSTEM security context. There are several ways to switch to this security context:

  • Create a scheduled task that runs under SYSTEM and executes a script. This method has the advantage that no third-party programs need to be executed.
  • Switch to the system context via psexec .

In the following the method with psexec is described. You can switch to the system context with the following command:

psexec -s -i cmd.exe

Command prompt: whoami returns "nt authority\system"

The following command line command is then executed:

certutil -repairstore my {Fingerabdruck}

If the command was successful, this is output on the command line.

certutil -repairstore my: provider Utimaco CryptoServer Key Storage Provider, "Signature test passed", "CertUtil: -repairstore command completed successfully."

If you now refresh the view in the management console for certificates of the computer account, you should now see that there is a private key to the certificate.

certlm, Personal\Certificates folder: certificate "ADCS Labor Issuing CA 2" (highlighted)