Check if a certificate matches the CSR that was sent for signing.

Author
By Darío Rivera
Posted On in OpenSSL

When we generate a CSR (Certificate Signing Request) and send it to be signed by a trusted entity, we must wait to receive the certificate to enter it into our system and configure it. Once the certificate arrives, we must validate if it is indeed the correct certificate, that is, it was generated based on our CSR.

Step 1: Obtain the public key

The first thing is to verify if we have access to the private key or only have access to the public part that generated the CSR. If for any reason you want to send the public part to a colleague for verification, you will need to execute the following command to generate it.

openssl rsa -in private_key.pem -pubout > public_key.pem

Step 2: Obtain the MD5 hash of the key

To obtain this hash, we can use the following command on the public key obtained above.

openssl pkey -pubin -in public_key.pem -pubout -outform pem | openssl md5

If you have direct access to the private key, you could use the following command.

openssl pkey -in private_key.pem -pubout -outform pem | openssl md5

We will get a result like the following:

2c2dac216dfb0b4e4304941e461f5714

Step 3: Obtain the MD5 hash of the certificate or chain of certificates

To obtain this hash, we can use the following command on the certificate or chain of certificates to be validated.

openssl x509 -in certificate.pem -pubkey -noout -outform pem | openssl md5

We will get a result like the following:

2c2dac216dfb0b4e4304941e461f5714

Step 4: Verify the hash match

If the hash turns out to be the same for both the public key and the certificate, it means that the certificate was generated for a CSR created by that key.


Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.