Skip to content

Commit 8066cb2

Browse files
committed
TLS scan the SUT multiple times with different cipiher suites and version
1 parent 0f70331 commit 8066cb2

File tree

2 files changed

+91
-3
lines changed

2 files changed

+91
-3
lines changed

config/nist-sp-800-52.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"tls_versions": [
3+
{
4+
"version": "1.3",
5+
"safer": true
6+
},
7+
{
8+
"version": "1.2",
9+
"safer": true
10+
},
11+
{
12+
"version": "1.1",
13+
"safer": false
14+
},
15+
{
16+
"version": "1.0",
17+
"safer": false
18+
},
19+
{
20+
"version": "3.0",
21+
"safer": false
22+
}
23+
],
24+
"cipher_suites": [
25+
{
26+
"cipher_suite": "TLS_AES_256_GCM_SHA384",
27+
"versions": "tls1_3",
28+
"safer": true
29+
},
30+
{
31+
"cipher_suite": "TLS_AES_128_GCM_SHA256",
32+
"versions": "tls1_3",
33+
"safer": true
34+
},
35+
{
36+
"cipher_suite": "TLS_RSA_WITH_AES_256_CBC_SHA",
37+
"versions": "tls1_2",
38+
"safer": false
39+
},
40+
{
41+
"cipher_suite": "TLS_RSA_WITH_AES_128_CBC_SHA",
42+
"versions": "tls1_2",
43+
"safer": false
44+
},
45+
{
46+
"cipher_suite": "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
47+
"versions": "tls1_2",
48+
"safer": false
49+
},
50+
{
51+
"cipher_suite": "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
52+
"versions": "tls1_2",
53+
"safer": false
54+
}
55+
]
56+
}

src/tlsscan

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
NIST_SP_800_52="config/nist-sp-800-52.json"
4+
35
chk_cmd()
46
{
57
if ! command -v $1 &>/dev/null; then
@@ -90,11 +92,27 @@ csvreport()
9092
EOF
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+
93104
opensslscan()
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+
135167
getsummary()
136168
{
137169
status_arr=(

0 commit comments

Comments
 (0)