You are here

How to Add Certificate Chains for SSL Certificates pkcs12 (p12, pfx) Using OpenSSL, how to convert them


How to Add Certificate Chains for SSL Certificates pkcs12 (p12, pfx) Using OpenSSL, how to convert them

When it comes to purchasing SSL certificates, there's a common challenge—sometimes, the certificate chain is provided separately from the certificate itself. This separation can lead to compatibility issues, as many systems require the complete certificate chain to establish trust. In this guide, we'll show you how to seamlessly add a certificate chain to your SSL certificate using OpenSSL. Additionally, we'll demonstrate how to extract the certificate and private key from a PKCS12 certificate, making it a comprehensive resource for managing SSL certificates.

Why OpenSSL:

OpenSSL is a versatile tool available on most Linux systems, and there's also a Windows version. It's essential for handling SSL certificates, ensuring they're correctly configured and compatible with various systems.

Step-by-Step Guide: Adding the Certificate Chain

1. Preparation:

  • Copy your SSL certificate to a dedicated folder.
  • Ensure you have OpenSSL installed (typically available by default on Linux).

2. Extracting the Certificate and Private Key:

  • Use the following commands:
openssl pkcs12 -in yourcert.pfx -nocerts -out yourcert.key
openssl pkcs12 -in yourcert.pfx -clcerts -nokeys -out yourcert.crt
  • You'll be prompted to enter your certificate's password.

3. Creating a New Certificate File:

  • Open yourcert.crt in a text editor.
  • Copy everything between '-----BEGIN CERTIFICATE-----' and '-----END CERTIFICATE-----,' including these lines, to a new file with the .crt extension (e.g., yourcert1.crt). For example:

-----BEGIN CERTIFICATE-----
MIIF3jCCA8agAwIBAgIQAf1tMPyjylGoG7xkDjUDLTANBgkqhkiG9w0BAQwFADCB
iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTAw
MjAxMDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCBiDELMAkGA1UEBhMCVVMxEzARBgNV
BAgTCk5ldyBKZXJzZXkxFDASBgNV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mtOuowhT6KO
VWKR82kV2LyI48SqC/3vqOlLVSoGIG1VeCkZ7l8wXEskEVX/JJpuXior7gtNn3/3
ATiUFJVDBwn7YKnuHKsSjKCaXqeYalltiz8I+8jRRa8YFWSQEg9zKC7F4iRO/Fjs
8PRF/iKz6y+O0tlFYQXBl2+odnKPi4w2r78NBc5xjeambx9spnFixdjQg3IM8WcR
iQycE0xyNN+81XHfqnHd4blsjDwSXWXavVcStkNr/+XeTWYRUc+ZruwXtuhxkYze
Sf7dNXGiFSeUHM9h4ya7b6NnJSFd5t0dCy5oGzuCr+yDZ4XUmFF0sbmZgIn/f3gZ
XHlKYC6SQK5MNyosycdiyA5d9zZbyuAlJQG03RoHnHcAP9Dc1ew91Pq7P8yF1m9/
qS3fuQL39ZeatTXaw2ewh0qpKJ4jjv9cJ2vhsE/zB+4ALtRZh8tSQZXq9EfX7mRB
VXyNWQKV3WKdwrnuWih0hKWbt5DHDAff9Yk2dDLWKMGwsAvgnEzDHNb842m1R0aB
L6KCq9NjRHDEjf8tM7qtj3u1cIiuPhnPQCjY/MiQu12ZIvVS5ljFH4gxQ+6IHdfG
jjxDah2nGN59PRbxYvnKkKj9
-----END CERTIFICATE-----

4. Managing the Certificate Chain:

  • Copy the certificate chain that your SSL certificate relies on into the same folder.
  • If you're unsure where to obtain the chain, you can easily extract it from a Windows machine's certificate details.

How to Add Certificate Chains for SSL Certificates Using OpenSSL

How to Add Certificate Chains for SSL Certificates Using OpenSSL

5. Preparing the Certificate Chain:

  • Convert the chain certificates to the PEM format using these commands:
openssl x509 -in intermediate.cer -out intermediate.pem
openssl x509 -in root.cer -out root.pem
openssl x509 -in yourcert.crt -out yourcert.pem

If your certificatte is in der format, you can convert it to base64 with a command:

openssl x509 -inform der -in root.cer -out root.pem

6. Combining Certificates:

  • Merge all certificates into a single file:
cat yourcert.pem intermediate.pem root.pem >> yourcert-chain.pem

7. Creating a PKCS12 Certificate:

  • Generate a PKCS12 certificate with the following command:
 openssl pkcs12 -export -out yourcert-fullchain.p12 -inkey yourcert.key -in yourcert-chain.pem
  • You'll need to set a password for the certificate.

8. Verification:

  • To ensure success, run the following command to display all certificates in the file:
keytool -list -v -keystore yourcert-fullchain.p12 -storepass [your_password] -storetype PKCS12 | more

Conclusion: By following these steps and using OpenSSL, you can easily add a certificate chain to your SSL certificate, resolving compatibility issues and ensuring the trustworthiness of your SSL-protected websites.

Remember: Properly configuring SSL certificates is crucial for maintaining a secure online presence and building trust with your website visitors. With OpenSSL as your trusted companion, you can navigate this process with ease.

0 0

Share the article with your friends in social networks, maybe it will be useful to them.


If the article helped you, you can >>thank the author<<