Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
ae0eb898 | 37 | ## Collect information about available recovery keys. |
2235222b MW |
38 | if [ -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 | ||
b411de67 MW |
48 | ## Collect the current instance number. |
49 | rcur=$(readlink $r/current) | |
50 | eval rcur_$r=\$rcur | |
51 | ||
ae0eb898 | 52 | ## Now work through the instances of this recovery key. |
2235222b | 53 | for ri in $r/*; do |
ae0eb898 MW |
54 | |
55 | ## Get the instance number. | |
2235222b MW |
56 | i=${ri##*/} |
57 | case "$i" in *[!0-9]*) continue ;; esac | |
ae0eb898 MW |
58 | |
59 | ## Read the keeper sharing parameters. | |
2235222b | 60 | for kp in $ri/*.param; do |
ae0eb898 MW |
61 | |
62 | ## Find the keeper name. | |
2235222b | 63 | k=${kp##*/}; k=${k%.param} |
ae0eb898 MW |
64 | |
65 | ## Add this keeper to the list if we haven't already, and clear the | |
66 | ## list of associated recovery keys. | |
2235222b | 67 | case $kk in *:$k:*) ;; *) kk=$kk$k:; unset rr_$k ;; esac |
ae0eb898 MW |
68 | |
69 | ## Associate this recovery key instance with the keeper set, and | |
70 | ## store information about the sharing. | |
71 | eval t_$k_$r_$i='$(sharethresh $kp)' | |
72 | eval "rr_$k=\${rr_$k+\$rr_$k }$r/$i" | |
2235222b MW |
73 | done |
74 | done | |
75 | done | |
76 | fi | |
77 | ||
ae0eb898 | 78 | ## Now work through the keeper sets. |
2235222b MW |
79 | if [ ! -d $KEYS/keeper ]; then |
80 | echo >&2 "$quis: no keepers" | |
81 | else | |
82 | cd $KEYS/keeper | |
ae0eb898 MW |
83 | |
84 | ## Iterate over the keeper sets. | |
85 | firstp=t | |
2235222b | 86 | for k in *; do |
ae0eb898 MW |
87 | |
88 | ## Make sure that this really looks like a keeper set. | |
2235222b MW |
89 | checkword "keeper set label" "$k" |
90 | if [ ! -r $k/meta ]; then continue; fi | |
ae0eb898 MW |
91 | |
92 | ## Read the keeper metadata, and print basic stuff about it. | |
2235222b MW |
93 | read n hunoz <$k/meta |
94 | readmeta $k/0 | |
ae0eb898 | 95 | case $firstp in t) firstp=nil ;; nil) echo ;; esac |
2235222b | 96 | echo "$k profile=$profile n=$n" |
ae0eb898 MW |
97 | |
98 | ## Print the sharing information, including the keeper nubids. | |
2235222b MW |
99 | echo " share" |
100 | i=0; while [ $i -lt $n ]; do | |
101 | nubid=$(cat $k/$i/nubid) | |
102 | echo " $i nubid=$nubid" | |
103 | i=$(( $i + 1 )) | |
104 | done | |
ae0eb898 MW |
105 | |
106 | ## Print the associated recovery keys. | |
2235222b MW |
107 | echo " recov" |
108 | eval rr=\$rr_$k | |
109 | for ri in $rr; do | |
ae0eb898 MW |
110 | |
111 | ## Pick out the hash and instance number, and extract the rest of the | |
112 | ## data from this recovery key. | |
113 | r=${ri%/*} i=${ri##*/} | |
114 | eval t=\$t_$k_$r_$i | |
115 | ||
116 | ## Start assembling an information line. | |
2235222b | 117 | info="$r/$i t=$t" |
ae0eb898 MW |
118 | |
119 | ## Determine the revelation status of the recovery key. There are | |
120 | ## maybe things to check: the revelation of the key by explicit | |
121 | ## instance, or, if applicable, as the current instance. Build in the | |
122 | ## positional parameters a sequence of DIR WHAT pairs to process. | |
123 | set $r.$i revealed | |
124 | eval rcur=\$rcur_$r | |
125 | case $rcur in $i) set "$@" $r.current current ;; esac | |
2235222b MW |
126 | while [ $# -gt 0 ]; do |
127 | rd=$SAFE/keys.reveal/$1 attr=$2; shift 2 | |
128 | if [ ! -d $rd ]; then | |
129 | case $attr in revealed) ;; *) info="$info $attr" ;; esac | |
130 | elif [ -f $rd/nub ]; then | |
131 | info="$info $attr=nub" | |
132 | else | |
133 | unset ss | |
134 | i=0; while [ $i -lt $n ]; do | |
135 | if [ -f $rd/$k.$i.share ]; then ss=${ss+$ss,}$i; fi | |
136 | i=$(( $i + 1 )) | |
137 | done | |
138 | info="$info $attr=$ss" | |
139 | fi | |
140 | done | |
ae0eb898 MW |
141 | |
142 | ## Print this information. | |
2235222b MW |
143 | echo " $info" |
144 | done | |
145 | done | |
146 | fi | |
147 | ||
148 | ###----- That's all, folks -------------------------------------------------- |