Creating a New CA (SHA-512, 4096-bit) with PKCS #11 Smart Card Storage and Subordinate CA
Create a certificate authority with a 4096-bit RSA key, SHA-512 signatures, PKCS #11 smart card key storage, and a subordinate CA.
In this note I create a new Certificate Authority (CA) with a 4096-bit RSA key and SHA-512 as the signature hash. The root private key lives on a PKCS #11 compatible smart card, and the root then signs a subordinate (sub) CA.
Why Use a Smart Card (PKCS #11)?
A private key in a file can be copied, and you may never notice. A key on a smart card, or on a Hardware Security Module (HSM), can't be easily exported in plain text. Signing and decryption happen on the card, so the key is less exposed, and many cards also have protection against physical tampering and side-channel attacks.
Recommended Security Controls
Keep the root CA offline, on a laptop or computer that is not connected to any network. Bring it online only in a secure environment, when you issue or renew certificates. It should be a dedicated machine with the bare minimum of software (OpenSSL, PKCS #11 drivers), patched and hardened.
Store the smart card with the root CA key in a locked safe or another secure place. Tamper-evident bags or containers help too.
Use a complex PIN or passphrase for the card (or HSM), and never store it on the same device or in the same physical location as the card. If you can, add one more factor to access CA resources, for example a separate password or token.
And keep logs of issuance, revocation and key usage, and review from time to time who has access to the CA environment.
Ok, let's move on to the technical steps.
Step-by-Step: Creating a Root CA (SHA-512, 4096-bit) on a Smart Card
3.1 Install Required Packages
On most Linux systems, you will need:
sudo apt-get update
sudo apt-get install opensc openssl libengine-pkcs11-openssl pkcs11-tools
- OpenSSL: Core cryptographic toolkit.
- OpenSC: Contains drivers and utilities for several PKCS #11 smart cards.
- pkcs11-tools: Utility set for managing PKCS #11 tokens.
- libengine-pkcs11-openssl: Engine plugin allowing OpenSSL to communicate with PKCS #11 compatible devices.
3.2 Initialize and Prepare Your Smart Card
- Insert the smart card into your reader.
- Initialize the card (careful, this may erase existing keys!). For example, with
pkcs15-initfrom OpenSC:
pkcs15-init --create-pkcs15 --profile pkcs15+onepin --pin 123456 --puk 654321
--pin 123456– sets your user PIN (example value; use a stronger PIN in reality).--puk 654321– sets an unblock code if the PIN is entered incorrectly too many times.
Alternatively, you can use pkcs11-tool commands depending on your card’s vendor and management software.
3.3 Generate or Import the Root CA Key onto the Smart Card
There are two ways to get the key onto the card:
- Generate directly on the card (more secure, I recommend this one).
- Generate externally and import (some cards may not support this, or you might prefer external generation).
3.3.1 Generating the Key on the Card
pkcs11-tool --module /usr/lib/opensc-pkcs11.so \
--login \
--keypairgen \
--key-type RSA:4096 \
--label "RootCA-Key" \
--id 01 \
--pin 123456
--modulepoints to your PKCS #11 driver (path may differ by system).--keypairgenperforms the on-card key generation.--label "RootCA-Key"helps identify the key.--id 01sets a hex identifier for the key, which you can reference later.
3.3.2 Creating the Root CA Certificate Request
- Create a configuration file for OpenSSL (let’s call it
root-ca.conf) specifying default settings, like so:
[ req ]
default_bits = 4096
default_keyfile = rootCA.key
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no
[ req_distinguished_name ]
C = US
ST = YourState
L = YourCity
O = YourOrganization
OU = Root CA
CN = vkafed.com Root CA
[ v3_req ]
keyUsage = critical, keyCertSign, cRLSign
basicConstraints = critical, CA:true
These commands need an OpenSSL version with engine support. OpenSSL 4.0 removed engines, and there you need the PKCS #11 provider instead.
Use OpenSSL’s PKCS #11 engine to create a certificate request that references the on-card key
openssl req -new -engine pkcs11 \
-keyform engine \
-key "pkcs11:object=RootCA-Key;type=private;pin-value=123456" \
-config root-ca.conf \
-sha512 \
-out rootCA.csr
3.3.3 Self-Sign the Root CA Certificate
Because this is a root CA, we are self-signing:
openssl x509 -req -in rootCA.csr -sha512 \
-engine pkcs11 -keyform engine \
-extfile root-ca.conf \
-extensions v3_req \
-signkey "pkcs11:object=RootCA-Key;type=private;pin-value=123456" \
-days 3650 \
-out rootCA.crt
-days 3650(10 years) is an example. Adjust it if needed.- The resulting file rootCA.crt is your self-signed root CA certificate. Check that it has
CA:TRUE:openssl x509 -in rootCA.crt -noout -ext basicConstraints. An earlier version of this note missed-extfile, and the certificate came out without it.
Store rootCA.crt in a secure offline location (and keep backups!).
4. Creating a Subordinate CA (SubCA)
Next, we create a subordinate CA signed by the root CA.
4.1 Generate SubCA Keys and CSR
You may generate this subordinate CA key in software or on another smart card, depending on your security policies. Below is a software-based example:
- Generate the key pair:
openssl genrsa -out subCA.key 4096
2. Create a configuration file for the SubCA (e.g., sub-ca.conf):
[ req ]
default_bits = 4096
default_keyfile = subCA.key
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no
[ req_distinguished_name ]
C = US
ST = YourState
L = YourCity
O = YourOrganization
OU = Sub CA
CN = vkafed.com Sub CA
[ v3_req ]
keyUsage = critical, keyCertSign, cRLSign
basicConstraints = critical, CA:true, pathlen=0
3. Generate the CSR:
openssl req -new -sha512 -key subCA.key -config sub-ca.conf -out subCA.csr
4.2 Sign the SubCA CSR Using the Offline Root CA
On your offline root CA machine (where rootCA.crt and root CA smart card are stored), sign the SubCA CSR:
openssl x509 -req -in subCA.csr \
-engine pkcs11 -CAkeyform engine \
-CA rootCA.crt \
-CAkey "pkcs11:object=RootCA-Key;type=private;pin-value=123456" \
-CAcreateserial \
-days 1825 \
-sha512 \
-extensions v3_req \
-extfile sub-ca.conf \
-out subCA.crt
-CAcreateserialwill create a filerootCA.srlthat tracks certificate serial numbers.-days 1825sets the SubCA certificate to be valid for 5 years (example; adjust if needed).
5. Final Security Considerations
Keep the root CA's smart card offline and physically secured. Maintain secure backups, preferably in another physical location.
Publish a Certificate Revocation List (CRL) or run Online Certificate Status Protocol (OCSP), so end users can check the certificate status, and host it in a reliable location.
If this CA is for production or for public trust, draft a Certificate Policy (CP) and a Certification Practice Statement (CPS).
Plan renewals so the sub CA and the end-entity certificates are renewed before they expire, and rotate (reissue) keys periodically.
Log all CA operations and watch your environment for unauthorized issuance attempts or suspicious access.