| 
									
										
										
										
											2022-03-09 12:28:22 -06:00
										 |  |  | #!/bin/bash | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # psk.test | 
					
						
							|  |  |  | # copyright wolfSSL 2016 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-12 00:20:38 -05:00
										 |  |  | # if we can, isolate the network namespace to eliminate port collisions. | 
					
						
							| 
									
										
										
										
											2022-05-05 15:59:11 -05:00
										 |  |  | if [[ -n "$NETWORK_UNSHARE_HELPER" ]]; then | 
					
						
							|  |  |  |      if [[ -z "$NETWORK_UNSHARE_HELPER_CALLED" ]]; then | 
					
						
							|  |  |  |          export NETWORK_UNSHARE_HELPER_CALLED=yes | 
					
						
							|  |  |  |          exec "$NETWORK_UNSHARE_HELPER" "$0" "$@" || exit $? | 
					
						
							|  |  |  |      fi | 
					
						
							|  |  |  | elif [ "${AM_BWRAPPED-}" != "yes" ]; then | 
					
						
							| 
									
										
										
										
											2020-09-12 00:20:38 -05:00
										 |  |  |     bwrap_path="$(command -v bwrap)" | 
					
						
							| 
									
										
										
										
											2020-09-14 16:06:45 -05:00
										 |  |  |     if [ -n "$bwrap_path" ]; then | 
					
						
							| 
									
										
										
										
											2020-09-12 00:20:38 -05:00
										 |  |  |         export AM_BWRAPPED=yes | 
					
						
							|  |  |  |         exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@" | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2020-09-14 16:06:45 -05:00
										 |  |  |     unset AM_BWRAPPED | 
					
						
							| 
									
										
										
										
											2020-09-12 00:20:38 -05:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  | # getting unique port is modeled after resume.test script | 
					
						
							|  |  |  | # need a unique port since may run the same time as testsuite | 
					
						
							|  |  |  | # use server port zero hack to get one | 
					
						
							|  |  |  | port=0 | 
					
						
							|  |  |  | no_pid=-1 | 
					
						
							|  |  |  | server_pid=$no_pid | 
					
						
							|  |  |  | counter=0 | 
					
						
							|  |  |  | # let's use absolute path to a local dir (make distcheck may be in sub dir) | 
					
						
							|  |  |  | # also let's add some randomness by adding pid in case multiple 'make check's | 
					
						
							|  |  |  | # per source tree | 
					
						
							|  |  |  | ready_file=`pwd`/wolfssl_psk_ready$$ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-08 18:42:30 -07:00
										 |  |  | echo "ready file \"$ready_file\"" | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | create_port() { | 
					
						
							| 
									
										
										
										
											2021-06-08 18:42:30 -07:00
										 |  |  |     while [ ! -s "$ready_file" -a "$counter" -lt 20 ]; do | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  |         echo -e "waiting for ready file..." | 
					
						
							|  |  |  |         sleep 0.1 | 
					
						
							|  |  |  |         counter=$((counter+ 1)) | 
					
						
							|  |  |  |     done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-08 18:42:30 -07:00
										 |  |  |     if test -e "$ready_file"; then | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  |         echo -e "found ready file, starting client..." | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 18:05:35 -05:00
										 |  |  |         # sleep for an additional 0.1 to mitigate race on write/read of $ready_file: | 
					
						
							|  |  |  |         sleep 0.1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  |         # get created port 0 ephemeral port | 
					
						
							| 
									
										
										
										
											2021-06-08 18:42:30 -07:00
										 |  |  |         port=`cat "$ready_file"` | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  |     else | 
					
						
							|  |  |  |         echo -e "NO ready file ending test..." | 
					
						
							|  |  |  |         do_cleanup | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | remove_ready_file() { | 
					
						
							| 
									
										
										
										
											2021-06-08 18:42:30 -07:00
										 |  |  |     if test -e "$ready_file"; then | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  |         echo -e "removing existing ready file" | 
					
						
							| 
									
										
										
										
											2021-06-08 18:42:30 -07:00
										 |  |  |     rm "$ready_file" | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  |     fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | do_cleanup() { | 
					
						
							|  |  |  |     echo "in cleanup" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if  [ $server_pid != $no_pid ] | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |         echo "killing server" | 
					
						
							|  |  |  |         kill -9 $server_pid | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |     remove_ready_file | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | do_trap() { | 
					
						
							|  |  |  |     echo "got trap" | 
					
						
							|  |  |  |     do_cleanup | 
					
						
							| 
									
										
										
										
											2022-03-08 12:51:48 -06:00
										 |  |  |     exit 1 | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | trap do_trap INT TERM | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1 | 
					
						
							| 
									
										
										
										
											2020-03-24 22:40:48 -06:00
										 |  |  | ./examples/client/client '-?' 2>&1 | grep -- 'Client not compiled in!' | 
					
						
							| 
									
										
										
										
											2018-06-13 11:42:16 +10:00
										 |  |  | if [ $? -eq 0 ]; then | 
					
						
							|  |  |  |     exit 0 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2020-03-24 22:40:48 -06:00
										 |  |  | ./examples/server/server '-?' 2>&1 | grep -- 'Server not compiled in!' | 
					
						
							| 
									
										
										
										
											2018-06-13 11:42:16 +10:00
										 |  |  | if [ $? -eq 0 ]; then | 
					
						
							|  |  |  |     exit 0 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Usual psk server / psk client. This use case is tested in | 
					
						
							|  |  |  | # tests/unit.test and is used here for just checking if PSK is enabled | 
					
						
							|  |  |  | port=0 | 
					
						
							| 
									
										
										
										
											2021-06-08 18:42:30 -07:00
										 |  |  | ./examples/server/server -s -R "$ready_file" -p $port & | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  | server_pid=$! | 
					
						
							|  |  |  | create_port | 
					
						
							|  |  |  | ./examples/client/client -s -p $port | 
					
						
							|  |  |  | RESULT=$? | 
					
						
							|  |  |  | remove_ready_file | 
					
						
							|  |  |  | # if fail here then is a settings issue so return 0 | 
					
						
							|  |  |  | if [ $RESULT -ne 0 ]; then | 
					
						
							|  |  |  |     echo -e "\n\nPSK not enabled" | 
					
						
							|  |  |  |     do_cleanup | 
					
						
							|  |  |  |     exit 0 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | echo "" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # client test against the server | 
					
						
							|  |  |  | ############################### | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 09:08:03 +10:00
										 |  |  | ./examples/client/client -v 3 2>&1 | grep -- 'Bad SSL version' | 
					
						
							|  |  |  | if [ $? -ne 0 ]; then | 
					
						
							|  |  |  |     # Usual server / client. This use case is tested in | 
					
						
							|  |  |  |     # tests/unit.test and is used here for just checking if cipher suite | 
					
						
							|  |  |  |     # is available (one case for example is with disable-asn) | 
					
						
							|  |  |  |     port=0 | 
					
						
							| 
									
										
										
										
											2021-06-08 18:42:30 -07:00
										 |  |  |     ./examples/server/server -R "$ready_file" -p $port -l DHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-DES-CBC3-SHA & | 
					
						
							| 
									
										
										
										
											2018-05-17 09:08:03 +10:00
										 |  |  |     server_pid=$! | 
					
						
							|  |  |  |     create_port | 
					
						
							|  |  |  |     ./examples/client/client -p $port | 
					
						
							|  |  |  |     RESULT=$? | 
					
						
							|  |  |  |     remove_ready_file | 
					
						
							|  |  |  |     # if fail here then is a settings issue so return 0 | 
					
						
							|  |  |  |     if [ $RESULT -ne 0 ]; then | 
					
						
							| 
									
										
										
										
											2019-12-24 12:29:33 -06:00
										 |  |  |         echo -e "\n\nIssue with chosen non PSK suites" | 
					
						
							| 
									
										
										
										
											2018-05-17 09:08:03 +10:00
										 |  |  |         do_cleanup | 
					
						
							|  |  |  |         exit 0 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |     echo "" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 09:24:28 +10:00
										 |  |  |     # psk server with non psk client | 
					
						
							|  |  |  |     port=0 | 
					
						
							| 
									
										
										
										
											2021-06-08 18:42:30 -07:00
										 |  |  |     ./examples/server/server -j -R "$ready_file" -p $port & | 
					
						
							| 
									
										
										
										
											2018-06-01 09:24:28 +10:00
										 |  |  |     server_pid=$! | 
					
						
							|  |  |  |     create_port | 
					
						
							|  |  |  |     ./examples/client/client -p $port | 
					
						
							|  |  |  |     RESULT=$? | 
					
						
							|  |  |  |     remove_ready_file | 
					
						
							|  |  |  |     if [ $RESULT -ne 0 ]; then | 
					
						
							|  |  |  |         echo -e "\n\nClient connection failed" | 
					
						
							|  |  |  |         do_cleanup | 
					
						
							|  |  |  |         exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |     echo "" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 09:08:03 +10:00
										 |  |  |     # check fail if no auth, psk server with non psk client | 
					
						
							|  |  |  |     echo "Checking fail when not sending peer cert" | 
					
						
							|  |  |  |     port=0 | 
					
						
							| 
									
										
										
										
											2021-06-08 18:42:30 -07:00
										 |  |  |     ./examples/server/server -j -R "$ready_file" -p $port & | 
					
						
							| 
									
										
										
										
											2018-05-17 09:08:03 +10:00
										 |  |  |     server_pid=$! | 
					
						
							|  |  |  |     create_port | 
					
						
							|  |  |  |     ./examples/client/client -x -p $port | 
					
						
							|  |  |  |     RESULT=$? | 
					
						
							|  |  |  |     remove_ready_file | 
					
						
							|  |  |  |     if [ $RESULT -eq 0 ]; then | 
					
						
							|  |  |  |         echo -e "\n\nClient connected when supposed to fail" | 
					
						
							|  |  |  |         do_cleanup | 
					
						
							|  |  |  |         exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2016-02-11 00:12:48 -07:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo -e "\nALL Tests Passed" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit 0 | 
					
						
							|  |  |  | 
 |