mirror of
https://github.com/mozilla/cipherscan.git
synced 2024-11-26 07:53:41 +01:00
replace if [ ... ] with if [[ ... ]]
Bash implements a backwards-compatible sh syntax for [ .. ], which handles undef variables poorly. Use [[ .. ]] instead, to take full advantage of the Bash improvements to the comparison brackets.
This commit is contained in:
parent
5f43f911bd
commit
6efb1a4afb
150
cipherscan
150
cipherscan
@ -14,12 +14,12 @@ REALPATH=$(dirname $0)
|
|||||||
# make sure this doesn't error out when readlink -f isn't available (OSX)
|
# make sure this doesn't error out when readlink -f isn't available (OSX)
|
||||||
readlink -f $0 &>/dev/null && REALPATH=$(dirname $(readlink -f $0))
|
readlink -f $0 &>/dev/null && REALPATH=$(dirname $(readlink -f $0))
|
||||||
OPENSSLBIN="${REALPATH}/openssl"
|
OPENSSLBIN="${REALPATH}/openssl"
|
||||||
if [ "$(uname -s)" == "Darwin" ]; then
|
if [[ "$(uname -s)" == "Darwin" ]]; then
|
||||||
OPENSSLBIN="${REALPATH}/openssl-darwin64"
|
OPENSSLBIN="${REALPATH}/openssl-darwin64"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# cipherscan requires bash4, which doesn't come by default in OSX
|
# cipherscan requires bash4, which doesn't come by default in OSX
|
||||||
if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
|
if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then
|
||||||
echo "Bash version 4 is required to run cipherscan."
|
echo "Bash version 4 is required to run cipherscan."
|
||||||
echo "Please upgrade your version of bash (ex: brew install bash)."
|
echo "Please upgrade your version of bash (ex: brew install bash)."
|
||||||
exit 1
|
exit 1
|
||||||
@ -28,9 +28,9 @@ fi
|
|||||||
# test that timeout or gtimeout (darwin) are present
|
# test that timeout or gtimeout (darwin) are present
|
||||||
TIMEOUTBIN="$(which timeout)"
|
TIMEOUTBIN="$(which timeout)"
|
||||||
|
|
||||||
if [ "$TIMEOUTBIN" == "" ]; then
|
if [[ "$TIMEOUTBIN" == "" ]]; then
|
||||||
TIMEOUTBIN="$(which gtimeout)"
|
TIMEOUTBIN="$(which gtimeout)"
|
||||||
if [ "$TIMEOUTBIN" == "" ]; then
|
if [[ "$TIMEOUTBIN" == "" ]]; then
|
||||||
echo "neither timeout nor gtimeout are present. install coreutils with {apt-get,yum,brew} install coreutils"
|
echo "neither timeout nor gtimeout are present. install coreutils with {apt-get,yum,brew} install coreutils"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -48,15 +48,15 @@ if [[ -e $(dirname $0)/openssl.cnf ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# find a list of trusted CAs on the local system, or use the provided list
|
# find a list of trusted CAs on the local system, or use the provided list
|
||||||
if [ -z "$CACERTS" ]; then
|
if [[ -z "$CACERTS" ]]; then
|
||||||
for f in /etc/pki/tls/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt; do
|
for f in /etc/pki/tls/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt; do
|
||||||
if [ -e "$f" ]; then
|
if [[ -e "$f" ]]; then
|
||||||
CACERTS="$f"
|
CACERTS="$f"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if [ ! -e "$CACERTS" ]; then
|
if [[ ! -e "$CACERTS" ]]; then
|
||||||
CACERTS="$(dirname $0)/ca-bundle.crt"
|
CACERTS="$(dirname $0)/ca-bundle.crt"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -192,13 +192,13 @@ EXAMPLES: $0 -starttls xmpp jabber.ccc.de:5222
|
|||||||
}
|
}
|
||||||
|
|
||||||
verbose() {
|
verbose() {
|
||||||
if [ $VERBOSE != 0 ]; then
|
if [[ $VERBOSE != 0 ]]; then
|
||||||
echo "$@" >&2
|
echo "$@" >&2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(){
|
debug(){
|
||||||
if [ $DEBUG == 1 ]; then
|
if [[ $DEBUG == 1 ]]; then
|
||||||
echo Debug: "$@" >&2
|
echo Debug: "$@" >&2
|
||||||
set -evx
|
set -evx
|
||||||
fi
|
fi
|
||||||
@ -416,7 +416,7 @@ test_cipher_on_target() {
|
|||||||
# sslv2 client hello doesn't support SNI extension
|
# sslv2 client hello doesn't support SNI extension
|
||||||
# in SSLv3 mode OpenSSL just ignores the setting so it's ok
|
# in SSLv3 mode OpenSSL just ignores the setting so it's ok
|
||||||
# -status exception is ignored in SSLv2, go figure
|
# -status exception is ignored in SSLv2, go figure
|
||||||
if [ "$tls_version" == "-ssl2" ]; then
|
if [[ "$tls_version" == "-ssl2" ]]; then
|
||||||
if [[ "$sslcommand" =~ (.*)(-servername\ [^ ]*)(.*) ]]; then
|
if [[ "$sslcommand" =~ (.*)(-servername\ [^ ]*)(.*) ]]; then
|
||||||
cmnd="${BASH_REMATCH[1]} ${BASH_REMATCH[3]}"
|
cmnd="${BASH_REMATCH[1]} ${BASH_REMATCH[3]}"
|
||||||
else
|
else
|
||||||
@ -447,7 +447,7 @@ test_cipher_on_target() {
|
|||||||
# compare the values not just checksums so that eventual collision
|
# compare the values not just checksums so that eventual collision
|
||||||
# doesn't mess up results
|
# doesn't mess up results
|
||||||
if [[ ${known_certs[$cksum]} == $cert ]]; then
|
if [[ ${known_certs[$cksum]} == $cert ]]; then
|
||||||
if [ -n "${current_certificates}" ]; then
|
if [[ -n "${current_certificates}" ]]; then
|
||||||
current_certificates+=","
|
current_certificates+=","
|
||||||
fi
|
fi
|
||||||
current_certificates+="\"${cert_checksums[$cksum]}\""
|
current_certificates+="\"${cert_checksums[$cksum]}\""
|
||||||
@ -498,7 +498,7 @@ test_cipher_on_target() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# save the sha sum for reporting
|
# save the sha sum for reporting
|
||||||
if [ -n "${current_certificates}" ]; then
|
if [[ -n "${current_certificates}" ]]; then
|
||||||
current_certificates+=","
|
current_certificates+=","
|
||||||
fi
|
fi
|
||||||
current_certificates+="\"${sha256sum}\""
|
current_certificates+="\"${sha256sum}\""
|
||||||
@ -515,20 +515,20 @@ test_cipher_on_target() {
|
|||||||
verbose "connection successful; protocol: $current_protocol, cipher: $current_cipher, previous cipher: $previous_cipher"
|
verbose "connection successful; protocol: $current_protocol, cipher: $current_cipher, previous cipher: $previous_cipher"
|
||||||
fi
|
fi
|
||||||
# handling of TLSv1.2 only cipher suites
|
# handling of TLSv1.2 only cipher suites
|
||||||
if [ ! -z "$previous_cipher" ] && [ "$previous_cipher" != "$current_cipher" ] && [ "$current_cipher" != "0000" ]; then
|
if [[ ! -z "$previous_cipher" ]] && [[ "$previous_cipher" != "$current_cipher" ]] && [[ "$current_cipher" != "0000" ]]; then
|
||||||
unset protocols
|
unset protocols
|
||||||
fi
|
fi
|
||||||
previous_cipher=$current_cipher
|
previous_cipher=$current_cipher
|
||||||
|
|
||||||
# connection succeeded, add TLS version to positive results
|
# connection succeeded, add TLS version to positive results
|
||||||
if [ -z "$protocols" ]; then
|
if [[ -z "$protocols" ]]; then
|
||||||
protocols=$current_protocol
|
protocols=$current_protocol
|
||||||
else
|
else
|
||||||
protocols="$protocols,$current_protocol"
|
protocols="$protocols,$current_protocol"
|
||||||
fi
|
fi
|
||||||
cipher=$current_cipher
|
cipher=$current_cipher
|
||||||
pfs=$current_pfs
|
pfs=$current_pfs
|
||||||
[ -z $pfs ] && pfs="None"
|
[[ -z $pfs ]] && pfs="None"
|
||||||
pubkey=$current_pubkey
|
pubkey=$current_pubkey
|
||||||
sigalg=$current_sigalg
|
sigalg=$current_sigalg
|
||||||
trusted=$current_trusted
|
trusted=$current_trusted
|
||||||
@ -539,13 +539,13 @@ test_cipher_on_target() {
|
|||||||
done
|
done
|
||||||
# if cipher is empty, that means none of the TLS version worked with
|
# if cipher is empty, that means none of the TLS version worked with
|
||||||
# the current cipher
|
# the current cipher
|
||||||
if [ -z "$cipher" ]; then
|
if [[ -z "$cipher" ]]; then
|
||||||
verbose "handshake failed, no ciphersuite was returned"
|
verbose "handshake failed, no ciphersuite was returned"
|
||||||
result='ConnectionFailure'
|
result='ConnectionFailure'
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
# if cipher contains NONE, the cipher wasn't accepted
|
# if cipher contains NONE, the cipher wasn't accepted
|
||||||
elif [ "$cipher" == '(NONE) ' ]; then
|
elif [[ "$cipher" == '(NONE) ' ]]; then
|
||||||
result="$cipher $protocols $pubkey $sigalg $trusted $tickethint $ocspstaple $pfs $current_curves $curves_ordering"
|
result="$cipher $protocols $pubkey $sigalg $trusted $tickethint $ocspstaple $pfs $current_curves $curves_ordering"
|
||||||
verbose "handshake failed, server returned ciphersuite '$result'"
|
verbose "handshake failed, server returned ciphersuite '$result'"
|
||||||
return 1
|
return 1
|
||||||
@ -556,9 +556,9 @@ test_cipher_on_target() {
|
|||||||
# if pfs uses ECDH, test supported curves
|
# if pfs uses ECDH, test supported curves
|
||||||
if [[ $pfs =~ ECDH ]]; then
|
if [[ $pfs =~ ECDH ]]; then
|
||||||
has_curves="True"
|
has_curves="True"
|
||||||
if [ $TEST_CURVES == "True" ]; then
|
if [[ $TEST_CURVES == "True" ]]; then
|
||||||
test_curves
|
test_curves
|
||||||
if [ "$ecc_ciphers" != "" ]; then
|
if [[ "$ecc_ciphers" != "" ]]; then
|
||||||
ecc_ciphers+=":"
|
ecc_ciphers+=":"
|
||||||
fi
|
fi
|
||||||
ecc_ciphers+="$cipher"
|
ecc_ciphers+="$cipher"
|
||||||
@ -582,7 +582,7 @@ bench_cipher() {
|
|||||||
for i in $(seq 1 $BENCHMARKITER); do
|
for i in $(seq 1 $BENCHMARKITER); do
|
||||||
debug Connection $i
|
debug Connection $i
|
||||||
(echo "Q" | $sslcommand 2>/dev/null 1>/dev/null)
|
(echo "Q" | $sslcommand 2>/dev/null 1>/dev/null)
|
||||||
if [ $? -gt 0 ]; then
|
if [[ $? -gt 0 ]]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -596,13 +596,13 @@ bench_cipher() {
|
|||||||
# Connect to the target and retrieve the chosen cipher
|
# Connect to the target and retrieve the chosen cipher
|
||||||
# recursively until the connection fails
|
# recursively until the connection fails
|
||||||
get_cipher_pref() {
|
get_cipher_pref() {
|
||||||
[ "$OUTPUTFORMAT" == "terminal" ] && [ $DEBUG -lt 1 ] && echo -n '.'
|
[[ "$OUTPUTFORMAT" == "terminal" ]] && [[ $DEBUG -lt 1 ]] && echo -n '.'
|
||||||
local ciphersuite="$1"
|
local ciphersuite="$1"
|
||||||
|
|
||||||
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
||||||
if [ -n "$CAPATH" ]; then
|
if [[ -n "$CAPATH" ]]; then
|
||||||
sslcommand+=" -CApath $CAPATH -showcerts"
|
sslcommand+=" -CApath $CAPATH -showcerts"
|
||||||
elif [ -e $CACERTS ]; then
|
elif [[ -e $CACERTS ]]; then
|
||||||
sslcommand+=" -CAfile $CACERTS"
|
sslcommand+=" -CAfile $CACERTS"
|
||||||
fi
|
fi
|
||||||
sslcommand+=" -status $SCLIENTARGS -connect $TARGET -cipher $ciphersuite"
|
sslcommand+=" -status $SCLIENTARGS -connect $TARGET -cipher $ciphersuite"
|
||||||
@ -611,7 +611,7 @@ get_cipher_pref() {
|
|||||||
test_cipher_on_target "$sslcommand"
|
test_cipher_on_target "$sslcommand"
|
||||||
local success=$?
|
local success=$?
|
||||||
# If the connection succeeded with the current cipher, benchmark and store
|
# If the connection succeeded with the current cipher, benchmark and store
|
||||||
if [ $success -eq 0 ]; then
|
if [[ $success -eq 0 ]]; then
|
||||||
cipherspref=("${cipherspref[@]}" "$result")
|
cipherspref=("${cipherspref[@]}" "$result")
|
||||||
ciphercertificates=("${ciphercertificates[@]}" "$certificates")
|
ciphercertificates=("${ciphercertificates[@]}" "$certificates")
|
||||||
pciph=($result)
|
pciph=($result)
|
||||||
@ -634,14 +634,14 @@ display_results_in_terminal() {
|
|||||||
for cipher in "${cipherspref[@]}"; do
|
for cipher in "${cipherspref[@]}"; do
|
||||||
# get first in array
|
# get first in array
|
||||||
pciph=($cipher)
|
pciph=($cipher)
|
||||||
if [ $DOBENCHMARK -eq 1 ]; then
|
if [[ $DOBENCHMARK -eq 1 ]]; then
|
||||||
bench_cipher "$pciph"
|
bench_cipher "$pciph"
|
||||||
r="$ctr $cipher $cipherbenchms"
|
r="$ctr $cipher $cipherbenchms"
|
||||||
else
|
else
|
||||||
r="$ctr $cipher"
|
r="$ctr $cipher"
|
||||||
fi
|
fi
|
||||||
local cipher_data=($cipher)
|
local cipher_data=($cipher)
|
||||||
if [ $ctr -eq 1 ]; then
|
if [[ $ctr -eq 1 ]]; then
|
||||||
pubkey="${cipher_data[2]}"
|
pubkey="${cipher_data[2]}"
|
||||||
sigalg="${cipher_data[3]}"
|
sigalg="${cipher_data[3]}"
|
||||||
trusted="${cipher_data[4]}"
|
trusted="${cipher_data[4]}"
|
||||||
@ -651,19 +651,19 @@ display_results_in_terminal() {
|
|||||||
curvesordering="${cipher_data[9]}"
|
curvesordering="${cipher_data[9]}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ "$pubkey" != "${cipher_data[2]}" ]; then
|
if [[ "$pubkey" != "${cipher_data[2]}" ]]; then
|
||||||
different=True
|
different=True
|
||||||
fi
|
fi
|
||||||
if [ "$sigalg" != "${cipher_data[3]}" ]; then
|
if [[ "$sigalg" != "${cipher_data[3]}" ]]; then
|
||||||
different=True
|
different=True
|
||||||
fi
|
fi
|
||||||
if [ "$trusted" != "${cipher_data[4]}" ]; then
|
if [[ "$trusted" != "${cipher_data[4]}" ]]; then
|
||||||
different=True
|
different=True
|
||||||
fi
|
fi
|
||||||
if [ "$tickethint" != "${cipher_data[5]}" ]; then
|
if [[ "$tickethint" != "${cipher_data[5]}" ]]; then
|
||||||
different=True
|
different=True
|
||||||
fi
|
fi
|
||||||
if [ "$ocspstaple" != "${cipher_data[6]}" ]; then
|
if [[ "$ocspstaple" != "${cipher_data[6]}" ]]; then
|
||||||
different=True
|
different=True
|
||||||
fi
|
fi
|
||||||
if [[ "$curvesordering" == "" && "${cipher_data[9]}" != "" ]]; then
|
if [[ "$curvesordering" == "" && "${cipher_data[9]}" != "" ]]; then
|
||||||
@ -678,26 +678,26 @@ display_results_in_terminal() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
header="prio ciphersuite protocols"
|
header="prio ciphersuite protocols"
|
||||||
if [ $different == "True" ]; then
|
if [[ $different == "True" ]]; then
|
||||||
header+=" pubkey_size signature_algoritm trusted ticket_hint ocsp_staple"
|
header+=" pubkey_size signature_algoritm trusted ticket_hint ocsp_staple"
|
||||||
fi
|
fi
|
||||||
header+=" pfs"
|
header+=" pfs"
|
||||||
if [ $has_curves == "True" ]; then
|
if [[ $has_curves == "True" ]]; then
|
||||||
header+=" curves"
|
header+=" curves"
|
||||||
if [[ $TEST_CURVES == "True" && $different == "True" ]]; then
|
if [[ $TEST_CURVES == "True" && $different == "True" ]]; then
|
||||||
header+=" curves_ordering"
|
header+=" curves_ordering"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ $DOBENCHMARK -eq 1 ]; then
|
if [[ $DOBENCHMARK -eq 1 ]]; then
|
||||||
header+=" avg_handshake_microsec"
|
header+=" avg_handshake_microsec"
|
||||||
fi
|
fi
|
||||||
ctr=0
|
ctr=0
|
||||||
for result in "${results[@]}"; do
|
for result in "${results[@]}"; do
|
||||||
if [ $ctr -eq 0 ]; then
|
if [[ $ctr -eq 0 ]]; then
|
||||||
echo $header
|
echo $header
|
||||||
ctr=$((ctr+1))
|
ctr=$((ctr+1))
|
||||||
fi
|
fi
|
||||||
if [ $different == "True" ]; then
|
if [[ $different == "True" ]]; then
|
||||||
echo $result|grep -v '(NONE)'
|
echo $result|grep -v '(NONE)'
|
||||||
else
|
else
|
||||||
# prints priority, ciphersuite, protocols and pfs
|
# prints priority, ciphersuite, protocols and pfs
|
||||||
@ -705,8 +705,8 @@ display_results_in_terminal() {
|
|||||||
fi
|
fi
|
||||||
done|column -t
|
done|column -t
|
||||||
echo
|
echo
|
||||||
if [ $different != "True" ]; then
|
if [[ $different != "True" ]]; then
|
||||||
if [ "$trusted" == "True" ]; then
|
if [[ "$trusted" == "True" ]]; then
|
||||||
echo "Certificate: trusted, $pubkey bit, $sigalg signature"
|
echo "Certificate: trusted, $pubkey bit, $sigalg signature"
|
||||||
else
|
else
|
||||||
echo "Certificate: UNTRUSTED, $pubkey bit, $sigalg signature"
|
echo "Certificate: UNTRUSTED, $pubkey bit, $sigalg signature"
|
||||||
@ -723,7 +723,7 @@ display_results_in_terminal() {
|
|||||||
else
|
else
|
||||||
echo "Cipher ordering: client"
|
echo "Cipher ordering: client"
|
||||||
fi
|
fi
|
||||||
if [ $TEST_CURVES == "True" ]; then
|
if [[ $TEST_CURVES == "True" ]]; then
|
||||||
echo "Curves ordering: $curvesordering"
|
echo "Curves ordering: $curvesordering"
|
||||||
echo "Curves fallback: $fallback_supported"
|
echo "Curves fallback: $fallback_supported"
|
||||||
fi
|
fi
|
||||||
@ -746,7 +746,7 @@ display_results_in_json() {
|
|||||||
echo -n "{\"target\":\"$TARGET\",\"utctimestamp\":\"$(date -u '+%FT%T.0Z')\",\"serverside\":\"${serverside}\",\"ciphersuite\": ["
|
echo -n "{\"target\":\"$TARGET\",\"utctimestamp\":\"$(date -u '+%FT%T.0Z')\",\"serverside\":\"${serverside}\",\"ciphersuite\": ["
|
||||||
for cipher in "${cipherspref[@]}"; do
|
for cipher in "${cipherspref[@]}"; do
|
||||||
local cipher_arr=($cipher)
|
local cipher_arr=($cipher)
|
||||||
[ $ctr -gt 0 ] && echo -n ','
|
[[ $ctr -gt 0 ]] && echo -n ','
|
||||||
echo -n "{\"cipher\":\"${cipher_arr[0]}\","
|
echo -n "{\"cipher\":\"${cipher_arr[0]}\","
|
||||||
echo -n "\"protocols\":[\"${cipher_arr[1]//,/\",\"}\"],"
|
echo -n "\"protocols\":[\"${cipher_arr[1]//,/\",\"}\"],"
|
||||||
echo -n "\"pubkey\":[\"${cipher_arr[2]//,/\",\"}\"],"
|
echo -n "\"pubkey\":[\"${cipher_arr[2]//,/\",\"}\"],"
|
||||||
@ -758,12 +758,12 @@ display_results_in_json() {
|
|||||||
echo -n "\"ticket_hint\":\"${cipher_arr[5]}\","
|
echo -n "\"ticket_hint\":\"${cipher_arr[5]}\","
|
||||||
echo -n "\"ocsp_stapling\":\"${cipher_arr[6]}\","
|
echo -n "\"ocsp_stapling\":\"${cipher_arr[6]}\","
|
||||||
pfs="${cipher_arr[7]}"
|
pfs="${cipher_arr[7]}"
|
||||||
[ "$pfs" == "" ] && pfs="None"
|
[[ "$pfs" == "" ]] && pfs="None"
|
||||||
echo -n "\"pfs\":\"$pfs\""
|
echo -n "\"pfs\":\"$pfs\""
|
||||||
if [[ "${cipher_arr[0]}" =~ ECDH ]]; then
|
if [[ "${cipher_arr[0]}" =~ ECDH ]]; then
|
||||||
echo -n ","
|
echo -n ","
|
||||||
echo -n "\"curves\":[\"${cipher_arr[8]//,/\",\"}\"]"
|
echo -n "\"curves\":[\"${cipher_arr[8]//,/\",\"}\"]"
|
||||||
if [ $TEST_CURVES == "True" ]; then
|
if [[ $TEST_CURVES == "True" ]]; then
|
||||||
echo -n ","
|
echo -n ","
|
||||||
echo -n "\"curves_ordering\":\"${cipher_arr[9]}\""
|
echo -n "\"curves_ordering\":\"${cipher_arr[9]}\""
|
||||||
fi
|
fi
|
||||||
@ -772,14 +772,14 @@ display_results_in_json() {
|
|||||||
ctr=$((ctr+1))
|
ctr=$((ctr+1))
|
||||||
done
|
done
|
||||||
echo -n ']'
|
echo -n ']'
|
||||||
if [ $TEST_CURVES == "True" ]; then
|
if [[ $TEST_CURVES == "True" ]]; then
|
||||||
echo -n ",\"curves_fallback\":\"$fallback_supported\""
|
echo -n ",\"curves_fallback\":\"$fallback_supported\""
|
||||||
fi
|
fi
|
||||||
echo -n ',"configs":{'
|
echo -n ',"configs":{'
|
||||||
ctr=0
|
ctr=0
|
||||||
for test_name in "${!tls_tolerance[@]}"; do
|
for test_name in "${!tls_tolerance[@]}"; do
|
||||||
local result=(${tls_tolerance[$test_name]})
|
local result=(${tls_tolerance[$test_name]})
|
||||||
[ $ctr -gt 0 ] && echo -n ","
|
[[ $ctr -gt 0 ]] && echo -n ","
|
||||||
echo -n "\"$test_name\":{"
|
echo -n "\"$test_name\":{"
|
||||||
if [[ ${result[0]} == "False" ]]; then
|
if [[ ${result[0]} == "False" ]]; then
|
||||||
echo -n "\"tolerant\":\"False\""
|
echo -n "\"tolerant\":\"False\""
|
||||||
@ -826,15 +826,15 @@ test_serverside_ordering() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
||||||
if [ -n "$CAPATH" ]; then
|
if [[ -n "$CAPATH" ]]; then
|
||||||
sslcommand+=" -CApath $CAPATH -showcerts"
|
sslcommand+=" -CApath $CAPATH -showcerts"
|
||||||
elif [ -e "$CACERTS" ]; then
|
elif [[ -e "$CACERTS" ]]; then
|
||||||
sslcommand+=" -CAfile $CACERTS"
|
sslcommand+=" -CAfile $CACERTS"
|
||||||
fi
|
fi
|
||||||
sslcommand+=" -status $SCLIENTARGS -connect $TARGET -cipher $ciphersuite"
|
sslcommand+=" -status $SCLIENTARGS -connect $TARGET -cipher $ciphersuite"
|
||||||
|
|
||||||
test_cipher_on_target "$sslcommand"
|
test_cipher_on_target "$sslcommand"
|
||||||
if [ $? -ne 0 ]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
serverside="True"
|
serverside="True"
|
||||||
else
|
else
|
||||||
local selected=($result)
|
local selected=($result)
|
||||||
@ -866,9 +866,9 @@ test_curves() {
|
|||||||
# prepare the ssl command we'll be using
|
# prepare the ssl command we'll be using
|
||||||
local sslcommand=""
|
local sslcommand=""
|
||||||
sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
||||||
if [ -n "$CAPATH" ]; then
|
if [[ -n "$CAPATH" ]]; then
|
||||||
sslcommand+=" -CApath $CAPATH -showcerts"
|
sslcommand+=" -CApath $CAPATH -showcerts"
|
||||||
elif [ -e "$CACERTS" ]; then
|
elif [[ -e "$CACERTS" ]]; then
|
||||||
sslcommand+=" -CAfile $CACERTS"
|
sslcommand+=" -CAfile $CACERTS"
|
||||||
fi
|
fi
|
||||||
sslcommand+=" -status $SCLIENTARGS -connect $TARGET -cipher $current_cipher"
|
sslcommand+=" -status $SCLIENTARGS -connect $TARGET -cipher $current_cipher"
|
||||||
@ -900,7 +900,7 @@ test_curves() {
|
|||||||
local ephem_data=(${current_pfs//,/ })
|
local ephem_data=(${current_pfs//,/ })
|
||||||
local cname=""
|
local cname=""
|
||||||
if [[ ${ephem_data[0]} =~ ECDH ]]; then
|
if [[ ${ephem_data[0]} =~ ECDH ]]; then
|
||||||
if [ "$current_curves" != "" ]; then
|
if [[ "$current_curves" != "" ]]; then
|
||||||
current_curves+=","
|
current_curves+=","
|
||||||
fi
|
fi
|
||||||
cname="$(get_curve_name ${ephem_data[1]})"
|
cname="$(get_curve_name ${ephem_data[1]})"
|
||||||
@ -908,14 +908,14 @@ test_curves() {
|
|||||||
current_curves+="$cname"
|
current_curves+="$cname"
|
||||||
fi
|
fi
|
||||||
for id in "${!curves[@]}"; do
|
for id in "${!curves[@]}"; do
|
||||||
if [ "$cname" == ${curves[$id]} ]; then
|
if [[ "$cname" == ${curves[$id]} ]]; then
|
||||||
# we know it's supported, remove it from set of offered ones
|
# we know it's supported, remove it from set of offered ones
|
||||||
unset curves[$id]
|
unset curves[$id]
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
[ "$OUTPUTFORMAT" == "terminal" ] && [ $DEBUG -lt 1 ] && echo -n '.'
|
[[ "$OUTPUTFORMAT" == "terminal" ]] && [[ $DEBUG -lt 1 ]] && echo -n '.'
|
||||||
done
|
done
|
||||||
|
|
||||||
# don't penalize servers that will negotiate all curves we know of...
|
# don't penalize servers that will negotiate all curves we know of...
|
||||||
@ -932,7 +932,7 @@ test_curves() {
|
|||||||
|
|
||||||
# server supports just one or none, so it effectively uses server side
|
# server supports just one or none, so it effectively uses server side
|
||||||
# ordering (as it dictates what curves client must support)
|
# ordering (as it dictates what curves client must support)
|
||||||
if [ ${#tmp_curves[@]} -lt 2 ]; then
|
if [[ ${#tmp_curves[@]} -lt 2 ]]; then
|
||||||
curves_ordering="server"
|
curves_ordering="server"
|
||||||
else
|
else
|
||||||
# server supports at least 2 curves, rotate their order, see if
|
# server supports at least 2 curves, rotate their order, see if
|
||||||
@ -961,7 +961,7 @@ test_curves() {
|
|||||||
verbose "Server did select ${ephem_data[1]} curve"
|
verbose "Server did select ${ephem_data[1]} curve"
|
||||||
curves_ordering="inconclusive-${ephem_data[1]}"
|
curves_ordering="inconclusive-${ephem_data[1]}"
|
||||||
local cname="$(get_curve_name ${ephem_data[1]})"
|
local cname="$(get_curve_name ${ephem_data[1]})"
|
||||||
if [ "$cname" == "$most_wanted" ]; then
|
if [[ "$cname" == "$most_wanted" ]]; then
|
||||||
curves_ordering="client"
|
curves_ordering="client"
|
||||||
else
|
else
|
||||||
curves_ordering="server"
|
curves_ordering="server"
|
||||||
@ -981,7 +981,7 @@ test_curves_fallback() {
|
|||||||
# client doesn't advertise support for curves the server needs
|
# client doesn't advertise support for curves the server needs
|
||||||
fallback_supported="unknown"
|
fallback_supported="unknown"
|
||||||
|
|
||||||
if [ "$ecc_ciphers" == "" ]; then
|
if [[ "$ecc_ciphers" == "" ]]; then
|
||||||
verbose "No ECC cipher found, can't test curve fallback"
|
verbose "No ECC cipher found, can't test curve fallback"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -989,9 +989,9 @@ test_curves_fallback() {
|
|||||||
# prepare the ssl command we'll be using
|
# prepare the ssl command we'll be using
|
||||||
local sslcommand=""
|
local sslcommand=""
|
||||||
sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
||||||
if [ -n "$CAPATH" ]; then
|
if [[ -n "$CAPATH" ]]; then
|
||||||
sslcommand+=" -CApath $CAPATH -showcerts"
|
sslcommand+=" -CApath $CAPATH -showcerts"
|
||||||
elif [ -e "$CACERTS" ]; then
|
elif [[ -e "$CACERTS" ]]; then
|
||||||
sslcommand+=" -CAfile $CACERTS"
|
sslcommand+=" -CAfile $CACERTS"
|
||||||
fi
|
fi
|
||||||
sslcommand+=" -status $SCLIENTARGS -connect $TARGET -cipher $ecc_ciphers"
|
sslcommand+=" -status $SCLIENTARGS -connect $TARGET -cipher $ecc_ciphers"
|
||||||
@ -1030,7 +1030,7 @@ test_curves_fallback() {
|
|||||||
local cname="$(get_curve_name ${ephem_data[1]})"
|
local cname="$(get_curve_name ${ephem_data[1]})"
|
||||||
verbose "Server selected curve $cname"
|
verbose "Server selected curve $cname"
|
||||||
for id in "${!curves[@]}"; do
|
for id in "${!curves[@]}"; do
|
||||||
if [ "${curves[id]}" == "$cname" ]; then
|
if [[ "${curves[id]}" == "$cname" ]]; then
|
||||||
unset curves[$id]
|
unset curves[$id]
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@ -1083,9 +1083,9 @@ test_tls_tolerance() {
|
|||||||
# cipher string and no options are specified)
|
# cipher string and no options are specified)
|
||||||
#
|
#
|
||||||
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
||||||
if [ -n "$CAPATH" ]; then
|
if [[ -n "$CAPATH" ]]; then
|
||||||
sslcommand+=" -CApath $CAPATH -showcerts"
|
sslcommand+=" -CApath $CAPATH -showcerts"
|
||||||
elif [ -e "$CACERTS" ]; then
|
elif [[ -e "$CACERTS" ]]; then
|
||||||
sslcommand+=" -CAfile $CACERTS"
|
sslcommand+=" -CAfile $CACERTS"
|
||||||
fi
|
fi
|
||||||
sslcommand+=" -connect $TARGET -cipher $CIPHERSUITE"
|
sslcommand+=" -connect $TARGET -cipher $CIPHERSUITE"
|
||||||
@ -1111,9 +1111,9 @@ test_tls_tolerance() {
|
|||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
|
|
||||||
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
||||||
if [ -n "$CAPATH" ]; then
|
if [[ -n "$CAPATH" ]]; then
|
||||||
sslcommand+=" -CApath $CAPATH -showcerts"
|
sslcommand+=" -CApath $CAPATH -showcerts"
|
||||||
elif [ -e "$CACERTS" ]; then
|
elif [[ -e "$CACERTS" ]]; then
|
||||||
sslcommand+=" -CAfile $CACERTS"
|
sslcommand+=" -CAfile $CACERTS"
|
||||||
fi
|
fi
|
||||||
sslcommand+=" -connect $TARGET -cipher $ciphers"
|
sslcommand+=" -connect $TARGET -cipher $ciphers"
|
||||||
@ -1185,9 +1185,9 @@ test_tls_tolerance() {
|
|||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
|
|
||||||
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
|
||||||
if [ -n "$CAPATH" ]; then
|
if [[ -n "$CAPATH" ]]; then
|
||||||
sslcommand+=" -CApath $CAPATH -showcerts"
|
sslcommand+=" -CApath $CAPATH -showcerts"
|
||||||
elif [ -e "$CACERTS" ]; then
|
elif [[ -e "$CACERTS" ]]; then
|
||||||
sslcommand+=" -CAfile $CACERTS"
|
sslcommand+=" -CAfile $CACERTS"
|
||||||
fi
|
fi
|
||||||
sslcommand+=" $SCLIENTARGS -connect $TARGET -cipher $ciphers:!SSLv2"
|
sslcommand+=" $SCLIENTARGS -connect $TARGET -cipher $ciphers:!SSLv2"
|
||||||
@ -1269,7 +1269,7 @@ test_tls_tolerance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# If no options are given, give usage information and exit (with error code)
|
# If no options are given, give usage information and exit (with error code)
|
||||||
if [ $# -eq 0 ]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
usage;
|
usage;
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -1353,7 +1353,7 @@ HOST=$(sed -e 's/:.*//'<<<"${TEMPTARGET}")
|
|||||||
PORT=$(sed -e 's/.*://'<<<"${TEMPTARGET}")
|
PORT=$(sed -e 's/.*://'<<<"${TEMPTARGET}")
|
||||||
|
|
||||||
# Default to https if no port given
|
# Default to https if no port given
|
||||||
if [ "$HOST" = "$PORT" ]; then
|
if [[ "$HOST" = "$PORT" ]]; then
|
||||||
PORT=443
|
PORT=443
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -1364,22 +1364,22 @@ TARGET=$HOST:$PORT
|
|||||||
debug "target: $TARGET"
|
debug "target: $TARGET"
|
||||||
|
|
||||||
# test our openssl is usable
|
# test our openssl is usable
|
||||||
if [ ! -x $OPENSSLBIN ]; then
|
if [[ ! -x $OPENSSLBIN ]]; then
|
||||||
OPENSSLBIN=$(which openssl)
|
OPENSSLBIN=$(which openssl)
|
||||||
if [ "$OUTPUTFORMAT" == "terminal" ]; then
|
if [[ "$OUTPUTFORMAT" == "terminal" ]]; then
|
||||||
echo "custom openssl not executable, falling back to system one from $OPENSSLBIN"
|
echo "custom openssl not executable, falling back to system one from $OPENSSLBIN"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $TEST_CURVES == "True" ]; then
|
if [[ $TEST_CURVES == "True" ]]; then
|
||||||
if [ ! -z "$($OPENSSLBIN s_client -curves 2>&1|head -1|grep 'unknown option')" ]; then
|
if [[ ! -z "$($OPENSSLBIN s_client -curves 2>&1|head -1|grep 'unknown option')" ]]; then
|
||||||
echo "curves testing not available with your version of openssl, disabling it"
|
echo "curves testing not available with your version of openssl, disabling it"
|
||||||
TEST_CURVES="False"
|
TEST_CURVES="False"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $VERBOSE != 0 ] ; then
|
if [[ $VERBOSE != 0 ]] ; then
|
||||||
[ -n "$CACERTS" ] && echo "Using trust anchors from $CACERTS"
|
[[ -n "$CACERTS" ]] && echo "Using trust anchors from $CACERTS"
|
||||||
echo "Loading $($OPENSSLBIN ciphers -v $CIPHERSUITE 2>/dev/null|grep Kx|wc -l) ciphersuites from $(echo -n $($OPENSSLBIN version 2>/dev/null))"
|
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
|
$OPENSSLBIN ciphers ALL 2>/dev/null
|
||||||
fi
|
fi
|
||||||
@ -1419,7 +1419,7 @@ if [[ $TEST_CURVES == "True" ]]; then
|
|||||||
test_curves_fallback
|
test_curves_fallback
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$OUTPUTFORMAT" == "json" ]; then
|
if [[ "$OUTPUTFORMAT" == "json" ]]; then
|
||||||
display_results_in_json
|
display_results_in_json
|
||||||
else
|
else
|
||||||
echo
|
echo
|
||||||
@ -1427,13 +1427,13 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# If asked, test every single cipher individually
|
# If asked, test every single cipher individually
|
||||||
if [ $ALLCIPHERS -gt 0 ]; then
|
if [[ $ALLCIPHERS -gt 0 ]]; then
|
||||||
echo; echo "All accepted ciphersuites"
|
echo; echo "All accepted ciphersuites"
|
||||||
for c in $($OPENSSLBIN ciphers -v ALL:COMPLEMENTOFALL 2>/dev/null |awk '{print $1}'|sort|uniq); do
|
for c in $($OPENSSLBIN ciphers -v ALL:COMPLEMENTOFALL 2>/dev/null |awk '{print $1}'|sort|uniq); do
|
||||||
r="fail"
|
r="fail"
|
||||||
osslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client $SCLIENTARGS -connect $TARGET -cipher $c"
|
osslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client $SCLIENTARGS -connect $TARGET -cipher $c"
|
||||||
test_cipher_on_target "$osslcommand"
|
test_cipher_on_target "$osslcommand"
|
||||||
if [ $? -eq 0 ]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
r="pass"
|
r="pass"
|
||||||
fi
|
fi
|
||||||
echo "$c $r"|awk '{printf "%-35s %s\n",$1,$2}'
|
echo "$c $r"|awk '{printf "%-35s %s\n",$1,$2}'
|
||||||
|
Loading…
Reference in New Issue
Block a user