Created
April 28, 2021 22:45
-
-
Save datadavev/b8966743bd972fe2b14d084788d5e4c0 to your computer and use it in GitHub Desktop.
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