psk.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. ./examples/client/client -? 2>&1 | grep -- 'Client not compiled in!'
  54. if [ $? -eq 0 ]; then
  55. exit 0
  56. fi
  57. ./examples/server/server -? 2>&1 | grep -- 'Server not compiled in!'
  58. if [ $? -eq 0 ]; then
  59. exit 0
  60. fi
  61. # Usual psk server / psk client. This use case is tested in
  62. # tests/unit.test and is used here for just checking if PSK is enabled
  63. port=0
  64. ./examples/server/server -s -R $ready_file -p $port &
  65. server_pid=$!
  66. create_port
  67. ./examples/client/client -s -p $port
  68. RESULT=$?
  69. remove_ready_file
  70. # if fail here then is a settings issue so return 0
  71. if [ $RESULT -ne 0 ]; then
  72. echo -e "\n\nPSK not enabled"
  73. do_cleanup
  74. exit 0
  75. fi
  76. echo ""
  77. # client test against the server
  78. ###############################
  79. ./examples/client/client -v 3 2>&1 | grep -- 'Bad SSL version'
  80. if [ $? -ne 0 ]; then
  81. # Usual server / client. This use case is tested in
  82. # tests/unit.test and is used here for just checking if cipher suite
  83. # is available (one case for example is with disable-asn)
  84. port=0
  85. ./examples/server/server -R $ready_file -p $port -l DHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-DES-CBC3-SHA &
  86. server_pid=$!
  87. create_port
  88. ./examples/client/client -p $port
  89. RESULT=$?
  90. remove_ready_file
  91. # if fail here then is a settings issue so return 0
  92. if [ $RESULT -ne 0 ]; then
  93. echo -e "\n\nIssue with chosen non PSK suites"
  94. do_cleanup
  95. exit 0
  96. fi
  97. echo ""
  98. # psk server with non psk client
  99. port=0
  100. ./examples/server/server -j -R $ready_file -p $port &
  101. server_pid=$!
  102. create_port
  103. ./examples/client/client -p $port
  104. RESULT=$?
  105. remove_ready_file
  106. if [ $RESULT -ne 0 ]; then
  107. echo -e "\n\nClient connection failed"
  108. do_cleanup
  109. exit 1
  110. fi
  111. echo ""
  112. # check fail if no auth, psk server with non psk client
  113. echo "Checking fail when not sending peer cert"
  114. port=0
  115. ./examples/server/server -j -R $ready_file -p $port &
  116. server_pid=$!
  117. create_port
  118. ./examples/client/client -x -p $port
  119. RESULT=$?
  120. remove_ready_file
  121. if [ $RESULT -eq 0 ]; then
  122. echo -e "\n\nClient connected when supposed to fail"
  123. do_cleanup
  124. exit 1
  125. fi
  126. fi
  127. echo -e "\nALL Tests Passed"
  128. exit 0