Skip to content

Instantly share code, notes, and snippets.

@mmaassen
Created June 20, 2013 13:02
Show Gist options
  • Save mmaassen/5822471 to your computer and use it in GitHub Desktop.
Save mmaassen/5822471 to your computer and use it in GitHub Desktop.
Simple certificate download script
#!/bin/bash
#---------------------------------
# Certificate Downloader
#---------------------------------
if [ $# -eq 0 ]; then
echo -e " [>] Usage: $0 [host] [port]"
exit 1
fi
echo "========================================="
echo " 1. Show Certificate"
echo " 2. Show Cert. Chain"
echo "========================================="
echo -n " [>] "
read SHOW
case $SHOW in
1)
openssl s_client -connect $1:$2 >/tmp/downloadServerCert.tmp </dev/null
;;
2)
openssl s_client -connect $1:$2 -showcerts >/tmp/downloadServerCert.tmp </dev/null
;;
esac
START="n"
exec</tmp/downloadServerCert.tmp
while read line; do
if [ "$line" == "-----BEGIN CERTIFICATE-----" ]; then
START="y"
fi
if [ "$line" == "-----END CERTIFICATE-----" ]; then
echo -e "$line"
START="n"
fi
if [ "$START" == "y" ]; then
echo -e "$line"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment