From 6a394b6c878e13c8a5e3fb77dd7d4a7bf7a27871 Mon Sep 17 00:00:00 2001 From: Pepi Zawodsky Date: Wed, 9 Apr 2014 20:19:56 +0200 Subject: [PATCH 1/3] Added check for missing OpenSSL arguments as suggested by Markus Manzke. --- cipherscan | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cipherscan b/cipherscan index 4d861aa..375a04a 100755 --- a/cipherscan +++ b/cipherscan @@ -15,6 +15,8 @@ DELAY=0 ALLCIPHERS=0 OUTPUTFORMAT="terminal" +# Error codes +E_MISSING_OPENSSL_PARAMETERS=250 # When we have valid cipherscan options, but are missing any parameters to pass to OpenSSL. usage() { echo -e "usage: $0 [-a|--allciphers] [-b|--benchmark] [-d|--delay seconds] [-D|--debug] [-j|--json] [-v|--verbose] [-o|--openssl file] [openssl s_client args] @@ -253,6 +255,13 @@ if [ $VERBOSE != 0 ] ; then fi # echo paramters left: $@ +# Testing for existence of OpenSSL parameters +if [ -z "$1" ]; then + + usage + exit $E_MISSING_OPENSSL_PARAMETERS +fi + TEMPTARGET=$(sed -e 's/^.* //'<<<"${@}") HOST=$(sed -e 's/:.*//'<<<"${TEMPTARGET}") From 16f4c5db74249c65e680f49a614fa635d6be6860 Mon Sep 17 00:00:00 2001 From: Pepi Zawodsky Date: Wed, 9 Apr 2014 22:30:43 +0200 Subject: [PATCH 2/3] Added some error handling for -o /path/to/openssl and a simple error reporting function. --- cipherscan | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/cipherscan b/cipherscan index 375a04a..8e35b39 100755 --- a/cipherscan +++ b/cipherscan @@ -17,6 +17,25 @@ OUTPUTFORMAT="terminal" # Error codes E_MISSING_OPENSSL_PARAMETERS=250 # When we have valid cipherscan options, but are missing any parameters to pass to OpenSSL. +ERROR_MESSAGE[$E_MISSING_OPENSSL_PARAMETERS]="Missing any OpenSSL parameters" + +E_OPENSSL_NOT_FOUND=249 # Cound't find the specified OpenSSL binary. +ERROR_MESSAGE[$E_OPENSSL_NOT_FOUND]="openssl not found" + +E_OPENSSL_NOT_EXECUTABLE=248 # Specified OpenSSL has been found but is not executable for user. +ERROR_MESSAGE[$E_OPENSSL_NOT_EXECUTABLE]="openssl not executable" + +function error_exit { + local ERRORCODE=$1 + echo verbose=$VERBOSE + echo debug=$DEBUG + if [ $VERBOSE -gt 0 ] || [ $DEBUG -gt 0 ]; then + if [ -n $ERROR_MESSAGE[$ERRORCODE] ]; then + echo "${ERROR_MESSAGE[$ERRORCODE]}" >&2 + fi + fi + exit $ERRORCODE +} usage() { echo -e "usage: $0 [-a|--allciphers] [-b|--benchmark] [-d|--delay seconds] [-D|--debug] [-j|--json] [-v|--verbose] [-o|--openssl file] [openssl s_client args] @@ -249,6 +268,21 @@ do esac done +# Check OpenSSL +if [ ! -x "$OPENSSLBIN" ]; then + # openssl does not exist || is not executable + if [ -a "$OPENSSLBIN" ]; then + # openssl does exist, but is not executable + error_exit $E_OPENSSL_NOT_EXECUTABLE + else + # openssl does not exist + error_exit $E_OPENSSL_NOT_FOUND + fi +# else + # File exists and IS executable +fi + + if [ $VERBOSE != 0 ] ; then echo "Loading $($OPENSSLBIN ciphers -v $CIPHERSUITE 2>/dev/null|grep Kx|wc -l) ciphersuites from $(echo -n $($OPENSSLBIN version 2>/dev/null))" $OPENSSLBIN ciphers ALL 2>/dev/null @@ -259,7 +293,7 @@ fi if [ -z "$1" ]; then usage - exit $E_MISSING_OPENSSL_PARAMETERS + error_exit $E_MISSING_OPENSSL_PARAMETERS fi From d434f68772b8d390a6e719427841d51185a3d770 Mon Sep 17 00:00:00 2001 From: Pepi Zawodsky Date: Tue, 15 Apr 2014 15:22:18 +0200 Subject: [PATCH 3/3] Changed error return codes to be in line with the advanced bash scripting recommendations of 64-113 --- cipherscan | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cipherscan b/cipherscan index 8e35b39..212b425 100755 --- a/cipherscan +++ b/cipherscan @@ -16,13 +16,13 @@ ALLCIPHERS=0 OUTPUTFORMAT="terminal" # Error codes -E_MISSING_OPENSSL_PARAMETERS=250 # When we have valid cipherscan options, but are missing any parameters to pass to OpenSSL. +E_MISSING_OPENSSL_PARAMETERS=113 # When we have valid cipherscan options, but are missing any parameters to pass to OpenSSL. ERROR_MESSAGE[$E_MISSING_OPENSSL_PARAMETERS]="Missing any OpenSSL parameters" -E_OPENSSL_NOT_FOUND=249 # Cound't find the specified OpenSSL binary. +E_OPENSSL_NOT_FOUND=112 # Cound't find the specified OpenSSL binary. ERROR_MESSAGE[$E_OPENSSL_NOT_FOUND]="openssl not found" -E_OPENSSL_NOT_EXECUTABLE=248 # Specified OpenSSL has been found but is not executable for user. +E_OPENSSL_NOT_EXECUTABLE=111 # Specified OpenSSL has been found but is not executable for user. ERROR_MESSAGE[$E_OPENSSL_NOT_EXECUTABLE]="openssl not executable" function error_exit {