Skip to content

Instantly share code, notes, and snippets.

@rajeswari199
Last active February 10, 2020 09:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajeswari199/136f8c6d56e08deb0fee82c5e16523bf to your computer and use it in GitHub Desktop.
Save rajeswari199/136f8c6d56e08deb0fee82c5e16523bf to your computer and use it in GitHub Desktop.
Outputs the private key validity for the provided SSL certificate.
#!/bin/bash
case $1 in
-[h?] | --help)
cat <<-____HALP
Usage: ${0##*/} [ --help ]
Execute it with the command: ./${0##*/} your_certificate.crt your_private_key.crt
____HALP
exit 0;;
esac
result=$((openssl x509 -noout -modulus -in $1 | openssl md5 ;\
openssl rsa -noout -modulus -in $2 | openssl md5) | uniq)
echo "$result"
count=$(awk 'BEGIN{print gsub(ARGV[2],"",ARGV[1])}' "$result" "stdin")
if [ $count -eq 1 ]; then
echo -e "\e[1m\e[32mPRIVATE KEY MATCHES THE SSL CERTIFICATE"
else
echo -e "\e[1m\e[31mPRIVATE KEY AND SSL CERTIFICATE DOESNOT MATCH"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment