Created
July 11, 2022 06:38
-
-
Save JonathonReinhart/263eac622bf97314c1c15fabd04eb0c6 to your computer and use it in GitHub Desktop.
Verify X.509 certificate and key match
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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