Skip to content

Instantly share code, notes, and snippets.

@crotel
Last active July 7, 2021 15:02
Show Gist options
  • Save crotel/521a3f48fbd082a620f00b5b412aa658 to your computer and use it in GitHub Desktop.
Save crotel/521a3f48fbd082a620f00b5b412aa658 to your computer and use it in GitHub Desktop.
A ssl cert and key verify shell
#!/bin/bash
# createAt 20210701
# Author: CROTEL
#
# Usage:
#
# ./sslverify.sh cert=/etc/nginx/ssl/server.crt key=/etc/nginx/ssl/server.key
#
# crt and key must use absolutely location
#
# updateAt 20210707
# add DNS, Subject, Issuer[s] and OCSP.
for ARGUMENT in "$@"
do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
case "$KEY" in
cert) CERTPATH=${VALUE} ;;
key) KEYPATH=${VALUE} ;;
*)
esac
done
function expir()
{
openssl x509 -text -noout -in $CERTPATH | grep -e 'Before\|After\|DNS\|Subject:\|Issuer[:s]\|OCSP'
}
function certmd5()
{
openssl x509 -noout -modulus -in $CERTPATH | openssl md5
}
function keymd5()
{
openssl rsa -noout -modulus -in $KEYPATH | openssl md5
}
echo "$(expir)"
if [[ "$certmd5" -eq "$keymd5" ]]
then
echo "Verified: OK"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment