==== 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 20381 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to 127.0.0.1 20381 port [tcp/*] succeeded! Connection received on 127.0.0.1 17899 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 20381 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 17899 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 20381 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 9945 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 18648 Connection to ::1 9945 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 9945 grep 'Connection received on ::1 ' server.err Connection received on ::1 18648 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 9945 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 29582 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to 127.0.0.1 29582 port [tcp/*] succeeded! Connection received on localhost 34808 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 29582 grep 'Connection received on localhost ' server.err Connection received on localhost 34808 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 29582 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 31252 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -n -v ::1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to ::1 31252 port [tcp/*] succeeded! Connection received on localhost 21784 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 31252 grep 'Connection received on localhost ' server.err Connection received on localhost 21784 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 31252 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 & Listening on 127.0.0.1 37282 let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -4 -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) 37282 port [tcp/*] succeeded! Connection received on 127.0.0.1 9371 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 37282 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 9371 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 37282 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 21169 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 30034 Connection to localhost (::1) 21169 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 21169 grep 'Connection received on ::1 ' server.err Connection received on ::1 30034 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (::1) 21169 port [tcp/*] succeeded! ==== run-tcp-bad-localhost-server ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress ! ./netcat-regress -4 -v -l ::1 0 >server.out 2>server.err grep 'non-recoverable failure in name resolution' server.err netcat-regress: getaddrinfo: non-recoverable failure in name resolution ==== run-tcp6-bad-localhost-server ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress ! ./netcat-regress -6 -v -l 127.0.0.0 0 >server.out 2>server.err grep 'no address associated with name' server.err netcat-regress: getaddrinfo: no address associated with name ==== run-tcp-bad-localhost-client ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f server.err; echo greeting | ./netcat-regress -n -v -l 127.0.0.1 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on 127.0.0.1 42754 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 42754: 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 10328 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 10328: 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 21910 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 25203 Connection to 127.0.0.1 21910 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 21910 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 25203 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 21910 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 21910 ==== 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 34724 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 12306 Connection to 127.0.0.1 34724 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 34724 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 12306 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 34724 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`$" Listening on 127.0.0.1 5571 34404 netcat-regress rm -f client.{out,err} :> server.out # server closes the listen socket and binds a new one with new port let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -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 5571 port [tcp/*] succeeded! Connection received on 127.0.0.1 12649 # 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 5571 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 29932 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 29932 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 28270 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: Sun Nov 17 02:59:04 2024 Valid Until: Tue Dec 17 02:59:04 2024 Cert Hash: SHA256:0e8e6d7c6723bdfc5b84841f2944dc7c7b71e8647423574ed496be580dc6d303 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 29932 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 28270 # 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 29932 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 2027 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 2027 port [tcp/*] succeeded! Connection received on ::1 18156 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: Sun Nov 17 02:59:05 2024 Valid Until: Tue Dec 17 02:59:05 2024 Cert Hash: SHA256:92bc1ee65337e42dfce2fd09b94cafa691bee106a343968253566034df6ba952 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 2027 grep 'Connection received on ::1 ' server.err Connection received on ::1 18156 grep 'Connection to ::1 .* succeeded!' client.err Connection to ::1 2027 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 21724 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) 21724 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 7390 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: Sun Nov 17 02:59:08 2024 Valid Until: Tue Dec 17 02:59:08 2024 Cert Hash: SHA256:d4150e665e826f31d1dea40a8c31fb2a97f745b961fe07cf00dce7a20dcbe37d 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 21724 grep 'Connection received on localhost ' server.err Connection received on localhost 7390 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 21724 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 33638 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 24311 let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done netcat-regress: tls handshake failed (handshake failed: error:02FFF020:system library:func(4095):Broken pipe) grep 'Listening on localhost ' server.err Listening on localhost 33638 grep 'Connection received on localhost ' server.err Connection received on localhost 24311 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 15862 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -e localhost -R ca.crt -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to 127.0.0.1 15862 port [tcp/*] succeeded! Connection received on 127.0.0.1 1757 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: Sun Nov 17 02:59:08 2024 Valid Until: Tue Dec 17 02:59:08 2024 Cert Hash: SHA256:d4150e665e826f31d1dea40a8c31fb2a97f745b961fe07cf00dce7a20dcbe37d 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 15862 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 1757 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 15862 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 37622 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 45081 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 37622 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 45081 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 37622 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 13800 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 grep: client.err: No such file or directory Connection received on localhost 20343 Connection to localhost (127.0.0.1) 13800 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: Sun Nov 17 02:59:08 2024 Valid Until: Tue Dec 17 02:59:08 2024 Cert Hash: SHA256:d4150e665e826f31d1dea40a8c31fb2a97f745b961fe07cf00dce7a20dcbe37d 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 13800 grep 'Connection received on localhost ' server.err Connection received on localhost 20343 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 13800 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:d4150e665e826f31d1dea40a8c31fb2a97f745b961fe07cf00dce7a20dcbe37d ==== 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 grep: server.err: No such file or directory grep: server.err: No such file or directory grep: server.err: No such file or directory Listening on localhost 1961 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 39185 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 1961 grep 'Connection received on localhost ' server.err Connection received on localhost 39185 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 1961 port [tcp/*] succeeded! grep 'peer certificate is not SHA256:' client.err netcat-regress: peer certificate is not SHA256:27aee03eec87a07bebe771e3b3fed4054be5f6ea02e11a4ea684e328b7624811 ! 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 6692 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 35218 Connection to localhost (127.0.0.1) 6692 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: Sun Nov 17 02:59:08 2024 Valid Until: Tue Dec 17 02:59:08 2024 Cert Hash: SHA256:d4150e665e826f31d1dea40a8c31fb2a97f745b961fe07cf00dce7a20dcbe37d 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: Sun Nov 17 02:59:16 2024 Valid Until: Tue Dec 17 02:59:16 2024 Cert Hash: SHA256:8a7fc68bc06ee38c386664af2fc1e5bbf78221fd4a065decac98b505a1d600bd 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 6692 grep 'Connection received on localhost ' server.err Connection received on localhost 35218 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 6692 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 grep: server.err: No such file or directory Listening on localhost 47540 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 47130 Connection to localhost (127.0.0.1) 47540 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: Sun Nov 17 02:59:08 2024 Valid Until: Tue Dec 17 02:59:08 2024 Cert Hash: SHA256:d4150e665e826f31d1dea40a8c31fb2a97f745b961fe07cf00dce7a20dcbe37d grep 'Listening on localhost ' server.err Listening on localhost 47540 grep 'Connection received on localhost ' server.err Connection received on localhost 47130 grep 'Connection to localhost .* succeeded!' client.err netcat-regress: No client certificate provided Connection to localhost (127.0.0.1) 47540 port [tcp/*] succeeded! grep 'Subject: .*/OU=server/CN=localhost' client.err Subject: /L=OpenBSD/O=netcat-regress/OU=server/CN=localhost grep 'Issuer: .*/OU=ca/CN=root' client.err Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root grep 'No client certificate provided' server.err netcat-regress: No client certificate provided ! grep 'greeting' client.out ! grep 'command' server.out ==== run-tls-client-bad-ca ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress # the server uses the wrong root ca to verify the client cert rm -f server.err; echo greeting | ./netcat-regress -c -R fake-ca.crt -C server.crt -K server.key -v -l localhost 0 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Listening on localhost 16456 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 18386 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 16456 grep 'Connection received on localhost ' server.err Connection received on localhost 18386 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 16456 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 47072 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -4 -c -R ca.crt -C client.crt -K client.key -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 20118 Connection to localhost (127.0.0.1) 47072 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: Sun Nov 17 02:59:08 2024 TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host 127.0.0.1 Valid Until: Tue Dec 17 02:59:08 2024 Peer name: localhost Cert Hash: SHA256:d4150e665e826f31d1dea40a8c31fb2a97f745b961fe07cf00dce7a20dcbe37d Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Sun Nov 17 02:59:16 2024 Valid Until: Tue Dec 17 02:59:16 2024 Cert Hash: SHA256:8a7fc68bc06ee38c386664af2fc1e5bbf78221fd4a065decac98b505a1d600bd 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 47072 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 20118 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 47072 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 8382 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) 8382 port [tcp/*] succeeded! Connection received on 127.0.0.1 44439 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: Sun Nov 17 02:59:08 2024 Valid Until: Tue Dec 17 02:59:08 2024 Cert Hash: SHA256:d4150e665e826f31d1dea40a8c31fb2a97f745b961fe07cf00dce7a20dcbe37d TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host 127.0.0.1 Peer name: 127.0.0.1 Subject: /L=OpenBSD/O=netcat-regress/OU=client/CN=localhost Issuer: /L=OpenBSD/O=netcat-regress/OU=ca/CN=root Valid From: Sun Nov 17 02:59:16 2024 Valid Until: Tue Dec 17 02:59:16 2024 Cert Hash: SHA256:8a7fc68bc06ee38c386664af2fc1e5bbf78221fd4a065decac98b505a1d600bd netcat-regress: name (127.0.0.1) not found in client cert grep 'Listening on 127.0.0.1 ' server.err Listening on 127.0.0.1 8382 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 44439 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 8382 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 31738 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R ca.crt -C client.crt -K client.key -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to localhost (127.0.0.1) 31738 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 11334 TLS handshake negotiated TLSv1.3/TLS_AES_256_GCM_SHA384 with host 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: Sun Nov 17 02:59:08 2024 Valid Until: Tue Dec 17 02:59:08 2024 Cert Hash: SHA256:d4150e665e826f31d1dea40a8c31fb2a97f745b961fe07cf00dce7a20dcbe37d 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: Sun Nov 17 02:59:16 2024 Valid Until: Tue Dec 17 02:59:16 2024 Cert Hash: SHA256:8a7fc68bc06ee38c386664af2fc1e5bbf78221fd4a065decac98b505a1d600bd 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 31738 grep 'Connection received on localhost ' server.err Connection received on localhost 11334 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 31738 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 40607 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # client does not see any problem, TLS handshake works, wait for exit rm -f client.err; echo command | ./netcat-regress -c -R ca.crt -C client.crt -K client.key -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on localhost 6643 Connection to localhost (127.0.0.1) 40607 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 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: Sun Nov 17 02:59:16 2024 Valid Until: Tue Dec 17 02:59:16 2024 Cert Hash: SHA256:8a7fc68bc06ee38c386664af2fc1e5bbf78221fd4a065decac98b505a1d600bd netcat-regress: peer certificate is not SHA256:27aee03eec87a07bebe771e3b3fed4054be5f6ea02e11a4ea684e328b7624811 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: Sun Nov 17 02:59:08 2024 Valid Until: Tue Dec 17 02:59:08 2024 Cert Hash: SHA256:d4150e665e826f31d1dea40a8c31fb2a97f745b961fe07cf00dce7a20dcbe37d nc localhost `cat server.port` 2>/dev/null || : grep 'Listening on localhost ' server.err Listening on localhost 40607 grep 'Connection received on localhost ' server.err Connection received on localhost 6643 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 40607 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:27aee03eec87a07bebe771e3b3fed4054be5f6ea02e11a4ea684e328b7624811 ! 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 27792 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # client provides no certificate rm -f client.err; echo command | ./netcat-regress -c -R ca.crt -v localhost `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to localhost (127.0.0.1) 27792 port [tcp/*] succeeded! Connection received on localhost 44236 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: Sun Nov 17 02:59:08 2024 Valid Until: Tue Dec 17 02:59:08 2024 Cert Hash: SHA256:d4150e665e826f31d1dea40a8c31fb2a97f745b961fe07cf00dce7a20dcbe37d 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 27792 grep 'Connection received on localhost ' server.err Connection received on localhost 44236 grep 'Connection to localhost .* succeeded!' client.err Connection to localhost (127.0.0.1) 27792 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 1086 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 19395 Connection to 127.0.0.1 1086 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: Sun Nov 17 02:59:04 2024 Valid Until: Tue Dec 17 02:59:04 2024 Cert Hash: SHA256:0e8e6d7c6723bdfc5b84841f2944dc7c7b71e8647423574ed496be580dc6d303 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 1086 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 19395 # 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 1086 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 1086 ==== 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 21189 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 21189 port [tcp/*] succeeded! Connection received on 127.0.0.1 9973 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: Sun Nov 17 02:59:04 2024 Valid Until: Tue Dec 17 02:59:04 2024 Cert Hash: SHA256:0e8e6d7c6723bdfc5b84841f2944dc7c7b71e8647423574ed496be580dc6d303 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 21189 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 9973 grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 21189 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`$" 5817 netcat-regress Listening on 127.0.0.1 41689 rm -f client.{out,err} :> server.out # server closes the listen socket and binds a new one with new port let timeout=`date +%s`+5; until grep -q 'Listening on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port rm -f client.err; echo command | ./netcat-regress -c -R 127.0.0.1.crt -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on 127.0.0.1 48165 Connection to 127.0.0.1 41689 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: Sun Nov 17 02:59:04 2024 Valid Until: Tue Dec 17 02:59:04 2024 Cert Hash: SHA256:0e8e6d7c6723bdfc5b84841f2944dc7c7b71e8647423574ed496be580dc6d303 # 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 41689 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 10754 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 42288 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 10754 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 42288 ==== 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 15863 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 17011 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on ::1 ' server.err Bound on ::1 15863 grep 'Connection received on ::1 ' server.err Connection received on ::1 17011 ==== 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 40469 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 18154 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 40469 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 18154 ==== 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 16449 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 25011 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on localhost ' server.err Bound on localhost 16449 grep 'Connection received on localhost ' server.err Connection received on localhost 25011 ==== 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 18405 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 20765 grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on localhost ' server.err Bound on localhost 18405 grep 'Connection received on localhost ' server.err Connection received on localhost 20765 ==== 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 12834 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 12834 # 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`$" 92052 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 10402 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 2127 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 10402 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 2127 # 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 10402 ==== 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$" 33837 netcat-regress rm -f client.{out,err} :> server.out rm -f client.err; echo command | ./netcat-regress -U -n -v server.sock 2>&1 >client.out | tee client.err & # server sends only one greeting, do not wait for a second one let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection received on server.sock ! grep 'greeting' client.out # truncation of log results in NUL bytes, do not match ^ grep 'command$' server.out Binary file server.out matches grep 'Connection received on server.sock$' server.err Binary file server.err matches # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-dgram ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f {client,server}.sock rm -f server.err; echo greeting | ./netcat-regress -U -u -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock rm -f client.err; echo command | ./netcat-regress -U -u -n -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on /tmp/nc.IWV4tYc1Uu Connection received on server.sock let timeout=`date +%s`+5; until grep -q 'Bound on ' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-dgram-namelookup ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f {client,server}.sock rm -f server.err; echo greeting | ./netcat-regress -U -u -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock rm -f client.err; echo command | ./netcat-regress -U -u -v server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on /tmp/nc.AAnXbM4Sod Connection received on server.sock let timeout=`date +%s`+5; until grep -q 'Bound on ' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-dgram-clientsock ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f {client,server}.sock rm -f server.err; echo greeting | ./netcat-regress -U -u -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock rm -f client.err; echo command | ./netcat-regress -U -u -n -v -s client.sock server.sock 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'greeting' client.out && grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on client.sock Connection received on server.sock grep '^greeting$' client.out greeting grep '^command$' server.out command grep 'Bound on server.sock$' server.err Bound on server.sock grep 'Connection received on server.sock$' server.err Connection received on server.sock # XXX message succeeded is missing ! grep 'Connection to server.sock .* succeeded!' client.err ==== run-unix-dgram-keep ==== pkill netcat-regress || true rm -f netcat-regress # copying global netcat to local name allows to pkill it during cleanup cp /usr/bin/nc netcat-regress chmod 755 netcat-regress rm -f {client,server}.sock rm -f server.err; echo greeting | ./netcat-regress -k -U -u -n -v -l server.sock 2>&1 >server.out | tee server.err & let timeout=`date +%s`+5; until grep -q 'Bound on ' server.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on server.sock rm -f client.err; echo command | ./netcat-regress -U -u -n -v server.sock 2>&1 >client.out | tee client.err & # server does not connect, nothing reaches the client let timeout=`date +%s`+5; until grep -q 'command' server.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Bound on /tmp/nc.7oIlv6UTAQ 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$" 25125 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.87Iw2EPQNP 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 30376 ./client-tcp -r greeting -s command 127.0.0.1 `cat server.port` >client.port peer: 127.0.0.1 20432 >>> greeting sock: 127.0.0.1 20432 peer: 127.0.0.1 30376 <<< 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 37019 ./client-tcp -r greeting -E -s command -N 127.0.0.1 `cat server.port` >client.port peer: 127.0.0.1 28884 >>> greeting sock: 127.0.0.1 28884 peer: 127.0.0.1 37019 <<< 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 16771 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 45903 sock: 127.0.0.1 45903 peer: 127.0.0.1 16771 <<< 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 16771 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 45903 ==== 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 46577 sed -E -n 's/(Listening|Bound) on .* //p' server.err >server.port # test client read from netcat, then send line, shutdown, wait for eof ./client-tcp -r greeting -s command -N -E 127.0.0.1 `cat server.port` >client.port sock: 127.0.0.1 6119 Connection received on 127.0.0.1 6119 peer: 127.0.0.1 46577 <<< 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 46577 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 6119 ==== 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 14572 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 27492 sock: 127.0.0.1 27492 peer: 127.0.0.1 14572 >>> 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 14572 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 27492 ==== 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 grep: server.err: No such file or directory Listening on 127.0.0.1 1983 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 42390 sock: 127.0.0.1 42390 peer: 127.0.0.1 1983 <<< 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 1983 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 42390 ==== 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 9387 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 30982 sock: 127.0.0.1 30982 peer: 127.0.0.1 9387 >>> 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 9387 grep 'Connection received on 127.0.0.1 ' server.err Connection received on 127.0.0.1 30982 ==== 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 47267 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 47263 >>> greeting Connection to 127.0.0.1 47267 port [tcp/*] succeeded! <<< command let timeout=`date +%s`+5; until grep -q 'greeting' client.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 47267 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 46406 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 43714 >>> greeting Connection to 127.0.0.1 46406 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 46406 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 20603 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 48284 Connection to 127.0.0.1 20603 port [tcp/*] succeeded! <<< command >>> greeting let timeout=`date +%s`+5; until grep -q 'greeting' client.out; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done grep '^greeting$' client.out greeting grep 'Connection to 127.0.0.1 .* succeeded!' client.err Connection to 127.0.0.1 20603 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 25150 # netcat calls shutdown on output after EOF on input rm -f client.err; echo command | ./netcat-regress -N -n -v 127.0.0.1 `cat server.port` 2>&1 >client.out | tee client.err & let timeout=`date +%s`+5; until grep -q 'Connection to .* succeeded' client.err; do [[ `date +%s` -lt $timeout ]] || { echo timeout; exit 1; }; done Connection to 127.0.0.1peer: 127.0.0.1 15261 >>> greeting <<< command <<< EOF 25150 port [tcp/*] succeeded! 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 25150 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 26544 # 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 36863 <<< command Connection to 127.0.0.1 26544 port [tcp/*] succeeded! <<< 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 26544 port [tcp/*] succeeded! ==== cleanup ==== pkill netcat-regress || true