rtpw_test_gcm.sh (6273B)
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 40 case $(uname -s) in 41 *CYGWIN*|*MINGW*) 42 EXE=".exe" 43 ;; 44 *Linux*) 45 EXE="" 46 if [ -n "$CRYPTO_LIBDIR" ] 47 then 48 export LD_LIBRARY_PATH="$CRYPTO_LIBDIR" 49 fi 50 ;; 51 *Darwin*) 52 EXE="" 53 if [ -n "$CRYPTO_LIBDIR" ] 54 then 55 export DYLD_LIBRARY_PATH="$CRYPTO_LIBDIR" 56 fi 57 ;; 58 esac 59 60 RTPW=./rtpw$EXE 61 [ -n "$MESON_EXE_WRAPPER" ] && RTPW="$MESON_EXE_WRAPPER $RTPW" 62 DEST_PORT=9999 63 DURATION=3 64 65 # First, we run "pkill" to get rid of all existing rtpw processes. 66 # This step also enables this script to clean up after itself; if this 67 # script is interrupted after the rtpw processes are started but before 68 # they are killed, those processes will linger. Re-running the script 69 # will get rid of them. 70 71 pkill -x rtpw 2>/dev/null 72 73 if test -n $MESON_EXE_WRAPPER || test -x $RTPW; then 74 75 GCMARGS128="-k 01234567890123456789012345678901234567890123456789012345 -g -e 128" 76 echo $0 ": starting GCM mode 128-bit rtpw receiver process... " 77 78 exec $RTPW $* $GCMARGS128 -r 127.0.0.1 $DEST_PORT & 79 80 receiver_pid=$! 81 82 echo $0 ": receiver PID = $receiver_pid" 83 84 sleep 1 85 86 # verify that the background job is running 87 ps -e | grep -q $receiver_pid 88 retval=$? 89 echo $retval 90 if [ $retval != 0 ]; then 91 echo $0 ": error" 92 exit 254 93 fi 94 95 echo $0 ": starting GCM 128-bit rtpw sender process..." 96 97 exec $RTPW $* $GCMARGS128 -s 127.0.0.1 $DEST_PORT & 98 99 sender_pid=$! 100 101 echo $0 ": sender PID = $sender_pid" 102 103 # verify that the background job is running 104 ps -e | grep -q $sender_pid 105 retval=$? 106 echo $retval 107 if [ $retval != 0 ]; then 108 echo $0 ": error" 109 exit 255 110 fi 111 112 sleep $DURATION 113 114 kill $receiver_pid 115 kill $sender_pid 116 117 wait $receiver_pid 2>/dev/null 118 wait $sender_pid 2>/dev/null 119 120 GCMARGS128="-k 01234567890123456789012345678901234567890123456789012345 -g -t 16 -e 128" 121 echo $0 ": starting GCM mode 128-bit (16 byte tag) rtpw receiver process... " 122 123 exec $RTPW $* $GCMARGS128 -r 127.0.0.1 $DEST_PORT & 124 125 receiver_pid=$! 126 127 echo $0 ": receiver PID = $receiver_pid" 128 129 sleep 1 130 131 # verify that the background job is running 132 ps -e | grep -q $receiver_pid 133 retval=$? 134 echo $retval 135 if [ $retval != 0 ]; then 136 echo $0 ": error" 137 exit 254 138 fi 139 140 echo $0 ": starting GCM 128-bit (16 byte tag) rtpw sender process..." 141 142 exec $RTPW $* $GCMARGS128 -s 127.0.0.1 $DEST_PORT & 143 144 sender_pid=$! 145 146 echo $0 ": sender PID = $sender_pid" 147 148 # verify that the background job is running 149 ps -e | grep -q $sender_pid 150 retval=$? 151 echo $retval 152 if [ $retval != 0 ]; then 153 echo $0 ": error" 154 exit 255 155 fi 156 157 sleep $DURATION 158 159 kill $receiver_pid 160 kill $sender_pid 161 162 wait $receiver_pid 2>/dev/null 163 wait $sender_pid 2>/dev/null 164 165 166 GCMARGS256="-k 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 -g -e 256" 167 echo $0 ": starting GCM mode 256-bit rtpw receiver process... " 168 169 exec $RTPW $* $GCMARGS256 -r 127.0.0.1 $DEST_PORT & 170 171 receiver_pid=$! 172 173 echo $0 ": receiver PID = $receiver_pid" 174 175 sleep 1 176 177 # verify that the background job is running 178 ps -e | grep -q $receiver_pid 179 retval=$? 180 echo $retval 181 if [ $retval != 0 ]; then 182 echo $0 ": error" 183 exit 254 184 fi 185 186 echo $0 ": starting GCM 256-bit rtpw sender process..." 187 188 exec $RTPW $* $GCMARGS256 -s 127.0.0.1 $DEST_PORT & 189 190 sender_pid=$! 191 192 echo $0 ": sender PID = $sender_pid" 193 194 # verify that the background job is running 195 ps -e | grep -q $sender_pid 196 retval=$? 197 echo $retval 198 if [ $retval != 0 ]; then 199 echo $0 ": error" 200 exit 255 201 fi 202 203 sleep $DURATION 204 205 kill $receiver_pid 206 kill $sender_pid 207 208 wait $receiver_pid 2>/dev/null 209 wait $sender_pid 2>/dev/null 210 211 GCMARGS256="-k a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 -g -t 16 -e 256" 212 echo $0 ": starting GCM mode 256-bit (16 byte tag) rtpw receiver process... " 213 214 exec $RTPW $* $GCMARGS256 -r 127.0.0.1 $DEST_PORT & 215 216 receiver_pid=$! 217 218 echo $0 ": receiver PID = $receiver_pid" 219 220 sleep 1 221 222 # verify that the background job is running 223 ps -e | grep -q $receiver_pid 224 retval=$? 225 echo $retval 226 if [ $retval != 0 ]; then 227 echo $0 ": error" 228 exit 254 229 fi 230 231 echo $0 ": starting GCM 256-bit (16 byte tag) rtpw sender process..." 232 233 exec $RTPW $* $GCMARGS256 -s 127.0.0.1 $DEST_PORT & 234 235 sender_pid=$! 236 237 echo $0 ": sender PID = $sender_pid" 238 239 # verify that the background job is running 240 ps -e | grep -q $sender_pid 241 retval=$? 242 echo $retval 243 if [ $retval != 0 ]; then 244 echo $0 ": error" 245 exit 255 246 fi 247 248 sleep $DURATION 249 250 kill $receiver_pid 251 kill $sender_pid 252 253 wait $receiver_pid 2>/dev/null 254 wait $sender_pid 2>/dev/null 255 256 echo $0 ": done (test passed)" 257 258 else 259 260 echo "error: can't find executable" $RTPW 261 exit 1 262 263 fi 264 265 # EOF