From 4063e38ccf99b2e676d26e5813974338323ce272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Meireles?= Date: Thu, 28 May 2015 16:51:33 +0100 Subject: [PATCH] simplify life for OSX users running gnu's coreutils... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: António Meireles --- testssl.sh | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/testssl.sh b/testssl.sh index bc6d9e7..ea62c66 100755 --- a/testssl.sh +++ b/testssl.sh @@ -1459,10 +1459,12 @@ server_defaults() { now=$(date "+%s") HTTP_TIME=$(awk -F': ' '/^date:/ { print $2 } /^Date:/ { print $2 }' $TMPFILE) if [ -n "$HTTP_TIME" ] ; then - case $SYSTEM in - *BSD|Darwin) HTTP_TIME=$(date -j -f "%a, %d %b %Y %T %Z" "$HTTP_TIME" "+%s" 2>/dev/null) ;; # the trailing \r confuses BSD flavors otherwise - *) HTTP_TIME=$(date --date="$HTTP_TIME" "+%s") ;; - esac + if [[ $(date --help 2>/dev/null) ]]; then + HTTP_TIME=$(date --date="$HTTP_TIME" "+%s") + else + HTTP_TIME=$(date -j -f "%a, %d %b %Y %T %Z" "$HTTP_TIME" "+%s" 2>/dev/null) # the trailing \r confuses BSD flavors otherwise + fi + difftime=$(($now - $HTTP_TIME)) [[ $difftime != "-"* ]] && [[ $difftime != "0" ]] && difftime="+$difftime" out "$difftime sec from localtime"; @@ -1599,7 +1601,7 @@ server_defaults() { out " Certificate Expiration " expire=$($OPENSSL x509 -in $HOSTCERT -checkend 0) if ! echo $expire | grep -qw not; then - pr_red "expired!" + pr_red "expired!" else SECS2WARN=$((24 * 60 * 60 * $DAYS2WARN2)) # low threshold first expire=$($OPENSSL x509 -in $HOSTCERT -checkend $SECS2WARN) @@ -1609,27 +1611,26 @@ server_defaults() { if echo "$expire" | grep -qw not; then pr_litegreen ">= $DAYS2WARN1 days" else - pr_brown "expires < $DAYS2WARN1 days" + pr_brown "expires < $DAYS2WARN1 days" fi else - pr_litered "expires < $DAYS2WARN2 days!" + pr_litered "expires < $DAYS2WARN2 days!" fi fi - case $SYSTEM in - *BSD|Darwin*) - enddate=$(date -j -f "%b %d %T %Y %Z" "$($OPENSSL x509 -in $HOSTCERT -noout -enddate | cut -d= -f 2)" +"%F %H:%M %z") - startdate=$(date -j -f "%b %d %T %Y %Z" "$($OPENSSL x509 -in $HOSTCERT -noout -startdate | cut -d= -f 2)" +"%F %H:%M") - ;; - *) - enddate=$(date --date="$($OPENSSL x509 -in $HOSTCERT -noout -enddate | cut -d= -f 2)" +"%F %H:%M %z") - startdate=$(date --date="$($OPENSSL x509 -in $HOSTCERT -noout -startdate | cut -d= -f 2)" +"%F %H:%M") - ;; - esac + + if [[ $(date --help 2>/dev/null) ]]; then + enddate=$(date --date="$($OPENSSL x509 -in $HOSTCERT -noout -enddate | cut -d= -f 2)" +"%F %H:%M %z") + startdate=$(date --date="$($OPENSSL x509 -in $HOSTCERT -noout -startdate | cut -d= -f 2)" +"%F %H:%M") + else + enddate=$(date -j -f "%b %d %T %Y %Z" "$($OPENSSL x509 -in $HOSTCERT -noout -enddate | cut -d= -f 2)" +"%F %H:%M %z") + startdate=$(date -j -f "%b %d %T %Y %Z" "$($OPENSSL x509 -in $HOSTCERT -noout -startdate | cut -d= -f 2)" +"%F %H:%M") + fi + outln " ($startdate --> $enddate)" savedir=$(pwd); cd $TEMPDIR $OPENSSL s_client -showcerts $STARTTLS -connect $NODEIP:$PORT $SNI 2>/dev/null ("level" c ".crt")} /---END CERTIFICATE-----/{inc=0}' + awk -v c=-1 '/-----BEGIN CERTIFICATE-----/{inc=1;c++} inc {print > ("level" c ".crt")} /---END CERTIFICATE-----/{inc=0}' nrsaved=$(ls $TEMPDIR/level?.crt 2>/dev/null | wc -w | sed 's/^ *//') outln " # of certificates provided $nrsaved" cd $savedir @@ -1945,10 +1946,11 @@ display_tls_serverhello() { tls_hello_protocol2="${tls_hello_ascii:18:4}" tls_hello_time="${tls_hello_ascii:22:8}" TLS_TIME=$(printf "%d\n" 0x$tls_hello_time) - case $SYSTEM in - *BSD|Darwin) tls_time=$(date -j -f %s "$TLS_TIME" "+%Y-%m-%d %r") ;; - *) tls_time=$(date --date="@$TLS_TIME" "+%Y-%m-%d %r") ;; - esac + if [[ $(date --help 2> /dev/null ) ]]; then + tls_time=$(date --date="@$TLS_TIME" "+%Y-%m-%d %r") + else + tls_time=$(date -j -f %s "$TLS_TIME" "+%Y-%m-%d %r") + fi tls_sid_len=$(printf "%d\n" 0x${tls_hello_ascii:86:2}) let sid_offset=88+$tls_sid_len*2 tls_cipher_suite="${tls_hello_ascii:$sid_offset:4}"