psk.test 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #!/bin/sh
  2. # psk.test
  3. # copyright wolfSSL 2016
  4. # if we can, isolate the network namespace to eliminate port collisions.
  5. if [ "${AM_BWRAPPED-}" != "yes" ]; then
  6. bwrap_path="$(command -v bwrap)"
  7. if [ -n "$bwrap_path" ]; then
  8. export AM_BWRAPPED=yes
  9. exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
  10. fi
  11. unset AM_BWRAPPED
  12. fi
  13. # getting unique port is modeled after resume.test script
  14. # need a unique port since may run the same time as testsuite
  15. # use server port zero hack to get one
  16. port=0
  17. no_pid=-1
  18. server_pid=$no_pid
  19. counter=0
  20. # let's use absolute path to a local dir (make distcheck may be in sub dir)
  21. # also let's add some randomness by adding pid in case multiple 'make check's
  22. # per source tree
  23. ready_file=`pwd`/wolfssl_psk_ready$$
  24. echo "ready file $ready_file"
  25. create_port() {
  26. while [ ! -s $ready_file -a "$counter" -lt 20 ]; do
  27. echo -e "waiting for ready file..."
  28. sleep 0.1
  29. counter=$((counter+ 1))
  30. done
  31. if test -e $ready_file; then
  32. echo -e "found ready file, starting client..."
  33. # sleep for an additional 0.1 to mitigate race on write/read of $ready_file:
  34. sleep 0.1
  35. # get created port 0 ephemeral port
  36. port=`cat $ready_file`
  37. else
  38. echo -e "NO ready file ending test..."
  39. do_cleanup
  40. fi
  41. }
  42. remove_ready_file() {
  43. if test -e $ready_file; then
  44. echo -e "removing existing ready file"
  45. rm $ready_file
  46. fi
  47. }
  48. do_cleanup() {
  49. echo "in cleanup"
  50. if [ $server_pid != $no_pid ]
  51. then
  52. echo "killing server"
  53. kill -9 $server_pid
  54. fi
  55. remove_ready_file
  56. }
  57. do_trap() {
  58. echo "got trap"
  59. do_cleanup
  60. exit -1
  61. }
  62. trap do_trap INT TERM
  63. [ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1
  64. ./examples/client/client '-?' 2>&1 | grep -- 'Client not compiled in!'
  65. if [ $? -eq 0 ]; then
  66. exit 0
  67. fi
  68. ./examples/server/server '-?' 2>&1 | grep -- 'Server not compiled in!'
  69. if [ $? -eq 0 ]; then
  70. exit 0
  71. fi
  72. # Usual psk server / psk client. This use case is tested in
  73. # tests/unit.test and is used here for just checking if PSK is enabled
  74. port=0
  75. ./examples/server/server -s -R $ready_file -p $port &
  76. server_pid=$!
  77. create_port
  78. ./examples/client/client -s -p $port
  79. RESULT=$?
  80. remove_ready_file
  81. # if fail here then is a settings issue so return 0
  82. if [ $RESULT -ne 0 ]; then
  83. echo -e "\n\nPSK not enabled"
  84. do_cleanup
  85. exit 0
  86. fi
  87. echo ""
  88. # client test against the server
  89. ###############################
  90. ./examples/client/client -v 3 2>&1 | grep -- 'Bad SSL version'
  91. if [ $? -ne 0 ]; then
  92. # Usual server / client. This use case is tested in
  93. # tests/unit.test and is used here for just checking if cipher suite
  94. # is available (one case for example is with disable-asn)
  95. port=0
  96. ./examples/server/server -R $ready_file -p $port -l DHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-DES-CBC3-SHA &
  97. server_pid=$!
  98. create_port
  99. ./examples/client/client -p $port
  100. RESULT=$?
  101. remove_ready_file
  102. # if fail here then is a settings issue so return 0
  103. if [ $RESULT -ne 0 ]; then
  104. echo -e "\n\nIssue with chosen non PSK suites"
  105. do_cleanup
  106. exit 0
  107. fi
  108. echo ""
  109. # psk server with non psk client
  110. port=0
  111. ./examples/server/server -j -R $ready_file -p $port &
  112. server_pid=$!
  113. create_port
  114. ./examples/client/client -p $port
  115. RESULT=$?
  116. remove_ready_file
  117. if [ $RESULT -ne 0 ]; then
  118. echo -e "\n\nClient connection failed"
  119. do_cleanup
  120. exit 1
  121. fi
  122. echo ""
  123. # check fail if no auth, psk server with non psk client
  124. echo "Checking fail when not sending peer cert"
  125. port=0
  126. ./examples/server/server -j -R $ready_file -p $port &
  127. server_pid=$!
  128. create_port
  129. ./examples/client/client -x -p $port
  130. RESULT=$?
  131. remove_ready_file
  132. if [ $RESULT -eq 0 ]; then
  133. echo -e "\n\nClient connected when supposed to fail"
  134. do_cleanup
  135. exit 1
  136. fi
  137. fi
  138. echo -e "\nALL Tests Passed"
  139. exit 0