4. mTLS in Apache HTTPD using a Self-Signed CA and Client Certificates
Creating a Self-Signed CA and Client Certificate Using Keystore Explorer (PKCS#12) for mTLS in Apache HTTPD
Overview
Section titled “Overview”This guide walks you through the process of generating a self-signed Certificate Authority (CA) and a client certificate using Keystore Explorer, with certificates stored in PKCS#12 (.p12) format. These certificates will be used to enable mutual TLS (mTLS) authentication in Apache HTTPD for the specific path /access/authn/cert.
Prerequisites
Section titled “Prerequisites”Before you begin, ensure you have:
- Keystore Explorer installed (Download)
- Apache HTTPD installed and configured
Step 1: Create a Self-Signed CA Certificate
Section titled “Step 1: Create a Self-Signed CA Certificate”- Open Keystore Explorer and create a new keystore (
PKCS#12format). - Click Tools → Generate Key Pair.
- Select RSA (2048-bit or higher) and click OK.
- Enter the Distinguished Name (DN) details (e.g.,
CN=MyCA, O=MyOrg, C=SE). - Set the validity period (e.g., 3650 days for 10 years). Press Apply to update the years.
- Click Add Extensions
- Click Use Standard Template
- Select CA and click OK
- Click OK.
- Click OK.
- Keep or change the Alias. Click OK
- Set a password for the key pair and click OK.
- Click OK.
- Save the keystore (
myCA.p12). - Set a password for the keystore and click OK.
Step 2: Export the CA Certificate
Section titled “Step 2: Export the CA Certificate”- Open
myCA.p12in Keystore Explorer. - Right-click the CA key pair → Export → Export Certificate Chain.
- Choose Head Only, X.509 and PEM format and save it as
ca.cer.
Step 3: Create a Client Certificate
Section titled “Step 3: Create a Client Certificate”- Open
myCA.p12in Keystore Explorer. - Right-click the CA key pair → Sign
- Select Sign new key pair, select (2048-bit or higher) and click OK.
- Set the validity period (e.g., 3650 days for 10 years). Press Apply to update the years.
- Enter the Distinguished Name (DN) details (e.g.,
CN=Client, O=MyOrg, C=SE). - Click Add Extensions
- Click Use Standard Template
- Select SSL Client and click OK
- Click OK
- Click OK.
- Keep or change the Alias. Click OK
- Set a password for the key pair and click OK.
- Right-click the Client key pair → Export → Export Key Pair.
- Select PKCS#12, set a password for the key pair and the path for the Export File.
- Click Export.
- Save the keystore if you would like to keep the client certificate in the keystore.
Step 4: Configure Apache HTTPD for mTLS on /access/authn/cert
Section titled “Step 4: Configure Apache HTTPD for mTLS on /access/authn/cert”-
Copy
ca.crtto the Apache configuration directory. -
Edit the Apache configuration file (
httpd.conforssl.conf) and add the following configuration:Add the ca certificate and disable TLS1.3, add our change the following settings:
SSLCACertificateFile "${SRVROOT}/conf/ca.cer"SSLProtocol all -SSLv3 -TLSv1.3SSLProxyProtocol all -SSLv3 -TLSv1.3Add the Location section:
<Location "/access/authn/cert">SSLVerifyClient requireSSLVerifyDepth 10# clear the SSL_* valuesRequestHeader set SSL_CLIENT_CERT ""RequestHeader set SSL_CLIENT_VERIFY ""# add whatever SSL_* variables needed to pass to web applicationRequestHeader set SSL_CLIENT_CERT "%{SSL_CLIENT_CERT}s"RequestHeader set SSL_CLIENT_VERIFY "%{SSL_CLIENT_VERIFY}s"RequestHeader add X-Forwarded-Scheme https</Location> -
Restart Apache:
Terminal window systemctl restart httpd
Step 6: Import the client keystore
Section titled “Step 6: Import the client keystore”- Import the certificate to the OS using the OS tool.
Conclusion
Section titled “Conclusion”You have successfully created a self-signed CA, a client certificate, and configured Apache HTTPD for mTLS authentication on the specific path /access/authn/cert using Keystore Explorer, with certificates stored in PKCS#12 (.p12) format.