==== run-tcp ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 26168 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 24360 Connection to 127.0.0.1 26168 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 26168 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 24360 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 26168 port [tcp/*] succeeded! ==== run-tcp6 ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l ::1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on ::1 43988 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -n -v ::1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on ::1 11938 Connection to ::1 43988 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on ::1 ' server.err Listening on ::1 43988 grep 'Connection received on ::1 ' server.err Connection received on ::1 11938 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 43988 port [tcp/*] succeeded! ==== run-tcp-localhost-server ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -4 -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on localhost 45740 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to 127.0.0.1 45740 port [tcp/*] succeeded! Connection received on localhost 14202 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on localhost ' server.err Listening on localhost 45740 grep 'Connection received on localhost ' server.err Connection received on localhost 14202 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 45740 port [tcp/*] succeeded! ==== run-tcp6-localhost-server ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -6 -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on localhost 5901 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -n -v ::1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to ::1 5901 port [tcp/*] succeeded! Connection received on localhost 24307 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on localhost ' server.err Listening on localhost 5901 grep 'Connection received on localhost ' server.err Connection received on localhost 24307 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 5901 port [tcp/*] succeeded! ==== run-tcp-localhost-client ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 34418 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -4 -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep: client.err: No such file or directory Connection received on 127.0.0.1 45884 grep: client.err: No such file or directory grep: client.err: No such file or directory grep: client.err: No such file or directory grep: client.err: No such file or directory grep: client.err: No such file or directory Connection to localhost (127.0.0.1) 34418 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 34418 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 45884 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 34418 port [tcp/*] succeeded! ==== run-tcp6-localhost-client ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l ::1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on ::1 38728 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -6 -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on ::1 38624 Connection to localhost (::1) 38728 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on ::1 ' server.err Listening on ::1 38728 grep 'Connection received on ::1 ' server.err Connection received on ::1 38624 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (::1) 38728 port [tcp/*] succeeded! ==== run-tcp-bad-localhost-server ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress ! ./netcat-regress -4 -v -l ::1 0 >server.out 2>server.err grep 'non-recoverable failure in name resolution' server.err netcat-regress: getaddrinfo: non-recoverable failure in name resolution ==== run-tcp6-bad-localhost-server ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress ! ./netcat-regress -6 -v -l 127.0.0.0 0 >server.out 2>server.err grep 'no address associated with name' server.err netcat-regress: getaddrinfo: no address associated with name ==== run-tcp-bad-localhost-client ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep: server.err: No such file or directory Listening on 127.0.0.1 15847 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port ! ./netcat-regress -4 -v ::1 `cat server.port` >client.out 2>client.err grep 'non-recoverable failure in name resolution' client.err netcat-regress: getaddrinfo for host "::1" port 15847: non-recoverable failure in name resolution ==== run-tcp6-bad-localhost-client ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & Listening on 127.0.0.1 2419 let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port ! ./netcat-regress -6 -v 127.0.0.1 `cat server.port` >client.out 2>client.err grep 'no address associated with name' client.err netcat-regress: getaddrinfo for host "127.0.0.1" port 2419: no address associated with name ==== run-tcp-sleep ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 27403 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 29421 Connection to 127.0.0.1 27403 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 27403 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 29421 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 27403 port [tcp/*] succeeded! # netcat waits for the other side to terminate, check it is sleeping let timeout=`date +%s`+5; while ps -xww -o comm,stat | grep -q 'netcat-regress .*R'; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done ps -xww -o comm,stat,args | grep '^netcat-regress .*S.* -v -l 127' netcat-regress Sp ./netcat-regress -n -v -l 127.0.0.1 0 ps -xww -o comm,stat,args | grep '^netcat-regress .*S.* -v 127' netcat-regress Sp ./netcat-regress -n -v 127.0.0.1 27403 ==== run-tcp-keep ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -k -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 23759 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 16628 Connection to 127.0.0.1 23759 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 23759 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 16628 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 23759 port [tcp/*] succeeded! # kill client and reconnect with a new one :> server.err pkill -l -f "^./netcat-regress .* 127.0.0.1 `cat server.port`$" 99964 netcat-regress Listening on 127.0.0.1 1485 rm -f client.{out,err} :> server.out # server closes the listen socket and binds a new one with new port let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to 127.0.0.1 1485 port [tcp/*] succeeded! Connection received on 127.0.0.1 4900 # server sends only one greeting, do not wait for a second one let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done ! grep 'greeting' client.out # truncation of log results in NUL bytes, do not match ^ grep 'command$' server.out Binary file server.out matches grep 'Listening on 127.0.0.1 ' server.err Binary file server.err matches grep 'Connection received on 127.0.0.1 ' server.err Binary file server.err matches grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 1485 port [tcp/*] succeeded! ==== run-tls ==== openssl req -batch -new -subj /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1/ -nodes -newkey rsa -keyout 127.0.0.1.key -x509 -out 127.0.0.1.crt Generating a 2048 bit RSA private key ................................................ ...................................... writing new private key to '127.0.0.1.key' ----- pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -c -C 127.0.0.1.crt -K 127.0.0.1.key -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 46235 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R 127.0.0.1.crt -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 36419 Connection to 127.0.0.1 46235 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host 127.0.0.1 Peer name: 127.0.0.1 Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 Issuer: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 Valid From: Fri Nov 15 10:55:42 2024 Valid Until: Sun Dec 15 10:55:42 2024 Cert Hash: SHA256:27f6f06aa389bd93f4118caacbbc10a25f401239c26cb02089963bbba1c04044 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 46235 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 36419 # XXX success message should be issued after TLS handshake grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 46235 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=127.0.0.1' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 grep 'Issuer: .*/OU=server/CN=127.0.0.1' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 ==== run-tls6 ==== openssl req -batch -new -subj /L=OpenBSD/O=netcat-regress/OU=server/CN=::1/ -nodes -newkey rsa -keyout 1.key -x509 -out 1.crt Generating a 2048 bit RSA private key ........................................ ...................................................................................................................... writing new private key to '1.key' ----- pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -c -C 1.crt -K 1.key -n -v -l ::1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on ::1 20770 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R 1.crt -n -v ::1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on ::1 30224 Connection to ::1 20770 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host ::1 Peer name: ::1 Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=::1 Issuer: /L=OpenBSD/O=netcat-regress/OU=server/CN=::1 Valid From: Fri Nov 15 10:55:44 2024 Valid Until: Sun Dec 15 10:55:44 2024 Cert Hash: SHA256:653ff3ed976f187cae618b49c63a4487d2178e391eb26156140e3bbf557003f9 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on ::1 ' server.err Listening on ::1 20770 grep 'Connection received on ::1 ' server.err Connection received on ::1 30224 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 20770 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=::1' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=::1 grep 'Issuer: .*/OU=server/CN=::1' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=server/CN=::1 ==== run-tls-localhost ==== openssl req -batch -new -subj /L=OpenBSD/O=netcat-regress/OU=ca/CN=root/ -nodes -newkey rsa -keyout ca.key -x509 -out ca.crt Generating a 2048 bit RSA private key ................................................. ..... writing new private key to 'ca.key' ----- openssl req -batch -new -subj /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost/ -nodes -newkey rsa -keyout server.key -out server.req Generating a 2048 bit RSA private key ............................................................................ ............................................................................ writing new private key to 'server.key' ----- openssl x509 -CAcreateserial -CAkey ca.key -CA ca.crt -req -in server.req -out server.crt Signature ok subject=/L=OpenBSD/O=netcat-regress/OU=server/CN=localhost pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -c -C server.crt -K server.key -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on localhost 24119 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R ca.crt -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on localhost 19495 Connection to localhost (127.0.0.1) 24119 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:48 2024 Valid Until: Sun Dec 15 10:55:48 2024 Cert Hash: SHA256:1551f859050e7cc766d7991ad64dcd03c63c73bc03cf58f694c5d4d6ee9342c0 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on localhost ' server.err Listening on localhost 24119 grep 'Connection received on localhost ' server.err Connection received on localhost 19495 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 24119 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=localhost' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root ==== run-tls-bad-ca ==== openssl req -batch -new -subj /L=OpenBSD/O=netcat-regress/OU=ca/CN=root/ -nodes -newkey rsa -keyout fake-ca.key -x509 -out fake-ca.crt Generating a 2048 bit RSA private key ............. ..... writing new private key to 'fake-ca.key' ----- pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -c -C server.crt -K server.key -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on localhost 20289 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # the client uses the wrong root ca to verify the server cert ! ./netcat-regress -c -R fake-ca.crt -v localhost `cat server.port` >client.out 2>client.err Connection received on localhost 38045 let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done netcat-regress: tls handshake failed (handshake failed: error:02FFF020:system library:func(4095):Broken pipe) grep 'Listening on localhost ' server.err Listening on localhost 20289 grep 'Connection received on localhost ' server.err Connection received on localhost 38045 grep 'certificate verification failed' client.err netcat-regress: tls handshake failed (certificate verification failed: certificate signature failure) ! grep 'greeting' client.out ! grep 'command' server.out ==== run-tls-name ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -c -C server.crt -K server.key -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 8713 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -e localhost -R ca.crt -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to 127.0.0.1 8713 port [tcp/*] succeeded! Connection received on 127.0.0.1 37871 let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host 127.0.0.1 Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:48 2024 Valid Until: Sun Dec 15 10:55:48 2024 Cert Hash: SHA256:1551f859050e7cc766d7991ad64dcd03c63c73bc03cf58f694c5d4d6ee9342c0 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 8713 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 37871 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 8713 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=localhost' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root ==== run-tls-bad-name ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -c -C server.crt -K server.key -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 47207 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # the common name in server.crt is localhost, not 127.0.0.1 ! ./netcat-regress -c -e 127.0.0.1 -R ca.crt -n -v 127.0.0.1 `cat server.port` >client.out 2>client.err Connection received on 127.0.0.1 33908 let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 47207 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 33908 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 47207 port [tcp/*] succeeded! grep "name \`127.0.0.1\' not present in server certificate" client.err netcat-regress: tls handshake failed (name `127.0.0.1' not present in server certificate) ! grep 'greeting' client.out ! grep 'command' server.out ==== run-tls-hash ==== openssl x509 -in server.crt -outform der | sha256 | sed s/^/SHA256:/ >server.hash pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -c -C server.crt -K server.key -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on localhost 24909 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # check that the server presents certificate with correct hash rm -f client.err; echo command | ./netcat-regress -c -H `cat server.hash` -R ca.crt -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to localhost (127.0.0.1) 24909 port [tcp/*] succeeded! Connection received on localhost 30800 let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:48 2024 Valid Until: Sun Dec 15 10:55:48 2024 Cert Hash: SHA256:1551f859050e7cc766d7991ad64dcd03c63c73bc03cf58f694c5d4d6ee9342c0 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on localhost ' server.err Listening on localhost 24909 grep 'Connection received on localhost ' server.err Connection received on localhost 30800 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 24909 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=localhost' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root grep 'Cert Hash: SHA256:' client.err Cert Hash: SHA256:1551f859050e7cc766d7991ad64dcd03c63c73bc03cf58f694c5d4d6ee9342c0 ==== run-tls-bad-hash ==== openssl x509 -in ca.crt -outform der | sha256 | sed s/^/SHA256:/ >ca.hash pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -c -C server.crt -K server.key -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on localhost 35658 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # server presents certificate with server.hash, ca.hash is wrong ! ./netcat-regress -c -H `cat ca.hash` -R ca.crt -v localhost `cat server.port` >client.out 2>client.err Connection received on localhost 12182 let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep 'Listening on localhost ' server.err Listening on localhost 35658 grep 'Connection received on localhost ' server.err Connection received on localhost 12182 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 35658 port [tcp/*] succeeded! grep 'peer certificate is not SHA256:' client.err netcat-regress: peer certificate is not SHA256:03f1041fa87aa73b7a15e5423ee833a329f51ec2bd7a5925ce24ed6fc68d8cd9 ! grep 'greeting' client.out ! grep 'command' server.out ==== run-tls-client ==== openssl req -batch -new -subj /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost/ -nodes -newkey rsa -keyout client.key -out client.req Generating a 2048 bit RSA private key ..... ...................................... writing new private key to 'client.key' ----- openssl x509 -CAcreateserial -CAkey ca.key -CA ca.crt -req -in client.req -out client.crt Signature ok subject=/L=OpenBSD/O=netcat-regress/OU=client/CN=localhost pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # use client certificate and validate at server rm -f server.err; echo greeting | ./netcat-regress -c -R ca.crt -C server.crt -K server.key -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on localhost 29525 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R ca.crt -C client.crt -K client.key -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to localhost (127.0.0.1) 29525 port [tcp/*] succeeded! Connection received on localhost 34821 let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:53 2024 Valid From: Fri Nov 15 10:55:48 2024 Valid Until: Sun Dec 15 10:55:53 2024 Valid Until: Sun Dec 15 10:55:48 2024 Cert Hash: SHA256:fc44830ceadf7b13f2fb69c1f7f6e52cdfbc413c7ea51336d97a2301197b274f Cert Hash: SHA256:1551f859050e7cc766d7991ad64dcd03c63c73bc03cf58f694c5d4d6ee9342c0 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on localhost ' server.err Listening on localhost 29525 grep 'Connection received on localhost ' server.err Connection received on localhost 34821 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 29525 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=localhost' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root grep 'Subject: .*/OU=client/CN=localhost' server.err Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' server.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root ==== run-tls-bad-client ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # require client certificate at server rm -f server.err; echo greeting | ./netcat-regress -c -T clientcert -R ca.crt -C server.crt -K server.key -v -l localhost 0 2>&1 >server.out | tee server.err & Listening on localhost 21367 let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # client does not provide certificate rm -f client.err; echo command | ./netcat-regress -c -R ca.crt -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep: client.err: No such file or directory Connection received on localhost 6796 Connection to localhost (127.0.0.1) 21367 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done netcat-regress: No client certificate provided TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:48 2024 Valid Until: Sun Dec 15 10:55:48 2024 Cert Hash: SHA256:1551f859050e7cc766d7991ad64dcd03c63c73bc03cf58f694c5d4d6ee9342c0 grep 'Listening on localhost ' server.err Listening on localhost 21367 grep 'Connection received on localhost ' server.err Connection received on localhost 6796 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 21367 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=localhost' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root grep 'No client certificate provided' server.err netcat-regress: No client certificate provided ! grep 'greeting' client.out ! grep 'command' server.out ==== run-tls-client-bad-ca ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # the server uses the wrong root ca to verify the client cert rm -f server.err; echo greeting | ./netcat-regress -c -R fake-ca.crt -C server.crt -K server.key -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on localhost 8731 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port ! ./netcat-regress -c -R ca.crt -C client.crt -K client.key -v localhost `cat server.port` >client.out 2>client.err Connection received on localhost 24847 netcat-regress: tls handshake failed (handshake failed: error:04FFF06A:rsa routines:CRYPTO_internal:block type is not 01) let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done nc localhost `cat server.port` 2>/dev/null || : grep 'Listening on localhost ' server.err Listening on localhost 8731 grep 'Connection received on localhost ' server.err Connection received on localhost 24847 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 8731 port [tcp/*] succeeded! # XXX no specific error message for bogus ca egrep 'CRYPTO_internal:(block type is not 01|data too large for modulus)' server.err netcat-regress: tls handshake failed (handshake failed: error:04FFF06A:rsa routines:CRYPTO_internal:block type is not 01) ! grep 'greeting' client.out ! grep 'command' server.out ==== run-tls-client-name ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # check client certificate name at server rm -f server.err; echo greeting | ./netcat-regress -c -e localhost -R ca.crt -C server.crt -K server.key -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & Listening on 127.0.0.1 26063 let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -4 -c -R ca.crt -C client.crt -K client.key -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 32753 Connection to localhost (127.0.0.1) 26063 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:48 2024 Valid Until: Sun Dec 15 10:55:48 2024 Cert Hash: SHA256:1551f859050e7cc766d7991ad64dcd03c63c73bc03cf58f694c5d4d6ee9342c0 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host 127.0.0.1 Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:53 2024 Valid Until: Sun Dec 15 10:55:53 2024 Cert Hash: SHA256:fc44830ceadf7b13f2fb69c1f7f6e52cdfbc413c7ea51336d97a2301197b274f grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 26063 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 32753 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 26063 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=localhost' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root grep 'Subject: .*/OU=client/CN=localhost' server.err Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' server.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root ==== run-tls-client-bad-name ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # client certificate is for localhost, check with 127.0.0.1 should fail rm -f server.err; echo greeting | ./netcat-regress -c -e 127.0.0.1 -R ca.crt -C server.crt -K server.key -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 25411 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # client does not see any problem, TLS handshake works, wait for exit rm -f client.err; echo command | ./netcat-regress -4 -c -R ca.crt -C client.crt -K client.key -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 44051 Connection to localhost (127.0.0.1) 25411 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host 127.0.0.1 Peer name: 127.0.0.1 Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:53 2024 Valid Until: Sun Dec 15 10:55:53 2024 Cert Hash: SHA256:fc44830ceadf7b13f2fb69c1f7f6e52cdfbc413c7ea51336d97a2301197b274f netcat-regress: name (127.0.0.1) not found in client certTLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:48 2024 Valid Until: Sun Dec 15 10:55:48 2024 Cert Hash: SHA256:1551f859050e7cc766d7991ad64dcd03c63c73bc03cf58f694c5d4d6ee9342c0 grep 'Listening on 127.0.0.1 ' server.err netcat-regress: tls read failed (read failed: error:02FFF036:system library:func(4095):Connection reset by peer) Listening on 127.0.0.1 25411 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 44051 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 25411 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=localhost' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root grep 'Subject: .*/OU=client/CN=localhost' server.err Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' server.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root grep 'name (127.0.0.1) not found in client cert' server.err netcat-regress: name (127.0.0.1) not found in client cert ! grep 'greeting' client.out ! grep 'command' server.out ==== run-tls-client-hash ==== openssl x509 -in client.crt -outform der | sha256 | sed s/^/SHA256:/ >client.hash pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # check client certificate hash at server rm -f server.err; echo greeting | ./netcat-regress -c -H `cat client.hash` -R ca.crt -C server.crt -K server.key -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on localhost 13888 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R ca.crt -C client.crt -K client.key -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on localhost 27771 Connection to localhost (127.0.0.1) 13888 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:53 2024 Valid Until: Sun Dec 15 10:55:53 2024 Cert Hash: SHA256:fc44830ceadf7b13f2fb69c1f7f6e52cdfbc413c7ea51336d97a2301197b274f TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:48 2024 Valid Until: Sun Dec 15 10:55:48 2024 Cert Hash: SHA256:1551f859050e7cc766d7991ad64dcd03c63c73bc03cf58f694c5d4d6ee9342c0 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on localhost ' server.err Listening on localhost 13888 grep 'Connection received on localhost ' server.err Connection received on localhost 27771 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 13888 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=localhost' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root grep 'Subject: .*/OU=client/CN=localhost' server.err Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' server.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root ==== run-tls-client-bad-hash ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # client presents certificate with client.hash, ca.hash is wrong rm -f server.err; echo greeting | ./netcat-regress -c -H `cat ca.hash` -R ca.crt -C server.crt -K server.key -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep: server.err: No such file or directory grep: server.err: No such file or directory Listening on localhost 38682 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # client does not see any problem, TLS handshake works, wait for exit rm -f client.err; echo command | ./netcat-regress -c -R ca.crt -C client.crt -K client.key -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on localhost 9139 Connection to localhost (127.0.0.1) 38682 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:48 2024 Valid Until: Sun Dec 15 10:55:48 2024 Cert Hash: SHA256:1551f859050e7cc766d7991ad64dcd03c63c73bc03cf58f694c5d4d6ee9342c0 nc localhost `cat server.port` 2>/dev/null || : TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:53 2024 Valid Until: Sun Dec 15 10:55:53 2024 Cert Hash: SHA256:fc44830ceadf7b13f2fb69c1f7f6e52cdfbc413c7ea51336d97a2301197b274f netcat-regress: peer certificate is not SHA256:03f1041fa87aa73b7a15e5423ee833a329f51ec2bd7a5925ce24ed6fc68d8cd9 grep 'Listening on localhost ' server.err Listening on localhost 38682 grep 'Connection received on localhost ' server.err Connection received on localhost 9139 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 38682 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=localhost' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root grep 'Subject: .*/OU=client/CN=localhost' server.err Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' server.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root grep 'peer certificate is not SHA256:' server.err netcat-regress: peer certificate is not SHA256:03f1041fa87aa73b7a15e5423ee833a329f51ec2bd7a5925ce24ed6fc68d8cd9 ! grep 'greeting' client.out ! grep 'command' server.out ==== run-tls-client-no-hash ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # check client certificate hash at server if available rm -f server.err; echo greeting | ./netcat-regress -c -H `cat client.hash` -R ca.crt -C server.crt -K server.key -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on localhost 1875 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # client provides no certificate rm -f client.err; echo command | ./netcat-regress -c -R ca.crt -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to localhost (127.0.0.1) 1875 port [tcp/*] succeeded! Connection received on localhost 16127 let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Fri Nov 15 10:55:48 2024 Valid Until: Sun Dec 15 10:55:48 2024 Cert Hash: SHA256:1551f859050e7cc766d7991ad64dcd03c63c73bc03cf58f694c5d4d6ee9342c0 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done # client certificate and hash is optional, transfer is successful grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on localhost ' server.err Listening on localhost 1875 grep 'Connection received on localhost ' server.err Connection received on localhost 16127 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 1875 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=localhost' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root # non existing hash is not checked ! grep 'Cert Hash: SHA256:' server.err ==== run-tls-sleep ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -c -C 127.0.0.1.crt -K 127.0.0.1.key -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 22385 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R 127.0.0.1.crt -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to 127.0.0.1 22385 port [tcp/*] succeeded! Connection received on 127.0.0.1 45109 let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host 127.0.0.1 Peer name: 127.0.0.1 Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 Issuer: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 Valid From: Fri Nov 15 10:55:42 2024 Valid Until: Sun Dec 15 10:55:42 2024 Cert Hash: SHA256:27f6f06aa389bd93f4118caacbbc10a25f401239c26cb02089963bbba1c04044 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 22385 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 45109 # XXX success message should be issued after TLS handshake grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 22385 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=127.0.0.1' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 grep 'Issuer: .*/OU=server/CN=127.0.0.1' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 # netcat waits for the other side to terminate, check it is sleeping let timeout=`date +%s`+5; while ps -xww -o comm,stat | grep -q 'netcat-regress .*R'; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done ps -xww -o comm,stat,args | grep '^netcat-regress .*S.* -v -l 127' netcat-regress Sp ./netcat-regress -c -C 127.0.0.1.crt -K 127.0.0.1.key -n -v -l 127.0.0.1 0 ps -xww -o comm,stat,args | grep '^netcat-regress .*S.* -v 127' netcat-regress Sp ./netcat-regress -c -R 127.0.0.1.crt -n -v 127.0.0.1 22385 ==== run-tls-keep ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -k -c -C 127.0.0.1.crt -K 127.0.0.1.key -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 30716 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R 127.0.0.1.crt -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 15099 Connection to 127.0.0.1 30716 port [tcp/*] succeeded! let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host 127.0.0.1 Peer name: 127.0.0.1 Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 Issuer: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 Valid From: Fri Nov 15 10:55:42 2024 Valid Until: Sun Dec 15 10:55:42 2024 Cert Hash: SHA256:27f6f06aa389bd93f4118caacbbc10a25f401239c26cb02089963bbba1c04044 let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 30716 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 15099 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 30716 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=127.0.0.1' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 grep 'Issuer: .*/OU=server/CN=127.0.0.1' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 # kill client and reconnect with a new one :> server.err pkill -l -f "^./netcat-regress .* 127.0.0.1 `cat server.port`$" 32171 netcat-regress rm -f client.{out,err} Listening on 127.0.0.1 15416 :> server.out # server closes the listen socket and binds a new one with new port let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R 127.0.0.1.crt -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to 127.0.0.1 15416 port [tcp/*] succeeded! Connection received on 127.0.0.1 41857 let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host 127.0.0.1 Peer name: 127.0.0.1 Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 Issuer: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 Valid From: Fri Nov 15 10:55:42 2024 Valid Until: Sun Dec 15 10:55:42 2024 Cert Hash: SHA256:27f6f06aa389bd93f4118caacbbc10a25f401239c26cb02089963bbba1c04044 # server sends only one greeting, do not wait for a second one let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done ! grep 'greeting' client.out # truncation of log results in NUL bytes, do not match ^ grep 'command$' server.out Binary file server.out matches grep 'Listening on 127.0.0.1 ' server.err Binary file server.err matches grep 'Connection received on 127.0.0.1 ' server.err Binary file server.err matches grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 15416 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=127.0.0.1' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 grep 'Issuer: .*/OU=server/CN=127.0.0.1' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 ==== run-udp ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -u -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on 127.0.0.1 47214 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # the -v option would cause udptest() to write additional X rm -f client.err; echo command | ./netcat-regress -u -n 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 23165 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on 127.0.0.1 ' server.err Bound on 127.0.0.1 47214 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 23165 ==== run-udp6 ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -u -n -v -l ::1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on ::1 27476 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # the -v option would cause udptest() to write additional X rm -f client.err; echo command | ./netcat-regress -u -n ::1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on ::1 10329 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on ::1 ' server.err Bound on ::1 27476 grep 'Connection received on ::1 ' server.err Connection received on ::1 10329 ==== run-udp-probe ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -u -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep: server.err: No such file or directory Bound on 127.0.0.1 45585 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -u -v -n 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 2790 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on 127.0.0.1 ' server.err Bound on 127.0.0.1 45585 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 2790 ==== run-udp-localhost ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -u -4 -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on localhost 41489 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # the -v option would cause udptest() to write additional X rm -f client.err; echo command | ./netcat-regress -u -4 localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on localhost 39572 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on localhost ' server.err Bound on localhost 41489 grep 'Connection received on localhost ' server.err Connection received on localhost 39572 ==== run-udp6-localhost ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -u -6 -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on localhost 22136 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # the -v option would cause udptest() to write additional X rm -f client.err; echo command | ./netcat-regress -u -6 localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on localhost 42974 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on localhost ' server.err Bound on localhost 22136 grep 'Connection received on localhost ' server.err Connection received on localhost 42974 ==== run-udp-keep ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -k -u -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on 127.0.0.1 14853 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # the -v option causes udptest() to write additional X rm -f client.err; echo command | ./netcat-regress -u -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & # server does not connect, nothing reaches the client let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done ! grep 'greeting' client.out grep '^command$' server.out command grep 'Bound on 127.0.0.1 ' server.err Bound on 127.0.0.1 14853 # client does not connect ! grep 'Connection received on ' server.err # kill client and reconnect with a new one :> server.err pkill -l -f "^./netcat-regress .* 127.0.0.1 `cat server.port`$" 98078 netcat-regress rm -f client.{out,err} :> server.out rm -f client.err; echo command | ./netcat-regress -u -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done ! grep 'greeting' client.out # truncation of log results in NUL bytes, do not match ^ grep 'command$' server.out Binary file server.out matches # server keeps socket and does not bind again ! grep 'Bound on ' server.err # client does not connect ! grep 'Connection received on ' server.err ==== run-udp-sleep ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -u -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on 127.0.0.1 33837 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # the -v option would cause udptest() to write additional X rm -f client.err; echo command | ./netcat-regress -u -n 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 5045 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on 127.0.0.1 ' server.err Bound on 127.0.0.1 33837 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 5045 # netcat waits for the other side to terminate, check it is sleeping let timeout=`date +%s`+5; while ps -xww -o comm,stat | grep -q 'netcat-regress .*R'; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done ps -xww -o comm,stat,args | grep '^netcat-regress .*S.* -v -l 127' netcat-regress Sp ./netcat-regress -u -n -v -l 127.0.0.1 0 ps -xww -o comm,stat,args | grep '^netcat-regress .*S.* -n 127' netcat-regress Sp ./netcat-regress -u -n 127.0.0.1 33837 ==== run-unix ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.sock rm -f server.err; echo greeting | ./netcat-regress -U -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock Listening on server.sock rm -f client.err; echo command | ./netcat-regress -U -n -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on server.sock grep '^greeting$' client.out greeting grep '^command$' server.out command # XXX message Bound and Listening is redundant grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Listening on server.sock$' server.err Listening on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-namelookup ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.sock rm -f server.err; echo greeting | ./netcat-regress -U -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock Listening on server.sock rm -f client.err; echo command | ./netcat-regress -U -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on server.sock grep '^greeting$' client.out greeting grep '^command$' server.out command # XXX message Bound and Listening is redundant grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Listening on server.sock$' server.err Listening on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-probe ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.sock rm -f server.err; echo greeting | ./netcat-regress -U -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock Listening on server.sock # connect and close immediately, check if socket is listening ./netcat-regress -N -U -v server.sock client.out 2>client.err Connection received on server.sock # XXX message Bound and Listening is redundant grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Listening on server.sock$' server.err Listening on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err # server accepts one connection, second connection should be refused ! ./netcat-regress -N -U -v server.sock client.out 2>client.err grep 'server.sock: Connection refused' client.err netcat-regress: server.sock: Connection refused # connection to non existing socket file should fail rm server.sock ! ./netcat-regress -N -U -v server.sock client.out 2>client.err grep 'server.sock: No such file or directory' client.err netcat-regress: server.sock: No such file or directory ==== run-unix-keep ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.sock rm -f server.err; echo greeting | ./netcat-regress -k -U -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock Listening on server.sock rm -f client.err; echo command | ./netcat-regress -U -n -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on server.sock grep '^greeting$' client.out greeting grep '^command$' server.out command # XXX message Bound and Listening is redundant grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Listening on server.sock$' server.err Listening on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err # kill client and reconnect with a new one :> server.err pkill -l -f "^./netcat-regress .* -v server.sock$" 20684 netcat-regress rm -f client.{out,err} :> server.out rm -f client.err; echo command | ./netcat-regress -U -n -v server.sock 2>&1 >client.out | tee client.err & # server sends only one greeting, do not wait for a second one let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on server.sock ! grep 'greeting' client.out # truncation of log results in NUL bytes, do not match ^ grep 'command$' server.out Binary file server.out matches grep 'Connection received on server.sock$' server.err Binary file server.err matches # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-dgram ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f {client,server}.sock rm -f server.err; echo greeting | ./netcat-regress -U -u -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock rm -f client.err; echo command | ./netcat-regress -U -u -n -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on /tmp/nc.fMXQffD0hb Connection received on server.sock let timeout=`date +%s`+5; until grep -q 'Bound on ' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-dgram-namelookup ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f {client,server}.sock rm -f server.err; echo greeting | ./netcat-regress -U -u -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock rm -f client.err; echo command | ./netcat-regress -U -u -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on /tmp/nc.S39LlnjhUL Connection received on server.sock let timeout=`date +%s`+5; until grep -q 'Bound on ' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-dgram-clientsock ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f {client,server}.sock rm -f server.err; echo greeting | ./netcat-regress -U -u -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock rm -f client.err; echo command | ./netcat-regress -U -u -n -v -s client.sock server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on client.sock Connection received on server.sock grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-dgram-keep ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f {client,server}.sock rm -f server.err; echo greeting | ./netcat-regress -k -U -u -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock rm -f client.err; echo command | ./netcat-regress -U -u -n -v server.sock 2>&1 >client.out | tee client.err & # server does not connect, nothing reaches the client let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on /tmp/nc.AFt0TojlN1 let timeout=`date +%s`+5; until grep -q 'Bound on ' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done ! grep 'greeting' client.out grep '^command$' server.out command grep 'Bound on server.sock$' server.err Bound on server.sock # client does not connect ! grep 'Connection received on ' server.err # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err # kill client and reconnect with a new one :> server.err pkill -l -f "^./netcat-regress .* -v server.sock$" 45069 netcat-regress rm -f client.{out,err} :> server.out rm -f client.err; echo command | ./netcat-regress -U -u -n -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on /tmp/nc.a42O4I1hje let timeout=`date +%s`+5; until grep -q 'Bound on ' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done ! grep 'greeting' client.out # truncation of log results in NUL bytes, do not match ^ grep 'command$' server.out Binary file server.out matches # server keeps socket and does not bind again ! grep 'Bound on ' server.err # client does not connect ! grep 'Connection received on ' server.err # XXX message succeeded is missing ! grep 'Connection to 127.0.0.1 .* succeeded!' client.err ==== run-tcp-test ==== cc -O2 -pipe -Wall -Wpointer-arith -Wuninitialized -Wstrict-prototypes -Wmissing-prototypes -Wunused -Wsign-compare -Wshadow -MD -MP -c /home/src/regress/usr.bin/nc/server-tcp.c cc -O2 -pipe -Wall -Wpointer-arith -Wuninitialized -Wstrict-prototypes -Wmissing-prototypes -Wunused -Wsign-compare -Wshadow -MD -MP -c /home/src/regress/usr.bin/nc/util.c cc -o server-tcp server-tcp.o util.o cc -O2 -pipe -Wall -Wpointer-arith -Wuninitialized -Wstrict-prototypes -Wmissing-prototypes -Wunused -Wsign-compare -Wshadow -MD -MP -c /home/src/regress/usr.bin/nc/client-tcp.c cc -o client-tcp client-tcp.o util.o pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # test the test tools ./server-tcp -s greeting -r command 127.0.0.1 0 >server.port sock: 127.0.0.1 18302 ./client-tcp -r greeting -s command 127.0.0.1 `cat server.port` >client.port peer: 127.0.0.1 13936 >>> greeting sock: 127.0.0.1 13936 peer: 127.0.0.1 18302 <<< greeting >>> command <<< command ==== run-tcp-test-shutdown ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # test the test tools ./server-tcp -s greeting -N -r command -E 127.0.0.1 0 >server.port sock: 127.0.0.1 39264 ./client-tcp -r greeting -E -s command -N 127.0.0.1 `cat server.port` >client.port peer: 127.0.0.1 31726 >>> greeting sock: 127.0.0.1 31726 peer: 127.0.0.1 39264 <<< greeting <<< EOF >>> command <<< command <<< EOF ==== run-tcp-server ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 1162 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # test client read from netcat, then send line and exit ./client-tcp -r greeting -s command 127.0.0.1 `cat server.port` >client.port Connection received on 127.0.0.1 15943 sock: 127.0.0.1 15943 peer: 127.0.0.1 1162 <<< greeting >>> command let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 1162 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 15943 ==== run-tcp-server-eof ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 35808 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # test client read from netcat, then send line, shutdown, wait for eof ./client-tcp -r greeting -s command -N -E 127.0.0.1 `cat server.port` >client.port Connection received on 127.0.0.1 36634 sock: 127.0.0.1 36634 peer: 127.0.0.1 35808 <<< greeting >>> command <<< EOF let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 35808 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 36634 ==== run-tcp-server-reverse-eof ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 7123 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # test client send to netcat, shutdown, then read line, wait for eof ./client-tcp -s command -N -r greeting -E 127.0.0.1 `cat server.port` >client.port Connection received on 127.0.0.1 33293 sock: 127.0.0.1 33293 peer: 127.0.0.1 7123 >>> command <<< greeting <<< EOF let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 7123 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 33293 ==== run-tcp-server-shutdown-eof ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # netcat calls shutdown on output after EOF on input rm -f server.err; echo greeting | ./netcat-regress -N -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 49116 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # test client read from netcat, then send line, wait for eof, shutdown ./client-tcp -r greeting -s command -E -N 127.0.0.1 `cat server.port` >client.port Connection received on 127.0.0.1 45917 sock: 127.0.0.1 45917 peer: 127.0.0.1 49116 <<< greeting >>> command <<< EOF let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 49116 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 45917 ==== run-tcp-server-shutdown-reverse-eof ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # netcat calls shutdown on output after EOF on input rm -f server.err; echo greeting | ./netcat-regress -N -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 45498 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # test client send to netcat, shutdown, then read line, wait for eof ./client-tcp -s command -N -r greeting -E 127.0.0.1 `cat server.port` >client.port Connection received on 127.0.0.1 27588 sock: 127.0.0.1 27588 peer: 127.0.0.1 45498 >>> command <<< greeting <<< EOF let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^command$' server.out command grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 45498 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 27588 ==== run-tcp-client ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # test server send to netcat, then read line and exit ./server-tcp -s greeting -r command 127.0.0.1 0 >server.port sock: 127.0.0.1 3483 rm -f client.err; echo command | ./netcat-regress -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to 127.0.0.1 3483 port [tcp/*] succeeded! peer: 127.0.0.1 13892 >>> greeting <<< command let timeout=`date +%s`+5; until grep -q 'greeting' client.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 3483 port [tcp/*] succeeded! ==== run-tcp-client-eof ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # test server send to netcat, shutdown, then read line, wait for eof ./server-tcp -s greeting -N -r command -E 127.0.0.1 0 >server.port sock: 127.0.0.1 8015 rm -f client.err; echo command | ./netcat-regress -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to 127.0.0.1 8015 port [tcp/*] succeeded! peer: 127.0.0.1 12546 >>> greeting <<< command <<< EOF let timeout=`date +%s`+5; until grep -q 'greeting' client.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 8015 port [tcp/*] succeeded! ==== run-tcp-client-reverse-eof ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # test server read from netcat, then read line, wait for eof, shutdown ./server-tcp -r command -s greeting -E -N 127.0.0.1 0 >server.port sock: 127.0.0.1 20826 rm -f client.err; echo command | ./netcat-regress -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done peer: 127.0.0.1 37834 Connection to 127.0.0.1 20826 port [tcp/*] succeeded! <<< command >>> greeting let timeout=`date +%s`+5; until grep -q 'greeting' client.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 20826 port [tcp/*] succeeded! ==== run-tcp-client-shutdown-eof ==== pkill netcat-regress || true <<< EOF rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # test server send to netcat, shutdown, then read line, wait for eof ./server-tcp -s greeting -N -r command -E 127.0.0.1 0 >server.port sock: 127.0.0.1 45264 # netcat calls shutdown on output after EOF on input rm -f client.err; echo command | ./netcat-regress -N -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done peer: 127.0.0.1 29498 Connection to 127.0.0.1 45264 port [tcp/*] succeeded! >>> greeting <<< command <<< EOF let timeout=`date +%s`+5; until grep -q 'greeting' client.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 45264 port [tcp/*] succeeded! ==== run-tcp-client-shutdown-reverse-eof ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # test server read from netcat, wait for eof, then read line, shutdown ./server-tcp -r command -E -s greeting -N 127.0.0.1 0 >server.port sock: 127.0.0.1 25288 # netcat calls shutdown on output after EOF on input rm -f client.err; echo command | ./netcat-regress -N -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done peer: 127.0.0.1 1224 Connection to 127.0.0.1 25288 port [tcp/*] succeeded! <<< command <<< EOF >>> greeting let timeout=`date +%s`+5; until grep -q 'greeting' client.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 25288 port [tcp/*] succeeded! ==== cleanup ==== pkill netcat-regress || true