more progress. recovery seems to be working now.
[distorted-keys] / stash
diff --git a/stash b/stash
new file mode 100644 (file)
index 0000000..98116b5
--- /dev/null
+++ b/stash
@@ -0,0 +1,58 @@
+### -*-sh-*-
+###
+### Stash a recovery blob of a secret
+###
+### (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
+RECOV LABEL [SECRET]
+Store a secret encrypted under the recovery key RECOV.
+
+The LABEL is used to identify the encrypted secret later to the \`recover'
+command.  The secret is read from SECRET, or stdin if SECRET is omitted or
+\`-'.
+HELP
+dohelp
+
+## Parse the command line.
+case $# in
+  2) if [ -t 0 ]; then echo >&2 "$quis: stdin is a terminal"; exit 1; fi ;;
+  3) ;;
+  *) echo >&2 "$usage"; exit 1 ;;
+esac
+recov=$1 label=$2; shift 2
+checkword "recovery key label" "$recov"
+checklabel "secret" "$label"
+
+## Do the thing.
+tmp=$(mktmp); cleanup rmtmp
+cat -- "$@" >$tmp/secret
+cd $KEYS/recov/$recov/current
+case $label in */*) mkdir -m755 -p ${label%/*} ;; esac
+ec_encrypt pub -i$tmp/secret -o$label.new
+mv $label.new $label.recov
+
+###----- That's all, folks --------------------------------------------------