Skip to content

Instantly share code, notes, and snippets.

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