1#!/bin/bash 2 3# 4# This script is used to run the oscore interop tests as specified in 5# https://core-wg.github.io/oscore/test-spec5.html 6# 7# By default, this script should be run in the examples directory. 8# 9# Run as 10# ./oscore_testcases.sh [-h remote-target-IP] [-B port-B-OSCORE] \ 11# [-D port-D-OSCORE] [-N port-NO-OSCORE] \ 12# [-s executable-for-interop-server] \ 13# [-c executable-for-client] \ 14# [-P] [-F] 15# 16# -h remote-target-IP 17# Remote server hosting interop tests if not running the interop server on this host. 18# 19# -B port-B-OSCORE 20# Port that the server listening on providing B OSCORE security profile 21# 22# -D port-D-OSCORE 23# Port that the server listening on providing D OSCORE security profile 24# 25# -N port-N-OSCORE 26# Port that the server listening on providing no security profile 27# 28# -s executable-for-interop-server 29# Exectuable to use for the interop server if not the default of ./oscore-interop-server. 30# 31# -c executable-for-client 32# Exectuable to use for the coap client if not the default of ./coap-client. 33# 34# -P 35# Output partial client logs 36# 37# -F 38# Output full client logs 39# 40 41INDIR=`dirname $0` 42 43# Defaults 44 45# host running oscore interop server 46TARGET_IP=127.0.0.1 47# Server with B OSCORE Security 48S_PORT_B=5683 49# Server with D OSCORE Security 50S_PORT_D=5685 51# Server with no Security 52S_PORT_N=5687 53# Client app 54CLIENT=$INDIR/coap-client 55# SERVER app 56SERVER=$INDIR/oscore-interop-server 57# Partial Logs 58PARTIAL_LOGS=no 59# Full Logs 60FULL_LOGS=no 61 62while getopts "c:h:s:B:D:FN:P" OPTION; do 63 case $OPTION in 64 c) 65 CLIENT="$OPTARG" 66 ;; 67 h) 68 TARGET_IP="$OPTARG" 69 ;; 70 s) 71 SERVER="$OPTARG" 72 ;; 73 B) 74 S_PORT_B="$OPTARG" 75 ;; 76 D) 77 S_PORT_D="$OPTARG" 78 ;; 79 F) 80 FULL_LOGS=yes 81 ;; 82 N) 83 S_PORT_N="$OPTARG" 84 ;; 85 P) 86 PARTIAL_LOGS=yes 87 ;; 88 *) 89 echo Error in options detected 90 echo Run as 91 echo "$0 [-h remote-target-IP] [-B port-B-OSCORE]" 92 echo " [-D port-D-OSCORE] [-N port-NO-OSCORE]" 93 echo " [-s executable-for-interop-server]" 94 echo " [-c executable-for-client]" 95 echo " [-P] [-F]" 96 exit 1 97 esac 98done 99 100timecheck () { 101 timeout $* 102 if [ $? = 124 ] ; then 103 echo "****** Timed Out ******" 104 fi 105} 106 107NO_PASS=0 108NO_FAIL=0 109# passfail count egrep-expression 110passfail () { 111 PASS=`cat /tmp/client_out | egrep "$2" | wc -l` 112 if [ "$PASS" = "$1" ] ; then 113 echo Pass 114 let "NO_PASS=$NO_PASS+1" 115 else 116 echo Fail 117 let "NO_FAIL=$NO_FAIL+1" 118 fi 119 if [ "$FULL_LOGS" = yes ] ; then 120 cat /tmp/client_out 121 elif [ "$PARTIAL_LOGS" = yes ] ; then 122 cat /tmp/client_out | egrep -v " DEBG | OSC " 123 fi 124} 125 126$SERVER -E $INDIR/interop/b_server.conf -v8 -p $S_PORT_B > /tmp/server_b 2>&1 & 127$SERVER -E $INDIR/interop/d_server.conf -v8 -p $S_PORT_D > /tmp/server_d 2>&1 & 128$SERVER -v8 -p $S_PORT_N > /tmp/server_n 2>&1 & 129 130sleep 1 131 132# Reset sequence number counters 133rm -f /tmp/client_a 134rm -f /tmp/client_c 135 136# Test 0 General checkout 137echo -n "Test 0 - " 138timecheck 10 $CLIENT -w -v8 coap://$TARGET_IP:$S_PORT_B/oscore/hello/coap 2>&1 | egrep -v " DEBG | OSC " > /tmp/client_out 139passfail 1 "^Hello World" 140 141# Test 1 142echo -n "Test 1 - " 143timeout 10 $CLIENT -w -v8 -E $INDIR/interop/a_client.conf,/tmp/client_a coap://$TARGET_IP:$S_PORT_B/oscore/hello/1 > /tmp/client_out 2>&1 144passfail 1 "^Hello World" 145 146# Test 2 147echo -n "Test 2 - " 148timeout 10 $CLIENT -w -v8 -E $INDIR/interop/c_client.conf,/tmp/client_c coap://$TARGET_IP:$S_PORT_D/oscore/hello/1 > /tmp/client_out 2>&1 149passfail 1 "^Hello World" 150 151# Test 3 152echo -n "Test 3 - " 153timeout 10 $CLIENT -w -v8 -E $INDIR/interop/a_client.conf,/tmp/client_a coap://$TARGET_IP:$S_PORT_B/oscore/hello/2?first=1 > /tmp/client_out 2>&1 154passfail 1 "^Hello World" 155 156# Test 4 157echo -n "Test 4 - " 158timeout 10 $CLIENT -w -v8 -E $INDIR/interop/a_client.conf,/tmp/client_a -A 0 coap://$TARGET_IP:$S_PORT_B/oscore/hello/3 > /tmp/client_out 2>&1 159passfail 1 "^Hello World" 160 161# Test 5 162echo -n "Test 5 - " 163timeout 10 $CLIENT -w -v8 -E $INDIR/interop/a_client.conf,/tmp/client_a -s 2 coap://$TARGET_IP:$S_PORT_B/oscore/hello/1 > /tmp/client_out 2>&1 164passfail 1 "^Hello World" 165 166# Test 6 167echo -n "Test 6 - " 168timeout 10 $CLIENT -w -v8 -E $INDIR/interop/a_client.conf,/tmp/client_a -s 4 coap://$TARGET_IP:$S_PORT_B/oscore/observe1 > /tmp/client_out > /tmp/client_out 2>&1 169passfail 3 "^one|^two|^5.00 Terminate Observe" 170 171# Test 7 172echo -n "Test 7 - " 173timeout 10 $CLIENT -w -v8 -E $INDIR/interop/a_client.conf,/tmp/client_a -s 2 coap://$TARGET_IP:$S_PORT_B/oscore/observe2 > /tmp/client_out 2>&1 174passfail 3 "^one|^two" 175 176# Test 8 177echo -n "Test 8 - " 178timeout 10 $CLIENT -w -v8 -E $INDIR/interop/a_client.conf,/tmp/client_a -m post -e "%4a" -t 0 coap://$TARGET_IP:$S_PORT_B/oscore/hello/6 > /tmp/client_out 2>&1 179passfail 1 "^J$" 180 181# Test 9 182echo -n "Test 9 - " 183timeout 10 $CLIENT -w -v8 -E $INDIR/interop/a_client.conf,/tmp/client_a -m put -e "%7a" -t 0 -O 1,0x7b coap://$TARGET_IP:$S_PORT_B/oscore/hello/7 > /tmp/client_out 2>&1 184passfail 1 "^z" 185 186# Test 10 187echo -n "Test 10 - " 188timeout 10 $CLIENT -w -v8 -E $INDIR/interop/a_client.conf,/tmp/client_a -m put -e "%8a" -t 0 -O 5 coap://$TARGET_IP:$S_PORT_B/oscore/hello/7 > /tmp/client_out 2>&1 189passfail 1 "^4.12 Precondition Failed" 190 191# Test 11 192if [ "$SUPPRESS" = no ] ; then 193 echo 194fi 195echo -n "Test 11 - " 196timeout 10 $CLIENT -w -v8 -E $INDIR/interop/a_client.conf,/tmp/client_a -m delete coap://$TARGET_IP:$S_PORT_B/oscore/test > /tmp/client_out 2>&1 197passfail 1 "^v:1 t:CON c:2.02 i:" 198 199# Test 12 200if [ "$SUPPRESS" = no ] ; then 201 echo 202fi 203echo -n "Test 12 - " 204timeout 10 $CLIENT -w -v8 -E $INDIR/interop/e_client.conf,/tmp/client_a coap://$TARGET_IP:$S_PORT_B/oscore/hello/1 > /tmp/client_out 2>&1 205passfail 1 "^4.01 Security context not found" 206 207# Test 13 208if [ "$SUPPRESS" = no ] ; then 209 echo 210fi 211echo -n "Test 13 - " 212timeout 10 $CLIENT -w -v8 -E $INDIR/interop/f_client.conf,/tmp/client_a coap://$TARGET_IP:$S_PORT_B/oscore/hello/1 > /tmp/client_out 2>&1 213passfail 1 "^4.00 Decryption failed" 214 215# Test 14 216if [ "$SUPPRESS" = no ] ; then 217 echo 218fi 219echo -n "Test 14 - " 220timeout 10 $CLIENT -w -v8 -E $INDIR/interop/g_client.conf,/tmp/client_a coap://$TARGET_IP:$S_PORT_B/oscore/hello/1 > /tmp/client_out 2>&1 221passfail 1 "WARN OSCORE: Decryption Failure, result code: -5" 222 223# Test 15 224if [ "$SUPPRESS" = no ] ; then 225 echo 226fi 227echo -n "Test 15 - " 228timeout 10 $CLIENT -w -v8 -E $INDIR/interop/a_client.conf coap://$TARGET_IP:$S_PORT_B/oscore/hello/1 > /tmp/client_out 2>&1 229passfail 1 "^4.01 Replay detected" 230 231# Test 16 232if [ "$SUPPRESS" = no ] ; then 233 echo 234fi 235echo -n "Test 16 - " 236timeout 10 $CLIENT -w -v8 -E $INDIR/interop/e_client.conf,/tmp/client_a coap://$TARGET_IP:$S_PORT_N/oscore/hello/coap > /tmp/client_out 2>&1 237passfail 1 "^4.02 Bad Option" 238 239# Test 17 240if [ "$SUPPRESS" = no ] ; then 241 echo 242fi 243echo -n "Test 17 - " 244timeout 10 $CLIENT -w -v8 coap://$TARGET_IP:$S_PORT_N/oscore/hello/1 > /tmp/client_out 2>&1 245passfail 1 "^4.01 Unauthorized" 246 247KILL_SERVER=`basename $SERVER` 248if [ ! -z "$KILL_SERVER" ] ; then 249 killall $KILL_SERVER 250fi 251 252echo 253echo =============== 254echo Pass: $NO_PASS 255echo Fail: $NO_FAIL 256#Starts with test 0 257echo Total: 18 258 259if [ "$NO_FAIL" != 0 ] ; then 260 exit 1 261fi 262