chiark / gitweb /
Multiple key types, key profiles, and user key storage.
[distorted-keys] / keys.new-keeper
diff --git a/keys.new-keeper b/keys.new-keeper
new file mode 100755 (executable)
index 0000000..45764bd
--- /dev/null
@@ -0,0 +1,82 @@
+#! /bin/sh
+###
+### Construct a new set of keeper keys
+###
+### (c) 2011 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
+[-p PROFILE] KEEPER N [OPTION=VALUE ...]
+Create a new set of keeper keys.
+
+The key nubs are stored in KEEPER/I for each 0 <= I < N in the current
+directory; presumably you'll do something sensible with them.  A new
+directory $KEYS/keeper/KEEPER is created (it is an error if it already
+exists), containing the key store directories and some metadata meta.
+HELP
+
+## Parse the command line.
+profile=${keeper_profile-keeper}
+while getopts "p:" opt; do
+  case "$opt" in
+    p) profile=$OPTARG ;;
+    *) usage_err ;;
+  esac
+done
+shift $(( $OPTIND - 1 ))
+case $# in 0 | 1) usage_err ;; esac
+keeper=$1 n=$2; shift 2
+checkword "keeper set label" "$keeper"
+checknumber "set size" "$n"
+checkword "profile label" "$profile"
+
+## Preflight checking.
+if [ -e $KEYS/keeper/$keeper ]; then
+  echo >&2 "$0: keeper set \`$keeper' already exists"
+  exit 1
+fi
+if [ -e $keeper ]; then
+  echo >&2 "$0: destination \`$keeper' already exists"
+  exit 1
+fi
+
+## Generate the private keys, one per file, and compute the public keys.
+mktmp
+rm -rf $keeper.new
+mkdir -m700 $keeper.new
+mkdir -p -m755 $KEYS/keeper/$keeper.new
+echo $n >$KEYS/keeper/$keeper.new/meta
+i=0
+while [ $i -lt $n ]; do
+  c_gensyskey $profile \
+    $KEYS/keeper/$keeper.new/$i \
+    $keeper.new/$i \
+    keeper="$keeper" seq="$i" tot="$n" "$@"
+  i=$(( $i + 1 ))
+done
+mv $keeper.new $keeper
+mv $KEYS/keeper/$keeper.new $KEYS/keeper/$keeper
+
+###----- That's all, folks --------------------------------------------------