From af15bd0f002c0523579b3807949fa54c05c793e3 Mon Sep 17 00:00:00 2001 From: David Cooper Date: Wed, 27 Sep 2017 13:39:45 -0400 Subject: [PATCH] Make more use of has_server_protocol() This PR makes a few changes related to add_tls_offered()/has_server_protocol(). * It changes run_beast() to check has_server_protocol() before running a test against the server when trying to determine whether the server supports SSLv3, TLSv1, TLSv1.1, and TLSv1.2. * It has run_server_defaults() and run_beast() call add_tls_offered() whenever it detects that a protocol is offered (This makes $PROTOS_OFFERED more complete in the case that run_protocols() isn't run.) Note that in order for the results of the calls to add_tls_offered() in cipher_pref_check() not to be lost, the method of providing the input to the while loop needed to be changed. * It changes add_tls_offered() and has_server_protocol() to use Bash string capabilities rather than grep in order to improve performance. --- testssl.sh | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/testssl.sh b/testssl.sh index 40c3bd3..84dade6 100755 --- a/testssl.sh +++ b/testssl.sh @@ -3968,13 +3968,12 @@ run_prototest_openssl() { # idempotent function to add SSL/TLS protocols. It should ease testing # PROTOS_OFFERED's content is in openssl terminology add_tls_offered() { - grep -qw "$1" <<< "$PROTOS_OFFERED" || PROTOS_OFFERED+="$1 " + [[ "$PROTOS_OFFERED" =~ "$1 " ]] || PROTOS_OFFERED+="$1 " } # function which checks whether SSLv2 - TLS 1.2 is being offereed has_server_protocol() { - [[ -z "$PROTOS_OFFERED" ]] && return 1 # if empty return 1, hinting to the caller to check at additional cost/connect - if grep -qw "$1" <<< "$PROTOS_OFFERED"; then + if [[ "$PROTOS_OFFERED" =~ "$1 " ]]; then return 0 fi return 1 @@ -4848,6 +4847,7 @@ run_server_preference() { cipher[i]="" fi fi + [[ -n "${cipher[i]}" ]] && add_tls_offered "$proto" i=$((i + 1)) done @@ -4964,7 +4964,7 @@ cipher_pref_check() { pr_bold " Cipher order" - tm_out " ssl3 00 SSLv3\n tls1 01 TLSv1\n tls1_1 02 TLSv1.1\n tls1_2 03 TLSv1.2\n" | while read p proto_hex proto; do + while read p proto_hex proto; do order=""; ciphers_found_with_sockets=false if [[ $p == ssl3 ]] && ! "$HAS_SSL3" && ! "$using_sockets"; then out "\n SSLv3: "; pr_local_problem "$OPENSSL doesn't support \"s_client -ssl3\""; @@ -5135,12 +5135,13 @@ cipher_pref_check() { fi if [[ -n "$order" ]]; then + add_tls_offered "$p" outln out "$(printf " %-10s " "$proto: ")" out "$(out_row_aligned_max_width "$order" " " $TERM_WIDTH)" fileout "order_$p" "INFO" "Default cipher order for protocol $p: $order" fi - done + done <<< "$(tm_out " ssl3 00 SSLv3\n tls1 01 TLSv1\n tls1_1 02 TLSv1.1\n tls1_2 03 TLSv1.2\n")" outln outln @@ -10775,9 +10776,17 @@ run_beast(){ # first determine whether it's mitigated by higher protocols for proto in tls1_1 tls1_2; do - $OPENSSL s_client -state -"$proto" $STARTTLS $BUGS -connect $NODEIP:$PORT $PROXY $SNI 2>>$ERRFILE >$TMPFILE >$ERRFILE >$TMPFILE $TMPFILE 2>>$ERRFILE