This is going to be a quick tutorial, but here's a quick way to generate a root certificate, server certificate, and bundle them together via pfx file. This can be useful to validate scenarios where a certificate chain is required. For this tutorial, we'll be using the openssl utility, which can be freely downloaded here: Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions (slproweb.com)
Generate the Root Certificate
Execute the following command to generate a key for the root certificate:
openssl ecparam -out root.key -name prime256v1 -genkey
Execute the following command to generate a certificate signing request. Note: During this step, you will be prompted to specify several certificate attributes; for the common name, you can specify the name you'd like as the issuer (i.e. MyCorp)
openssl req -new -sha256 -key root.key -out root.csr
Execute the following to generate the public certificate. During this step, you'll specify the validity of the root certificate (you may want this to be longer than 365 days as the root).
openssl x509 -req -sha256 -days 3650 -in root.csr -signkey root.key -out root.crt
Generate the Server Certificate
Execute the following command to generate a private key for the server certificate:
openssl ecparam -out server-cert.key -name prime256v1 -genkey
Execute the following command to generate a certificate signing request. Note: During this step, you will be prompted to specify several certificate attributes; for the common name, specify the FQDN to your server. You do not need to start the value of the common name with CN=
openssl req -new -sha256 -key server-cert.key -out server-cert.csr
Execute the following command to generate the public certificate for the server certificate. During this step, you'll specify the validity of the server certificate. Generally speaking, the validity of this certificate would be much shorter than your root.
openssl x509 -req -in server-cert.csr -CA root.crt -CAkey root.key -CAcreateserial -out server-cert.crt -days 365 -sha256
Verify certificate chain
Optionally, you can verify the issuer or expiry dates of the server certificate is correct via the following command:
openssl x509 -in server-cert.crt -text -noout
Generate PFX from Root and Server certificate
Execute the following command to generate a PFX file containing the public and private keys of the server certificate as well as public key of the root certificate. Note, you will be prompted for a password for the PFX file, which can increase security when needing to move these sensitive files around.
openssl pkcs12 -export -out mycert.pfx -inkey server-cert.key -in server-cert.crt -certfile root.crt