Skip to content

Instantly share code, notes, and snippets.

@RafPe
Last active April 28, 2016 20:14
Show Gist options
  • Select an option

  • Save RafPe/5e5eab7e17ad49712728fbea4b92aacf to your computer and use it in GitHub Desktop.

Select an option

Save RafPe/5e5eab7e17ad49712728fbea4b92aacf to your computer and use it in GitHub Desktop.
Verify key and certificate with openssl
#!/bin/bash
#==============================================================================
#title : ssl-verify-key-cert.sh
#description : Script verify key and certificate
#authors : RafPe
#date : 20160426
#version : 1.0
#notes :
#==============================================================================
# Check number of arguments and print usage if we dont have enough
if [[ $# < 2 ]]
then
echo "�~V~H�~V~H�~U~W �~V~H�~V~H�~U~W�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~U~W �~V~H�~V~H�~V~H�~V~H�~V~H�~U~W �~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~U~W �~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~U~W"
echo "�~V~H�~V~H�~U~Q �~V~H�~V~H�~U~Q�~V~H�~V~H�~U~T�~U~P�~U~P�~U~P�~U~P�~U~]�~V~H�~V~H�~U~T�~U~P�~U~P�~V~H�~V~H�~U~W�~V~H�~V~H�~U~T�~U~P�~U~P�~U~P�~U~P�~U~] �~V~H�~V~H�~U~T�~U~P�~U~P�~U~P�~U~P�~U~]"
echo "�~V~H�~V~H�~U~Q �~V~H�~V~H�~U~Q�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~U~W�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~U~Q�~V~H�~V~H�~U~Q �~V~H�~V~H�~V~H�~U~W�~V~H�~V~H�~V~H�~V~H�~V~H�~U~W "
echo "�~V~H�~V~H�~U~Q �~V~H�~V~H�~U~Q�~U~Z�~U~P�~U~P�~U~P�~U~P�~V~H�~V~H�~U~Q�~V~H�~V~H�~U~T�~U~P�~U~P�~V~H�~V~H�~U~Q�~V~H�~V~H�~U~Q �~V~H�~V~H�~U~Q�~V~H�~V~H�~U~T�~U~P�~U~P�~U~] "
echo "�~U~Z�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~U~T�~U~]�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~U~Q�~V~H�~V~H�~U~Q �~V~H�~V~H�~U~Q�~U~Z�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~U~T�~U~]�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~V~H�~U~W"
echo "�~U~Z�~U~P�~U~P�~U~P�~U~P�~U~P�~U~] �~U~Z�~U~P�~U~P�~U~P�~U~P�~U~P�~U~P�~U~]�~U~Z�~U~P�~U~] �~U~Z�~U~P�~U~] �~U~Z�~U~P�~U~P�~U~P�~U~P�~U~P�~U~] �~U~Z�~U~P�~U~P�~U~P�~U~P�~U~P�~U~P�~U~]"
echo ""
echo "$0 <certificate-file> <certificate-key>"
echo ""
exit 1
fi
# Get our parameters assigned to variables
certificate_file=$1
certificate_key=$2
# Print information about what we are working with
echo "Certificate : $certificate_file"
echo "Key : $certificate_key"
# Compute md5
certificate_md5=$(openssl x509 -noout -modulus -in $certificate_file | openssl md5)
key_md5=$(openssl rsa -noout -modulus -in $certificate_key | openssl md5)
# Display final information
if [ "$key_md5" != "$certificate_md5" ]
then
echo "[ NO MATCH] Certificate and key do not match!"
echo "[ NO MATCH] Certificate : $certificate_md5"
echo "[ NO MATCH] Key : $key_md5"
exit 0
else
echo "[ MATCH ] Certificate and key do match!"
echo "[ MATCH ] Certificate : $certificate_md5"
echo "[ MATCH ] Key : $key_md5"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment