Skip to content

Instantly share code, notes, and snippets.

@chrisnew
Created January 18, 2015 22:17
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 chrisnew/fadc014062ce16fe1127 to your computer and use it in GitHub Desktop.
Save chrisnew/fadc014062ce16fe1127 to your computer and use it in GitHub Desktop.
A simple shell script which checks TLS server for certificate algorithm and supported ciphers using OpenSSL.
#!/usr/bin/env bash
# tlschecker.sh, version 0.1.0
# based on https://superuser.com/revisions/224263/3
#
# changelog:
# - added argument for hostname
# - made port optional
# - openssl uses SNI
# - displays subject, issuer, algorithm of certificate
# - some output tweaking
if [[ -z "$1" ]] ; then
echo "$0 <server>[:<port>]"
exit -1
fi
SERVER=$1
DELAY=1
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')
if [[ ! "$SERVER" =~ :[0-9]+$ ]] ; then
SERVER="$SERVER:443"
fi
openssl version
echo
echo Certificate:
openssl s_client -servername $SERVER -connect $SERVER < /dev/null 2>/dev/null | openssl x509 -text -in /dev/stdin | grep -E "(Signature Algorithm|Subject|Issuer):" | uniq
sleep $DELAY
echo
echo Ciphers:
for cipher in ${ciphers[@]}
do
echo -n " $cipher: "
result=$(echo -n | openssl s_client -cipher "$cipher" -connect "$SERVER" 2>&1)
if [[ "$result" =~ "Cipher is ${cipher}" || "$result" =~ "Cipher :" ]] ; then
echo YES
else
if [[ "$result" =~ ":error:" ]] ; then
error=$(echo -n $result | cut -d':' -f6)
echo NO \($error\)
else
echo UNKNOWN RESPONSE
echo $result
fi
fi
sleep $DELAY
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment