@@ -108,8 +108,13 @@ test_cipher_on_target() {
108
108
fi
109
109
# filter out the OCSP server certificate
110
110
tmp=$( awk ' BEGIN { pr="yes" } /^======================================/ { if ( pr=="yes" ) pr="no"; else pr="yes" } { if ( pr == "yes" ) print }' <<< " $tmp" )
111
+ current_certcn=$( grep " subject=" <<< " $tmp" | grep -oP " (?<=CN\=)[^ |\/]+" )
112
+ current_subjaltnames=$( ${OPENSSLBIN} x509 -noout -text 2> /dev/null <<< " $tmp" | awk ' /X509v3 Subject Alternative Name/ {getline;gsub(/ /, "", $0);print}' | tr -d " DNS:" )
111
113
current_cipher=$( grep " New, " <<< " $tmp" | awk ' {print $5}' )
112
114
current_pfs=$( grep ' Server Temp Key' <<< " $tmp" | awk ' {print $4$5$6$7}' )
115
+ if [ -z $current_pfs ]; then
116
+ current_pfs=" None"
117
+ fi
113
118
current_protocol=$( egrep " ^\s+Protocol\s+:" <<< " $tmp" | awk ' {print $3}' )
114
119
current_pubkey=$( grep ' Server public key is ' <<< " $tmp" | awk ' {print $5}' )
115
120
if [ -z $current_pubkey ]; then
@@ -147,6 +152,16 @@ test_cipher_on_target() {
147
152
else
148
153
protocols=" $protocols ,$current_protocol "
149
154
fi
155
+ certcns=" $current_certcn "
156
+ # Let's add the alternative subject names if they exist
157
+ if [ -n " $current_subjaltnames " ]; then
158
+ IFS=' ,' read -ra subjaltnamesarray <<< " $current_subjaltnames"
159
+ for altname in " ${subjaltnamesarray[@]} " ; do
160
+ if [[ " $altname " != " $current_certcn " ]]; then
161
+ certcns=" $certcns ,$altname "
162
+ fi
163
+ done
164
+ fi
150
165
cipher=$current_cipher
151
166
pfs=$current_pfs
152
167
pubkey=$current_pubkey
@@ -165,13 +180,13 @@ test_cipher_on_target() {
165
180
166
181
# if cipher contains NONE, the cipher wasn't accepted
167
182
elif [ " $cipher " == ' (NONE) ' ]; then
168
- result=" $cipher $protocols $pubkey $sigalg $trusted $tickethint $ocspstaple $pfs "
183
+ result=" $cipher $protocols $pubkey $sigalg $trusted $tickethint $ocspstaple $pfs $certcns "
169
184
verbose " handshake failed, server returned ciphersuite '$result '"
170
185
return 1
171
186
172
187
# the connection succeeded
173
188
else
174
- result=" $cipher $protocols $pubkey $sigalg $trusted $tickethint $ocspstaple $pfs "
189
+ result=" $cipher $protocols $pubkey $sigalg $trusted $tickethint $ocspstaple $pfs $certcns "
175
190
verbose " handshake succeeded, server returned ciphersuite '$result '"
176
191
return 0
177
192
fi
@@ -226,6 +241,7 @@ get_cipher_pref() {
226
241
display_results_in_terminal () {
227
242
# Display the results
228
243
ctr=1
244
+ local certcns
229
245
local pubkey
230
246
local sigalg
231
247
local trusted
@@ -246,6 +262,7 @@ display_results_in_terminal() {
246
262
trusted=$( awk ' {print $5}' <<< $cipher )
247
263
tickethint=$( awk ' {print $6}' <<< $cipher )
248
264
ocspstaple=$( awk ' {print $7}' <<< $cipher )
265
+ certcns=$( awk ' {print $9}' <<< $cipher )
249
266
else
250
267
if [ " $pubkey " != " $( awk ' {print $3}' <<< $cipher ) " ]; then
251
268
different=True
@@ -291,11 +308,28 @@ display_results_in_terminal() {
291
308
fi
292
309
done| column -t
293
310
echo
311
+
312
+ matchhostname=0
313
+ hostcertcn=" Not a match"
314
+ if [ -z " $certcns " ]; then
315
+ hostcertcn=" CN not found"
316
+ else
317
+ IFS=' ,' read -ra certcnsarray <<< " $certcns"
318
+ for certcn in " ${certcnsarray[@]} " ; do
319
+ if [[ " $certcn " == " $HOST " ]]; then
320
+ matchhostname=1
321
+ hostcertcn=" $certcn "
322
+ break
323
+ fi
324
+ done
325
+
326
+
327
+ fi
294
328
if [ $different != " True" ]; then
295
329
if [ " $trusted " == " True" ]; then
296
- echo " Certificate: trusted, $pubkey bit, $sigalg signature"
330
+ echo " Certificate: $hostcertcn , trusted, $pubkey bit, $sigalg signature"
297
331
else
298
- echo " Certificate: UNTRUSTED, $pubkey bit, $sigalg signature"
332
+ echo " Certificate: $hostcertcn , UNTRUSTED, $pubkey bit, $sigalg signature"
299
333
fi
300
334
echo " TLS ticket lifetime hint: $tickethint "
301
335
fi
@@ -304,6 +338,13 @@ display_results_in_terminal() {
304
338
else
305
339
echo " OCSP stapling: not supported"
306
340
fi
341
+ if [ $matchhostname -eq 0 ]; then
342
+ echo " WARNING - None of the CNs match the hostname given"
343
+ fi
344
+ if [ -n " $certcns " ]; then
345
+ echo " Here is the list of common names found in the certificate"
346
+ echo $certcns
347
+ fi
307
348
}
308
349
309
350
@@ -315,6 +356,7 @@ display_results_in_json() {
315
356
[ $ctr -gt 0 ] && echo -n ' ,'
316
357
echo -n " {\" cipher\" :\" $( echo $cipher | awk ' {print $1}' ) \" ,"
317
358
echo -n " \" protocols\" :[\" $( echo $cipher | awk ' {print $2}' | sed ' s/,/","/g' ) \" ],"
359
+ echo -n " \" certcns\" :[\" $( echo $cipher | awk ' {print $9}' | sed ' s/,/","/g' ) \" ],"
318
360
echo -n " \" pubkey\" :[\" $( echo $cipher | awk ' {print $3}' | sed ' s/,/","/g' ) \" ],"
319
361
echo -n " \" sigalg\" :[\" $( echo $cipher | awk ' {print $4}' | sed ' s/,/","/g' ) \" ],"
320
362
echo -n " \" trusted\" :\" $( echo $cipher | awk ' {print $5}' | sed ' s/,/","/g' ) \" ,"
0 commit comments