2
0

dtls13.test 5.2 KB

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