keys.*: Enforce separation between user's files and the system.
[distorted-keys] / keys.keeper-nub
diff --git a/keys.keeper-nub b/keys.keeper-nub
new file mode 100755 (executable)
index 0000000..67a9b32
--- /dev/null
@@ -0,0 +1,66 @@
+#! /bin/sh
+###
+### Collect the value of a newly created keeper nub
+###
+### (c) 2012 Mark Wooding
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This file is part of the distorted.org.uk key management suite.
+###
+### distorted-keys 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.
+###
+### distorted-keys 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 distorted-keys; if not, write to the Free Software Foundation,
+### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+set -e
+case "${KEYSLIB+t}" in t) ;; *) echo >&2 "$0: KEYSLIB unset"; exit 1 ;; esac
+. "$KEYSLIB"/keyfunc.sh
+
+defhelp <<HELP
+KEEPER I
+Write the nub for private key I of the keeper set KEEPER to standard output.
+
+The nub is read from the safe but temporary place where \`keys new-keeper'
+left them.
+HELP
+
+## Parse the command line.
+case $# in 2) ;; *) usage_err ;; esac
+keeper=$1 index=$2
+checkword "keeper label" "$keeper"
+checknumber "index" "$index"
+
+## Find out about the set.
+if [ ! -f $KEYS/keeper/$keeper/meta ]; then
+  echo >&2 "$quis: unknown keeper set \`$keeper'"
+  exit 1
+fi
+read n hunoz <$KEYS/keeper/$keeper/meta
+
+if [ $index -ge $n ]; then
+  echo >&2 "$quis: index $index out of range (must be less than $n)"
+  exit 1
+fi
+
+## Check that nubs are available for the keeper set.
+reqsafe
+if [ ! -d $SAFE/keys.keeper/$keeper/ ]; then
+  echo >&2 "$quis: no nubs available for keeper set \`$keeper'"
+  exit 1
+fi
+
+## Done.
+cat $SAFE/keys.keeper/$keeper/$index
+
+###----- That's all, folks --------------------------------------------------