Created
February 27, 2012 19:15
-
-
Save bferg/1926416 to your computer and use it in GitHub Desktop.
Compare SSL files' key references
This file contains 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 | |
# | |
# Compare SSL files' key references. | |
# Take a list of SSL certificate (.crt), certificate sign request | |
# (.csr) and/or key (.key) files, extract the modulus and compare, and | |
# return a nonzero exit code if they do not match. | |
# | |
check='' | |
for name in "$@"; do | |
if [ "${name: -3}" == "crt" ]; then | |
op="x509" | |
fi | |
if [ "${name: -3}" == "csr" ]; then | |
op="req" | |
fi | |
if [ "${name: -3}" == "key" ]; then | |
op="rsa" | |
fi | |
csum=`openssl $op -noout -modulus -in $name | openssl md5` | |
if [ ${#check} -eq 0 ]; then | |
check=$csum | |
else | |
if [ "$check" != "$csum" ]; then | |
echo "Key mismatch" | |
exit 1 | |
fi | |
fi | |
done | |
echo "Keys match" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment