Skip to content

Commit 045778b

Browse files
author
David Cooper
committed
Fix #1311
This commit fixes #1311 by only rating the lack of a server-enforced ciper order negatively if there is a difference in the quality rating of the ciphers offered for a particular protocol.
1 parent 8d9b11b commit 045778b

1 file changed

Lines changed: 101 additions & 13 deletions

File tree

testssl.sh

Lines changed: 101 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ NR_HEADER_FAIL=0 # .. for HTTP_GET
268268
PROTOS_OFFERED="" # This keeps which protocol is being offered. See has_server_protocol().
269269
TLS12_CIPHER_OFFERED="" # This contains the hexcode of a cipher known to be supported by the server with TLS 1.2
270270
CURVES_OFFERED="" # This keeps which curves have been detected. Just for error handling
271+
NO_CIPHER_ORDER_LEVEL=5 # This is the finding level to report if the server does not enforce a cipher order for one or more protocol versions.
271272
KNOWN_OSSL_PROB=false # We need OpenSSL a few times. This variable is an indicator if we can't connect. Eases handling
272273
DETECTED_TLS_VERSION="" # .. as hex string, e.g. 0300 or 0303
273274
APP_TRAF_KEY_INFO="" # Information about the application traffic keys for a TLS 1.3 connection.
@@ -4243,6 +4244,7 @@ ciphers_by_strength() {
42434244
local available proto_supported=false
42444245
local id
42454246
local has_dh_bits="$HAS_DH_BITS"
4247+
local -i quality worst_cipher=8 best_cipher=0 difference_rating=5
42464248

42474249
# for local problem if it happens
42484250
"$wide" || out " "
@@ -4505,12 +4507,51 @@ ciphers_by_strength() {
45054507
fi
45064508

45074509
if "$wide" && [[ "${FUNCNAME[1]}" == run_server_preference ]] && "$proto_supported"; then
4508-
if [[ $proto_ossl == tls1_3 ]]; then
4509-
outln " (no server order, thus listed by strength)"
4510-
elif ! "$serverpref_known"; then
4510+
if ! "$serverpref_known"; then
45114511
outln " (listed by strength)"
45124512
else
4513-
prln_svrty_high " (no server order, thus listed by strength)"
4513+
# Determine the best and worst quality level findings for the supported ciphers
4514+
for (( i=0 ; i<nr_ciphers; i++ )); do
4515+
if "${ciphers_found[i]}"; then
4516+
if [[ "${rfc_ciph[i]}" != - ]]; then
4517+
get_cipher_quality "${rfc_ciph[i]}"
4518+
else
4519+
get_cipher_quality ${ciph[i]}
4520+
fi
4521+
quality=$?
4522+
[[ $quality -lt $worst_cipher ]] && worst_cipher=$quality
4523+
[[ $quality -gt $best_cipher ]] && best_cipher=$quality
4524+
fi
4525+
done
4526+
# Assign a rating (severity level) based on the difference between the levels
4527+
# of the best and worst supported ciphers.
4528+
if [[ $worst_cipher -ne $best_cipher ]]; then
4529+
case $best_cipher in
4530+
3|5|6|7)
4531+
difference_rating=$worst_cipher
4532+
[[ $difference_rating -gt 5 ]] && difference_rating=5
4533+
;;
4534+
4)
4535+
case $worst_cipher in
4536+
3) difference_rating=4 ;;
4537+
2) difference_rating=2 ;;
4538+
1) difference_rating=1 ;;
4539+
esac
4540+
;;
4541+
2)
4542+
difference_rating=2
4543+
;;
4544+
esac
4545+
fi
4546+
4547+
[[ $difference_rating -lt $NO_CIPHER_ORDER_LEVEL ]] && NO_CIPHER_ORDER_LEVEL=$difference_rating
4548+
case $difference_rating in
4549+
5) outln " (no server order, thus listed by strength)" ;;
4550+
4) prln_svrty_low " (no server order, thus listed by strength)" ;;
4551+
3) prln_svrty_medium " (no server order, thus listed by strength)" ;;
4552+
2) prln_svrty_high " (no server order, thus listed by strength)" ;;
4553+
1) prln_svrty_critical " (no server order, thus listed by strength)" ;;
4554+
esac
45144555
fi
45154556
elif "$wide" && "$proto_supported" || [[ $proto != -ssl2 ]]; then
45164557
outln
@@ -6650,7 +6691,7 @@ run_server_preference() {
66506691
local has_cipher_order=false has_tls13_cipher_order=false
66516692
local addcmd="" addcmd2=""
66526693
local using_sockets=true
6653-
local jsonID="cipher_order"
6694+
local jsonID="cipher_order" fileout_msg="" fileout_rating="" terminal_msg=""
66546695
local cwe="CWE-310"
66556696
local cve=""
66566697

@@ -6824,23 +6865,58 @@ run_server_preference() {
68246865

68256866
pr_bold " Has server cipher order? "
68266867
jsonID="cipher_order"
6868+
case $NO_CIPHER_ORDER_LEVEL in
6869+
5) fileout_rating="INFO" ;;
6870+
4) fileout_rating="LOW" ;;
6871+
3) fileout_rating="MEDIUM" ;;
6872+
2) fileout_rating="HIGH" ;;
6873+
1) fileout_rating="CRITICAL" ;;
6874+
esac
68276875
if "$TLS13_ONLY" && ! "$has_tls13_cipher_order"; then
6828-
out "no (TLS 1.3 only)"
6876+
terminal_msg="no (TLS 1.3 only)"
68296877
limitedsense=" (limited sense as client will pick)"
6830-
fileout "$jsonID" "INFO" "not a cipher order for TLS 1.3 configured"
6878+
fileout_msg="not a cipher order for TLS 1.3 configured"
68316879
elif ! "$TLS13_ONLY" && [[ -z "$cipher2" ]]; then
68326880
pr_warning "unable to determine"
68336881
elif ! "$has_cipher_order" && ! "$has_tls13_cipher_order"; then
68346882
# server used the different ends (ciphers) from the client hello
6835-
pr_svrty_high "no (NOT ok)"
6883+
terminal_msg="no (NOT ok)"
6884+
[[ "$fileout_rating" == INFO ]] && terminal_msg="no"
68366885
limitedsense=" (limited sense as client will pick)"
6837-
fileout "$jsonID" "HIGH" "NOT a cipher order configured"
6886+
fileout_msg="NOT a cipher order configured"
68386887
elif "$has_cipher_order" && ! "$has_tls13_cipher_order" && [[ "$default_proto" == TLSv1.3 ]]; then
6839-
pr_svrty_good "yes (OK)"; out " -- only for < TLS 1.3"
6840-
fileout "$jsonID" "OK" "server -- TLS 1.3 client determined"
6888+
if [[ $NO_CIPHER_ORDER_LEVEL -eq 5 ]]; then
6889+
pr_svrty_good "yes (OK)"; out " -- only for < TLS 1.3"
6890+
fileout "$jsonID" "OK" "server -- TLS 1.3 client determined"
6891+
else
6892+
# The server does not enforce a cipher order for TLS 1.3 and it
6893+
# accepts some lower quality TLS 1.3 ciphers.
6894+
terminal_msg="only for < TLS 1.3"
6895+
fileout_msg="server -- TLS 1.3 client determined"
6896+
fi
68416897
elif ! "$has_cipher_order" && "$has_tls13_cipher_order"; then
6842-
pr_svrty_high "no (NOT ok)"; out " -- only for TLS 1.3"
6843-
fileout "$jsonID" "HIGH" "server -- < TLS 1.3 client determined"
6898+
case "$fileout_rating" in
6899+
"INFO")
6900+
out "only for TLS 1.3"
6901+
fileout "$jsonID" "INFO" "server -- < TLS 1.3 client determined"
6902+
;;
6903+
"LOW")
6904+
pr_svrty_low "no (NOT ok)"; out " -- only for TLS 1.3"
6905+
fileout "$jsonID" "LOW" "server -- < TLS 1.3 client determined"
6906+
;;
6907+
"MEDIUM")
6908+
pr_svrty_medium "no (NOT ok)"; out " -- only for TLS 1.3"
6909+
fileout "$jsonID" "MEDIUM" "server -- < TLS 1.3 client determined"
6910+
;;
6911+
"HIGH")
6912+
pr_svrty_high "no (NOT ok)"; out " -- only for TLS 1.3"
6913+
fileout "$jsonID" "HIGH" "server -- < TLS 1.3 client determined"
6914+
;;
6915+
"CRITICAL")
6916+
pr_svrty_critical "no (NOT ok)"; out " -- only for TLS 1.3"
6917+
fileout "$jsonID" "CRITICAL" "server -- < TLS 1.3 client determined"
6918+
;;
6919+
esac
68446920
else
68456921
if "$has_tls13_cipher_order"; then
68466922
if "$TLS13_ONLY"; then
@@ -6857,6 +6933,17 @@ run_server_preference() {
68576933
fileout "$jsonID" "OK" "server"
68586934
fi
68596935
fi
6936+
if [[ -n "$fileout_msg" ]]; then
6937+
case "$fileout_rating" in
6938+
"INFO") out "$terminal_msg" ;;
6939+
"OK") pr_svrty_good "$terminal_msg" ;;
6940+
"LOW") pr_svrty_low "$terminal_msg" ;;
6941+
"MEDIUM") pr_svrty_medium "$terminal_msg" ;;
6942+
"HIGH") pr_svrty_high "$terminal_msg" ;;
6943+
"CRITICAL") pr_svrty_critical "$terminal_msg" ;;
6944+
esac
6945+
fileout "$jsonID" "$fileout_rating" "$fileout_msg"
6946+
fi
68606947
outln
68616948

68626949
pr_bold " Negotiated protocol "
@@ -23469,6 +23556,7 @@ reset_hostdepended_vars() {
2346923556
PROTOS_OFFERED=""
2347023557
TLS12_CIPHER_OFFERED=""
2347123558
CURVES_OFFERED=""
23559+
NO_CIPHER_ORDER_LEVEL=5
2347223560
KNOWN_OSSL_PROB=false
2347323561
TLS13_ONLY=false
2347423562
CLIENT_AUTH="none"

0 commit comments

Comments
 (0)