1#!/usr/local/bin/bash
2
3hs="$1"
4len=${#hs}
5echo "# ciphers: $((len/4))"
6
7mapfile="etc/cipher-mapping.txt"
8[ -s $mapfile ] || mapfile="../$mapfile"
9[ -s $mapfile ] || exit 255
10
11cip=""
12first=true
13
14for ((i=0; i<len ; i+=4)); do
15	printf "%02d" "$i"
16	echo -n ": ${hs:$i:4}"
17	grepstr="0x${hs:$i:2},0x${hs:$((i+2)):2}"
18        echo -n " --> $grepstr --> "
19        cip=$(grep -i -E "^ *${grepstr}" $mapfile | awk '{ print $3 }')
20	if [[ $grepstr == 0x00,0xff ]]; then
21		echo TLS_EMPTY_RENEGOTIATION_INFO_SCSV
22	else
23		echo $cip
24	fi
25	if "$first"; then
26		ciphers="$cip"
27		first=false
28	else
29		ciphers="$ciphers:$cip"
30	fi
31done
32
33echo
34# remove leading : because of GREASE, and trailing because of TLS_EMPTY_RENEGOTIATION_INFO_SCSV
35ciphers="${ciphers%:}"
36echo ${ciphers#:}
37