chiark / gitweb /
aeb18161445e7277aeb59aa102f3283479cf8890
[distorted-keys] / new-keeper
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
24 set -e
25 case "${KEYSLIB+t}" in t) ;; *) echo >&2 "$0: KEYSLIB unset"; exit 1 ;; esac
26 . "$KEYSLIB"/keyfunc.sh
27
28 defhelp <<HELP
29 KEEPER N
30 Create a new set of keeper keys.
31
32 The private keys are stored in KEEPER/I for each 0 <= I < N in the current
33 directory; presumably you'll do something sensible with them.  A new
34 directory $KEYS/keeper/KEEPER is created (it is an error if it already
35 exists), containing the public keys I.pub and some metadata meta.
36 HELP
37 dohelp
38
39 ## Parse the command line.
40 case $# in 2) ;; *) echo >&2 "$usage"; exit 1 ;; esac
41 keeper=$1 n=$2
42 checkword "keeper set label" "$keeper"
43 checknumber "set size" "$n"
44
45 ## Preflight checking.
46 if [ -e $KEYS/keeper/$keeper ]; then
47   echo >&2 "$0: keeper set \`$keeper' already exists"
48   exit 1
49 fi
50 if [ -e $keeper ]; then
51   echo >&2 "$0: destination \`$keeper' already exists"
52   exit 1
53 fi
54
55 ## Generate the private keys, one per file, and compute the public keys.
56 tmp=$(mktmp); cleanup rmtmp
57 rm -rf $keeper.new
58 mkdir -m700 $keeper.new
59 mkdir -p -m755 $KEYS/keeper/$keeper.new
60 echo $n >$KEYS/keeper/$keeper.new/meta
61 i=0
62 while [ $i -lt $n ]; do
63   ec_keygen $keeper.new/$i $KEYS/keeper/$keeper.new/$i.pub
64   i=$(( i + 1 ))
65 done
66 mv $keeper.new $keeper
67 mv $KEYS/keeper/$keeper.new $KEYS/keeper/$keeper
68
69 ###----- That's all, folks --------------------------------------------------