Skip to content

Instantly share code, notes, and snippets.

@JonathonReinhart
Created July 11, 2022 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathonReinhart/263eac622bf97314c1c15fabd04eb0c6 to your computer and use it in GitHub Desktop.
Save JonathonReinhart/263eac622bf97314c1c15fabd04eb0c6 to your computer and use it in GitHub Desktop.
Verify X.509 certificate and key match
#!/bin/bash
if [[ $# -ne 2 ]]; then
echo "Usage: $(basename $0) CERTFILE KEYFILE"
exit 1
fi
certpath="$1"
keypath="$2"
certmod=$(openssl x509 -modulus -noout -in "$certpath")
keymod=$(openssl rsa -modulus -noout -in "$keypath")
#echo "Cert modulus: $certmod"
#echo "Key modulus: $keymod"
if [[ "$certmod" != "$keymod" ]]; then
echo -e "\e[31mERROR: Key and certificate do not match!\e[m"
exit 2
fi
echo -e "\e[32mOK: Key and certificate match.\e[m"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment