Major change of approach and rewrite.
[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
16mkdir publish.new/ssh-ca
17for kt in $rawkeytypes; do
18 cp ca/ca-$kt.pub publish.new/ssh-ca/
19 read pub <ca/ca-$kt.pub
20 echo "$@cert-authority $scope $pub" >publish.new/ssh-ca/ca-$kt.entry
21done
22
23## Sign the various host keys.
24exec 3<etc/hosts 4>publish.new/ssh-ca/hosts.list
25last=%%%
26while read line <&3; do
27
28 ## Ignore comments and empty lines.
29 case "$line" in
30 "#"* | "") continue ;;
31 ##*[! ]*) ;;
32 ##*) continue ;;
33 esac
34
35 ## Read the host line.
36 set -- $line
37 host=$1
38 names=""
39
40 ## If this is a different host, then start a new section of the list.
41 case "$host" in "$last") ;; *) { echo; echo "$host"; } >&4 ;; esac
42 last=$host
43
44 ## Build a list of names for the host.
45 for n in "$@"; do
46 names=${names:+$names,}$n
47 case "$n" in
48 *.* | *:*) ;;
49 *) names=${names:+$names,}$n.$domain ;;
50 esac
51 done
52
53 ## Sign certificates.
54 for kt in $rawkeytypes; do
55 if [ ! -f host/$host-$kt.pub ]; then continue; fi
56 cp host/$host-$kt.pub publish.new/ssh-ca/
57 ssh-keygen -q -sca/ca-$kt \
58 -h -I"$cacomment:$host.$domain" -n$names \
59 -V$validity \
60 publish.new/ssh-ca/$host-$kt.pub
61 mv publish.new/ssh-ca/$host-$kt-cert.pub \
62 publish.new/ssh-ca/$host-$kt.cert
63 ssh-keygen -lv -fpublish.new/ssh-ca/$host-$kt.pub | sed 's,^,| ,' >&4
64 done
65done
66exec 3>&- 4>&-
67
68## Sign the list.
69run_gpg --armor -o publish.new/ssh-ca/hosts.asc \
70 --clearsign publish.new/ssh-ca/hosts.list
71rm publish.new/ssh-ca/hosts.list
72
73## Include a copy of the public key.
74run_gpg --export --armor -o publish.new/ssh-ca/ca-gnupg.asc
75
76## Include a copy of the complete archive.
77(cd publish.new; tar czf ssh-ca.tar.gz ssh-ca/)
78mv publish.new/ssh-ca.tar.gz publish.new/ssh-ca/
79
80## Done.
81rm -rf publish
82mv publish.new publish