Created
June 20, 2013 13:02
-
-
Save mmaassen/5822471 to your computer and use it in GitHub Desktop.
Simple certificate download script
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 | |
#--------------------------------- | |
# 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