Commit | Line | Data |
---|---|---|
a91e8fcb MW |
1 | #! /bin/sh |
2 | ||
3 | set -e | |
4 | . lib/func.sh | |
5 | ||
6 | ## The key types are adorned with bit lengths. Work out the raw key type | |
7 | ## names. | |
8 | rawkeytypes="" | |
9 | for kt in $keytypes; do | |
10 | rawkeytypes="$rawkeytypes ${kt%:*}" | |
11 | done | |
12 | ||
13 | ## Start a new output directory. | |
14 | rm -rf publish.new | |
15 | mkdir publish.new | |
6e968190 MW |
16 | exec 3<etc/hosts 4>publish.new/hosts.list |
17 | echo ":certificate-authority" >&4 | |
a91e8fcb | 18 | for kt in $rawkeytypes; do |
50b96dc7 | 19 | cp ca/ca-$kt.pub publish.new/ |
a91e8fcb | 20 | read pub <ca/ca-$kt.pub |
6e968190 MW |
21 | echo "@cert-authority $scope $pub" | |
22 | tee publish.new/ca-$kt.entry >&4 | |
23 | ssh-keygen -lv -fca/ca-$kt.pub | sed 's,^,| ,' >&4 | |
a91e8fcb MW |
24 | done |
25 | ||
26 | ## Sign the various host keys. | |
a91e8fcb MW |
27 | last=%%% |
28 | while read line <&3; do | |
29 | ||
30 | ## Ignore comments and empty lines. | |
31 | case "$line" in | |
32 | "#"* | "") continue ;; | |
33 | ##*[! ]*) ;; | |
34 | ##*) continue ;; | |
35 | esac | |
36 | ||
37 | ## Read the host line. | |
38 | set -- $line | |
39 | host=$1 | |
40 | names="" | |
58f8f79d | 41 | nicks="" |
a91e8fcb MW |
42 | |
43 | ## If this is a different host, then start a new section of the list. | |
fcacefc9 | 44 | case "$last" in |
fcacefc9 | 45 | "$host") ;; |
6e968190 | 46 | *) { echo; echo ":host $host"; } >&4 ;; |
fcacefc9 | 47 | esac |
a91e8fcb MW |
48 | last=$host |
49 | ||
50 | ## Build a list of names for the host. | |
51 | for n in "$@"; do | |
a91e8fcb | 52 | case "$n" in |
6e968190 | 53 | .*) for h in $nicks; do names=${names:+$names,}$h$n.$domain; done ;; |
58f8f79d | 54 | *.* | *:*) names=${names:+$names,}$n ;; |
6e968190 | 55 | *) nicks=${nicks:+$nicks }$n names=${names:+$names,}$n.$domain ;; |
a91e8fcb MW |
56 | esac |
57 | done | |
58 | ||
59 | ## Sign certificates. | |
60 | for kt in $rawkeytypes; do | |
61 | if [ ! -f host/$host-$kt.pub ]; then continue; fi | |
50b96dc7 | 62 | cp host/$host-$kt.pub publish.new/ |
8bcf3925 | 63 | ssh-keygen -q -tv00 -sca/ca-$kt \ |
a91e8fcb MW |
64 | -h -I"$cacomment:$host.$domain" -n$names \ |
65 | -V$validity \ | |
50b96dc7 MW |
66 | publish.new/$host-$kt.pub |
67 | mv publish.new/$host-$kt-cert.pub \ | |
68 | publish.new/$host-$kt.cert | |
6e968190 | 69 | { printf "%s " $names; cat host/$host-$kt.pub; } >&4 |
12ee14a5 | 70 | ssh-keygen -lv -fhost/$host-$kt.pub | sed 's,^,| ,' >&4 |
a91e8fcb MW |
71 | done |
72 | done | |
73 | exec 3>&- 4>&- | |
74 | ||
75 | ## Sign the list. | |
50b96dc7 MW |
76 | run_gpg --armor -o publish.new/hosts.asc \ |
77 | --clearsign publish.new/hosts.list | |
78 | rm publish.new/hosts.list | |
a91e8fcb MW |
79 | |
80 | ## Include a copy of the public key. | |
50b96dc7 | 81 | run_gpg --export --armor -o publish.new/ca-gnupg.asc |
a91e8fcb MW |
82 | |
83 | ## Done. | |
1535a6d2 MW |
84 | if [ -d publish ]; then |
85 | rm -rf publish.old | |
86 | mv publish publish.old | |
87 | fi | |
a91e8fcb | 88 | mv publish.new publish |
50b96dc7 | 89 | rm -rf publish.old |