Created
March 7, 2019 21:02
-
-
Save datadavev/7deb35c09492dfc4c7bf0c212ed1184b to your computer and use it in GitHub Desktop.
Show status of a remote certificate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Dump a cert or show dates valid | |
# | |
# e.g. to show valid dates: | |
# ./certshow -d google.com:443 | |
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