==== run-tcp ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 22823 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 10891 Connection to 127.0.0.1 22823 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 22823 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 10891 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 22823 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 11654 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 17367 Connection to ::1 11654 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 11654 grep 'Connection received on ::1 ' server.err Connection received on ::1 17367 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 11654 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 21844 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 36340 Connection to 127.0.0.1 21844 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 21844 grep 'Connection received on localhost ' server.err Connection received on localhost 36340 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 21844 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 23222 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 grep: client.err: No such file or directory Connection received on localhost 42532 Connection to ::1 23222 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 23222 grep 'Connection received on localhost ' server.err Connection received on localhost 42532 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 23222 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 17228 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 26086 Connection to localhost (127.0.0.1) 17228 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 17228 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 26086 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 17228 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 14436 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 17667 Connection to localhost (::1) 14436 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 14436 grep 'Connection received on ::1 ' server.err Connection received on ::1 17667 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (::1) 14436 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 & Listening on 127.0.0.1 43145 let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port ! ./netcat-regress -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 43145: 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 38515 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 38515: 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 21922 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 30791 Connection to 127.0.0.1 21922 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 21922 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 30791 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 21922 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 21922 ==== 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 11444 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 44016 Connection to 127.0.0.1 11444 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 11444 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 44016 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 11444 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`$" 23276 netcat-regress Listening on 127.0.0.1 32147 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 11773 Connection to 127.0.0.1 32147 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 32147 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 38669 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R 127.0.0.1.crt -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 5197 grep: client.err: No such file or directory Connection to 127.0.0.1 38669 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: Sat Nov 16 02:58:56 2024 Valid Until: Mon Dec 16 02:58:56 2024 Cert Hash: SHA256:25def8c77c3538b340cb27c819148daefac9dfd3770b299ee3a540e754ab8dd8 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 38669 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 5197 # 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 38669 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 34080 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 to ::1 34080 port [tcp/*] succeeded! Connection received on ::1 8503 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: Sat Nov 16 02:59:00 2024 Valid Until: Mon Dec 16 02:59:00 2024 Cert Hash: SHA256:f5fcf413532feb789db52ba5ceb3bebc94942cc3591e3f39876f840f10b0c432 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 34080 grep 'Connection received on ::1 ' server.err Connection received on ::1 8503 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 34080 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 18768 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 to localhost (127.0.0.1) 18768 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 Connection received on localhost 15469 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: Sat Nov 16 02:59:04 2024 Valid Until: Mon Dec 16 02:59:04 2024 Cert Hash: SHA256:866b0a8d8c8ddf7e079f487792235b357b5299b2e2f8593b7eae6826aad24f45 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 18768 grep 'Connection received on localhost ' server.err Connection received on localhost 15469 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 18768 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 3840 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 48623 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:1403941B:SSL routines:ACCEPT_SR_CERT_VRFY:tlsv1 alert decrypt error) grep 'Listening on localhost ' server.err Listening on localhost 3840 grep 'Connection received on localhost ' server.err Connection received on localhost 48623 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 21122 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 received on 127.0.0.1 3191 Connection to 127.0.0.1 21122 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: localhost Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Sat Nov 16 02:59:04 2024 Valid Until: Mon Dec 16 02:59:04 2024 Cert Hash: SHA256:866b0a8d8c8ddf7e079f487792235b357b5299b2e2f8593b7eae6826aad24f45 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 21122 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 3191 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 21122 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 45079 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 34716 let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 45079 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 34716 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 45079 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 31621 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 35244 Connection to localhost (127.0.0.1) 31621 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: Sat Nov 16 02:59:04 2024 Valid Until: Mon Dec 16 02:59:04 2024 Cert Hash: SHA256:866b0a8d8c8ddf7e079f487792235b357b5299b2e2f8593b7eae6826aad24f45 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 31621 grep 'Connection received on localhost ' server.err Connection received on localhost 35244 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 31621 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:866b0a8d8c8ddf7e079f487792235b357b5299b2e2f8593b7eae6826aad24f45 ==== 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 21483 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 35620 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 21483 grep 'Connection received on localhost ' server.err Connection received on localhost 35620 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 21483 port [tcp/*] succeeded! grep 'peer certificate is not SHA256:' client.err netcat-regress: peer certificate is not SHA256:c5d449f5bf36d8c8a4efe6be93bab7aea0231558010d6beb279a6554653e5f77 ! 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 6722 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 & Connection received on localhost 30589 Connection to localhost (127.0.0.1) 6722 port [tcp/*] succeeded! 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 TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host localhost Peer name: localhost 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: Sat Nov 16 02:59:04 2024 Valid Until: Mon Dec 16 02:59:04 2024 Cert Hash: SHA256:866b0a8d8c8ddf7e079f487792235b357b5299b2e2f8593b7eae6826aad24f45 Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Sat Nov 16 02:59:13 2024 Valid Until: Mon Dec 16 02:59:13 2024 Cert Hash: SHA256:aabc740b5342ad4629a6858ca37ccb481ea79e64d0f2ae65015187d48d9527a5 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 6722 grep 'Connection received on localhost ' server.err Connection received on localhost 30589 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 6722 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 25373 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 received on localhost 9722 Connection to localhost (127.0.0.1) 25373 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: Sat Nov 16 02:59:04 2024 Valid Until: Mon Dec 16 02:59:04 2024 Cert Hash: SHA256:866b0a8d8c8ddf7e079f487792235b357b5299b2e2f8593b7eae6826aad24f45 netcat-regress: No client certificate provided grep 'Listening on localhost ' server.err Listening on localhost 25373 grep 'Connection received on localhost ' server.err Connection received on localhost 9722 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 25373 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 grep: server.err: No such file or directory Listening on localhost 5879 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 25614 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 5879 grep 'Connection received on localhost ' server.err Connection received on localhost 25614 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 5879 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 29441 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) 29441 port [tcp/*] succeeded! Connection received on 127.0.0.1 47268 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=client/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Sat Nov 16 02:59:13 2024 Valid Until: Mon Dec 16 02:59:13 2024 Cert Hash: SHA256:aabc740b5342ad4629a6858ca37ccb481ea79e64d0f2ae65015187d48d9527a5 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: Sat Nov 16 02:59:04 2024 Valid Until: Mon Dec 16 02:59:04 2024 Cert Hash: SHA256:866b0a8d8c8ddf7e079f487792235b357b5299b2e2f8593b7eae6826aad24f45 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 29441 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 47268 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 29441 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 31128 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 to localhost (127.0.0.1) 31128 port [tcp/*] succeeded! Connection received on 127.0.0.1 12930 let timeout=`date +%s`+5; until grep -q 'Cert Hash:' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host 127.0.0.1 Peer name: 127.0.0.1 Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root 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: Sat Nov 16 02:59:13 2024 Valid From: Sat Nov 16 02:59:04 2024 Valid Until: Mon Dec 16 02:59:04 2024 Cert Hash: SHA256:866b0a8d8c8ddf7e079f487792235b357b5299b2e2f8593b7eae6826aad24f45 grep 'Listening on 127.0.0.1 ' server.err Valid Until: Mon Dec 16 02:59:13 2024 Cert Hash: SHA256:aabc740b5342ad4629a6858ca37ccb481ea79e64d0f2ae65015187d48d9527a5 Listening on 127.0.0.1 31128 grep 'Connection received on 127.0.0.1 ' server.err netcat-regress: name (127.0.0.1) not found in client cert Connection received on 127.0.0.1 12930 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 31128 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 34198 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 15932 Connection to localhost (127.0.0.1) 34198 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: Sat Nov 16 02:59:04 2024 Valid Until: Mon Dec 16 02:59:04 2024 Cert Hash: SHA256:866b0a8d8c8ddf7e079f487792235b357b5299b2e2f8593b7eae6826aad24f45 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: Sat Nov 16 02:59:13 2024 Valid Until: Mon Dec 16 02:59:13 2024 Cert Hash: SHA256:aabc740b5342ad4629a6858ca37ccb481ea79e64d0f2ae65015187d48d9527a5 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 34198 grep 'Connection received on localhost ' server.err Connection received on localhost 15932 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 34198 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 40415 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 to localhost (127.0.0.1) 40415 port [tcp/*] succeeded! Connection received on localhost 34198 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: Sat Nov 16 02:59:04 2024 Valid Until: Mon Dec 16 02:59:04 2024 Cert Hash: SHA256:866b0a8d8c8ddf7e079f487792235b357b5299b2e2f8593b7eae6826aad24f45 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: Sat Nov 16 02:59:13 2024 Valid Until: Mon Dec 16 02:59:13 2024 Cert Hash: SHA256:aabc740b5342ad4629a6858ca37ccb481ea79e64d0f2ae65015187d48d9527a5 netcat-regress: peer certificate is not SHA256:c5d449f5bf36d8c8a4efe6be93bab7aea0231558010d6beb279a6554653e5f77 nc localhost `cat server.port` 2>/dev/null || : grep 'Listening on localhost ' server.err Listening on localhost 40415 grep 'Connection received on localhost ' server.err Connection received on localhost 34198 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 40415 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:c5d449f5bf36d8c8a4efe6be93bab7aea0231558010d6beb279a6554653e5f77 ! 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 37999 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 31169 Connection to localhost (127.0.0.1) 37999 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: Sat Nov 16 02:59:04 2024 Valid Until: Mon Dec 16 02:59:04 2024 Cert Hash: SHA256:866b0a8d8c8ddf7e079f487792235b357b5299b2e2f8593b7eae6826aad24f45 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 37999 grep 'Connection received on localhost ' server.err Connection received on localhost 31169 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 37999 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 45422 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 45422 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 Connection received on 127.0.0.1 28361 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: Sat Nov 16 02:58:56 2024 Valid Until: Mon Dec 16 02:58:56 2024 Cert Hash: SHA256:25def8c77c3538b340cb27c819148daefac9dfd3770b299ee3a540e754ab8dd8 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 45422 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 28361 # 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 45422 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 45422 ==== 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 19729 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R 127.0.0.1.crt -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 22222 Connection to 127.0.0.1 19729 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: Sat Nov 16 02:58:56 2024 Valid Until: Mon Dec 16 02:58:56 2024 Cert Hash: SHA256:25def8c77c3538b340cb27c819148daefac9dfd3770b299ee3a540e754ab8dd8 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 19729 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 22222 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 19729 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`$" 19288 netcat-regress rm -f client.{out,err} Listening on 127.0.0.1 28017 :> server.out # server closes the listen socket and binds a new one with new port let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R 127.0.0.1.crt -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 23171 Connection to 127.0.0.1 28017 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: Sat Nov 16 02:58:56 2024 Valid Until: Mon Dec 16 02:58:56 2024 Cert Hash: SHA256:25def8c77c3538b340cb27c819148daefac9dfd3770b299ee3a540e754ab8dd8 # 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 28017 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=127.0.0.1' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 grep 'Issuer: .*/OU=server/CN=127.0.0.1' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=server/CN=127.0.0.1 ==== run-udp ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -u -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on 127.0.0.1 9983 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 12188 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 9983 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 12188 ==== 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 44187 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 39541 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on ::1 ' server.err Bound on ::1 44187 grep 'Connection received on ::1 ' server.err Connection received on ::1 39541 ==== 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 12668 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 4056 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 12668 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 4056 ==== 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 14938 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 25611 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on localhost ' server.err Bound on localhost 14938 grep 'Connection received on localhost ' server.err Connection received on localhost 25611 ==== 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 9599 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 32398 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on localhost ' server.err Bound on localhost 9599 grep 'Connection received on localhost ' server.err Connection received on localhost 32398 ==== 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 8917 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 8917 # 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`$" 43683 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 33381 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 33354 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 33381 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 33354 # 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 33381 ==== run-unix ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.sock rm -f server.err; echo greeting | ./netcat-regress -U -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock Listening on server.sock rm -f client.err; echo command | ./netcat-regress -U -n -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on server.sock grep '^greeting$' client.out greeting grep '^command$' server.out command # XXX message Bound and Listening is redundant grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Listening on server.sock$' server.err Listening on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-namelookup ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.sock rm -f server.err; echo greeting | ./netcat-regress -U -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock Listening on server.sock rm -f client.err; echo command | ./netcat-regress -U -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on server.sock grep '^greeting$' client.out greeting grep '^command$' server.out command # XXX message Bound and Listening is redundant grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Listening on server.sock$' server.err Listening on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-probe ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.sock rm -f server.err; echo greeting | ./netcat-regress -U -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock Listening on server.sock # connect and close immediately, check if socket is listening ./netcat-regress -N -U -v server.sock client.out 2>client.err Connection received on server.sock # XXX message Bound and Listening is redundant grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Listening on server.sock$' server.err Listening on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err # server accepts one connection, second connection should be refused ! ./netcat-regress -N -U -v server.sock client.out 2>client.err grep 'server.sock: Connection refused' client.err netcat-regress: server.sock: Connection refused # connection to non existing socket file should fail rm server.sock ! ./netcat-regress -N -U -v server.sock client.out 2>client.err grep 'server.sock: No such file or directory' client.err netcat-regress: server.sock: No such file or directory ==== run-unix-keep ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.sock rm -f server.err; echo greeting | ./netcat-regress -k -U -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock Listening on server.sock rm -f client.err; echo command | ./netcat-regress -U -n -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on server.sock grep '^greeting$' client.out greeting grep '^command$' server.out command # XXX message Bound and Listening is redundant grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Listening on server.sock$' server.err Listening on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err # kill client and reconnect with a new one :> server.err pkill -l -f "^./netcat-regress .* -v server.sock$" 9003 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 grep: server.err: No such file or directory Bound on server.sock rm -f client.err; echo command | ./netcat-regress -U -u -n -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on /tmp/nc.hJWBCO4Gay 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 Connection received on server.sock Bound on /tmp/nc.wa1jFUsDxK 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 & Bound on /tmp/nc.KVpnDFxg6h # 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 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$" 9220 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.Ao3AiqQ5am 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 14899 ./client-tcp -r greeting -s command 127.0.0.1 `cat server.port` >client.port peer: 127.0.0.1 46142 >>> greeting sock: 127.0.0.1 46142 peer: 127.0.0.1 14899 <<< 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 31784 ./client-tcp -r greeting -E -s command -N 127.0.0.1 `cat server.port` >client.port peer: 127.0.0.1 10340 >>> greeting sock: 127.0.0.1 10340 peer: 127.0.0.1 31784 <<< 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 28168 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # test client read from netcat, then send line and exit ./client-tcp -r greeting -s command 127.0.0.1 `cat server.port` >client.port Connection received on 127.0.0.1 34880 sock: 127.0.0.1 34880 peer: 127.0.0.1 28168 <<< 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 28168 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 34880 ==== 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 9695 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # test client read from netcat, then send line, shutdown, wait for eof ./client-tcp -r greeting -s command -N -E 127.0.0.1 `cat server.port` >client.port Connection received on 127.0.0.1 20941 sock: 127.0.0.1 20941 peer: 127.0.0.1 9695 <<< 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 9695 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 20941 ==== 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 20951 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 43234 sock: 127.0.0.1 43234 peer: 127.0.0.1 20951 >>> 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 20951 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 43234 ==== 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 3379 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 20538 sock: 127.0.0.1 20538 peer: 127.0.0.1 3379 <<< 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 3379 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 20538 ==== 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 42938 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 41738 sock: 127.0.0.1 41738 peer: 127.0.0.1 42938 >>> 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 42938 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 41738 ==== 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 3708 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 39386 Connection to 127.0.0.1 3708 port [tcp/*] succeeded! >>> greeting <<< command let timeout=`date +%s`+5; until grep -q 'greeting' client.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 3708 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 26127 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 26127 port [tcp/*] succeeded! peer: 127.0.0.1 36234 >>> 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 26127 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 42730 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 42730 port [tcp/*] succeeded! peer: 127.0.0.1 3032 <<< 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 42730 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 22642 # netcat calls shutdown on output after EOF on input rm -f client.err; echo command | ./netcat-regress -N -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done peer: 127.0.0.1 18286 >>> greeting Connection to 127.0.0.1 22642 port [tcp/*] succeeded! <<< 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 22642 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 28253 # netcat calls shutdown on output after EOF on input rm -f client.err; echo command | ./netcat-regress -N -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done peer: 127.0.0.1 17830 Connection to 127.0.0.1 28253 port [tcp/*] succeeded! <<< command <<< EOF >>> greeting let timeout=`date +%s`+5; until grep -q 'greeting' client.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 28253 port [tcp/*] succeeded! ==== cleanup ==== pkill netcat-regress || true