Allow explicit selection of recovery instances.
[distorted-keys] / keys.list-keepers
1 #! /bin/sh
2 ###
3 ### List the available keeper sets
4 ###
5 ### (c) 2012 Mark Wooding
6 ###
7
8 ###----- Licensing notice ---------------------------------------------------
9 ###
10 ### This file is part of the distorted.org.uk key management suite.
11 ###
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.
16 ###
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.
21 ###
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.
25
26 set -e
27 case "${KEYSLIB+t}" in t) ;; *) echo >&2 "$0: KEYSLIB unset"; exit 1 ;; esac
28 . "$KEYSLIB"/keyfunc.sh
29
30 defhelp <<HELP
31
32 List the available keeper sets, and the recovery secrets they protect.
33 HELP
34
35 case $# in 0) ;; *) usage_err ;; esac
36
37 ## Collect information about available recovery keys.
38 if [ -d $KEYS/recov ]; then
39 cd $KEYS/recov
40
41 ## No keeper sets encountered yet.
42 kk=:
43
44 ## Iterate over recovery keys.
45 for r in *; do
46 if [ ! -d $r ]; then continue; fi
47
48 ## Now work through the instances of this recovery key.
49 for ri in $r/*; do
50
51 ## Get the instance number.
52 i=${ri##*/}
53 case "$i" in *[!0-9]*) continue ;; esac
54
55 ## Read the keeper sharing parameters.
56 for kp in $ri/*.param; do
57
58 ## Find the keeper name.
59 k=${kp##*/}; k=${k%.param}
60
61 ## Add this keeper to the list if we haven't already, and clear the
62 ## list of associated recovery keys.
63 case $kk in *:$k:*) ;; *) kk=$kk$k:; unset rr_$k ;; esac
64
65 ## Associate this recovery key instance with the keeper set, and
66 ## store information about the sharing.
67 eval t_$k_$r_$i='$(sharethresh $kp)'
68 eval "rr_$k=\${rr_$k+\$rr_$k }$r/$i"
69 done
70 done
71 done
72 fi
73
74 ## Now work through the keeper sets.
75 if [ ! -d $KEYS/keeper ]; then
76 echo >&2 "$quis: no keepers"
77 else
78 cd $KEYS/keeper
79
80 ## Iterate over the keeper sets.
81 firstp=t
82 for k in *; do
83
84 ## Make sure that this really looks like a keeper set.
85 checkword "keeper set label" "$k"
86 if [ ! -r $k/meta ]; then continue; fi
87
88 ## Read the keeper metadata, and print basic stuff about it.
89 read n hunoz <$k/meta
90 readmeta $k/0
91 case $firstp in t) firstp=nil ;; nil) echo ;; esac
92 echo "$k profile=$profile n=$n"
93
94 ## Print the sharing information, including the keeper nubids.
95 echo " share"
96 i=0; while [ $i -lt $n ]; do
97 nubid=$(cat $k/$i/nubid)
98 echo " $i nubid=$nubid"
99 i=$(( $i + 1 ))
100 done
101
102 ## Print the associated recovery keys.
103 echo " recov"
104 eval rr=\$rr_$k
105 for ri in $rr; do
106
107 ## Pick out the hash and instance number, and extract the rest of the
108 ## data from this recovery key.
109 r=${ri%/*} i=${ri##*/}
110 eval t=\$t_$k_$r_$i
111
112 ## Start assembling an information line.
113 info="$r/$i t=$t"
114
115 ## Determine the revelation status of the recovery key. There are
116 ## maybe things to check: the revelation of the key by explicit
117 ## instance, or, if applicable, as the current instance. Build in the
118 ## positional parameters a sequence of DIR WHAT pairs to process.
119 set $r.$i revealed
120 eval rcur=\$rcur_$r
121 case $rcur in $i) set "$@" $r.current current ;; esac
122 while [ $# -gt 0 ]; do
123 rd=$SAFE/keys.reveal/$1 attr=$2; shift 2
124 if [ ! -d $rd ]; then
125 case $attr in revealed) ;; *) info="$info $attr" ;; esac
126 elif [ -f $rd/nub ]; then
127 info="$info $attr=nub"
128 else
129 unset ss
130 i=0; while [ $i -lt $n ]; do
131 if [ -f $rd/$k.$i.share ]; then ss=${ss+$ss,}$i; fi
132 i=$(( $i + 1 ))
133 done
134 info="$info $attr=$ss"
135 fi
136 done
137
138 ## Print this information.
139 echo " $info"
140 done
141 done
142 fi
143
144 ###----- That's all, folks --------------------------------------------------