From 43b35b8cc29eaa7aa4ea0172726393bf9e9e2b68 Mon Sep 17 00:00:00 2001 From: David Cooper Date: Tue, 8 Nov 2016 10:10:14 -0500 Subject: [PATCH] Curve X25519 fixes This PR fixes two issues related to curve X25519. First, while OpenSSL 1.1.0 supports curve X25519, it is not included in the output of `$OPENSSL ecparam -list_curves`. I tried several versions of OpenSSL (and one version of LibreSSL), and every version output either "Error with command" or "unknown option" in response to `$OPENSSL s_client -curves $curve` if it either did not support the `-curves` option or did not support `$curve`. (When the `-curve` option was supported with `$curve`, a "connect" error was output.) The second issue is that the "Server Temp Key" line in the output of `s_client` is different for curve X25519. For other elliptic curves, the output is ``` Server Temp Key: ECDH, P-256, 256 bits ``` For X25519 it is: ``` Server Temp Key: X25519, 253 bits ``` So, `read_dhbits_from_file()` needs to allow for `$what_dh` being "X25519" rather than "ECDH" and `run_pfs()` needs to allow for the possibility that the curve name will be the first field rather than the second. --- testssl.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/testssl.sh b/testssl.sh index 4d97e30..4ae4bd7 100755 --- a/testssl.sh +++ b/testssl.sh @@ -3503,6 +3503,10 @@ read_dhbits_from_file() { grep -q bits <<< $bits || bits=$(awk -F',' '{ print $2 }' <<< $temp) bits=$(tr -d ' bits' <<< $bits) + if [[ "$what_dh" == "X25519" ]] || [[ "$what_dh" == "X448" ]]; then + what_dh="ECDH" + fi + debugme echo ">$HAS_DH_BITS|$what_dh|$bits<" [[ -n "$what_dh" ]] && HAS_DH_BITS=true # FIX 190 @@ -5235,8 +5239,8 @@ run_pfs() { # find out what elliptic curves are supported. curves_offered="" for curve in "${curves_ossl[@]}"; do - $OPENSSL ecparam -list_curves | grep -q $curve - [[ $? -eq 0 ]] && nr_curves+=1 && supported_curves+=("$curve") + $OPENSSL s_client -curves $curve 2>&1 | egrep -iaq "Error with command|unknown option" + [[ $? -ne 0 ]] && nr_curves+=1 && supported_curves+=("$curve") done # OpenSSL limits the number of curves that can be specified in the @@ -5262,7 +5266,8 @@ run_pfs() { fi if [[ "$sclient_success" -eq 0 ]]; then temp=$(awk -F': ' '/^Server Temp Key/ { print $2 }' "$tmpfile") - curve_found="$(awk -F', ' '{ print $2 }' <<< $temp)" + curve_found="$(awk -F',' '{ print $1 }' <<< $temp)" + [[ "$curve_found" == "ECDH" ]] && curve_found="$(awk -F', ' '{ print $2 }' <<< $temp)" j=0; curve_used="" for curve in "${curves_ossl[@]}"; do [[ "${curves_ossl_output[j]}" == "$curve_found" ]] && curve_used="${curves_ossl[j]}" && break