Skip to content

Instantly share code, notes, and snippets.

@datadavev
Created April 23, 2018 20:30
Show Gist options
  • Save datadavev/04fe3fff27b217f10fd9d22c1f57738b to your computer and use it in GitHub Desktop.
Save datadavev/04fe3fff27b217f10fd9d22c1f57738b to your computer and use it in GitHub Desktop.
Quickly check certificate validity from the command line.
#!/bin/bash
show_validity=0
function showHelp() {
cat << EOF
Show a certificate from a remote service.
Usage:
certshow [-d] TARGET[:PORT]
-d Show validity information only.
EOF
}
while getopts "h?d" opt; do
case "${opt}" in
h|\?)
showHelp
exit 0
;;
d)
show_validity=1
;;
esac
done
shift $((OPTIND-1))
TARGET="${1}"
if [[ "${TARGET}" != *:* ]]; then
TARGET="${TARGET}:443"
fi
if [[ ${show_validity} == "1" ]]; then
echo "Q" | openssl s_client -connect "${TARGET}" | openssl x509 -text -noout | grep -A3 "^[[:space:]]*Validity"
exit 0
fi
echo "Q" | openssl s_client -connect "${TARGET}" | openssl x509 -text -noout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment