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