Olson CloudWorks πŸš€

Verify a certificate chain using openssl verify

September 19, 2026

πŸ“‚ Categories: Programming
Verify a certificate chain using openssl verify

In today’s digital landscape, ensuring the security and trustworthiness of online communications is paramount. One crucial aspect of this security is the validity of SSL/TLS certificates. Certificate chains, which link a website’s certificate back to a trusted root authority, are fundamental to establishing this trust. OpenSSL, a powerful and widely-used cryptographic toolkit, provides the openssl verify command for verifying these certificate chains. This process confirms that a certificate is legitimate, has been issued by a trusted Certificate Authority (CA), and hasn’t been tampered with. Mastering how to verify a certificate chain using openssl verify is essential for system administrators, developers, and anyone responsible for maintaining secure online services. Understanding the intricacies involved in this verification process helps prevent man-in-the-middle attacks and ensures data integrity, critical for maintaining a secure online environment. By leveraging OpenSSL, you can confidently establish the authenticity and reliability of SSL/TLS certificates, fortifying your defenses against cyber threats and building trust with your users. This article will guide you through the steps and concepts necessary to effectively use openssl verify.

Understanding Certificate Chains

A certificate chain is a hierarchical structure of digital certificates, starting with the end-entity certificate (e.g., a website’s certificate) and tracing back to a trusted root certificate authority (CA). Each certificate in the chain is signed by the next certificate in the hierarchy, forming a chain of trust. The root CA certificate is self-signed, meaning it’s signed by itself, and is considered a trusted anchor. Intermediate certificates bridge the gap between the end-entity certificate and the root CA, as browsers and operating systems typically only trust a limited number of root CAs directly. A valid certificate chain ensures that the end-entity certificate is ultimately traceable back to a trusted root CA, thereby validating its authenticity.

The importance of a valid certificate chain cannot be overstated. Without it, browsers will display warnings indicating that the website’s certificate is not trusted, which can deter users and damage the website’s reputation. A broken or incomplete certificate chain is a common cause of such warnings. These warnings indicate a potential security risk and can lead to a loss of user trust and potential abandonment of the website. Properly configuring and verifying the certificate chain is therefore a critical step in ensuring a secure and trustworthy online experience for your users.

According to a study by the Ponemon Institute, the average cost of a data breach in 2023 was $4.45 million. IBM’s 2023 Cost of a Data Breach Report highlights that compromised credentials are a common attack vector, and ensuring the validity of SSL/TLS certificates is one step in preventing such breaches. Validating the certificate chain helps to prevent man-in-the-middle attacks, where attackers intercept communication between the client and server, potentially stealing sensitive data. By verifying the chain, you ensure that you are communicating with the legitimate server and not an imposter.

Using OpenSSL Verify Command

The openssl verify command is a powerful tool for validating certificate chains. The basic syntax is: openssl verify [options] certificate. The “certificate” is typically the end-entity certificate file. However, to verify the entire chain, you often need to provide the intermediate certificate(s) as well. This can be done by concatenating the end-entity certificate and the intermediate certificate(s) into a single file, or by using the -CAfile option to specify a file containing trusted CA certificates.

Here’s a featured snippet-optimized paragraph explaining the process. To verify a certificate chain using openssl verify, you need to provide the end-entity certificate and the necessary intermediate certificates. You can combine these certificates into a single file or use the -CAfile option to specify a file containing trusted CA certificates. The command checks if the certificate is valid, hasn’t expired, and is signed by a trusted CA. A successful verification returns “OK,” while errors indicate issues with the certificate chain.

Let’s look at some common options:

  • -CAfile filename: Specifies a file containing trusted CA certificates. This is crucial for verifying the certificate chain against known trusted authorities.
  • -CApath directory: Specifies a directory containing trusted CA certificates. OpenSSL will search this directory for certificates to use for verification.
  • -untrusted file: Specifies a file containing untrusted certificates. This is helpful when you need to provide intermediate certificates that are not part of your trusted CA store.

Example: openssl verify -CAfile ca-chain.pem website.crt. This command verifies website.crt against the certificates in ca-chain.pem. The ca-chain.pem file should contain one or more trusted CA certificates. Practical Steps to Verify a Certificate Chain

Verifying a certificate chain involves several steps. First, you need to obtain the end-entity certificate and any intermediate certificates. Often, the intermediate certificates are provided by the Certificate Authority that issued the end-entity certificate. These certificates can be downloaded from the CA’s website or obtained from the server configuration. Next, you need to prepare a file containing the trusted CA certificates. Your operating system typically has a default store of trusted CAs, but you can also create your own file.

Here’s how to verify a certificate chain using openssl verify in practice:

  1. Obtain the end-entity certificate (e.g., website.crt) and any intermediate certificates (e.g., intermediate.crt). These are usually provided by your certificate authority.
  2. Create a file containing the trusted CA certificates (e.g., ca-chain.pem). This file should contain the root CA certificate and any necessary intermediate CA certificates.
  3. Run the openssl verify command: openssl verify -CAfile ca-chain.pem website.crt.
  4. Interpret the output. “OK” indicates successful verification. Errors indicate problems with the chain, such as an untrusted certificate or a missing intermediate certificate.

For example, let’s say you have example.com.crt (the website’s certificate) and intermediate.pem (the intermediate certificate). You can create a ca-chain.pem file by concatenating the intermediate certificate and the root CA certificate (if you have it separately). Then, run openssl verify -CAfile ca-chain.pem example.com.crt. This command will check if example.com.crt is valid and trusted, using the certificates in ca-chain.pem to build the chain. According to DigiCert, a leading Certificate Authority, “Properly installed and configured SSL certificates are crucial for securing websites and applications.” DigiCert Installation Guide

Troubleshooting Common Issues

Several issues can arise when verifying certificate chains. One common problem is a missing intermediate certificate. If the openssl verify command reports “unable to get local issuer certificate,” it usually means that one or more intermediate certificates are missing from the chain. To fix this, ensure that all necessary intermediate certificates are included in the -CAfile or -untrusted file. Another common issue is an expired certificate. The openssl verify command will report “certificate has expired” if the certificate’s validity period has ended. In this case, you need to renew the certificate.

Another potential problem is an untrusted root CA. If the root CA is not trusted by your system, the verification will fail. This can happen if you are using a self-signed certificate or a certificate issued by a CA that is not included in your trusted CA store. To resolve this, you need to add the root CA certificate to your trusted CA store. This process varies depending on your operating system and browser. Refer to the documentation for your specific environment for instructions on how to add trusted CA certificates. Use this guide to learn more about potential issues.

Here’s a list of common errors and how to address them:

  • “unable to get local issuer certificate”: Missing intermediate certificate. Add the missing intermediate certificate to the -CAfile or -untrusted file.
  • “certificate has expired”: The certificate is no longer valid. Renew the certificate.
  • “self signed certificate in certificate chain”: The certificate chain includes a self-signed certificate that is not trusted. Ensure that all certificates in the chain are issued by trusted CAs.
Infographic here
FAQ Section -----------
What is a certificate chain?
A certificate chain is a hierarchical structure of digital certificates, linking an end-entity certificate to a trusted root CA.
Why is it important to verify a certificate chain?
Verifying a certificate chain ensures the authenticity and trustworthiness of an SSL/TLS certificate, preventing man-in-the-middle attacks and ensuring data integrity.
What does "unable to get local issuer certificate" mean?
This error indicates that one or more intermediate certificates are missing from the chain.
How do I fix a missing intermediate certificate?
Add the missing intermediate certificate(s) to the -CAfile or -untrusted file when using openssl verify.
What if I get a "certificate has expired" error?
This means the certificate is no longer valid and needs to be renewed.
In conclusion, mastering the openssl verify command is an indispensable skill for anyone managing secure online services. By understanding the intricacies of certificate chains and troubleshooting common issues, you can ensure the trustworthiness of your SSL/TLS certificates and protect your users from potential security threats. Remember to always keep your trusted CA store up-to-date and to regularly verify your certificate chains to maintain a secure and reliable online environment. For further reading, consider exploring the official OpenSSL documentation and resources from reputable Certificate Authorities such as Let's Encrypt [Let's Encrypt Documentation](https://letsencrypt.org/docs/certificate-chain/). Explore topics like SSL/TLS best practices, certificate management, and advanced OpenSSL techniques to enhance your security posture and build trust with your users.

Question & Answer :
I’m building a own certificate chain with following componenents:

Root Certificate - Intermediate Certificate - User Certificate 

Root Cert is a self signed certificate, Intermediate Certificate is signed by Root and User by Intermediate.

Now I want to verify if a User Certificate has its anchor by Root Certificate.

With

openssl verify -verbose -CAfile RootCert.pem Intermediate.pem 

the validation is ok. In the next step I validate the User Cert with

openssl verify -verbose -CAfile Intermediate.pem UserCert.pem 

and the validation shows

error 20 at 0 depth lookup:unable to get local issuer certificate 

What is wrong?

From verify documentation:

If a certificate is found which is its own issuer it is assumed to be the root CA.

In other words, root CA needs to be self signed for verify to work. This is why your second command didn’t work. Try this instead:

openssl verify -CAfile RootCert.pem -untrusted Intermediate.pem UserCert.pem 

It will verify your entire chain in a single command.