Replace OLDIFS/IFS joins with join_array_by_char(), avoiding $(...) subshell slowdown.

This commit is contained in:
Richard Soderberg 2015-09-05 02:46:04 -07:00
parent 487f7cb6a4
commit 2764a16693
1 changed files with 27 additions and 29 deletions

View File

@ -173,6 +173,19 @@ FALLBACKCIPHERSUITE=(
'EXP-RC2-CBC-MD5' 'EXP-RC2-CBC-MD5'
'EXP-RC4-MD5' 'EXP-RC4-MD5'
) )
join_array_by_char() {
# Two or less parameters (join + 0 or 1 value), then no need to set IFS because no join occurs.
if (( $# >= 3 )); then
# Three or more parameters (join + 2 values), then we need to set IFS for the join.
local IFS=$1
fi
# Discard the join string (usually ':', could be others).
shift
# Store the joined string in the result.
joined_array="$*"
}
DEBUG=0 DEBUG=0
VERBOSE=0 VERBOSE=0
DELAY=0 DELAY=0
@ -436,10 +449,8 @@ parse_openssl_output() {
local match=($data) local match=($data)
unset match[0] unset match[0]
unset match[1] unset match[1]
local old_IFS="$IFS" join_array_by_char '_' "${match[@]}"
IFS="_" current_sigalg="$joined_array"
current_sigalg="${match[*]}"
IFS="$old_IFS"
fi fi
done <<<"$ossl_out" done <<<"$ossl_out"
fi fi
@ -896,10 +907,8 @@ test_curves() {
local curves=(${CURVES[*]}) local curves=(${CURVES[*]})
OLDIFS="$IFS" join_array_by_char ':' "${curves[@]}"
IFS=':' verbose "Will test following curves: $joined_array"
verbose "Will test following curves: ${curves[*]}"
IFS="$OLDIFS"
# prepare the ssl command we'll be using # prepare the ssl command we'll be using
local sslcommand="" local sslcommand=""
@ -921,10 +930,8 @@ test_curves() {
# tries to negotiate a curve we didn't advertise # tries to negotiate a curve we didn't advertise
# #
while [[ ${#curves[@]} -gt 0 ]]; do while [[ ${#curves[@]} -gt 0 ]]; do
OLDIFS="$IFS" join_array_by_char ':' "${curves[@]}"
IFS=':' local test_curves="$joined_array"
local test_curves="${curves[*]}"
IFS="$OLDIFS"
verbose "Testing $test_curves with command $sslcommand" verbose "Testing $test_curves with command $sslcommand"
ratelimit ratelimit
@ -1043,10 +1050,8 @@ test_curves_fallback() {
# #
local curves=(${CURVES[*]}) local curves=(${CURVES[*]})
while [[ ${#curves[@]} -gt 0 ]]; do while [[ ${#curves[@]} -gt 0 ]]; do
OLDIFS="$IFS" join_array_by_char ':' "${curves[@]}"
IFS=':' local test_curves="$joined_array"
local test_curves="${curves[*]}"
IFS="$OLDIFS"
verbose "Testing $sslcommand -curves $test_curves" verbose "Testing $sslcommand -curves $test_curves"
ratelimit ratelimit
@ -1141,10 +1146,8 @@ test_tls_tolerance() {
# #
# try a smaller, but still v2 compatible Client Hello # try a smaller, but still v2 compatible Client Hello
# #
OLDIFS="$IFS" join_array_by_char ':' "${SHORTCIPHERSUITE[@]}"
IFS=":" local ciphers="$joined_array"
local ciphers="${SHORTCIPHERSUITE[*]}"
IFS="$OLDIFS"
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client" local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
if [[ -n "$CAPATH" ]]; then if [[ -n "$CAPATH" ]]; then
@ -1215,10 +1218,8 @@ test_tls_tolerance() {
# #
# use v3 format TLSv1.2 hello, small cipher list # use v3 format TLSv1.2 hello, small cipher list
# #
OLDIFS="$IFS" join_array_by_char ':' "${SHORTCIPHERSUITE[@]}"
IFS=":" local ciphers="$joined_array"
local ciphers="${SHORTCIPHERSUITE[*]}"
IFS="$OLDIFS"
local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client" local sslcommand="$TIMEOUTBIN $TIMEOUT $OPENSSLBIN s_client"
if [[ -n "$CAPATH" ]]; then if [[ -n "$CAPATH" ]]; then
@ -1480,11 +1481,8 @@ if [[ ${#cipherspref[@]} -eq 0 ]] || [[ ${pref[1]} == "SSLv2" ]]; then
cipherspref=() cipherspref=()
ciphercertificates=() ciphercertificates=()
results=() results=()
OLDIFS="$IFS" join_array_by_char ':' "${FALLBACKCIPHERSUITE[@]}"
IFS=":" get_cipher_pref "$joined_array"
CIPHERS="${FALLBACKCIPHERSUITE[*]}"
IFS="$OLDIFS"
get_cipher_pref "$CIPHERS"
fi fi
test_tls_tolerance test_tls_tolerance