Implementing Two-Tier PKI on Windows Server 2022 – Part 2

28 Sep 2024 | PKI, Microsoft

In Part 1 of our guide on implementing a Two-Tier PKI on Windows Server 2022, we introduced the basics of PKI, set up the lab configuration, and established the offline Root CA. Now, in Part 2, we’ll dive deeper into configuring the Subordinate CA.

Introduction

Before proceeding, make sure you’ve read Part 1 to understand the context and setup. Remember, this guide is intended for testing and learning purposes only. I can’t be held responsible for any damage (financial, physical, emotional, etc.) that may result from following these steps. PKI is complex, so it’s crucial to have a solid understanding of the topic before you begin.

For lab setup and additional details, refer to Part 1 of the guide.

Subordinate CA Configuration

Our SubCA is already part of the pwoks.local domain. Let’s start configuring it. Important: Do not turn off the Root CA until the entire PKI implementation is complete!

DNS Configuration:

On your domain controller, in the DNS zone (e.g., pwoks.local), add the following CNAME records:

  • OCSP.pwoks.local
  • PKI.pwoks.local

For the alias name of the new CNAME record, enter OCSP (and for the second record, enter PKI). In the FQDN field of the CNAME record, enter SubCA.pwoks.local (the name and domain of the Subordinate CA) for both records.

This is how everything should look once configured.

DNS configuration in DC for pki and ocsp

If done correctly, pinging pki.pwoks.local or ocsp.pwoks.local from a client should resolve to the IP of the Subordinate CA.

ping test to pki and ocsp

Next, we’ll move on to configuring the Subordinate CA, named SubCA in this example.

Create CAPolicy.inf File:

Just like with the Root CA, create a CAPolicy.inf file and place it in the root directory of Windows (C:\Windows\CAPolicy.inf). If you have your PEN number, modify the OID line in the InternalPolicy section to OID=1.3.6.1.4.1.XX (where XX is your PEN number).

Here is the CAPolicy.inf file needed for the Subordinate CA.

[Version]
Signature=”$Windows NT$”
[PolicyStatementExtension]
Policies = AllIssuancePolicy, InternalPolicy
Critical = FALSE
[AllIssuancePolicy]
OID = 2.5.29.32.0
[InternalPolicy]
OID = 1.2.3.4.1455.67.89.5
Notice = “The Pwoks.local Certification Authority is internal only.”
URL = http://pki.pwoks.local/cps.html
[Certsrv_Server]
RenewalKeyLength = 4096
RenewalValidityPeriod = Years
RenewalValidityPeriodUnits = 5
AlternateSignatureAlgorithm = 0
LoadDefaultTemplates = 1

Install AD CS Role:

Ensure you are logged in to the Subordinate CA as a Domain Administrator to avoid any issues during installation and configuration.
Open Server Manager and add the Active Directory Certificate Services role.
Add AD CS Role

Confirm the pop-up window, then select Certification Authority and Certification Authority Web Enrollment.
Add CA and Web Enrollment role services

On the Web Server screen, confirm everything and click Next.
Web Server Role Services

Configure Subordinate CA:

In Server Manager, select Configure Active Directory Certificate Services on the destination server. Use Domain Administrator and select Certification Authority and Certification Authority Web Enrollment.
Configure AD CS Role Services

Choose the following settings:

  • Certificate Authority Setup Type: Enterprise CA
  • Certificate Authority Type: Subordinate CA
  • Cryptographic Provider: RSA#Microsoft Software Key Storage Provider
  • Key Length: 4096 Bits
  • Signature Hash Algorithm: SHA256
  • CA Common Name: pwoks-SubCA-CA
  • Validity Period: 5 years

Save certificate request file to Subordinate Server
Save a certificate request file for subordinate ca

The expected result is that we need to send the generated .req file to the Root CA to issue a certificate.

Issue Subordinate Certificate:

Start certsrv.msc on the Subordinate CA to validate the setup. The service will be stopped until we get the certificate from the Root CA.
subordinateca service status
On the Subordinate CA (SubCA), create a folder named C:\CertData. Copy the .crl and .crt files created on the Root CA into this folder. The .req file should also be in the root of the C: drive.
Create CertData folder

Transfer the .req file from the Subordinate CA to the Root CA. Since keeping the Root CA on the network isn’t advisable use a USB drive
Copy Certification Request file to rootCA

Creating the CertData Virtual Directory on SubCA

Open IIS Manager. Expand Sites, right-click on Default Web Site, and select Add Virtual Directory.
Add CertData virtual directory on IIS

Enter CertData as the alias and C:\CertData as the physical path. Confirm with OK. Select the newly created virtual directory, click on Directory Browsing, and enable it.
Enable Directory Browsing on CertData

Restart IIS to apply the changes. And now we need to validate the setup. From a client machine, access http://pki.test.local/CertData/ in a browser to ensure everything is set up correctly.
CertData IIS access validation

Enable Double Escaping in IIS

In IIS on the Subordinate CA, go to Default Website. Select Request Filtering from the middle window, then Edit Feature Settings. Enable Allow double escaping and confirm with OK.
Allow Double Escaping

Creating the Subordinate Certificate

On the Root CA, open the Certification Authority console (certsrv.msc). Right-click on Root CA, select All Tasks, and then Submit new request.
Submit Cert Request on RootCA

Browse to C:\RootCA and select the .req file from the Subordinate CA
Select req file

Issue the Certificate:

On the Root CA, right-click on the request ID (e.g., request ID 2) and select All Tasks > Issue.
Issue pending request on RootCA

The certificate will now appear in the Issued Certificates section.
Issued Certificates

Double-click the certificate to verify its details, such as a validity period of 5 years and specifications like RSA 4096 and SHA256.

Export the Certificate:

While viewing the certificate details, go to the Details tab and click on Copy to File….
Exporting Certificate

This will start the Certificate Export Wizard. Click Next. Select the .P7B format and check the option to Include all certificates in the certification path if possible.
Export Certificate file format

Save the file as SubordinateCA.p7b in the C:\RootCA folder.

Transfer the Certificate:

Transfer the SubordinateCA.p7b file from the Root CA to the Subordinate CA (SubCA) using a USB drive or network, depending on your company’s security policies. Copy the file to the C:\ directory on SubCA.
Copy p7b certificate from RootCA to SubordinateCA

Install the CA Certificate on Subordinate CA:

On the Subordinate CA (SubCA), open the Certification Authority console (certsrv.msc). Right-click on your server, select All Tasks > Install CA Certificate….
Install Issued Certificate to SubCA

If you encounter the error “Cannot verify certificate chain. Do you wish to ignore the error and continue? The revocation function was unable to check revocation because the revocation server was offline 0x80092013”, confirm with OK
AD CS Cert Verification Error

Now Start Service
Start Service

oppps… Another error
Start Service Error

To fix this issue open a command prompt as an administrator on the Subordinate CA. Run the following command to ignore offline revocation checks:

certutil –setreg ca\CRLFlags +CRLF_REVCHECK_IGNORE_OFFLINE
Fix Service Start Error
Attempt to start the Certification Authority service againCA Service Started
By following these steps, you should be able to successfully issue and install the Subordinate CA certificate, even if the Root CA is offline during the process

Set Maximum Certificate Age

To ensure that certificates issued by SubCA are valid for only one year, open PowerShell as an administrator and enter the following command:

certutil.exe -setreg CA\ValidityPeriodUnits 1
certutil.exe -setreg CA\ValidityPeriod “Years”
net stop CertSvc
net start CertSvc

Set Maximum Certificate Age
While you’re at it, you can set a few other configurations:

Certutil -setreg CA\CRLPeriodUnits 1
Certutil -setreg CA\CRLPeriod “Weeks”
Certutil -setreg CA\CRLDeltaPeriodUnits 1
Certutil -setreg CA\CRLDeltaPeriod “Days”
Certutil -setreg CA\CRLOverlapPeriodUnits 12
Certutil -setreg CA\CRLOverlapPeriod “Hours”
net stop CertSvc
net start CertSvc

Additional Settings for Certificate Issuing

Let’s back to IIS. Open IIS and select CertEnroll. From the main screen, select Directory Browsing and enable it.Enable directory Browsing for CertEnroll
Restart the IIS. Test the link: http://pki.pwoks.local/CertEnroll. If you can click on files and download them, it works. If not, check the double escaping configured earlier.Validate Certenroll

Enable Auditing

Enable audit object access in Local Security Policy for both failure and success. Open PowerShell as an administrator and type:

certutil.exe -setreg CA\AuditFilter 127
net stop CertSvc
net start CertSvc

Subordinate CA CDP and AIA Configuration

Repeat the CDP and AIA configuration on the Subordinate CA. Run Command Prompt as an administrator and type the following in one line:

AIA Configuration:
certutil -setreg CA\CACertPublicationURLs “1:C:\Windows\system32\CertSrv\CertEnroll\%1_%3%4.crt\n2:ldap:///CN=%7,CN=AIA,CN=Public Key Services,CN=Services,%6%11\n2:http://pki.pwoks.local/CertEnroll/%1_%3%4.crt”

 

CDP Configuration:
certutil -setreg CA\CRLPublicationURLs “65:C:\Windows\system32\CertSrv\CertEnroll\%3%8%9.crl\n79:ldap:///CN=%7%8,CN=%2,CN=CDP,CN=Public Key Services,CN=Services,%6%10\n6:http://pki.pwoks.local/CertEnroll/%3%8%9.crl”

Check the values with:

certutil -getreg CA\CRLPublicationURLs
certutil -getreg CA\CACertPublicationURLs
Check AIA and CDP Values

Restart the services:

net stop CertSvc
net start CertSvc

Publish the configurations:

certutil -crl
Open certsrv.msc, select Properties of the server, and go to the Extension tab. For CDP, select http and ensure that “Include in CRLs…” and “Include in CDP…” are selected.
SubCA CDP

For AIA, ensure that “Include in AIA extension” is selected for the http link.SubCA AIA

Certificate Practice Statement Document

Create cps.html and copy the following code into it. Then, copy cps.html to c:\inetpub\wwwroot:

<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″>
<title>Pwoks Domain Certification Practice Statement</title>
</head>
<body>
<h1>Pwoks Domain Certification Practice Statement</h1>
<p>The Pwoks Domain Certification Authority is internal only.</p>
<p>All issued certificates are for internal usage only.</p>
<p>Unauthorized usage strictly forbidden.</p>
</body>
</html>

You can edit it according to your needs.

CPS test

Firewall Rules

Ensure the firewall is on and enable the following rules:

Echo Request – ICMPv4-in (ICMP) so we can ping
World Wide Web Services HTTP Traffic-In TCP/80
World Wide Web Services HTTPS Traffic-In TCP/443

Add Root CA to Active Directory

Since the Root CA is offline, add it to Active Directory so it is recognized. Run PowerShell as an administrator and type:

certutil.exe -dspublish `
-f “C:\CertData\RootCA_Pwoks-RootCA-CA.crt” RootCA

certutil.exe -addstore `
-f root “C:\CertData\RootCA_Pwoks-RootCA-CA.crt”

certutil.exe -addstore `
-f root “C:\CertData\Pwoks-RootCA-CA.crl”

LET AD to recognize RootCA

If you encounter issues, open Command Prompt as an administrator, navigate to C:\CertData where you have the RootCA CRL and CRT files, and execute the following command:

certutil -f -dspublish Pwoks-RootCA-CA.crl

Copy the ROOTCA CRL and CRT files from C:\CertData to C:\Windows\System32\certsrv\CertEnroll.

Active Directory Configuration

On your Domain Controller, open Active Directory Sites and Services. Select View and enable Show Services Node.
DC AD Site Services
Open Public Key Services and click on AIA. You should see both SubCA and ROOTCA
PKS AIA
Under CDP, you should have two subfolders named SubCA (Subordinate CA) and RootCA (Offline Root CA), each with distribution points inside.
PKS CDP

Verifying PKI Infrastructure

On SubCA, run pkiview.msc. Ensure there are no red crosses or “unable to download” statuses for the offline Root CA and Subordinate CA.
PKI View Status
If you encounter issues, ensure the rootca CRL and CRT files are in C:\Windows\System32\certsrv\CertEnroll and execute the extra dspublish command for the CRL in Command Prompt.
Congratulations! You now have a functional Two-Tier CA. Remember not to turn off the Root CA until the entire PKI implementation is complete.

Categories

Recent Posts

Implementing Two-Tier PKI on Windows Server 2022 – Part 6

Implementing Two-Tier PKI on Windows Server 2022 – Part 6

Implementing Two-Tier PKI on Windows Server 2022 – Part 6 Active Directory Certificate Services offers numerous predefined templates for various uses. We’ll explore some of these templates, customize them, and discuss best practices. Key Points for Certificate...

Implementing Two-Tier PKI on Windows Server 2022 – Part 6

Implementing Two-Tier PKI on Windows Server 2022 – Part 5

In part five, we will cover Private Key Archive and Recovery. Backup is crucial, and we should implement it in this architecture. We will also explore Certificate Templates to enable Private Key Archival. Let’s begin. If there’s anything unclear, please refer to the...

Implementing Two-Tier PKI on Windows Server 2022 – Part 6

Implementing Two-Tier PKI on Windows Server 2022 – Part 4

In the first and second parts, we deployed PKI, and in the third part, we made these certificates available on our domain via group policy. Now, we will configure the Online Responder Role, which is crucial for the revocation of certificates. This guide will show you...

Implementing Two-Tier PKI on Windows Server 2022 – Part 6

Implementing Two-Tier PKI on Windows Server 2022 – Part 3

Configuring Root and Subordinate Certificates Deployment via Group Policy on Windows Server 2022 In the first two parts, we successfully set up our Two-Tier PKI infrastructure on Windows Server 2022. In this third part, we’ll configure the deployment of root and...

Share This