tls-cert-fail.test 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/bin/sh
  2. #tls-cert-fail.test
  3. asn_no_signer_e="-188"
  4. asn_sig_confirm_e="-155"
  5. exit_code=1
  6. counter=0
  7. # need a unique resume port since may run the same time as testsuite
  8. # use server port zero hack to get one
  9. tls_port=0
  10. #no_pid tells us process was never started if -1
  11. no_pid=-1
  12. #server_pid captured on startup, stores the id of the server process
  13. server_pid=$no_pid
  14. # let's use absolute path to a local dir (make distcheck may be in sub dir)
  15. # also let's add some randomness by adding pid in case multiple 'make check's
  16. # per source tree
  17. ready_file=`pwd`/wolfssl_tls_ready$$
  18. remove_ready_file() {
  19. if test -e $ready_file; then
  20. echo -e "removing existing ready file"
  21. rm $ready_file
  22. fi
  23. }
  24. # trap this function so if user aborts with ^C or other kill signal we still
  25. # get an exit that will in turn clean up the file system
  26. abort_trap() {
  27. echo "script aborted"
  28. if [ $server_pid != $no_pid ]
  29. then
  30. echo "killing server"
  31. kill -9 $server_pid
  32. fi
  33. exit_code=2 #different exit code in case of user interrupt
  34. echo "got abort signal, exiting with $exit_code"
  35. exit $exit_code
  36. }
  37. trap abort_trap INT TERM
  38. # trap this function so that if we exit on an error the file system will still
  39. # be restored and the other tests may still pass. Never call this function
  40. # instead use "exit <some value>" and this function will run automatically
  41. restore_file_system() {
  42. remove_ready_file
  43. }
  44. trap restore_file_system EXIT
  45. run_tls_no_signer_test() {
  46. echo -e "\nStarting example server for tls no signer fail test...\n"
  47. remove_ready_file
  48. # starts the server on tls_port, -R generates ready file to be used as a
  49. # mutex lock. We capture the processid into the variable server_pid
  50. ./examples/server/server -R $ready_file -p $tls_port &
  51. server_pid=$!
  52. while [ ! -s $ready_file -a "$counter" -lt 20 ]; do
  53. echo -e "waiting for ready file..."
  54. sleep 0.1
  55. counter=$((counter+ 1))
  56. done
  57. if test -e $ready_file; then
  58. echo -e "found ready file, starting client..."
  59. else
  60. echo -e "NO ready file ending test..."
  61. exit 1
  62. fi
  63. # get created port 0 ephemeral port
  64. tls_port=`cat $ready_file`
  65. # starts client on tls_port and captures the output from client
  66. capture_out=$(./examples/client/client -p $tls_port -H badCert 2>&1)
  67. client_result=$?
  68. wait $server_pid
  69. server_result=$?
  70. case "$capture_out" in
  71. *$asn_no_signer_e*)
  72. # only exit with zero on detection of the expected error code
  73. echo ""
  74. echo "$capture_out"
  75. echo ""
  76. echo "No signer error as expected! Test pass"
  77. echo ""
  78. exit_code=0
  79. ;;
  80. *)
  81. echo ""
  82. echo "Client did not return asn_no_signer_e as expected: $capture_out"
  83. echo ""
  84. exit_code=1
  85. esac
  86. }
  87. run_tls_sig_confirm_test() {
  88. echo -e "\nStarting example server for tls sig confirm fail test...\n"
  89. remove_ready_file
  90. # starts the server on tls_port, -R generates ready file to be used as a
  91. # mutex lock. We capture the processid into the variable server_pid
  92. ./examples/server/server -R $ready_file -p $tls_port -H badCert &
  93. server_pid=$!
  94. while [ ! -s $ready_file -a "$counter" -lt 20 ]; do
  95. echo -e "waiting for ready file..."
  96. sleep 0.1
  97. counter=$((counter+ 1))
  98. done
  99. if test -e $ready_file; then
  100. echo -e "found ready file, starting client..."
  101. else
  102. echo -e "NO ready file ending test..."
  103. exit 1
  104. fi
  105. # get created port 0 ephemeral port
  106. tls_port=`cat $ready_file`
  107. # starts client on tls_port and captures the output from client
  108. capture_out=$(./examples/client/client -p $tls_port 2>&1)
  109. client_result=$?
  110. wait $server_pid
  111. server_result=$?
  112. case "$capture_out" in
  113. *$asn_sig_confirm_e*)
  114. # only exit with zero on detection of the expected error code
  115. echo ""
  116. echo "$capture_out"
  117. echo ""
  118. echo "Sig confirm error as expected! Test pass"
  119. echo ""
  120. exit_code=0
  121. ;;
  122. *)
  123. echo ""
  124. echo "Client did not return asn_sig_confirm_e as expected: $capture_out"
  125. echo ""
  126. exit_code=1
  127. esac
  128. }
  129. ######### begin program #########
  130. # run the test
  131. run_tls_no_signer_test
  132. tls_port=0
  133. run_tls_sig_confirm_test
  134. echo "exiting with $exit_code"
  135. exit $exit_code
  136. ########## end program ##########