1
0

psk.test 3.4 KB

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