Cryptographic Hardening of SCEP Transactions for the Network Device Enrollment Service (NDES)

The Simple Certificate Enrollment Protocol (SCEP) is an ancient protocol from the early 2000s. It does not use Transport Layer Security (TLS). Therefore, the protocol messages themselves are encrypted and signed at the message level (PKCS #7 / CMS).

When sending the certificate request to the NDES server, the client will encrypt the certificate request with the NDES server's CEP Encryption certificate (which was previously communicated to it via the GetCACert message).

When the issued certificate is received, the NDES server will encrypt the response with a self-signed certificate temporarily created by the SCEP client.

In both cases, a symmetric encryption algorithm is used.

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.

The possible capabilities are defined for SCEP in RFC 8894 and are communicated to the SCEP client via the "GetCACaps" operation.

CapabilityDescription
AESSupport for the Advanced Encryption Standard (AES128-CBC).
DES3Support for the Triple Data Encryption Standard (3DES-CBC).
GetNextCACertFor the rollover of certification authority certificates.
Not supported by NDES.
POSTPKIOperationPerform the operations using HTTP POST instead of GET.
RenewalRenewing a certificate using an existing certificate .
SHA-1Support for the SHA-1 hash algorithm.
SHA-256Support for the SHA-256 hash algorithm.
SHA-512Support for the SHA-512 hash algorithm.
SCEPStandardIndicates that the server supports all SCEP standard operations that are mandatory to implement according to the RFC. These include, among others, "AES", "POSTPKIOperation", and "SHA-256".

Default setting for NDES

NDES communicates the following capabilities to SCEP clients in its out-of-the-box state:

  • POSTPKIOperation
  • Renewal
  • SHA-512
  • SHA-256
  • SHA-1
  • DES3

You can query the capabilities from the NDES server using a browser or PowerShell.

Invoke-WebRequest -Uri "http://localhost/certsrv/mscep/mscep.dll/pkiclient.exe?operation=GetCACaps"

Browser: the NDES GetCACaps response lists SHA-512, SHA-256, SHA-1 and DES3

As you can see, the more modern AES algorithm is missing here. In the following, we want to get NDES to offer it as well.

The SCEP standard specifies only the 128-bit AES-CBC algorithm. Theoretically, SCEP clients could also use other algorithms. However, there are no corresponding standardized capabilities.

Changing the Default Settings

It is important to understand that we are simply using capabilities to communicate which algorithms the NDES server definitely supports. Clients are not required to adhere to the propagated capabilities. NDES will accept all algorithms from RC2 to AES right out of the box. Assuming that clients understand and use the advertised capabilities, we can at least ensure that clients use AES instead of 3DES. However, we cannot enforce anything.

You can configure the propagated capabilities using the following registry key on the NDES server:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MSCEP\CACapabilitiesAlgorithms

This registry key does not exist in the NDES default installation. It can be created using the following command (with default settings):

certutil -f -setreg mscep\CACapabilitiesAlgorithms\CACapabilitiesAlgorithms "SHA-512\nSHA-256\nSHA-1\nDES3"

The "POSTPKIOperation" and "Renewal" operations are not configurable; therefore, they neither need to nor can be set via the registry.

For example, to add support for the Advanced Encryption Standard (AES):

certutil -setreg mscep\CACapabilitiesAlgorithms\CACapabilitiesAlgorithms +AES

The values are stored in the registry as plain strings and are output in that format. Therefore, it is essential to pay attention to the correct spelling (as defined in RFC 8894 ).

For example, to remove support for Triple DES and SHA-1:

certutil -setreg mscep\CACapabilitiesAlgorithms\CACapabilitiesAlgorithms -DES3
certutil -setreg mscep\CACapabilitiesAlgorithms\CACapabilitiesAlgorithms -"SHA-1"

The removal of 3DES and SHA-1 should be carefully considered, as they can be used as a fallback for clients that do not support AES. If these capabilities are removed, clients may end up using even weaker algorithms. It is best to place them below stronger algorithms.

Once the change has been made, the NDES service must be restarted. The easiest way to do this is to restart the IIS service.

iisreset

Browser: the NDES GetCACaps response now lists only SHA-512, SHA-256 and AES

Client side behavior

How SCEP clients behave depends on the specific implementation.

With some SCEP clients (e.g., BlackBerry Enterprise Mobility Suite), you can configure the use of specific algorithms (the capabilities offered by the NDES server are then generally ignored).

SCEP clients that use the Windows APIs (such as Microsoft Intune, certutil, or PSCertificateEnrollment) evaluate the capabilities offered by the NDES server from top to bottom and use the first hash algorithm and encryption algorithm in the list that are supported by the client's public key. Which ones these are depends on which algorithm and which CSP/KSP was used for the certificate request.

But be careful! If a client doesn't support any of the offered algorithms, it will fall back to something that the underlying CSP/KSP understands! More on this below.

Functional test

After making our changes, we should verify that the NDES service is working properly. Complete instructions can be found in the article "Performing a functional test for the Network Device Enrollment Service (NDES) ".

We'll focus on the actual process of requesting a certificate via SCEP. We can do this easily using the PSCertificateEnrollment PowerShell module. It queries the NDES server's capabilities and applies them accordingly when requesting the certificate.

It is important to understand that, by default, PSCertificateEnrollment uses the "Microsoft Software Key Storage Provider" for the certificate request's key pair, which supports both 3DES and AES.

$otp = Get-NDESOTP -ComputerName NDES01.intra.adcslabor.de
Get-NDESCertificate `
  -Subject "CN=hello" `
  -ChallengePassword $otp `
  -ComputerName "NDES01.intra.adcslabor.de"

PowerShell: Get-NDESCertificate with -Subject "CN=hello" returns a certificate with the subject CN=hello

Since SCEP uses unencrypted HTTP by default, we can use Wireshark to examine the communication and extract the SCEP message.

Wireshark, filter "http": HTTP POST to /certsrv/mscep/mscep.dll/pkiclient.exe with 3598 bytes of data

We can now open it with the ASN.1 Editor by Vadims Podans and take a look at the inner PKCS7 message.

With the default settings of NDES, we will see "3des" here as the encryption algorithm for the PKCS7 enveloped data.

ASN.1 view of a SCEP request: encryption algorithm 3des (1.2.840.113549.3.7) marked in red

After changing the capabilities, we should see that it now says "aes128-CBC".

ASN.1 view of a SCEP request: encryption algorithm aes128-CBC (2.16.840.1.101.3.4.1.2) marked in red

Pitfalls

Which encryption is actually used depends on several factors.

The key storage provider of the requesting client must be compatible

NDES does not enforce any specific algorithm. Clients get through even with completely outdated algorithms.

For testing purposes, we'll generate our key pair on the client once using the (not recommended!) Microsoft Base Cryptographic Provider v1.0 , which supports neither 3DES nor AES.

$otp = Get-NDESOTP -ComputerName NDES01.intra.adcslabor.de
Get-NDESCertificate `
  -Subject "CN=hello" `
  -ChallengePassword $otp `
  -ComputerName "NDES01.intra.adcslabor.de" `
  -Ksp "Microsoft Base Cryptographic Provider v1.0"

Now we can see that the message was encrypted using the RC2 algorithm. NDES accepts this message and processes it without any problems.

ASN.1 view of a SCEP request: encryption algorithm rc2 (1.2.840.113549.3.2) marked in red

The key storage provider of the NDES server must be compatible

The key storage of the NDES server (more precisely, of the CEP Encryption certificate used) must also support the algorithms used.

At first glance, that sounds counterintuitive, because NDES only supports cryptographic service providers (CSP), very few of which support 3DES, let alone AES.

However, if a Microsoft software CSP is used, the NDES server's CryptoAPI (CAPI2) will transparently open the key of the CEP Encryption certificate as an NCrypt key to perform the operation.

If, on the other hand, a third-party cryptographic service provider is used (for example, when a hardware security module is used for NDES), this is not possible. If the third-party CSP has not implemented the relevant algorithms, they cannot be used with NDES.

If a SCEP certificate request fails for this reason, NDES will log the event with ID 18 of the source Microsoft-Windows-NetworkDeviceEnrollmentService . On the client side, the NDES server will return error code 0x80090005 (-2146893819 NTE_BAD_DATA).

Conclusion

By adjusting the capabilities communicated by NDES to clients, we can, under certain circumstances, get them to use AES instead of 3DES as the default encryption algorithm.

Even if we don't do this, NDES already accepts AES-encrypted SCEP messages in its default configuration.

In addition, it has now become standard practice to configure HTTPS for NDES , so the entire discussion is rather academic anyway, since in this case there is an additional TLS layer, which ultimately makes the inner encryption algorithm less relevant.

External sources