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