11#! /bin/bash
22
3+ NIST_SP_800_52=" config/nist-sp-800-52.json"
4+
35chk_cmd ()
46{
57 if ! command -v $1 & > /dev/null; then
@@ -90,11 +92,27 @@ csvreport()
9092EOF
9193}
9294
95+ # For TLS 1.2 and older versions, OpenSSL maintains a ciphersuite name
96+ # different from the name specified in RFC
97+ declare -A tls12_ossl_cs=(
98+ [" TLS_RSA_WITH_AES_256_CBC_SHA" ]=" AES256-SHA"
99+ [" TLS_RSA_WITH_AES_128_CBC_SHA" ]=" AES128-SHA"
100+ [" TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" ]=" ECDHE-RSA-AES256-SHA"
101+ [" TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" ]=" ECDHE-RSA-AES128-SHA"
102+ )
103+
93104opensslscan ()
94105{
95106 tmp=/tmp/tls.out
96107 rm -f $tmp 2> /dev/null
97- timeout 2s openssl s_client -CApath /etc/ssl/certs/ -connect " $TLS_Address " -brief < /dev/null 2> $tmp
108+ if [ $1 == " tls1_3" ]; then
109+ cipher_suite=$2
110+ s_client_opt=" -ciphersuites $cipher_suite -$1 "
111+ else
112+ cipher_suite=${tls12_ossl_cs[$2]}
113+ s_client_opt=" -cipher $cipher_suite -$1 "
114+ fi
115+ timeout 2s openssl s_client -connect $TLS_Address -CApath /etc/ssl/certs/ $s_client_opt -brief < /dev/null 2> $tmp
98116# echo "ret=$ret"
99117# cat $tmp
100118 conn_estd=0
@@ -105,6 +123,9 @@ opensslscan()
105123 key=${line/:*/ }
106124 val=${line/*: / }
107125 key=${key// / _}
126+ if [ " $val " == " $cipher_suite " ]; then
127+ val=$2
128+ fi
108129 printf -v " TLS_$key " ' %s' " $val "
109130 TLS_Status=" TLS"
110131 done < $tmp
@@ -119,19 +140,30 @@ unsetvars()
119140 unset $varlist
120141}
121142
122- scantls ()
143+ dotlsconnect ()
123144{
124145 TLS_Status=" PLAIN_TEXT"
125146 nc -w 1 -z ${TLS_Address/:/ }
126147 case " $? " in
127- 0) opensslscan ;;
148+ 0) opensslscan $1 $2 ;;
128149 * ) TLS_Status=" CONNFAIL" ;;
129150 esac
130151
131152 jsonreport
132153 csvreport
133154}
134155
156+ scantls ()
157+ {
158+ cs_count=` jq ' .cipher_suites | length' $NIST_SP_800_52 `
159+ for(( i= 0 ; i< $cs_count ; i++ )) ; do
160+ cipher_suite=` jq .cipher_suites[$i ].cipher_suite $NIST_SP_800_52 -r`
161+ tls_version=` jq .cipher_suites[$i ].versions $NIST_SP_800_52 -r`
162+ echo " TLS Connect with $tls_version and $cipher_suite "
163+ dotlsconnect $tls_version $cipher_suite
164+ done
165+ }
166+
135167getsummary ()
136168{
137169 status_arr=(
0 commit comments