Created
November 1, 2018 21:12
-
-
Save dade80vr/ddefa7ea4481d88deac2561914e4f52a to your computer and use it in GitHub Desktop.
Bash script to check if a certificate and a private key match
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 | |
cert=$1 | |
key=$2 | |
if [[ $# -eq 0 ]] | |
then | |
echo "Arguments not given. Usage: ./checkcert.sh CERTIFICATE.crt PRIVKEY.key" | |
else | |
crthash=$(openssl x509 -noout -modulus -in "$cert" | openssl md5) | |
echo $cert $crthash | |
keyhash=$(openssl rsa -noout -modulus -in "$key" | openssl md5) | |
if [ "$keyhash" = "$crthash" ] | |
then | |
keytest=$(openssl rsa -in "$key" -check -noout) | |
echo $key $keyhash | |
echo "---- "$keytest" ----" | |
else | |
echo "!!!! Invalid key for given cert !!!!" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment