From c14ea2efc8c279e6f596293e9b6c616adcd900bb Mon Sep 17 00:00:00 2001 From: David Cooper Date: Tue, 22 Mar 2022 15:10:28 -0400 Subject: [PATCH] Use tls_sockets() in run_tls_fallback_scsv() This commit adds the use of tls_sockets() to run_tls_fallback_scsv() to perform testing when the --ssl-native flag is not used. With this commit, run_tls_fallback_scsv() only uses tls_sockets() instead of $OPENSSL if the ClientHello needs to include the TLS_FALLBACK_SCSV flag, but it is not supported by $OPENSSL, or if the protocol that would be negotiated is SSLv3 and $OPENSSL does not support SSLv3. --- testssl.sh | 91 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 18 deletions(-) diff --git a/testssl.sh b/testssl.sh index 6e3429d..2e8c2c5 100755 --- a/testssl.sh +++ b/testssl.sh @@ -13599,6 +13599,7 @@ parse_tls_serverhello() { fi if [[ $tls_alert_ascii_len -gt 0 ]]; then + echo "CONNECTED(00000003)" > $TMPFILE debugme echo "TLS alert messages:" for (( i=0; i+3 < tls_alert_ascii_len; i+=4 )); do tls_err_level=${tls_alert_ascii:i:2} # 1: warning, 2: fatal @@ -13798,10 +13799,12 @@ parse_tls_serverhello() { [[ $DEBUG -ge 1 ]] && tmpfile_handle ${FUNCNAME[0]}.txt return 1 fi - if [[ $DEBUG -eq 0 ]]; then - echo "CONNECTED(00000003)" > $TMPFILE - else - echo "CONNECTED(00000003)" >> $TMPFILE + if [[ $tls_alert_ascii_len -eq 0 ]]; then + if [[ $DEBUG -eq 0 ]]; then + echo "CONNECTED(00000003)" > $TMPFILE + else + echo "CONNECTED(00000003)" >> $TMPFILE + fi fi # First parse the server hello handshake message @@ -17096,16 +17099,19 @@ run_tls_poodle() { # the countermeasure to protect against protocol downgrade attacks. # run_tls_fallback_scsv() { - local -i ret=0 + local -i ret=0 debug_level local high_proto="" low_proto="" local p high_proto_str protos_to_try + local using_sockets=true local jsonID="fallback_SCSV" + "$SSL_NATIVE" && using_sockets=false + [[ $VULN_COUNT -le $VULN_THRESHLD ]] && outln && pr_headlineln " Testing for TLS_FALLBACK_SCSV Protection " && outln pr_bold " TLS_FALLBACK_SCSV"; out " (RFC 7507) " # First check we have support for TLS_FALLBACK_SCSV in our local OpenSSL - if ! "$HAS_FALLBACK_SCSV"; then + if ! "$HAS_FALLBACK_SCSV" && ! "$using_sockets"; then prln_local_problem "$OPENSSL lacks TLS_FALLBACK_SCSV support" fileout "$jsonID" "WARN" "$OPENSSL lacks TLS_FALLBACK_SCSV support" return 1 @@ -17123,11 +17129,23 @@ run_tls_fallback_scsv() { high_proto="$p" break fi - [[ "$p" == ssl3 ]] && ! "$HAS_SSL3" && continue - $OPENSSL s_client $(s_client_options "-$p $STARTTLS $BUGS -connect $NODEIP:$PORT $PROXY $SNI") >$TMPFILE 2>$ERRFILE $TMPFILE 2>$ERRFILE $TMPFILE 2>$ERRFILE $TMPFILE 2>$ERRFILE $TMPFILE $TMPFILE "$TEMPDIR/$NODEIP.parse_tls_serverhello.txt" + + # tls_sockets() needs to parse the full response since the following code is + # looking for "BEGIN CERTIFICATE" when the TLS connection is successful. It + # may be possible to speed up this code by having the following code check + # the return value from tls_sockets() to determine whether the connection was + # successful rather than looking for "BEGIN CERTIFICATE". + case "$low_proto" in + "tls1_1") + tls_sockets "02" "56,00, $TLS_CIPHER" "all" "" "true" ;; + "tls1") + tls_sockets "01" "56,00, $TLS_CIPHER" "all" "" "true" ;; + "ssl3") + tls_sockets "00" "56,00, $TLS_CIPHER" "all" "" "true" ;; + esac + mv "$TEMPDIR/$NODEIP.parse_tls_serverhello.txt" "$TMPFILE" + DEBUG=$debug_level + fi if grep -q "CONNECTED(00" "$TMPFILE"; then if grep -qa "BEGIN CERTIFICATE" "$TMPFILE"; then if [[ -z "$POODLE" ]]; then