Created
April 23, 2018 20:30
-
-
Save datadavev/04fe3fff27b217f10fd9d22c1f57738b to your computer and use it in GitHub Desktop.
Quickly check certificate validity from the command line.
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 | |
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