rtpw_test_gcm.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #!/bin/sh
  2. #
  3. # usage: rtpw_test <rtpw_commands>
  4. #
  5. # tests the rtpw sender and receiver functions
  6. #
  7. # Copyright (c) 2001-2017, Cisco Systems, Inc.
  8. # All rights reserved.
  9. #
  10. # Redistribution and use in source and binary forms, with or without
  11. # modification, are permitted provided that the following conditions
  12. # are met:
  13. #
  14. # Redistributions of source code must retain the above copyright
  15. # notice, this list of conditions and the following disclaimer.
  16. #
  17. # Redistributions in binary form must reproduce the above
  18. # copyright notice, this list of conditions and the following
  19. # disclaimer in the documentation and/or other materials provided
  20. # with the distribution.
  21. #
  22. # Neither the name of the Cisco Systems, Inc. nor the names of its
  23. # contributors may be used to endorse or promote products derived
  24. # from this software without specific prior written permission.
  25. #
  26. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30. # COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  31. # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  32. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  33. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  35. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  37. # OF THE POSSIBILITY OF SUCH DAMAGE.
  38. #
  39. case $(uname -s) in
  40. *CYGWIN*|*MINGW*)
  41. EXE=".exe"
  42. ;;
  43. *Linux*)
  44. EXE=""
  45. if [ -n "$CRYPTO_LIBDIR" ]
  46. then
  47. export LD_LIBRARY_PATH="$CRYPTO_LIBDIR"
  48. fi
  49. ;;
  50. *Darwin*)
  51. EXE=""
  52. if [ -n "$CRYPTO_LIBDIR" ]
  53. then
  54. export DYLD_LIBRARY_PATH="$CRYPTO_LIBDIR"
  55. fi
  56. ;;
  57. esac
  58. RTPW=./rtpw$EXE
  59. [ -n "$MESON_EXE_WRAPPER" ] && RTPW="$MESON_EXE_WRAPPER $RTPW"
  60. DEST_PORT=9999
  61. DURATION=3
  62. # First, we run "killall" to get rid of all existing rtpw processes.
  63. # This step also enables this script to clean up after itself; if this
  64. # script is interrupted after the rtpw processes are started but before
  65. # they are killed, those processes will linger. Re-running the script
  66. # will get rid of them.
  67. killall rtpw 2>/dev/null
  68. if test -n $MESON_EXE_WRAPPER || test -x $RTPW; then
  69. GCMARGS128="-k 01234567890123456789012345678901234567890123456789012345 -g -e 128"
  70. echo $0 ": starting GCM mode 128-bit rtpw receiver process... "
  71. exec $RTPW $* $GCMARGS128 -r 127.0.0.1 $DEST_PORT &
  72. receiver_pid=$!
  73. echo $0 ": receiver PID = $receiver_pid"
  74. sleep 1
  75. # verify that the background job is running
  76. ps -e | grep -q $receiver_pid
  77. retval=$?
  78. echo $retval
  79. if [ $retval != 0 ]; then
  80. echo $0 ": error"
  81. exit 254
  82. fi
  83. echo $0 ": starting GCM 128-bit rtpw sender process..."
  84. exec $RTPW $* $GCMARGS128 -s 127.0.0.1 $DEST_PORT &
  85. sender_pid=$!
  86. echo $0 ": sender PID = $sender_pid"
  87. # verify that the background job is running
  88. ps -e | grep -q $sender_pid
  89. retval=$?
  90. echo $retval
  91. if [ $retval != 0 ]; then
  92. echo $0 ": error"
  93. exit 255
  94. fi
  95. sleep $DURATION
  96. kill $receiver_pid
  97. kill $sender_pid
  98. wait $receiver_pid 2>/dev/null
  99. wait $sender_pid 2>/dev/null
  100. GCMARGS128="-k 01234567890123456789012345678901234567890123456789012345 -g -t 16 -e 128"
  101. echo $0 ": starting GCM mode 128-bit (16 byte tag) rtpw receiver process... "
  102. exec $RTPW $* $GCMARGS128 -r 127.0.0.1 $DEST_PORT &
  103. receiver_pid=$!
  104. echo $0 ": receiver PID = $receiver_pid"
  105. sleep 1
  106. # verify that the background job is running
  107. ps -e | grep -q $receiver_pid
  108. retval=$?
  109. echo $retval
  110. if [ $retval != 0 ]; then
  111. echo $0 ": error"
  112. exit 254
  113. fi
  114. echo $0 ": starting GCM 128-bit (16 byte tag) rtpw sender process..."
  115. exec $RTPW $* $GCMARGS128 -s 127.0.0.1 $DEST_PORT &
  116. sender_pid=$!
  117. echo $0 ": sender PID = $sender_pid"
  118. # verify that the background job is running
  119. ps -e | grep -q $sender_pid
  120. retval=$?
  121. echo $retval
  122. if [ $retval != 0 ]; then
  123. echo $0 ": error"
  124. exit 255
  125. fi
  126. sleep $DURATION
  127. kill $receiver_pid
  128. kill $sender_pid
  129. wait $receiver_pid 2>/dev/null
  130. wait $sender_pid 2>/dev/null
  131. GCMARGS256="-k 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 -g -e 256"
  132. echo $0 ": starting GCM mode 256-bit rtpw receiver process... "
  133. exec $RTPW $* $GCMARGS256 -r 127.0.0.1 $DEST_PORT &
  134. receiver_pid=$!
  135. echo $0 ": receiver PID = $receiver_pid"
  136. sleep 1
  137. # verify that the background job is running
  138. ps -e | grep -q $receiver_pid
  139. retval=$?
  140. echo $retval
  141. if [ $retval != 0 ]; then
  142. echo $0 ": error"
  143. exit 254
  144. fi
  145. echo $0 ": starting GCM 256-bit rtpw sender process..."
  146. exec $RTPW $* $GCMARGS256 -s 127.0.0.1 $DEST_PORT &
  147. sender_pid=$!
  148. echo $0 ": sender PID = $sender_pid"
  149. # verify that the background job is running
  150. ps -e | grep -q $sender_pid
  151. retval=$?
  152. echo $retval
  153. if [ $retval != 0 ]; then
  154. echo $0 ": error"
  155. exit 255
  156. fi
  157. sleep $DURATION
  158. kill $receiver_pid
  159. kill $sender_pid
  160. wait $receiver_pid 2>/dev/null
  161. wait $sender_pid 2>/dev/null
  162. GCMARGS256="-k a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 -g -t 16 -e 256"
  163. echo $0 ": starting GCM mode 256-bit (16 byte tag) rtpw receiver process... "
  164. exec $RTPW $* $GCMARGS256 -r 127.0.0.1 $DEST_PORT &
  165. receiver_pid=$!
  166. echo $0 ": receiver PID = $receiver_pid"
  167. sleep 1
  168. # verify that the background job is running
  169. ps -e | grep -q $receiver_pid
  170. retval=$?
  171. echo $retval
  172. if [ $retval != 0 ]; then
  173. echo $0 ": error"
  174. exit 254
  175. fi
  176. echo $0 ": starting GCM 256-bit (16 byte tag) rtpw sender process..."
  177. exec $RTPW $* $GCMARGS256 -s 127.0.0.1 $DEST_PORT &
  178. sender_pid=$!
  179. echo $0 ": sender PID = $sender_pid"
  180. # verify that the background job is running
  181. ps -e | grep -q $sender_pid
  182. retval=$?
  183. echo $retval
  184. if [ $retval != 0 ]; then
  185. echo $0 ": error"
  186. exit 255
  187. fi
  188. sleep $DURATION
  189. kill $receiver_pid
  190. kill $sender_pid
  191. wait $receiver_pid 2>/dev/null
  192. wait $sender_pid 2>/dev/null
  193. echo $0 ": done (test passed)"
  194. else
  195. echo "error: can't find executable" $RTPW
  196. exit 1
  197. fi
  198. # EOF