Skip to content

Instantly share code, notes, and snippets.

@besmirzanaj
Last active June 8, 2018 19:37
Show Gist options
  • Save besmirzanaj/9d25b104308df9a1d1cc64d6af2cd03d to your computer and use it in GitHub Desktop.
Save besmirzanaj/9d25b104308df9a1d1cc64d6af2cd03d to your computer and use it in GitHub Desktop.
check if a certificate was generated by provided key
#!/bin/bash
# check certificate if it is generated from this key
# usage check_ssl_key_crt.sh "key file" "certificate"
[ $# -eq 0 ] && { echo "Usage: $0 'key file' ' ' 'cert file'" exit 999; }
if [[ $((openssl x509 -noout -modulus -in $2 | openssl md5 | awk '{print $2}'; openssl rsa -noout -modulus -in $1 | openssl md5 | awk '{print $2}') | uniq -c | wc -l) -eq 1 ]]
then printf "Everything ok with this certificate.\n It was generated by key $1\n"
else printf "Certificate $2 compromised or generated with another key."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment