initial checkin: still somewhat sketchy
[distorted-keys] / new-keeper
CommitLineData
53263601
MW
1#! /bin/sh
2###
3### Construct a new set of keeper keys
4###
5### (c) 2011 Mark Wooding
6###
7
8###----- Licensing notice ---------------------------------------------------
9###
10### This program is free software; you can redistribute it and/or modify
11### it under the terms of the GNU General Public License as published by
12### the Free Software Foundation; either version 2 of the License, or
13### (at your option) any later version.
14###
15### This program is distributed in the hope that it will be useful,
16### but WITHOUT ANY WARRANTY; without even the implied warranty of
17### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18### GNU General Public License for more details.
19###
20### You should have received a copy of the GNU General Public License
21### along with this program; if not, write to the Free Software Foundation,
22### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24set -e
25case "${KEYSLIB+t}" in t) ;; *) echo >&2 "$0: KEYSLIB unset"; exit 1 ;; esac
26. "$KEYSLIB"/keyfunc.sh
27
28defhelp <<HELP
29KEEPER N
30Create a new set of keeper keys.
31
32The private keys are stored in KEEPER/I for each 0 <= I < N in the current
33directory; presumably you'll do something sensible with them. A new
34directory $KEYS/keeper/KEEPER is created (it is an error if it already
35exists), containing the public keys I.pub and some metadata meta.
36HELP
37dohelp
38
39## Parse the command line.
40case $# in 2) ;; *) echo >&2 "$usage"; exit 1 ;; esac
41keeper=$1 n=$2
42checkword "keeper set label" "$keeper"
43checknumber "set size" "$n"
44
45## Preflight checking.
46if [ -e $KEYS/keeper/$keeper ]; then
47 echo >&2 "$0: keeper set \`$keeper' already exists"
48 exit 1
49fi
50if [ -e $keeper ]; then
51 echo >&2 "$0: destination \`$keeper' already exists"
52 exit 1
53fi
54
55## Generate the private keys, one per file, and compute the public keys.
56tmp=$(mktmp); cleanup rmtmp
57rm -rf $keeper.new
58mkdir -m700 $keeper.new
59mkdir -p -m755 $KEYS/keeper/$keeper.new
60echo $n >$KEYS/keeper/$keeper.new/meta
61i=0
62while [ $i -lt $n ]; do
63 ec_keygen $keeper.new/$i $KEYS/keeper/$keeper.new/$i.pub
64 i=$(( i + 1 ))
65done
66mv $keeper.new $keeper
67mv $KEYS/keeper/$keeper.new $KEYS/keeper/$keeper
68
69###----- That's all, folks --------------------------------------------------