There are number of tools available to create SSL/TLS key pair and CSR. Here I'm going to use openssl.
1. Let's first create a key pair
In this example, we are creating a key of type RSA with 2048-bit key length. It is recommended that you create a password protected private key.
2. Let's create a CSR.
Openssl allows to provide input information using a openssl configuration file while creating a CSR. Good thing about the configuration file is that it can be stored in the version control system like git and re-used. Look the config file example below. Let's call it mycsr.cnf
Here we are using
mycsr.cnf
to feed the necessary information required to create the CSR. Since we are using encrypted key, let's pass the password using option
-passin pass:<password>
. If you don't use the
-passin
option, it will prompt you for the password. Here, it will generate the
myserver.csr
Note: you can also generate CSR using the existing private key and existing certificate. See the commands below. Openssl prior to version 3.x, may not support the '-copy_extensions copyall'.
Review the generated CSR. In the example below, we are verifying the mycsr.csr
created above.
3. Send your CSR to CA and Get the Signed Certs
Once your
Certificate Authority (CA) receives the CSR, they process it and may send a link from where signed certificate(s) can be downloaded. The provided link may contain download options for Root CA cert, one or more intermediate cert(s) and server/domain cert. Depending upon how and for which server/application you are installing certificate, you may want to create a single PEM file from all provided certs. Here is how you can do it:
Notes:
- make sure the certificate file are in PEM format. In order to check, just open the file in text editor like
Notepad++
and see if it starts with -----BEGIN
and content is in 'ASCII'. Certs can be converted from other format to PEM using openssl commands as follows:
- Open the merged file
cert-bundle.pem
above in text editor and make sure that each -----BEGIN
is in new line.
- If you are not able to install the password protected key, remove the password as follows:
4. Install and Verify your Certificate
Installation really depends on what your target server/application is. Here I'm showing a quick example for
nginx. Here is a configuration snippet to enable SSL/TLS for
nginx:
Once the configuration is updated, start the
nginx and access default page in the browser like 'https://myexampleserver.ca'
5. [Optional] Create .p12 key store for your Keys and Certs
PKCS 12 is a industry standard for storing many cryptography objects in a single file. Here is how you can create a PKCS 12 archive.
Notes:
- if the file passed using option
-infile/in
has both certs and private key, then -inkey
option is not required. - if the file passed using option
-infile/in
has all the certs (including the server, intermediate, and rootca) included, then the -certfile
option is not required. Usually the practice is to pass server cert file using -infile/in
option, private key using -inkey
option and rootCA, intermediate certs using -certfile
option.
6. [Optional] Use .p12 with Java Keytool or KeyStore Explorer (KSE)
You can open the
.p12
file directly into
KSE and use KSE functionalities. You can use the
Java keytool as well. Here is an example of listing certs using Java keytool:
- List certs using keytool
- Convert to JKS if necessary. You'll be prompted for passwords
No comments:
Post a Comment