Test code for a HTTP GET request over sockets

It doesn't run per default and it doens't work yet. Just to share the idea.
This commit is contained in:
Dirk Wetter 2019-01-26 14:18:04 +01:00
parent 7de93e26dc
commit e02b313394
1 changed files with 33 additions and 23 deletions

View File

@ -1968,29 +1968,39 @@ run_http_header() {
fi fi
[[ -z "$1" ]] && url="/" || url="$1" [[ -z "$1" ]] && url="/" || url="$1"
printf "$GET_REQ11" | $OPENSSL s_client $(s_client_options "$OPTIMAL_PROTO $BUGS -quiet -ign_eof -connect $NODEIP:$PORT $PROXY $SNI") >$HEADERFILE 2>$ERRFILE & if [[ "$SOCKETHEADER" == true ]]; then
wait_kill $! $HEADER_MAXSLEEP # This is just for testing only. It doesn't work (yet)
if [[ $? -eq 0 ]]; then tls_sockets "03" "$TLS12_CIPHER" "" "" "" false
# Issue HTTP GET again as it properly finished within $HEADER_MAXSLEEP and didn't hang. debugme echo "--> $?"
# Doing it again in the foreground to get an accurate header time printf -- "%b" "$GET_REQ11" >&5 # This GET request is not being logged on the server side --> probably we're still on the TLS layer
printf "$GET_REQ11" | $OPENSSL s_client $(s_client_options "$OPTIMAL_PROTO $BUGS -quiet -ign_eof -connect $NODEIP:$PORT $PROXY $SNI") >$HEADERFILE 2>$ERRFILE cat <&5 >$HEADERFILE
NOW_TIME=$(date "+%s") debugme xxd "$HEADERFILE" # 1503 -> TLS alert
HTTP_TIME=$(awk -F': ' '/^date:/ { print $2 } /^Date:/ { print $2 }' $HEADERFILE) close_socket
HAD_SLEPT=0
else else
# 1st GET request hung and needed to be killed. Check whether it succeeded anyway: printf "$GET_REQ11" | $OPENSSL s_client $(s_client_options "$OPTIMAL_PROTO $BUGS -quiet -ign_eof -connect $NODEIP:$PORT $PROXY $SNI") >$HEADERFILE 2>$ERRFILE &
if grep -Eiaq "XML|HTML|DOCTYPE|HTTP|Connection" $HEADERFILE; then wait_kill $! $HEADER_MAXSLEEP
# correct by seconds we slept, HAD_SLEPT comes from wait_kill() if [[ $? -eq 0 ]]; then
NOW_TIME=$(($(date "+%s") - HAD_SLEPT)) # Issue HTTP GET again as it properly finished within $HEADER_MAXSLEEP and didn't hang.
# Doing it again in the foreground to get an accurate header time
printf "$GET_REQ11" | $OPENSSL s_client $(s_client_options "$OPTIMAL_PROTO $BUGS -quiet -ign_eof -connect $NODEIP:$PORT $PROXY $SNI") >$HEADERFILE 2>$ERRFILE
NOW_TIME=$(date "+%s")
HTTP_TIME=$(awk -F': ' '/^date:/ { print $2 } /^Date:/ { print $2 }' $HEADERFILE) HTTP_TIME=$(awk -F': ' '/^date:/ { print $2 } /^Date:/ { print $2 }' $HEADERFILE)
HAD_SLEPT=0
else else
prln_warning " likely HTTP header requests failed (#lines: $(wc -l $HEADERFILE | awk '{ print $1 }'))" # 1st GET request hung and needed to be killed. Check whether it succeeded anyway:
[[ "$DEBUG" -lt 1 ]] & outln "Rerun with DEBUG>=1 and inspect $HEADERFILE\n" if grep -Eiaq "XML|HTML|DOCTYPE|HTTP|Connection" $HEADERFILE; then
fileout "HTTP_status_code" "WARN" "HTTP header request failed" # correct by seconds we slept, HAD_SLEPT comes from wait_kill()
debugme cat $HEADERFILE NOW_TIME=$(($(date "+%s") - HAD_SLEPT))
((NR_HEADER_FAIL++)) HTTP_TIME=$(awk -F': ' '/^date:/ { print $2 } /^Date:/ { print $2 }' $HEADERFILE)
connectivity_problem $NR_HEADER_FAIL $MAX_HEADER_FAIL "HTTP header connect problem" "repeated HTTP header connect problems, doesn't make sense to continue" else
return 1 prln_warning " likely HTTP header requests failed (#lines: $(wc -l $HEADERFILE | awk '{ print $1 }'))"
[[ "$DEBUG" -lt 1 ]] & outln "Rerun with DEBUG>=1 and inspect $HEADERFILE\n"
fileout "HTTP_status_code" "WARN" "HTTP header request failed"
debugme cat $HEADERFILE
((NR_HEADER_FAIL++))
connectivity_problem $NR_HEADER_FAIL $MAX_HEADER_FAIL "HTTP header connect problem" "repeated HTTP header connect problems, doesn't make sense to continue"
return 1
fi
fi fi
fi fi
if [[ ! -s $HEADERFILE ]]; then if [[ ! -s $HEADERFILE ]]; then
@ -12596,13 +12606,13 @@ tls_sockets() {
local -i hello_done=0 local -i hello_done=0
local cipher="" key_and_iv="" decrypted_response local cipher="" key_and_iv="" decrypted_response
[[ "$5" == "true" ]] && offer_compression=true [[ "$5" == true ]] && offer_compression=true
[[ "$6" == "false" ]] && close_connection=false [[ "$6" == false ]] && close_connection=false
tls_low_byte="$1" tls_low_byte="$1"
if [[ -n "$2" ]]; then # use supplied string in arg2 if there is one if [[ -n "$2" ]]; then # use supplied string in arg2 if there is one
cipher_list_2send="$2" cipher_list_2send="$2"
else # otherwise use std ciphers then else # otherwise use std ciphers then
if [[ "$tls_low_byte" == "03" ]]; then if [[ "$tls_low_byte" == 03 ]]; then
cipher_list_2send="$TLS12_CIPHER" cipher_list_2send="$TLS12_CIPHER"
else else
cipher_list_2send="$TLS_CIPHER" cipher_list_2send="$TLS_CIPHER"