rtpw_test_gcm.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. export LD_LIBRARY_PATH=$CRYPTO_LIBDIR
  46. ;;
  47. *Darwin*)
  48. EXE=""
  49. export DYLD_LIBRARY_PATH=$CRYPTO_LIBDIR
  50. ;;
  51. esac
  52. RTPW=./rtpw$EXE
  53. DEST_PORT=9999
  54. DURATION=3
  55. # First, we run "killall" to get rid of all existing rtpw processes.
  56. # This step also enables this script to clean up after itself; if this
  57. # script is interrupted after the rtpw processes are started but before
  58. # they are killed, those processes will linger. Re-running the script
  59. # will get rid of them.
  60. killall rtpw 2>/dev/null
  61. if test -x $RTPW; then
  62. GCMARGS128="-k 01234567890123456789012345678901234567890123456789012345 -g -e 128"
  63. echo $0 ": starting GCM mode 128-bit rtpw receiver process... "
  64. exec $RTPW $* $GCMARGS128 -r 127.0.0.1 $DEST_PORT &
  65. receiver_pid=$!
  66. echo $0 ": receiver PID = $receiver_pid"
  67. sleep 1
  68. # verify that the background job is running
  69. ps -e | grep -q $receiver_pid
  70. retval=$?
  71. echo $retval
  72. if [ $retval != 0 ]; then
  73. echo $0 ": error"
  74. exit 254
  75. fi
  76. echo $0 ": starting GCM 128-bit rtpw sender process..."
  77. exec $RTPW $* $GCMARGS128 -s 127.0.0.1 $DEST_PORT &
  78. sender_pid=$!
  79. echo $0 ": sender PID = $sender_pid"
  80. # verify that the background job is running
  81. ps -e | grep -q $sender_pid
  82. retval=$?
  83. echo $retval
  84. if [ $retval != 0 ]; then
  85. echo $0 ": error"
  86. exit 255
  87. fi
  88. sleep $DURATION
  89. kill $receiver_pid
  90. kill $sender_pid
  91. wait $receiver_pid 2>/dev/null
  92. wait $sender_pid 2>/dev/null
  93. GCMARGS128="-k 01234567890123456789012345678901234567890123456789012345 -g -t 16 -e 128"
  94. echo $0 ": starting GCM mode 128-bit (16 byte tag) rtpw receiver process... "
  95. exec $RTPW $* $GCMARGS128 -r 127.0.0.1 $DEST_PORT &
  96. receiver_pid=$!
  97. echo $0 ": receiver PID = $receiver_pid"
  98. sleep 1
  99. # verify that the background job is running
  100. ps -e | grep -q $receiver_pid
  101. retval=$?
  102. echo $retval
  103. if [ $retval != 0 ]; then
  104. echo $0 ": error"
  105. exit 254
  106. fi
  107. echo $0 ": starting GCM 128-bit (16 byte tag) rtpw sender process..."
  108. exec $RTPW $* $GCMARGS128 -s 127.0.0.1 $DEST_PORT &
  109. sender_pid=$!
  110. echo $0 ": sender PID = $sender_pid"
  111. # verify that the background job is running
  112. ps -e | grep -q $sender_pid
  113. retval=$?
  114. echo $retval
  115. if [ $retval != 0 ]; then
  116. echo $0 ": error"
  117. exit 255
  118. fi
  119. sleep $DURATION
  120. kill $receiver_pid
  121. kill $sender_pid
  122. wait $receiver_pid 2>/dev/null
  123. wait $sender_pid 2>/dev/null
  124. GCMARGS256="-k 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 -g -e 256"
  125. echo $0 ": starting GCM mode 256-bit rtpw receiver process... "
  126. exec $RTPW $* $GCMARGS256 -r 127.0.0.1 $DEST_PORT &
  127. receiver_pid=$!
  128. echo $0 ": receiver PID = $receiver_pid"
  129. sleep 1
  130. # verify that the background job is running
  131. ps -e | grep -q $receiver_pid
  132. retval=$?
  133. echo $retval
  134. if [ $retval != 0 ]; then
  135. echo $0 ": error"
  136. exit 254
  137. fi
  138. echo $0 ": starting GCM 256-bit rtpw sender process..."
  139. exec $RTPW $* $GCMARGS256 -s 127.0.0.1 $DEST_PORT &
  140. sender_pid=$!
  141. echo $0 ": sender PID = $sender_pid"
  142. # verify that the background job is running
  143. ps -e | grep -q $sender_pid
  144. retval=$?
  145. echo $retval
  146. if [ $retval != 0 ]; then
  147. echo $0 ": error"
  148. exit 255
  149. fi
  150. sleep $DURATION
  151. kill $receiver_pid
  152. kill $sender_pid
  153. wait $receiver_pid 2>/dev/null
  154. wait $sender_pid 2>/dev/null
  155. GCMARGS256="-k a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 -g -t 16 -e 256"
  156. echo $0 ": starting GCM mode 256-bit (16 byte tag) rtpw receiver process... "
  157. exec $RTPW $* $GCMARGS256 -r 127.0.0.1 $DEST_PORT &
  158. receiver_pid=$!
  159. echo $0 ": receiver PID = $receiver_pid"
  160. sleep 1
  161. # verify that the background job is running
  162. ps -e | grep -q $receiver_pid
  163. retval=$?
  164. echo $retval
  165. if [ $retval != 0 ]; then
  166. echo $0 ": error"
  167. exit 254
  168. fi
  169. echo $0 ": starting GCM 256-bit (16 byte tag) rtpw sender process..."
  170. exec $RTPW $* $GCMARGS256 -s 127.0.0.1 $DEST_PORT &
  171. sender_pid=$!
  172. echo $0 ": sender PID = $sender_pid"
  173. # verify that the background job is running
  174. ps -e | grep -q $sender_pid
  175. retval=$?
  176. echo $retval
  177. if [ $retval != 0 ]; then
  178. echo $0 ": error"
  179. exit 255
  180. fi
  181. sleep $DURATION
  182. kill $receiver_pid
  183. kill $sender_pid
  184. wait $receiver_pid 2>/dev/null
  185. wait $sender_pid 2>/dev/null
  186. echo $0 ": done (test passed)"
  187. else
  188. echo "error: can't find executable" $RTPW
  189. exit 1
  190. fi
  191. # EOF