dtls13.test 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/bin/bash
  2. set -e
  3. cleanup () {
  4. echo
  5. echo "Cleaning up..."
  6. if [ ! -z "$UDP_PROXY_PID" ];then
  7. echo "Killing udp_proxy $UDP_PROXY_PID"
  8. kill $UDP_PROXY_PID
  9. fi
  10. if [ ! -z "$SERVER_PID" ];then
  11. echo "Killing server $SERVER_PID"
  12. kill $SERVER_PID
  13. fi
  14. }
  15. trap cleanup err exit
  16. WOLFSSL_ROOT=$(pwd)
  17. if [ -z $UDP_PROXY_PATH ];then
  18. UDP_PROXY_PATH=$WOLFSSL_ROOT/../udp-proxy/udp_proxy
  19. fi
  20. PROXY_PORT=12345
  21. SERVER_PORT=11111
  22. NEW_SESSION_TICKET_SIZE=200
  23. KEY_UPDATE_SIZE=35
  24. (killall udp_proxy || true)
  25. (killall lt-server || true)
  26. (killall lt-client || true)
  27. # $WOLFSSL_ROOT/tests/unit.test tests/test-dtls13.conf
  28. test_dropping_packets () {
  29. for i in $(seq 0 11);do
  30. echo -e "\ndropping packet $i\n" | tee -a /tmp/serr | tee -a /tmp/cerr | tee -a /tmp/udp
  31. $UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -f $i -u >>/tmp/udp &
  32. UDP_PROXY_PID=$!
  33. $WOLFSSL_ROOT/examples/server/server -v4 -u -Ta 2>>/tmp/serr &
  34. SERVER_PID=$!
  35. sleep 0.2
  36. now=$(date +%s.%N)
  37. $WOLFSSL_ROOT/examples/client/client -v4 -u -p$PROXY_PORT 2>>/tmp/cerr
  38. elapsed=$(echo $(date +%s.%N) - $now | bc)
  39. echo "it took ${elapsed} sec(s)" >> /tmp/udp
  40. wait $SERVER_PID
  41. SERVER_PID=
  42. kill $UDP_PROXY_PID
  43. UDP_PROXY_PID=
  44. done
  45. echo -e "\nTesting WANT_WRITE\n" | tee -a /tmp/serr | tee -a /tmp/cerr | tee -a /tmp/udp
  46. # dropping last ack would be client error as wolfssl_read doesn't support WANT_WRITE as returned error
  47. for i in $(seq 0 10);do
  48. echo -e "\ndropping packet $i\n" | tee -a /tmp/serr | tee -a /tmp/cerr | tee -a /tmp/udp
  49. $UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -f $i -u >>/tmp/udp &
  50. UDP_PROXY_PID=$!
  51. $WOLFSSL_ROOT/examples/server/server -v4 -u -Ta -6 2>>/tmp/serr &
  52. SERVER_PID=$!
  53. sleep 0.2
  54. now=$(date +%s.%N)
  55. $WOLFSSL_ROOT/examples/client/client -v4 -u -p$PROXY_PORT -6 2>>/tmp/cerr
  56. elapsed=$(echo $(date +%s.%N) - $now | bc)
  57. echo "it took ${elapsed} sec(s)" >> /tmp/udp
  58. wait $SERVER_PID
  59. SERVER_PID=
  60. kill $UDP_PROXY_PID
  61. UDP_PROXY_PID=
  62. done
  63. }
  64. # this test is based on detecting newSessionTicket message by its size. This is rather fragile.
  65. test_dropping_new_session_ticket() {
  66. echo -e "\ndropping new session ticket packet of size $NEW_SESSION_TICKET_SIZE\n" | tee -a /tmp/serr | tee -a /tmp/cerr | tee -a /tmp/udp
  67. $UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -F $NEW_SESSION_TICKET_SIZE -u >>/tmp/udp &
  68. UDP_PROXY_PID=$!
  69. $WOLFSSL_ROOT/examples/server/server -v4 -w -u 2>>/tmp/serr &
  70. SERVER_PID=$!
  71. sleep 0.2
  72. now=$(date +%s.%N)
  73. $WOLFSSL_ROOT/examples/client/client -v4 -u -p$PROXY_PORT -w --waitTicket 2>>/tmp/cerr
  74. elapsed=$(echo $(date +%s.%N) - $now | bc)
  75. echo "it took ${elapsed} sec(s)" >> /tmp/udp
  76. wait $SERVER_PID
  77. SERVER_PID=
  78. kill $UDP_PROXY_PID
  79. UDP_PROXY_PID=
  80. }
  81. test_permutations () {
  82. SIDE=$1
  83. PERMUTATIONS=$(python3 << EOF
  84. import itertools
  85. for p in itertools.permutations("$2"):
  86. print(''.join(p))
  87. EOF
  88. )
  89. echo "Testing $SIDE msg permutations"
  90. for i in $PERMUTATIONS;do
  91. echo -n "Testing $SIDE order $i"
  92. UDP_LOGFILE=/tmp/udp-$SIDE-$i
  93. $UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -u -r $i -l $UDP_LOGFILE -S $SIDE &
  94. UDP_PROXY_PID=$!
  95. $WOLFSSL_ROOT/examples/server/server -v4 -u -Ta -w &> /tmp/serr &
  96. SERVER_PID=$!
  97. sleep 0.2
  98. now=$(date +%s.%N)
  99. $WOLFSSL_ROOT/examples/client/client -v4 -u -p$PROXY_PORT -w &> /tmp/cerr
  100. elapsed=$(echo $(date +%s.%N) - $now | bc)
  101. udp_lines=$(grep -P 'client:|server:' $UDP_LOGFILE | wc -l)
  102. echo " took ${elapsed} sec(s) and produced ${udp_lines} messages"
  103. wait $SERVER_PID
  104. SERVER_PID=
  105. kill $UDP_PROXY_PID
  106. UDP_PROXY_PID=
  107. rm $UDP_LOGFILE
  108. done
  109. echo "All $SIDE msg permutations succeeded"
  110. }
  111. test_time_delays () {
  112. DELAYS=$(python3 << EOF
  113. import itertools
  114. t = [0.1, 0.5, 1.1]
  115. tt = []
  116. for i in itertools.product(t, t, t):
  117. tt.append(i * 15)
  118. for i in tt:
  119. print(','.join(map(lambda x: str(x) , i)))
  120. EOF
  121. )
  122. for DELAY in $DELAYS;do
  123. echo -n "Testing delay $DELAY"
  124. UDP_LOGFILE=/tmp/udp-delay-$DELAY
  125. $UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -u -l "$UDP_LOGFILE" -t $DELAY &
  126. UDP_PROXY_PID=$!
  127. $WOLFSSL_ROOT/examples/server/server -v4 -u -Ta -w &> /tmp/serr &
  128. SERVER_PID=$!
  129. sleep 0.2
  130. now=$(date +%s.%N)
  131. $WOLFSSL_ROOT/examples/client/client -v4 -u -p$PROXY_PORT -w &> /tmp/cerr
  132. elapsed=$(echo $(date +%s.%N) - $now | bc)
  133. udp_lines=$(grep -P 'client:|server:' "$UDP_LOGFILE" | wc -l)
  134. echo " took ${elapsed} sec(s) and produced ${udp_lines} messages"
  135. wait $SERVER_PID
  136. SERVER_PID=
  137. kill $UDP_PROXY_PID
  138. UDP_PROXY_PID=
  139. rm "$UDP_LOGFILE"
  140. done
  141. }
  142. test_dropping_packets
  143. test_permutations client 012
  144. test_dropping_new_session_ticket
  145. if [ ! -z $DTLS13_DO_SERVER_PERMUTATION_TEST ];then
  146. test_permutations server 0123456
  147. fi
  148. # TODO: fix udp_proxy to not re-order close alert before app data
  149. if [ ! -z $DTLS13_DO_DELAY_TEST ];then
  150. test_time_delays
  151. fi