Skip to content

Instantly share code, notes, and snippets.

@agustik
Created March 14, 2017 10:38
Show Gist options
  • Select an option

  • Save agustik/dd4a5b5bc77546a9b893d3c255af4eaf to your computer and use it in GitHub Desktop.

Select an option

Save agustik/dd4a5b5bc77546a9b893d3c255af4eaf to your computer and use it in GitHub Desktop.
Get all supported ciphers for tls/ssl connection
#!/usr/bin/bash
# OpenSSL requires the port number.
HOST=$1
PORT=$2
if [ -z "$PORT" ]; then
PORT="443"
fi
SERVER="${HOST}:${PORT}"
DELAY=1
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')
version=$(openssl version);
echo "Obtaining cipher list from ${version} on server: $SERVER".
function sizeOf(){
local _i=0;
for cipher in ${ciphers[@]}; do
_i=$(($_i + 1));
done
echo $_i
}
totalCiphers=$(sizeOf $ciphers)
i=0;
for cipher in ${ciphers[@]}; do
echo -n "Testing $cipher $i/$totalCiphers - "
result=$(echo -n | openssl s_client -cipher "$cipher" -connect $SERVER 2>&1)
if [[ "$result" =~ ":error:" ]] ; then
error=$(echo -n $result | cut -d':' -f6)
echo NO \($error\)
else
if [[ "$result" =~ "Cipher is ${cipher}" || "$result" =~ "Cipher :" ]] ; then
echo YES
else
echo UNKNOWN RESPONSE
echo $result
fi
fi
i=$(($i + 1));
sleep $DELAY
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment