OpenSSL
- Managing a Public Key Infrastructure (PKI) with OpenSSL
- Importing a Certificate into the Java Keystore
Managing a Public Key Infrastructure (PKI) with OpenSSL
Creating the Certificate Authority (CA)
First we create an RSA key and certificate request for the CA:
In the next step, we self-sign this certificate request in order to create the CA certificate:
The configuration file ca.cnf used in this example has the following content:
Creating and Signing a Server Certificate
In order to create the certificate request and RSA key, we use the following command:
In this example, we do not protect the private key with a password (-nodes option). If you do not want to request a SHA2-signed certificate but prefer a traditional (SHA1 signed) certificate instead, remove the -sha256 option.
The certificate request is signed with the following command:
For the first certificate being signed, the option -CAcreateserial has to be added to the command line, so that OpenSSL creates the files holding the serials. The configuration file server.cnf used in this example has the following content:
extendedKeyUsage=serverAuth
nsCertType=server
In order to add subject alternative names to the certificate, the following line can be added to the server.cnf file:
Signing a Client Certificate
The steps are exactly the same as for a server certificate. However, instead of server.cnf a different configuration file is used:
extendedKeyUsage=clientAuth
nsCertType=client
Using an EC key
In order to generate an eliptic curve key with the req command, a suitable parameters file has to be generated first:
Instead of the P-256 curve, another curve can be chose of course. This parameter file can then be used with the -newkey parameter of the req command:
Importing a Certificate into the Java Keystore
See KeyStore.
Creating a PKCS#12 file
The following command can be used to create a PKCS#12 file containing the certificate, its private key and the root-certificate. Such a file can be used to import the certificate in software (e.g. web browser or e-mail client for client certificates):