3 ### Reveal shares of a secret distributed among keepers
5 ### (c) 2011 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the distorted.org.uk key management suite.
12 ### distorted-keys is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### distorted-keys is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with distorted-keys; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 case "${KEYSLIB+t}" in t
) ;; *) echo >&2 "$0: KEYSLIB unset"; exit 1 ;; esac
28 .
"$KEYSLIB"/keyfunc.sh
31 [-i INST] RECOV KEEPER
32 Reveal a share of a recovery key distributed among keepers.
34 If enough shares have been revealed, reconstruct the recovery private key.
35 The keeper nub is read from stdin.
38 ## Parse the command line.
40 while getopts "i:" opt
; do
46 shift $
(( $OPTIND - 1 ))
47 case $# in 2) ;; *) usage_err
;; esac
48 recov
=$1 keeper
=$2; shift 2
49 checkword
"recovery instance" "$inst"
50 checkword
"recovery key" "$recov"
51 checkword
"keeper set label" "$keeper"
53 ## Check that this is a sensible thing to do.
54 kdir
=$KEYS/keeper
/$keeper
55 if [ ! -f
$kdir/meta
]; then
56 echo >&2 "$quis: unknown keeper set \`$keeper'"
59 if [ ! -l
$KEYS/recov
/$recov/current
]; then
60 echo >&2 "$quis: unknown recovery key \`$recov'"
63 rdir
=$KEYS/recov
/$recov/$inst
64 if [ ! -f
$rdir/$keeper.param
]; then
65 echo >&2 "$quis: recovery key \`$recov' not kept by keeper set \`$keeper'"
69 ## Grab the key, because we'll need to read it several times.
73 ## Read the threshold from the recovery metadata.
74 t
=$
(sharethresh
$rdir/$keeper.param
)
76 ## Find out which keeper index it corresponds to.
77 read n hunoz
<$kdir/meta
80 while [ $i -lt
$n ]; do
82 nubbin
=$
(nubid
<$tmp/secret
)
83 nubid
=$
(cat $kdir/$i/nubid
)
84 case "$nubbin" in "$nubid") foundp
=t
; break ;; esac
88 nil
) echo >&2 "$quis: nub doesn't match keeper \`$keeper'"; exit 1 ;;
91 ## Establish the recovery staging area. See whether we've done enough
95 mkdir
-p
-m700
$SAFE/keys.reveal
96 reveal
=$SAFE/keys.reveal
/$tag
97 if [ ! -d
$reveal ]; then mkdir
-m700
$reveal; fi
100 echo >&2 "$quis: recovery key \`$recov/$inst' already revealed"
104 ## Decrypt the share.
106 if [ -f
$keeper.
$i.share
]; then
107 echo >&2 "$quis: share $i already revealed"
109 c_sysdecrypt
$kdir/$i $tmp/secret \
110 <$rdir/$keeper.
$i.share \
112 mv $keeper.
$i.new
$keeper.
$i.share
115 ## See if there's enough for a recovery.
117 for j
in $keeper.
*.share
; do if [ -f
"$j" ]; then n
=$
(( $n + 1 )); fi; done
118 if [ $n -lt
$t ]; then
119 echo >&2 "$quis: share $i revealed; $(( $t - $n )) more required"
121 cat $rdir/$keeper.param
$keeper.
*.share
>$keeper.shares
122 $bindir/shamir recover
<$keeper.shares
>nub.new
123 c_sysprepare
$rdir/store
124 nubbin
=$
(nubid
<nub.new
)
125 nubid
=$
(cat $rdir/store
/nubid
)
129 echo >&2 "$quis: recovered nub doesn't match stored hash"
135 echo >&2 "$quis: recovery key \`$recov/$inst' revealed"
138 ###----- That's all, folks --------------------------------------------------