Skip to content

Commit 9e09d2c

Browse files
authored
Merge pull request #2863 from testssl/reliability_quic
More reliability for QUIC test
2 parents 31804ac + 0225bc3 commit 9e09d2c

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

testssl.sh

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -877,14 +877,20 @@ strip_spaces() {
877877
echo "${1// /}"
878878
}
879879

880-
# https://web.archive.org/web/20121022051228/http://codesnippets.joyent.com/posts/show/1816
881880
strip_leading_space() {
881+
# https://web.archive.org/web/20121022051228/http://codesnippets.joyent.com/posts/show/1816
882882
printf "%s" "${1#"${1%%[![:space:]]*}"}"
883883
}
884+
884885
strip_trailing_space() {
885886
printf "%s" "${1%"${1##*[![:space:]]}"}"
886887
}
887888

889+
filter_printable() {
890+
# redir of stderr as Mac's sed might throw an error
891+
sed -i 's/[^[:print:]]//g' $1 2>/dev/null
892+
}
893+
888894
is_number() {
889895
[[ "$1" =~ ^[1-9][0-9]*$ ]] && \
890896
return 0 || \
@@ -904,8 +910,8 @@ strip_quote() (
904910
)"
905911
)
906912

907-
# Converts a string containing PEM encoded data to one line.
908913
pem_to_one_line() {
914+
# Converts a string containing PEM encoded data to one line.
909915
local pem="$1"
910916
local header="" footer=""
911917

@@ -2570,18 +2576,21 @@ connectivity_problem() {
25702576
fi
25712577
}
25722578

2579+
25732580
sanitze_http_header() {
2574-
# sed implementations tested were sometime not fine with header containing x0d x0a (CRLF) which is the usual
2575-
# case. Also we use tr here to remove any crtl chars which the server side offers --> possible security problem
2576-
# Only allowed now is LF + CR. See #2337. awk, see above, doesn't seem to care -- but not under MacOS.
2577-
sed -e '/^$/q' -e '/^[^a-zA-Z_0-9]$/q' $HEADERFILE | tr -d '\000-\011\013\014\016-\037' >$HEADERFILE.tmp
2578-
# Now to be more sure we delete from '<' or '{' maybe with a leading blank until the end
2579-
sed -e '/^ *<.*$/d' -e '/^ *{.*$/d' $HEADERFILE.tmp >$HEADERFILE
2580-
debugme echo -e "---\n $(< $HEADERFILE) \n---"
2581+
# some sed implementations were sometime not fine with HTTP headers containing x0d x0a (CRLF: usual case)
2582+
# Also we use tr here to remove any crtl chars which the server side offers --> possible security problem.
2583+
# Only allowed now is LF + CR. See #2337. awk, see above, doesn't seem to care -- not under MacOS.
2584+
2585+
sed -e '/^$/q' -e '/^[^a-zA-Z_0-9]$/q' $1 | tr -d '\000-\011\013\014\016-\037' >$1.tmp
2586+
# Now to be more sure we delete from '<' or '{' maybe with a leading blank until the end (HTTP body)
2587+
sed -e '/^ *<.*$/d' -e '/^ *{.*$/d' $1.tmp >$1
2588+
debugme echo -e "---\n $(< $1) \n---"
25812589
}
25822590

25832591

2584-
#problems not handled: chunked
2592+
# problems not handled: chunked
2593+
#
25852594
run_http_header() {
25862595
local header
25872596
local referer useragent
@@ -2611,9 +2620,9 @@ run_http_header() {
26112620
tm_out "$GET_REQ11" | $OPENSSL s_client $(s_client_options "$OPTIMAL_PROTO $BUGS -quiet -ign_eof -connect $NODEIP:$PORT $PROXY $SNI") >$HEADERFILE 2>$ERRFILE
26122621
NOW_TIME=$(date "+%s")
26132622
HAD_SLEPT=0
2614-
sanitze_http_header
2623+
sanitze_http_header $HEADERFILE
26152624
else
2616-
sanitze_http_header
2625+
sanitze_http_header $HEADERFILE
26172626
# 1st GET request hung and needed to be killed. Check whether it succeeded anyway:
26182627
if grep -Eiaq "XML|HTML|DOCTYPE|HTTP|Connection" $HEADERFILE; then
26192628
# correct by seconds we slept, HAD_SLEPT comes from wait_kill()
@@ -6216,6 +6225,7 @@ sub_quic() {
62166225
local alpn=""
62176226
local use_openssl=""
62186227
local proxy_hint_str=""
6228+
local ret=""
62196229
local sclient_outfile="$TEMPDIR/$NODEIP.quic_connect.txt"
62206230
local sclient_errfile="$TEMPDIR/$NODEIP.quic_connect_err.txt"
62216231
local jsonID="QUIC"
@@ -6226,7 +6236,7 @@ sub_quic() {
62266236
pr_bold " QUIC ";
62276237

62286238
if "$HAS2_QUIC" || "$HAS_QUIC"; then
6229-
# Proxying QUIC is not supported
6239+
# Proxying QUIC seems not supported
62306240
# The s_client call would block if either the remote side doesn't support QUIC or outbound traffic is blocked
62316241
if "$HAS2_QUIC"; then
62326242
use_openssl="$OPENSSL2"
@@ -6236,18 +6246,30 @@ sub_quic() {
62366246
OPENSSL_CONF='' $use_openssl s_client -quic -alpn h3 -connect $NODEIP:$PORT -servername $NODE </dev/null \
62376247
2>$sclient_errfile >$sclient_outfile &
62386248
wait_kill $! $QUIC_WAIT
6239-
if [[ $? -ne 0 ]]; then
6249+
ret=$?
6250+
if [[ $ret -eq 3 ]]; then
6251+
# process was killed
62406252
if [[ -n "$PROXY" ]]; then
6241-
proxy_hint_str="(tried directly, is not proxyable): "
6253+
proxy_hint_str="(QUIC is not proxyable, tried directly): "
62426254
fi
62436255
outln "${proxy_hint_str}not offered or timed out"
62446256
fileout "$jsonID" "INFO" "$proxy_hint_str not offered"
62456257
else
6246-
pr_svrty_best "offered (OK)"
6247-
fileout "$jsonID" "OK" "offered"
6248-
alpn="$(awk -F':' '/^ALPN protocol/ { print $2 }' < $sclient_outfile)"
6249-
alpn="$(strip_spaces $alpn)"
6250-
outln ": $(awk '/^Protocol:/ { print $2 }' < $sclient_outfile) ($alpn)"
6258+
# 0 would be process terminated before be killed. Now find out what happened...
6259+
filter_printable $sclient_outfile
6260+
if [[ $(< $sclient_outfile) =~ CERTIFICATE----- ]]; then
6261+
pr_svrty_best "offered (OK)"
6262+
fileout "$jsonID" "OK" "offered"
6263+
alpn="$(awk -F':' '/^ALPN protocol/ { print $2 }' < $sclient_outfile)"
6264+
alpn="$(strip_spaces $alpn)"
6265+
outln ": $(awk '/^Protocol:/ { print $2 }' 2>/dev/null < $sclient_outfile) ($alpn)"
6266+
elif [[ $(< $sclient_outfile) =~ ^CONNECTED\( ]]; then
6267+
outln "not offered (but UDP connection succeeded)"
6268+
fileout "$jsonID" "INFO" "not offered (but UDP connection succeeded)"
6269+
else
6270+
outln "not offered"
6271+
fileout "$jsonID" "INFO" "not offered"
6272+
fi
62516273
fi
62526274
else
62536275
prln_local_problem "No OpenSSL QUIC support"

0 commit comments

Comments
 (0)