Debugging and Testing Certificates With OpenSSL
The following are some examples show how to use OpenSSL commands to work with existing certificates to debug and test the infrastructure. The examples provided here aren't comprehensive and are intended to supplement the existing OpenSSL manual pages.
Check That a Private Key Matches a Certificate
The modulus and public exponent parts of the key and certificate must match. These values are often long and difficult to check. The easiest way to compare the modulus in the key and certificate is to create a SHA256 hash of each and compare those instead, for example:
sudo openssl x509 -noout -modulus -in server.crt | openssl sha256
sudo openssl rsa -noout -modulus -in server.key | openssl sha256
You can also check the modulus in a CSR to see if it matches a key or certificate, as follows:
sudo openssl req -noout -modulus -in server.csr | openssl sha256