Generate an HAProxy server certificate for testing
This section covers the following tasks:
- Install haproxy.
- Generate a key pair on the Vectera Plus by using pkcs11-tool.
- Generate a self-signed certificate for HAProxy by using OpenSSL.
- Store a reference to the HSM-stored private key inside a special PEM object with the label PKCS#11 PROVIDER URI. This object is a container for the PKCS #11 URI and contains no keying material.
To generate a new key pair on the , use pkcs11-tool, which is included in the OpenSC package available through the default package manager in most Linux distributions.
In a terminal, run the following commands to update the package index and install haproxy:
In a terminal, run the following command:
If you haven't set the FXPKCS11_MODULE environment variable to the location of the FXPKCS11 library file, update the --module parameter to specify the full path to the module (such as /usr/local/bin/fxpkcs11/libfxpkcs11.so).
Enter the identity password configured in the fxpkcs11.cfg file when prompted for the User PIN.
If the command succeeds, the keys display in the output, as shown in the following example:
The command creates the following keys:
- A private RSA 2048 key with asymmetric decrypt, sign, signRecover, and unwrap usage
- A public RSA 2048 key with encrypt, verify, verifyRecover, and wrap usage.
Use OpenSSL to perform the following steps to generate a self-signed certificate for HAProxy from the key pair stored on the HSM.
In a terminal, run the following command:
If the command is successful, your current directory contains a new file named haproxy-cert.pem.
Download the uri2pem.py script.
Install the asn1crypto dependency, which you need to run the uri2pem.py script.
Run the script with the following command:
If the script completes without any errors, the special PEM stanza outputs to the terminal in the following format:
The preceding stanza decodes to the PKCS #11 URI of the private key stored on the HSM. This object is a container for the PKCS #11 URI and contains no keying material.
Copy and paste the PKCS#11 PROVIDER URI output into a new file and name it haproxy-cert.pem.key. Be sure to include the BEGIN and END lines.