chiark / gitweb /
keyfunc.sh.in: Make sure we can match the `0' string.
[distorted-keys] / keys.list-keepers
CommitLineData
2235222b
MW
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
26set -e
27case "${KEYSLIB+t}" in t) ;; *) echo >&2 "$0: KEYSLIB unset"; exit 1 ;; esac
28. "$KEYSLIB"/keyfunc.sh
29
30defhelp <<HELP
31
32List the available keeper sets, and the recovery secrets they protect.
33HELP
34
35case $# in 0) ;; *) usage_err ;; esac
36
ae0eb898 37## Collect information about available recovery keys.
2235222b
MW
38if [ -d $KEYS/recov ]; then
39 cd $KEYS/recov
ae0eb898
MW
40
41 ## No keeper sets encountered yet.
2235222b 42 kk=:
ae0eb898
MW
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.
2235222b 49 for ri in $r/*; do
ae0eb898
MW
50
51 ## Get the instance number.
2235222b
MW
52 i=${ri##*/}
53 case "$i" in *[!0-9]*) continue ;; esac
ae0eb898
MW
54
55 ## Read the keeper sharing parameters.
2235222b 56 for kp in $ri/*.param; do
ae0eb898
MW
57
58 ## Find the keeper name.
2235222b 59 k=${kp##*/}; k=${k%.param}
ae0eb898
MW
60
61 ## Add this keeper to the list if we haven't already, and clear the
62 ## list of associated recovery keys.
2235222b 63 case $kk in *:$k:*) ;; *) kk=$kk$k:; unset rr_$k ;; esac
ae0eb898
MW
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"
2235222b
MW
69 done
70 done
71 done
72fi
73
ae0eb898 74## Now work through the keeper sets.
2235222b
MW
75if [ ! -d $KEYS/keeper ]; then
76 echo >&2 "$quis: no keepers"
77else
78 cd $KEYS/keeper
ae0eb898
MW
79
80 ## Iterate over the keeper sets.
81 firstp=t
2235222b 82 for k in *; do
ae0eb898
MW
83
84 ## Make sure that this really looks like a keeper set.
2235222b
MW
85 checkword "keeper set label" "$k"
86 if [ ! -r $k/meta ]; then continue; fi
ae0eb898
MW
87
88 ## Read the keeper metadata, and print basic stuff about it.
2235222b
MW
89 read n hunoz <$k/meta
90 readmeta $k/0
ae0eb898 91 case $firstp in t) firstp=nil ;; nil) echo ;; esac
2235222b 92 echo "$k profile=$profile n=$n"
ae0eb898
MW
93
94 ## Print the sharing information, including the keeper nubids.
2235222b
MW
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
ae0eb898
MW
101
102 ## Print the associated recovery keys.
2235222b
MW
103 echo " recov"
104 eval rr=\$rr_$k
105 for ri in $rr; do
ae0eb898
MW
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.
2235222b 113 info="$r/$i t=$t"
ae0eb898
MW
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
2235222b
MW
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
ae0eb898
MW
137
138 ## Print this information.
2235222b
MW
139 echo " $info"
140 done
141 done
142fi
143
144###----- That's all, folks --------------------------------------------------