PKCS#11 HSM
DS servers support key management using a Public-Key Cryptography Standard #11 (PKCS#11) token store. The PKCS#11 standard defines a cryptographic token interface, a platform-independent API for storing keys in a Hardware Security Module (HSM), for example.
DS servers rely on the PKCS#11 interface and Java APIs to use it. DS servers don’t support vendor-specific interfaces.
|
DS servers use an HSM only to hold asymmetric key pairs and, optionally, CA certificates. (Since the CA certificate holds the CA’s public key, which isn’t secret, store it in a separate, file-based keystore or PEM file, not in the HSM.) The asymmetric key pairs you can store in the HSM are the server’s TLS keys, the shared master key, and the optional shared signing key for the deployment. DS servers use the shared master key to wrap symmetric (secret) keys. DS servers store secret keys in the data they encrypt. For this reason, DS servers don’t use the HSM for secret keys. |
Using a PKCS#11 device for storing DS keys involves:
-
Storing the keys on the PKCS#11 device.
How you generate and store keys in your HSM depends on the device. Learn more in the documentation for your device.
-
Creating the DS PKCS#11 key manager provider to access the device.
The DS server accesses a PKCS#11 device using a PIN. You can provide the PIN in the server configuration or in a separate file. Store the PIN as a cleartext value DS can read on startup.
-
Configuring DS components to use the key manager provider.
For example, DS connection handlers reference the key manager provider in their configurations.
Prepare the HSM and keys
|
-
Install BouncyHsm.
-
Go to the BouncyHsm UI in a browser.
-
Create a slot.
-
Record the user PIN for use when configuring DS.
-
Record the SO PIN in case you choose to reinitialize the token.
-
Record the slot ID for use when creating the Java PKCS#11 configuration file.
-
-
Generate a key pair using the following hints:
Field Value Key type
EC key pair
EC name or OID
secp256r1CKA LABEL
ssl-key-pairFor signing and verification
Selected
For encryption and decryption
Selected
Private key is sensitive
Selected
-
Generate a certificate using the following hint:
Field Value Subject
CN=localhost,O=Example Corp,C=FR -
Download the BouncyHsm PKCS#11 library through the UI.
-
Create a Java PKCS#11 configuration file,
/path/to/hsm.conf, to access BouncyHsm.The following example uses the Linux library file and slot
1. Adjust the BouncyHsm library path and use the BouncyHsm slot ID shown in the UI:name = BouncyHsm library = /path/to/BouncyHsm.Pkcs11.so slot = 1Learn about the configuration file format in the Java PKCS#11 Reference Guide.
Find recommendations for production deployments in the platform documentation page, HSMs and platform software.
-
Verify Java can access the device using your configuration.
The following example uses the Java
keytoolcommand to list the keys:$ keytool \ -list \ -keystore NONE \ -storetype PKCS11 \ -storepass password \ -providerClass sun.security.pkcs11.SunPKCS11 \ -providerArg /path/to/hsm.confOutputKeystore type: PKCS11 Keystore provider: SunPKCS11-BouncyHsm Your keystore contains 1 entry ssl-key-pair, PrivateKeyEntry, Certificate fingerprint (SHA-256): <fingerprint>
You have successfully prepared the HSM and keys for use with DS.
Let DS access the HSM
|
DS presents its certificate to client applications, so get it signed by a CA they trust. For evaluation only with BouncyHsm, use the |
Repeat these steps for each DS server:
-
Make the plaintext user PIN for the slot available to the DS server.
Store the PIN in a single-line file with restricted permissions:
$ ls -l /path/to/opendj/config/bouncyhsm.pin -rw------- 1 user staff/path/to/opendj/opendj/config/bouncyhsm.pin DS reads the file when the server starts.
For some HSMs, you provide the PKCS#11 token credentials as part of the configuration instead. In such cases, you don’t need a file for the PIN as in this example.
-
Configure a PKCS#11 key manager provider to access the HSM.
The following example creates a provider for BouncyHsm:
-
The
pkcs11-provider-name:SunPKCS11setting uses the Java name for the PKCS#11 provider. -
The
pkcs11-provider-arg:/path/to/hsm.confsetting holds the absolute path to the Java PKCS#11 configuration file. -
The configuration uses the
bouncyhsm.pinfile to get the user PIN for the slot. -
The command connects to the administrative port (
4444) where the existingPKCS12keystore contains the trusted CA certificate.
$ dsconfig \ create-key-manager-provider \ --provider-name BouncyHsm \ --type pkcs11 \ --set enabled:true \ --set pkcs11-provider-name:SunPKCS11 \ --set pkcs11-provider-arg:/path/to/hsm.conf \ --set key-store-pin:"&{file:config/bouncyhsm.pin}" \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --trustStorePath /path/to/opendj/config/keystore \ --trustStoreType PKCS12 \ --trustStorePassword:file /path/to/opendj/config/keystore.pin \ --no-prompt -
Use the keys in the HSM
-
Configure a connection handler to use the PKCS#11 key manager provider.
The following example configures an existing LDAPS connection handler to use the BouncyHsm provider. The command connects to the administrative port (
4444) where the existingPKCS12keystore contains the trusted CA certificate:$ dsconfig \ set-connection-handler-prop \ --handler-name LDAPS \ --set key-manager-provider:BouncyHsm \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --trustStorePath /path/to/opendj/config/keystore \ --trustStoreType PKCS12 \ --trustStorePassword:file /path/to/opendj/config/keystore.pin \ --no-prompt -
Check TLS with the HSM configured:
$ ldapsearch \ --hostname localhost \ --port 1636 \ --useSSL \ --baseDN dc=example,dc=com \ "(uid=bjensen)" \ cnOutputUser DN : CN=localhost, O=Example Corp, C=FR Issuer : CN=localhost, O=Example Corp, C=FR Validity : <validity-period> Do you trust this server certificate? 1) No 2) Yes, for this session only 3) Yes, also add it to a truststore 4) View certificate details Enter choice: [1]: 2 dn: uid=bjensen,ou=People,dc=example,dc=com cn: Barbara Jensen cn: Babs Jensen
You have successfully demonstrated using keys in an HSM for DS TLS connections.
Store shared master keys in the HSM
|
-
Generate a shared master key pair in the HSM using the following hints:
Setting Value Key algorithm
RSAKey size
Use at least
3072bitsAlso generate a self-signed certificate for the key pair.
-
(Optional) For FIPS compliance, use separate keys for signing backups and for key wrapping.
In this case, generate a second shared master key pair and certificate for signing backups with a different alias from the default (
master-key). -
For each DS server, create the PKCS#11 key manager provider to access the HSM, without starting the server.
Use the
dsconfig create-key-manager-providercommand with--offline. -
For each DS server, update the Crypto Manager to reference the PKCS#11 key manager provider.
For example, set the key manager provider for the Crypto Manager to
<my-hsm-provider>:$ dsconfig \ set-crypto-manager-prop \ --set key-manager-provider:<my-hsm-provider> \ --set master-key-alias:<shared-master-key-alias> \ --offline \ --no-promptThe following example for FIPS compliance uses separate keys for key wrapping and signing backups:
$ dsconfig \ set-crypto-manager-prop \ --set key-manager-provider:<my-hsm-provider> \ --set master-key-alias:<wrapping-key-alias> \ --set signing-key-alias:<signing-key-alias> \ --offline \ --no-prompt -
For each DS server, apply Setup profiles with the
setup-profilecommand, and complete any necessary preliminary configuration. -
Start each DS server.
You have successfully configured DS servers to use shared master key(s) in your HSM.