53

I'm trying to validate/verify that the rsa key, ca-bundle, and certificate stored here are ok. They are not being served by a webserver. How can I verify them?

  • Look at the openssl x509 manual section. – alex Jul 7 '11 at 16:03
  • The OpenSSL verify manual can help you here. Also, see this page has some excellent examples. – Stefan Lasiewski Jul 7 '11 at 16:55
61

Assuming your certificates are in PEM format, you can do:

openssl verify cert.pem

If your "ca-bundle" is a file containing additional intermediate certificates in PEM format:

openssl verify -untrusted ca-bundle cert.pem

If your openssl isn't set up to automatically use an installed set of root certificates (e.g. in /etc/ssl/certs), then you can use -CApath or -CAfile to specify the CA.

  • 9
    Warning, the openssl verify command is more permissive than you might expect! By default, in addition to checking the given CAfile, it also checks for any matching CAs in the system's certs directory e.g. /etc/ssl/certs. To prevent this behavior and make sure you're checking against your particular CA cert given by CAfile, you must also pass a -CApath option with a non-existant directory, e.g.: openssl verify -verbose -CApath nosuchdir -CAfile cacert.pem server.crt – DSimon Jan 20 '16 at 19:35
  • 2
    One further caveat: If you use -CApath nosuchdir then the combination of server.crt and cacert.pem must include the root CA; if openssl can only work up to an intermediate CA with those files then it will complain. – DSimon Jan 21 '16 at 16:32
  • It says no such file in /certs/. will this cause a problem? because im stacked in a situation where my server works, http curl works, but https.. curl gets error. where the website stopped working. – Giorgi Gvimradze Oct 28 at 10:46
18

Here is one-liner to verify a certificate chain:

openssl verify -verbose -x509_strict -CAfile ca.pem -CApath nosuchdir cert_chain.pem

This doesn't require to install CA anywhere.

See https://stackoverflow.com/questions/20409534/how-does-an-ssl-certificate-chain-bundle-work for details.

  • 1
    Warning, the -CAfile option is more permissive than you might expect. See my comment on the accepted answer for details. – DSimon Jan 20 '16 at 19:36
  • 1
    @DSimon, I added -CApath nosuchdir this to answer. Thank you. – Vadzim Jan 21 '16 at 9:10
  • No problem, glad to help. :-) One caveat that I figured out after posting my earlier comment: if the file specified with -CAfile is itself just an intermediate certificate, then openssl will complain. This is correct behavior, since verify requires a complete chain all the way up to a root CA, but can be misleading. – DSimon Jan 21 '16 at 16:30
  • 2
    My version (OpenSSL 1.1.1 11 Sep 2018) requires the argument to -CApath to be an existing directory. – Jake Cobb Jul 23 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.