chiark / gitweb /
server/tun-slip.c: Fix signed/unsigned char mismatch.
[tripe] / server / tests.at
index c490ff2b36d3cfa19e8ca007e61f06bfe92681e7..1171fa221fcde53121dd8580fffe854f8153c1e6 100644 (file)
@@ -38,6 +38,9 @@ m4_define([TRIPE],
      $abs_top_builddir/server/tripe -F -d. -aadmin -p0 -b127.0.0.1 -talice])
 m4_define([TRIPECTL], [$abs_top_builddir/client/tripectl -d. -aadmin])
 m4_define([USLIP], [$abs_top_builddir/uslip/tripe-uslip])
+m4_define([PKSTREAM],
+  [$abs_top_builddir/pkstream/pkstream -b127.0.0.1 -p127.0.0.1])
+m4_define([MITM], [$abs_top_builddir/proxy/tripe-mitm])
 
 ## Sequences.  (These are used for testing the replay protection machinery.)
 m4_define([R32], [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15   dnl
@@ -179,10 +182,24 @@ m4_define([WITH_3TRIPES],
          [WITH_TRIPEX([$3], [$4 $7],
          [$8])])])])
 
-## COMMS_EPING(adir, aname, bdir, bname)
+## RETRY(n, body)
+m4_define([RETRY], [
+  n=0 rc=1
+  while test $n -lt $1; do
+    if $2
+    then rc=0; break
+    fi
+    n=$(( $n + 1 ))
+  done
+  exit $rc
+])
+
+## COMMS_EPING(adir, aname, bdir, bname, [n])
 m4_define([COMMS_EPING], [
-  AT_CHECK([TRIPECTL -d$1 EPING $4],, [ignore])
-  AT_CHECK([TRIPECTL -d$3 EPING $2],, [ignore])
+  AT_CHECK([RETRY([m4_default([$5], [1])],
+    [TRIPECTL -d$1 EPING $4])],, [ignore])
+  AT_CHECK([RETRY([m4_default([$5], [1])],
+    [TRIPECTL -d$3 EPING $2])],, [ignore])
 ])
 
 ## COMMS_SLIP(adir, aname, bdir, bname)
@@ -228,13 +245,15 @@ m4_define([AWAIT_KXDONE], [
   TRIPECTL -d$4 WARN test POP
 ])
 
-## ESTABLISH(adir, aname, aopts, bdir, bname, bopts)
+## ESTABLISH(adir, aname, aopts, bdir, bname, bopts, [aport], [bport])
 m4_define([ESTABLISH], [
 
   ## Set up the establishment.
   AWAIT_KXDONE([$1], [$2], [$4], [$5], [
-    AT_CHECK([TRIPECTL -d$1 ADD -cork $6 $5 INET 127.0.0.1 $(cat $4/port)])
-    AT_CHECK([TRIPECTL -d$4 ADD $3 $2 INET 127.0.0.1 $(cat $1/port)])
+    AT_CHECK([TRIPECTL -d$1 ADD -cork $6 $5 INET 127.0.0.1 \
+      m4_if([$8], [], [$(cat $4/port)], [$8])])
+    AT_CHECK([TRIPECTL -d$4 ADD $3 $2 INET 127.0.0.1 \
+      m4_if([$7], [], [$(cat $1/port)], [$7])])
   ])
 
   ## Check transport pinging.
@@ -354,6 +373,246 @@ WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
 
 AT_CLEANUP
 
+###--------------------------------------------------------------------------
+### Mobile peer tracking.
+
+AT_SETUP([peer tracking])
+AT_KEYWORDS([mobile])
+export TRIPE_SLIPIF=USLIP
+
+for p in alice bob carol; do (mkdir $p; cd $p; SETUPDIR([alpha])); done
+
+## WITH_PKSTREAM(adir, aport, bdir, bport, body)
+m4_define([WITH_PKSTREAM], [
+  echo >&2 "pkstream: $1 <--> :$2 <-pkstream-> :$4 <--> $3"
+  PKSTREAM -l$4 127.0.0.1:$4 127.0.0.1:$(cat $3/port)& pkstream_$3_$1=$!
+  sleep 1
+  PKSTREAM -c127.0.0.1:$4 127.0.0.1:$2 127.0.0.1:$(cat $1/port)&
+  pkstream_$1_$3=$!
+  set +x
+  $5
+  kill $pkstream_$3_$1 $pkstream_$1_$3
+])
+
+WITH_3TRIPES([alice], [bob], [carol], [-nslip],
+            [-talice], [-tbob], [-tcarol], [
+
+  ## We need an indirection layer between the two peers so that we can
+  ## simulate the effects of NAT remapping.  The nearest thing we have to
+  ## this is pkstream, so we may as well use that.
+  ##
+  ## alice <--> :5311 <-pkstream-> :5312 <--> bob
+  ## alice <--> :5321 <-pkstream-> :5322 <--> carol
+
+  WITH_PKSTREAM([alice], [5311], [bob], [5312], [
+    ESTABLISH([alice], [alice], [], [bob], [bob], [-mobile], [5312], [5311])
+  ])
+
+  WITH_PKSTREAM([alice], [5319], [bob], [5312], [
+    COMMS_EPING([bob], [bob], [alice], [alice])
+    COMMS_SLIP([bob], [bob], [alice], [alice])
+  ])
+
+  WITH_PKSTREAM([alice], [5321], [carol], [5322], [
+    ESTABLISH([alice], [alice], [], [carol], [carol], [-mobile],
+       [5322], [5321])
+  ])
+
+  WITH_PKSTREAM([alice], [5311], [bob], [5312], [
+  WITH_PKSTREAM([alice], [5321], [carol], [5322], [
+    COMMS_EPING([bob], [bob], [alice], [alice])
+    COMMS_EPING([carol], [carol], [alice], [alice])
+    COMMS_SLIP([bob], [bob], [alice], [alice])
+    COMMS_SLIP([carol], [carol], [alice], [alice])
+  ])])
+
+  WITH_PKSTREAM([alice], [5321], [bob], [5312], [
+  WITH_PKSTREAM([alice], [5311], [carol], [5322], [
+    COMMS_EPING([bob], [bob], [alice], [alice])
+    COMMS_EPING([carol], [carol], [alice], [alice])
+    COMMS_SLIP([bob], [bob], [alice], [alice])
+    COMMS_SLIP([carol], [carol], [alice], [alice])
+  ])])
+  wait
+])
+
+AT_CLEANUP
+
+###--------------------------------------------------------------------------
+### Adverse communication.
+
+AT_SETUP([server retry])
+AT_KEYWORDS([backoff])
+export TRIPE_SLIPIF=USLIP
+
+for i in alice bob; do (mkdir $i; cd $i; SETUPDIR([beta])); done
+
+WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
+
+  ## Set up the evil proxy.
+  alicemitm=24516 bobmitm=14016
+  MITM -kalice/keyring.pub >mitm.out 2>mitm.err \
+    peer:alice:$alicemitm:127.0.0.1:$(cat alice/port) \
+    peer:bob:$bobmitm:127.0.0.1:$(cat bob/port) \
+    filt:drop:5 filt:send& mitmpid=$!
+  strace -omitm.trace -p$mitmpid& mitmtrace=$!
+  trap 'kill $mitmpid $mitmtrace; exit 127' EXIT INT QUIT TERM HUP
+
+  ## Try to establish keys anyway.
+  AWAIT_KXDONE([alice], [alice], [bob], [bob], [
+    AT_CHECK([TRIPECTL -dalice ADD -cork bob   INET 127.0.0.1 $alicemitm])
+    AT_CHECK([TRIPECTL -dbob   ADD       alice INET 127.0.0.1 $bobmitm])
+  ])
+
+  ## Check pinging.
+  COMMS_EPING([alice], [alice], [bob], [bob], [10])
+  COMMS_EPING([bob], [bob], [alice], [alice], [10])
+
+  ## Tear down the MITM proxy.
+  kill $mitmpid
+  wait $mitmpid
+  wait $mitmtrace
+])
+
+AT_CLEANUP
+
+###--------------------------------------------------------------------------
+### Key management.
+
+AT_SETUP([server key-management])
+AT_KEYWORDS([keymgmt])
+export TRIPE_SLIPIF=USLIP
+
+## Determine all of the nets and the principals.
+princs=""
+nets=" "
+while read princ pnets; do
+  princs="$princs $princ"
+  for n in $pnets; do
+    case " $nets " in *" $n "*) ;; *) nets="$nets$n " ;; esac
+  done
+done <<PRINC
+alice  alpha   beta
+bob    alpha   beta
+carol  beta
+PRINC
+
+## Build the master keyring.  All key tags here are of the form PRINC/NET.
+for n in $nets; do
+  key -k$abs_top_srcdir/t/keyring-$n extract keyring-$n $princs
+  for p in $princs; do key -kkeyring-$n tag $p $p/$n; done
+  key merge keyring-$n
+  rm keyring-$n
+done
+key extract -f-secret keyring.pub
+
+## Set up the principals' directories.
+for p in $princs; do
+  mkdir $p
+  cp keyring keyring.pub $p/
+done
+
+WITH_3TRIPES([alice], [bob], [carol], [-nslip -Tmx],
+       [-talice/alpha], [-tbob/alpha], [-tcarol/beta], [
+
+  ## Establish this little merry-go-round.
+  ESTABLISH([alice], [alice], [-key alice/alpha],
+       [bob], [bob], [-key bob/alpha])
+  ESTABLISH([alice], [alice], [-key alice/beta],
+       [carol], [carol], [-priv alice/beta -key carol/beta])
+  ESTABLISH([bob], [bob], [-key bob/beta],
+       [carol], [carol], [-priv bob/beta -key carol/beta])
+
+  ## Tweak Bob's alpha key.
+  for p in $princs; do
+    TRIPECTL -d$p WARN test COMMENT tweak bob/alpha
+  done
+
+  key -k$abs_top_srcdir/t/keyring-alpha extract keyring-bob-new bob-new
+  key merge keyring-bob-new
+  key tag -r bob-new bob/alpha
+  key extract -f-secret keyring.pub
+  for p in alice bob; do cp keyring keyring.pub $p/; done
+
+  ## Kick the peers to see whether they update.
+  AWAIT_KXDONE([alice], [alice], [bob], [bob], [
+    TRIPECTL -dalice RELOAD
+    TRIPECTL -dbob RELOAD
+    TRIPECTL -dalice FORCEKX bob
+    TRIPECTL -dbob FORCEKX alice
+  ])
+
+  COMMS_EPING([alice], [alice], [bob], [bob])
+  COMMS_EPING([bob], [bob], [alice], [alice])
+
+  ## Update the beta ring.
+  key merge $abs_top_srcdir/t/keyring-beta-new
+  for p in $princs; do key tag -r $p $p/beta; done
+  key extract -f-secret keyring.pub
+
+  ## Update alice's and carol's private keys, bob's public.  This should be
+  ## insufficient for them to switch, but the results could be interesting.
+  for p in $princs; do
+    TRIPECTL -d$p WARN test COMMENT tweak beta step 1
+  done
+
+  for p in alice carol; do cp keyring $p/; done
+  cp keyring.pub bob/
+  for p in $princs; do TRIPECTL -d$p RELOAD; done
+
+  AT_DATA([algs-alpha], [dnl
+kx-group=ec kx-group-order-bits=256 kx-group-elt-bits=512
+hash=rmd160 mgf=rmd160-mgf hash-sz=20
+cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
+cipher-data-limit=67108864
+mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
+])
+
+  AT_DATA([algs-beta-old], [dnl
+kx-group=prime kx-group-order-bits=160 kx-group-elt-bits=1023
+hash=rmd160 mgf=rmd160-mgf hash-sz=20
+cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
+cipher-data-limit=67108864
+mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
+])
+
+  AT_DATA([algs-beta-new], [dnl
+kx-group=ec kx-group-order-bits=161 kx-group-elt-bits=320
+hash=rmd160 mgf=rmd160-mgf hash-sz=20
+cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
+cipher-data-limit=67108864
+mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
+])
+
+  cp algs-alpha expout;    AT_CHECK([TRIPECTL -dalice ALGS],,       [expout])
+  cp algs-beta-old expout; AT_CHECK([TRIPECTL -dalice ALGS carol],, [expout])
+  cp algs-beta-old expout; AT_CHECK([TRIPECTL -dbob   ALGS carol],, [expout])
+  cp algs-beta-new expout; AT_CHECK([TRIPECTL -dcarol ALGS],,       [expout])
+  cp algs-beta-old expout; AT_CHECK([TRIPECTL -dcarol ALGS alice],, [expout])
+
+  ## Now copy the full keys.  We expect this to provoke key exchange.
+  for p in $princs; do
+    TRIPECTL -d$p WARN test COMMENT tweak beta step 2
+  done
+
+  for p in $princs; do cp keyring keyring.pub $p/; done
+
+  AWAIT_KXDONE([alice], [alice], [carol], [carol], [
+    TRIPECTL -dalice RELOAD
+    AWAIT_KXDONE([bob], [bob], [carol], [carol], [
+      TRIPECTL -dbob RELOAD
+      TRIPECTL -dcarol RELOAD
+    ])
+  ])
+
+  cp algs-alpha expout;    AT_CHECK([TRIPECTL -dalice ALGS],,       [expout])
+  cp algs-beta-new expout; AT_CHECK([TRIPECTL -dalice ALGS carol],, [expout])
+  cp algs-beta-new expout; AT_CHECK([TRIPECTL -dbob   ALGS carol],, [expout])
+  cp algs-beta-new expout; AT_CHECK([TRIPECTL -dcarol ALGS],,       [expout])
+])
+
+AT_CLEANUP
+
 ###--------------------------------------------------------------------------
 ### Services.