Created
May 29, 2019 17:02
-
-
Save peterwwillis/ee05b14bf983d774892ac9713af97483 to your computer and use it in GitHub Desktop.
Download a TLS certificate
This file contains 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/sh | |
set -e | |
_get_cert () { | |
openssl s_client -showcerts -connect "$1":"$2" </dev/null 2>/dev/null | openssl x509 -outform PEM | |
} | |
if [ $# -lt 2 ] ; then | |
echo "Usage: $0 HOST PORT [OUTFILE]" | |
echo "" | |
echo "Connects to TCP PORT on HOST and downloads TLS certificates." | |
echo "Saves to OUTFILE if it is specified, otherwise outputs to standard out." | |
exit 1 | |
fi | |
HOST="$1"; shift | |
PORT="$1"; shift | |
if [ $# -gt 0 ] ; then | |
_get_cert "$HOST" "$PORT" > "$1" | |
else | |
_get_cert "$HOST" "$PORT" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment