Generating Keys and Certificate for SSL

  1. Generate the RSA key using p11tool2.

›_ Console

# p11tool2 slot=4 LoginUser=123456 

PubKeyAttr=CKA_LABEL="RSAKey",CKA_ID=0x45 

PrvKeyAttr=CKA_LABEL="RSAKey",CKA_ID=0x45  GenerateKeyPair=RSA 
  1. Verify that the keys are generated onto the HSM using following command.

›_ Console

# p11tool2 LoginUser=<cryptouser_password> ListObjects 

Example:

image-3284599083-1.jpg

List keys

  1. Generate a certificate request.

›_ Console

# openssl req -engine pkcs11 -new -key "pkcs11:token=Nginx;object=RSAKey" 

-keyform engine -out RSACSR.csr 

Here, Nginx is the token label and RSAKey is the key on the HSM. Provide Cryptouser PIN when prompted. Also provide other required information for certificate.

image-3284599083-2.jpg

Certificate request output

image-3284599083-3.jpg

Content of certificate request file

  1. Get this CSR signed by your CA and copy the signed certificate to NGINX server.

  2. Alternatively, you can create the self-signed certificate based on the generated key.

›_ Console

# openssl req -engine pkcs11 -new -x509 -days 365 -key 

"pkcs11:token=Nginx;object=RSAKey" -keyform engine -out RSA.cert 

Here, Nginx is the token label and RSAKey is the key on the HSM. Provide Cryptouser PIN when prompted. Also provide other required information for certificate.

image-3284599083-4.jpg

Self-signed certificate generation output

image-3284599083-5.jpg

Content of self-signed certificate file

It is recommended to use CA signed certificate for production environment.