Skip to content

Instantly share code, notes, and snippets.

@peterwwillis
Created May 29, 2019 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterwwillis/ee05b14bf983d774892ac9713af97483 to your computer and use it in GitHub Desktop.
Save peterwwillis/ee05b14bf983d774892ac9713af97483 to your computer and use it in GitHub Desktop.
Download a TLS certificate
#!/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