==== 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 grep: server.err: No such file or directory Listening on 127.0.0.1 9783 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 21077 grep: client.err: No such file or directory Connection to 127.0.0.1 9783 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 9783 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 21077 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 9783 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 26475 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 26598 Connection to ::1 26475 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 26475 grep 'Connection received on ::1 ' server.err Connection received on ::1 26598 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 26475 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 8256 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 localhost 41165 Connection to 127.0.0.1 8256 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 localhost ' server.err Listening on localhost 8256 grep 'Connection received on localhost ' server.err Connection received on localhost 41165 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 8256 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 19886 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 19886 port [tcp/*] succeeded! Connection received on localhost 8450 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 19886 grep 'Connection received on localhost ' server.err Connection received on localhost 8450 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 19886 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 31454 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 Connection received on 127.0.0.1 47724 Connection to localhost (127.0.0.1) 31454 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 31454 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 47724 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 31454 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 42022 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 36005 Connection to localhost (::1) 42022 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 42022 grep 'Connection received on ::1 ' server.err Connection received on ::1 36005 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (::1) 42022 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 Listening on 127.0.0.1 32519 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 32519: 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 & 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 42050 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 42050: 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 11672 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 40913 Connection to 127.0.0.1 11672 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 11672 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 40913 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 11672 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 11672 ==== 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 34591 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 36844 Connection to 127.0.0.1 34591 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 34591 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 36844 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 34591 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`$" 1131 netcat-regress Listening on 127.0.0.1 48801 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 received on 127.0.0.1 33559 Connection to 127.0.0.1 48801 port [tcp/*] succeeded! # 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 48801 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 47854 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 47854 port [tcp/*] succeeded! Connection received on 127.0.0.1 6887 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: Thu Nov 14 02:56:23 2024 Valid Until: Sat Dec 14 02:56:23 2024 Cert Hash: SHA256:e1b1d8d1235275a4949f9498b9f1463f7f0970b0972a2fc5fdf3402494de543c 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 47854 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 6887 # 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 47854 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 22484 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 28628 Connection to ::1 22484 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: Thu Nov 14 02:56:25 2024 Valid Until: Sat Dec 14 02:56:25 2024 Cert Hash: SHA256:787acd0f7a97ffeaf7d2ed9af204a37e5accd3b8604ac98d0bfc897f2fafb5bd 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 22484 grep 'Connection received on ::1 ' server.err Connection received on ::1 28628 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 22484 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 43199 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 19360 Connection to localhost (127.0.0.1) 43199 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: Thu Nov 14 02:56:28 2024 Valid Until: Sat Dec 14 02:56:28 2024 Cert Hash: SHA256:c0b8312a50e98e3b48ad3938a54f30b6523e0752da6fbef7bd7b96386429cd01 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 43199 grep 'Connection received on localhost ' server.err Connection received on localhost 19360 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 43199 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 24472 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 39698 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 24472 grep 'Connection received on localhost ' server.err Connection received on localhost 39698 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 7560 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 7560 port [tcp/*] succeeded! Connection received on 127.0.0.1 9531 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: Thu Nov 14 02:56:28 2024 Valid Until: Sat Dec 14 02:56:28 2024 Cert Hash: SHA256:c0b8312a50e98e3b48ad3938a54f30b6523e0752da6fbef7bd7b96386429cd01 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 7560 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 9531 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 7560 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 19476 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 28655 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 read failed (read failed: error:02FFF036:system library:func(4095):Connection reset by peer) grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 19476 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 28655 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 19476 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 25323 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 received on localhost 43794 Connection to localhost (127.0.0.1) 25323 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: Thu Nov 14 02:56:28 2024 Valid Until: Sat Dec 14 02:56:28 2024 Cert Hash: SHA256:c0b8312a50e98e3b48ad3938a54f30b6523e0752da6fbef7bd7b96386429cd01 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 25323 grep 'Connection received on localhost ' server.err Connection received on localhost 43794 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 25323 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:c0b8312a50e98e3b48ad3938a54f30b6523e0752da6fbef7bd7b96386429cd01 ==== 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 29037 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 9547 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 29037 grep 'Connection received on localhost ' server.err Connection received on localhost 9547 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 29037 port [tcp/*] succeeded! grep 'peer certificate is not SHA256:' client.err netcat-regress: peer certificate is not SHA256:88052618ea66b925864ddb9ba1c6643ea318e75b864075248833d2a8af8bb5b7 ! 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 11918 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) 11918 port [tcp/*] succeeded! Connection received on localhost 9444 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: Thu Nov 14 02:56:28 2024 Valid Until: Sat Dec 14 02:56:28 2024 Cert Hash: SHA256:c0b8312a50e98e3b48ad3938a54f30b6523e0752da6fbef7bd7b96386429cd01 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: Thu Nov 14 02:56:35 2024 Valid Until: Sat Dec 14 02:56:35 2024 Cert Hash: SHA256:8f49c353c6a3be500e79315de3360891a4546ff4847530ed614cd146083de13f 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 11918 grep 'Connection received on localhost ' server.err Connection received on localhost 9444 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 11918 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 & 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 2362 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 Connection to localhost (127.0.0.1) 2362 port [tcp/*] succeeded! Connection received on localhost 27282 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: Thu Nov 14 02:56:28 2024 Valid Until: Sat Dec 14 02:56:28 2024 Cert Hash: SHA256:c0b8312a50e98e3b48ad3938a54f30b6523e0752da6fbef7bd7b96386429cd01 netcat-regress: No client certificate provided grep 'Listening on localhost ' server.err Listening on localhost 2362 grep 'Connection received on localhost ' server.err Connection received on localhost 27282 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 2362 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 9743 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 45420 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 9743 grep 'Connection received on localhost ' server.err Connection received on localhost 45420 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 9743 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 & 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 46208 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 to localhost (127.0.0.1) 46208 port [tcp/*] succeeded! Connection received on 127.0.0.1 39859 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: Thu Nov 14 02:56:28 2024 Valid Until: Sat Dec 14 02:56:28 2024 Cert Hash: SHA256:c0b8312a50e98e3b48ad3938a54f30b6523e0752da6fbef7bd7b96386429cd01 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: Thu Nov 14 02:56:35 2024 Valid Until: Sat Dec 14 02:56:35 2024 Cert Hash: SHA256:8f49c353c6a3be500e79315de3360891a4546ff4847530ed614cd146083de13f 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 46208 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 39859 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 46208 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 32697 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 24616 Connection to localhost (127.0.0.1) 32697 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 TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost 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: Thu Nov 14 02:56:35 2024 Valid Until: Sat Dec 14 02:56:35 2024 Cert Hash: SHA256:8f49c353c6a3be500e79315de3360891a4546ff4847530ed614cd146083de13f netcat-regress: name (127.0.0.1) not found in client cert 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: Thu Nov 14 02:56:28 2024 Valid Until: Sat Dec 14 02:56:28 2024 Cert Hash: SHA256:c0b8312a50e98e3b48ad3938a54f30b6523e0752da6fbef7bd7b96386429cd01 grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 32697 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 24616 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 32697 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 44953 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 16377 Connection to localhost (127.0.0.1) 44953 port [tcp/*] succeeded! 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: Thu Nov 14 02:56:28 2024 Valid Until: Sat Dec 14 02:56:28 2024 Cert Hash: SHA256:c0b8312a50e98e3b48ad3938a54f30b6523e0752da6fbef7bd7b96386429cd01 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 let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Valid From: Thu Nov 14 02:56:35 2024 Valid Until: Sat Dec 14 02:56:35 2024 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 Cert Hash: SHA256:8f49c353c6a3be500e79315de3360891a4546ff4847530ed614cd146083de13f grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Listening on localhost ' server.err Listening on localhost 44953 grep 'Connection received on localhost ' server.err Connection received on localhost 16377 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 44953 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 Listening on localhost 10676 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 8976 Connection to localhost (127.0.0.1) 10676 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: Thu Nov 14 02:56:28 2024 Valid Until: Sat Dec 14 02:56:28 2024 Cert Hash: SHA256:c0b8312a50e98e3b48ad3938a54f30b6523e0752da6fbef7bd7b96386429cd01 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: Thu Nov 14 02:56:35 2024 Valid Until: Sat Dec 14 02:56:35 2024 Cert Hash: SHA256:8f49c353c6a3be500e79315de3360891a4546ff4847530ed614cd146083de13f netcat-regress: peer certificate is not SHA256:88052618ea66b925864ddb9ba1c6643ea318e75b864075248833d2a8af8bb5b7 grep 'Listening on localhost ' server.err Listening on localhost 10676 grep 'Connection received on localhost ' server.err Connection received on localhost 8976 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 10676 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:88052618ea66b925864ddb9ba1c6643ea318e75b864075248833d2a8af8bb5b7 ! 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 15067 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 received on localhost 32885 Connection to localhost (127.0.0.1) 15067 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: Thu Nov 14 02:56:28 2024 Valid Until: Sat Dec 14 02:56:28 2024 Cert Hash: SHA256:c0b8312a50e98e3b48ad3938a54f30b6523e0752da6fbef7bd7b96386429cd01 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 15067 grep 'Connection received on localhost ' server.err Connection received on localhost 32885 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 15067 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 34226 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 grep: client.err: No such file or directory Connection received on 127.0.0.1 4068 Connection to 127.0.0.1 34226 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: Thu Nov 14 02:56:23 2024 Valid Until: Sat Dec 14 02:56:23 2024 Cert Hash: SHA256:e1b1d8d1235275a4949f9498b9f1463f7f0970b0972a2fc5fdf3402494de543c 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 34226 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 4068 # 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 34226 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 34226 ==== 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 3805 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 3805 port [tcp/*] succeeded! Connection received on 127.0.0.1 9126 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: Thu Nov 14 02:56:23 2024 Valid Until: Sat Dec 14 02:56:23 2024 Cert Hash: SHA256:e1b1d8d1235275a4949f9498b9f1463f7f0970b0972a2fc5fdf3402494de543c 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 3805 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 9126 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 3805 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`$" Listening on 127.0.0.1 11629 67855 netcat-regress 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 -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 grep: client.err: No such file or directory grep: client.err: No such file or directory Connection received on 127.0.0.1 9308 Connection to 127.0.0.1 11629 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: Thu Nov 14 02:56:23 2024 Valid Until: Sat Dec 14 02:56:23 2024 Cert Hash: SHA256:e1b1d8d1235275a4949f9498b9f1463f7f0970b0972a2fc5fdf3402494de543c # 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 11629 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 grep: server.err: No such file or directory grep: server.err: No such file or directory Bound on 127.0.0.1 48138 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 34428 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 48138 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 34428 ==== 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 1613 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 32844 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on ::1 ' server.err Bound on ::1 1613 grep 'Connection received on ::1 ' server.err Connection received on ::1 32844 ==== 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 Bound on 127.0.0.1 9661 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 19105 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 9661 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 19105 ==== 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 18986 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 15206 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on localhost ' server.err Bound on localhost 18986 grep 'Connection received on localhost ' server.err Connection received on localhost 15206 ==== 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 35528 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 40424 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on localhost ' server.err Bound on localhost 35528 grep 'Connection received on localhost ' server.err Connection received on localhost 40424 ==== 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 18198 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 18198 # 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`$" 86639 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 29582 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 24958 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 29582 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 24958 # 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 29582 ==== 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 & Connection received on server.sock 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 # 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$" 56917 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 & Bound on /tmp/nc.lLUYarsTMG 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 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.Wyzl0FHQiL 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.oLoDtk9yyF 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$" 91974 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.f1WgXKDXSQ 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 38879 ./client-tcp -r greeting -s command 127.0.0.1 `cat server.port` >client.port peer: 127.0.0.1 43538 >>> greeting sock: 127.0.0.1 43538 peer: 127.0.0.1 38879 <<< 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 20816 ./client-tcp -r greeting -E -s command -N 127.0.0.1 `cat server.port` >client.port peer: 127.0.0.1 44707 >>> greeting sock: 127.0.0.1 44707 peer: 127.0.0.1 20816 <<< 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 24812 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 sock: 127.0.0.1 47308 peer: 127.0.0.1 24812 Connection received on 127.0.0.1 47308 <<< 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 24812 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 47308 ==== 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 43890 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 sock: 127.0.0.1 36333 peer: 127.0.0.1 43890 Connection received on 127.0.0.1 36333 <<< 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 43890 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 36333 ==== 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 39793 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 sock: 127.0.0.1 41517 peer: 127.0.0.1 39793 >>> command Connection received on 127.0.0.1 41517 <<< 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 39793 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 41517 ==== 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 26065 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 27310 sock: 127.0.0.1 27310 peer: 127.0.0.1 26065 <<< 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 26065 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 27310 ==== 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 33565 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 33416 sock: 127.0.0.1 33416 peer: 127.0.0.1 33565 >>> 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 33565 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 33416 ==== 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 9708 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 23606 >>> greeting Connection to 127.0.0.1 9708 port [tcp/*] succeeded! <<< 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 9708 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 40830 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 40830 port [tcp/*] succeeded! peer: 127.0.0.1 16013 >>> 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 40830 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 32520 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 48413 Connection to 127.0.0.1 32520 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 32520 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 20582 # 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 Connection to 127.0.0.1 20582 port [tcp/*] succeeded! peer: 127.0.0.1 20667 >>> 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 20582 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 45724 # 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 Connection to 127.0.0.1 45724 port [tcp/*] succeeded! peer: 127.0.0.1 21305 <<< 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 45724 port [tcp/*] succeeded! ==== cleanup ==== pkill netcat-regress || true