keys: Add test script.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 8 Dec 2008 12:10:39 +0000 (12:10 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 8 Dec 2008 20:11:32 +0000 (20:11 +0000)
I've recently found a number of bugs in this area, so it's probably
worth writing a test script to make sure they stay dead.

This wouldn't be complete without some edits to the tripe-keys script,
so (a) make it executable in the build tree, and (b) flush output before
running subprocesses so that the output appears in the correct order
even when it's redirected to a file.

keys/Makefile.am
keys/tests.at [new file with mode: 0644]
keys/tripe-keys.in
t/Makefile.am
t/atlocal.in

index 954e5d9..b0e295b 100644 (file)
@@ -38,7 +38,7 @@ CLEANFILES            += tripe-keys
 
 tripe-keys: tripe-keys.in Makefile
        $(confsubst) $(srcdir)/tripe-keys.in >$@.new $(SUBSTITUTIONS) && \
-               mv $@.new $@
+               chmod +x $@.new && mv $@.new $@
 
 ## Manual pages.
 man_MANS               += tripe-keys.8 tripe-keys.conf.5
diff --git a/keys/tests.at b/keys/tests.at
new file mode 100644 (file)
index 0000000..94d4463
--- /dev/null
@@ -0,0 +1,144 @@
+### -*-autotest-*-
+###
+### Test script for key-management
+###
+### (c) 2008 Straylight/Edgeware
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This file is part of Trivial IP Encryption (TrIPE).
+###
+### TrIPE is free software; you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation; either version 2 of the License, or
+### (at your option) any later version.
+###
+### TrIPE is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with TrIPE; if not, write to the Free Software Foundation,
+### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+AT_SETUP([key management])
+AT_KEYWORDS([keys python])
+
+###--------------------------------------------------------------------------
+### Make sure that this has a chance of working.
+
+AT_CHECK([
+  case "$HAVE_PYTHON_TRUE$HAVE_PYCATACOMB_TRUE" in
+    "") ;;
+    *) exit 77 ;;
+  esac
+])
+
+AT_TESTED([curl key catsign rsync])
+
+###--------------------------------------------------------------------------
+### Create the initial environment.
+
+work=$(pwd)
+mkdir alice bob stage dist
+
+cd "$work"/alice
+
+cat <<EOF >tripe-keys.master
+## Distribution parameters.
+base-url = file://$work/dist/
+base-dir = $work/stage/
+upload-hook = rsync -aI --delete $work/stage/ $work/dist/
+
+## Cryptographic parameters.
+kx = ec
+kx-expire = now + 1 year
+sig-fresh = 1 month ago
+sig-expire now + 1 year
+master-keygen-flags =
+
+## Master key integrity.
+master-sequence = @MASTER-SEQUENCE@
+hk-master = @HK-MASTER@
+EOF
+
+###--------------------------------------------------------------------------
+### Simple key establishment.
+
+## Alice sets up her repository and generates a key.
+AT_CHECK([BUILDDIR/tripe-keys setup && test -d repos],, [ignore])
+AT_CHECK([BUILDDIR/tripe-keys generate alice],, [ignore])
+AT_CHECK([test -r peer-alice.pub])
+cp peer-alice.pub repos/
+AT_CHECK([BUILDDIR/tripe-keys rebuild],, [ignore])
+AT_CHECK([BUILDDIR/tripe-keys upload],, [ignore])
+
+## Bob fetches a copy and generates his own key.
+cd "$work"/bob
+AT_CHECK([test -r "$work"/dist/tripe-keys.conf])
+cp "$work"/dist/tripe-keys.conf .
+AT_CHECK([BUILDDIR/tripe-keys update],, [ignore])
+AT_CHECK([BUILDDIR/tripe-keys generate bob],, [ignore])
+AT_CHECK([test -r peer-bob.pub])
+
+## Alice collects Bob's key and installs it.
+cd "$work/alice"
+cp "$work"/bob/peer-bob.pub repos/
+AT_CHECK([BUILDDIR/tripe-keys rebuild],, [ignore])
+AT_CHECK([BUILDDIR/tripe-keys upload],, [ignore])
+
+## Bob fetches the new update and checks that his key's there.
+cd "$work"/bob
+AT_CHECK([BUILDDIR/tripe-keys update],, [ignore])
+AT_CHECK([cmp peer-bob.pub repos/peer-bob.pub])
+
+###--------------------------------------------------------------------------
+### Alice rolls over her master key.
+
+## Alice generates a new master key and publishes it.
+cd "$work"/alice
+AT_CHECK([BUILDDIR/tripe-keys newmaster],, [ignore])
+AT_CHECK([BUILDDIR/tripe-keys upload],, [ignore])
+
+cd "$work"/dist
+AT_CHECK([test -r tripe-keys.sig-0 && test -r tripe-keys.sig-1])
+
+## Bob fetches a new copy.  He gets warned that something unusual has
+## happened.
+cd "$work"/bob
+AT_CHECK([BUILDDIR/tripe-keys update],, [ignore],
+[tripe-keys: configuration file changed: recommend running another update
+])
+
+## Alice can now destroy her old master key.
+cd "$work"/alice
+AT_CHECK([key -kmaster delete master-0])
+AT_CHECK([BUILDDIR/tripe-keys upload],, [ignore])
+
+## This is OK because Bob has rolled over to the new key.
+cd "$work"/bob
+AT_CHECK([BUILDDIR/tripe-keys update],, [ignore])
+
+###--------------------------------------------------------------------------
+### Check good behaviour on signature verification failures.
+
+## Corrupt the distribution tarball.
+cd "$work"/dist
+mkdir tmp
+cd tmp
+tar xfz ../tripe-keys.tar.gz
+touch repos/bogus-file
+tar cfz ../tripe-keys.tar.gz *
+
+## Bob tries fetching again.  The update will notice the problem; none of his
+## files will change.
+cd "$work"/bob
+md5sum repos/* keyring keyring.pub tripe-keys.conf >old-state.md5
+AT_CHECK([BUILDDIR/tripe-keys update], [1], [ignore], [ignore])
+AT_CHECK([md5sum -c old-state.md5],, [ignore])
+
+###----- That's all, folks --------------------------------------------------
+
+AT_CLEANUP
index 3ca2834..b195342 100644 (file)
@@ -143,6 +143,7 @@ def run(args):
       nargs += a[1:].split()
   args = nargs
   print '+ %s' % ' '.join(args)
+  SYS.stdout.flush()
   rc = OS.spawnvp(OS.P_WAIT, args[0], args)
   if rc != 0:
     raise SubprocessError, rc
index 0266547..0e05409 100644 (file)
@@ -30,4 +30,7 @@ autotest_TESTS                 =
 ###--------------------------------------------------------------------------
 ### Test directories.
 
+## Key management.
+autotest_TESTS         += $(top_srcdir)/keys/tests.at
+
 ###----- That's all, folks --------------------------------------------------
index c5a355f..12b6902 100644 (file)
@@ -26,4 +26,8 @@
 ###--------------------------------------------------------------------------
 ### Configuration snippets.
 
+## Python
+HAVE_PYTHON_TRUE=@HAVE_PYTHON_TRUE@
+HAVE_PYCATACOMB_TRUE=@HAVE_PYCATACOMB_TRUE@
+
 ###----- That's all, folks --------------------------------------------------