Read more

HowTo: verify SSL private key matches SSL certificate

Marius Schuller
June 21, 2016Software engineer at makandra GmbH

When receiving a new SSL-Certificate for an existing SSL-key it should be checked that they match cryptographically.
Maybe the customer accidentally created a new key and certificate and sent us just the certificate.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show snapshot

It's also possible that the certificate chain is in the wrong order. Make sure that the server certificate is the first. This is also necessary for nginx.

It is recommended to pipe the public keys of both files through an hashing algorithm, to easier identify differences. Instead of comparing the modulus the same syntax applies to RSA and ECDSA certificates:

openssl pkey -pubout -in server.key | openssl sha1

openssl req -pubkey -noout -in server.csr | openssl sha1

openssl x509 -pubkey -noout -in server.crt | openssl sha1

If they match, the resulting hash will be identical:

$ openssl pkey -pubout -in | openssl sha1
(stdin)= 559bd107c03237891a468f2c3dcbb0a47035e797

$ openssl x509 -pubkey -noout -in | openssl sha1
(stdin)= 559bd107c03237891a468f2c3dcbb0a47035e797


You can also use the graphical tool XCA.

Posted by Marius Schuller to makandra Operations (2016-06-21 14:12)