How secure is the "Allow private key to be exported" setting in the certificate templates?

PKI administrators often assume that the option in the certificate template not to allow the private key to be exported is binding.

Template properties "ADCS Labor Benutzer", "Request Handling" tab: "Allow private key to be exported" is not enabled (marked in yellow)

However, that is not the case.

This is merely a default setting, which the enrollee can change at any time when submitting the certificate request manually.

When submitting a request via the Microsoft Management Console (MMC), you can expand the "Details" section during the certificate template selection step. There, you will find a "Properties" button.

Dialog "Certificate Information": template "ADCS Labor Benutzer" with STATUS: Available, "Details" and "Properties" buttons marked in yellow

Here, on the "Private Key" tab, we'll find the option to enable exporting.

Dialog "Certificate Properties", "Private Key" tab: "Make private key exportable" is enabled (marked in yellow)

Furthermore, even a key generated as non-exportable is not safe from export. There are relevant tools to export such certificates including their keys.

Hardening Options with TameMyCerts

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.

Whether a private key can be exported or not cannot be determined from the certificate request. The entire concept of exportability is also a Microsoft-proprietary feature of the Cryptographic Service Provider or Key Storage Provider and therefore exists only within this ecosystem.

To regain a certain degree of control, we can take advantage of the fact that—when a certificate request is generated using a Windows API—the certificate request contains metadata indicating which process generated the key pair.

However, it should be noted right away that this meta-information can be falsified by the enrollee with sufficient effort.

Request data: attribute 1.3.6.1.4.1.311.21.20 (Client Information) with User INTRA\rudi, Machine CLIENT2.intra.adcslabor.de and Process powershell.exe marked in red

The TameMyCerts Policy Module for Microsoft Active Directory Certificate Services can determine the process used to create the certificate request from the request itself and, based on this information, decide whether or not to issue a certificate.

Most users would likely request such an exportable certificate using the Microsoft Management Console (MMC). Exportable keys could also be generated using other tools (such as certreq.exe, certutil.exe, or OpenSSL).

With TameMyCerts, we can explicitly block these processes.

OpenSSL and other non-Microsoft tools do not include process information in the certificate request. In this case, TameMyCerts would also reject the certificate request.

<CertificateRequestPolicy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
  <DisallowedProcesses>
    <string>mmc.exe</string>
    <string>powershell.exe</string>
    <string>certutil.exe</string>
    <string>certreq.exe</string>
    <!-- OpenSSL doesn't include process information and will therefore be denied as well -->
  </DisallowedProcesses>
  <!-- additional Directives go here -->
</CertificateRequestPolicy>

An even more elegant solution would be to allow only the Windows autoenrollment process. This process runs under the Windows Task Scheduler (taskhostw.exe).

<CertificateRequestPolicy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <AllowedProcesses>
    <string>taskhostw.exe</string>
  </AllowedProcesses>
  <!-- additional Directives go here -->
</CertificateRequestPolicy>

If a user attempts to request a certificate using an unauthorized process, TameMyCerts detects this and rejects the certificate request.

Dialog "Certificate Enrollment": Computer_Online_process_allowed with STATUS: Request denied, 0x80094012 (-2146877422 CERTSRV_E_TEMPLATE_DENIED)

TameMyCerts will write a corresponding entry to the certification authority's event log on the certification authority. This can even trigger an alarm.

Event 6, TameMyCerts: Request 4180 for Computer_Online_process_allowed was denied because process "mmc.exe" is not on the list of allowed process names

External sources