blob: 1077358ff9f0bf2c4a02ed826460023cd1fcc57a [file] [log] [blame]
djm@openbsd.org86936ec2015-01-30 01:11:39 +00001# $OpenBSD: krl.sh,v 1.6 2015/01/30 01:11:39 djm Exp $
Damien Millerebafebd2013-01-18 11:51:56 +11002# Placed in the Public Domain.
3
4tid="key revocation lists"
5
Damien Miller2653f5c2013-02-14 10:14:51 +11006# If we don't support ecdsa keys then this tell will be much slower.
7ECDSA=ecdsa
8if test "x$TEST_SSH_ECC" != "xyes"; then
Damien Miller6d77d6e2013-02-14 10:31:03 +11009 ECDSA=rsa
Damien Miller2653f5c2013-02-14 10:14:51 +110010fi
11
Damien Millerebafebd2013-01-18 11:51:56 +110012# Do most testing with ssh-keygen; it uses the same verification code as sshd.
13
14# Old keys will interfere with ssh-keygen.
15rm -f $OBJ/revoked-* $OBJ/krl-*
16
17# Generate a CA key
Damien Miller2653f5c2013-02-14 10:14:51 +110018$SSHKEYGEN -t $ECDSA -f $OBJ/revoked-ca -C "" -N "" > /dev/null ||
Damien Millerebafebd2013-01-18 11:51:56 +110019 fatal "$SSHKEYGEN CA failed"
djm@openbsd.org51b64e42014-11-17 00:21:40 +000020$SSHKEYGEN -t ed25519 -f $OBJ/revoked-ca2 -C "" -N "" > /dev/null ||
21 fatal "$SSHKEYGEN CA2 failed"
Damien Millerebafebd2013-01-18 11:51:56 +110022
23# A specification that revokes some certificates by serial numbers
24# The serial pattern is chosen to ensure the KRL includes list, range and
25# bitmap sections.
26cat << EOF >> $OBJ/revoked-serials
27serial: 1-4
28serial: 10
29serial: 15
30serial: 30
31serial: 50
32serial: 999
33# The following sum to 500-799
34serial: 500
35serial: 501
36serial: 502
37serial: 503-600
38serial: 700-797
39serial: 798
40serial: 799
41serial: 599-701
Damien Millerc1dc24b2014-07-02 17:02:03 +100042# Some multiple consecutive serial number ranges
43serial: 10000-20000
44serial: 30000-40000
Damien Millerebafebd2013-01-18 11:51:56 +110045EOF
46
Damien Millerebafebd2013-01-18 11:51:56 +110047# A specification that revokes some certificated by key ID.
48touch $OBJ/revoked-keyid
49for n in 1 2 3 4 10 15 30 50 `jot 500 300` 999 1000 1001 1002; do
djm@openbsd.orgd3716ca2015-01-19 17:31:13 +000050 test "x$n" = "x499" && continue
Damien Millerebafebd2013-01-18 11:51:56 +110051 # Fill in by-ID revocation spec.
52 echo "id: revoked $n" >> $OBJ/revoked-keyid
53done
54
55keygen() {
56 N=$1
57 f=$OBJ/revoked-`printf "%04d" $N`
58 # Vary the keytype. We use mostly ECDSA since this is fastest by far.
Damien Miller2653f5c2013-02-14 10:14:51 +110059 keytype=$ECDSA
Damien Millerebafebd2013-01-18 11:51:56 +110060 case $N in
61 2 | 10 | 510 | 1001) keytype=rsa;;
djm@openbsd.orgd3716ca2015-01-19 17:31:13 +000062 4 | 30 | 520 | 1002) keytype=ed25519;;
Damien Millerebafebd2013-01-18 11:51:56 +110063 esac
64 $SSHKEYGEN -t $keytype -f $f -C "" -N "" > /dev/null \
65 || fatal "$SSHKEYGEN failed"
66 # Sign cert
67 $SSHKEYGEN -s $OBJ/revoked-ca -z $n -I "revoked $N" $f >/dev/null 2>&1 \
68 || fatal "$SSHKEYGEN sign failed"
69 echo $f
70}
71
72# Generate some keys.
73verbose "$tid: generating test keys"
74REVOKED_SERIALS="1 4 10 50 500 510 520 799 999"
75for n in $REVOKED_SERIALS ; do
76 f=`keygen $n`
djm@openbsd.org86936ec2015-01-30 01:11:39 +000077 RKEYS="$RKEYS ${f}.pub"
78 RCERTS="$RCERTS ${f}-cert.pub"
Damien Millerebafebd2013-01-18 11:51:56 +110079done
djm@openbsd.orgd3716ca2015-01-19 17:31:13 +000080UNREVOKED_SERIALS="5 9 14 16 29 49 51 499 800 1010 1011"
81UNREVOKED=""
82for n in $UNREVOKED_SERIALS ; do
83 f=`keygen $n`
djm@openbsd.org86936ec2015-01-30 01:11:39 +000084 UKEYS="$UKEYS ${f}.pub"
85 UCERTS="$UCERTS ${f}-cert.pub"
Damien Millerebafebd2013-01-18 11:51:56 +110086done
87
88genkrls() {
89 OPTS=$1
90$SSHKEYGEN $OPTS -kf $OBJ/krl-empty - </dev/null \
91 >/dev/null || fatal "$SSHKEYGEN KRL failed"
djm@openbsd.org86936ec2015-01-30 01:11:39 +000092$SSHKEYGEN $OPTS -kf $OBJ/krl-keys $RKEYS \
Damien Millerebafebd2013-01-18 11:51:56 +110093 >/dev/null || fatal "$SSHKEYGEN KRL failed"
djm@openbsd.org86936ec2015-01-30 01:11:39 +000094$SSHKEYGEN $OPTS -kf $OBJ/krl-cert $RCERTS \
Damien Millerebafebd2013-01-18 11:51:56 +110095 >/dev/null || fatal "$SSHKEYGEN KRL failed"
djm@openbsd.org86936ec2015-01-30 01:11:39 +000096$SSHKEYGEN $OPTS -kf $OBJ/krl-all $RKEYS $RCERTS \
Damien Millerebafebd2013-01-18 11:51:56 +110097 >/dev/null || fatal "$SSHKEYGEN KRL failed"
98$SSHKEYGEN $OPTS -kf $OBJ/krl-ca $OBJ/revoked-ca.pub \
99 >/dev/null || fatal "$SSHKEYGEN KRL failed"
djm@openbsd.org51b64e42014-11-17 00:21:40 +0000100# This should fail as KRLs from serial/key-id spec need the CA specified.
Damien Millerebafebd2013-01-18 11:51:56 +1100101$SSHKEYGEN $OPTS -kf $OBJ/krl-serial $OBJ/revoked-serials \
102 >/dev/null 2>&1 && fatal "$SSHKEYGEN KRL succeeded unexpectedly"
103$SSHKEYGEN $OPTS -kf $OBJ/krl-keyid $OBJ/revoked-keyid \
104 >/dev/null 2>&1 && fatal "$SSHKEYGEN KRL succeeded unexpectedly"
djm@openbsd.org86936ec2015-01-30 01:11:39 +0000105# These should succeed; they specify an explicit CA key.
106$SSHKEYGEN $OPTS -kf $OBJ/krl-serial -s $OBJ/revoked-ca \
107 $OBJ/revoked-serials >/dev/null || fatal "$SSHKEYGEN KRL failed"
108$SSHKEYGEN $OPTS -kf $OBJ/krl-keyid -s $OBJ/revoked-ca.pub \
109 $OBJ/revoked-keyid >/dev/null || fatal "$SSHKEYGEN KRL failed"
110# These should succeed; they specify an wildcard CA key.
111$SSHKEYGEN $OPTS -kf $OBJ/krl-serial-wild -s NONE $OBJ/revoked-serials \
112 >/dev/null || fatal "$SSHKEYGEN KRL failed"
113$SSHKEYGEN $OPTS -kf $OBJ/krl-keyid-wild -s NONE $OBJ/revoked-keyid \
Damien Millerebafebd2013-01-18 11:51:56 +1100114 >/dev/null || fatal "$SSHKEYGEN KRL failed"
djm@openbsd.org51b64e42014-11-17 00:21:40 +0000115# Revoke the same serials with the second CA key to ensure a multi-CA
116# KRL is generated.
117$SSHKEYGEN $OPTS -kf $OBJ/krl-serial -u -s $OBJ/revoked-ca2 \
118 $OBJ/revoked-serials >/dev/null || fatal "$SSHKEYGEN KRL failed"
Damien Millerebafebd2013-01-18 11:51:56 +1100119}
120
Damien Miller36aba252013-11-21 14:24:42 +1100121## XXX dump with trace and grep for set cert serials
122## XXX test ranges near (u64)-1, etc.
123
Damien Millerebafebd2013-01-18 11:51:56 +1100124verbose "$tid: generating KRLs"
125genkrls
126
127check_krl() {
128 KEY=$1
129 KRL=$2
130 EXPECT_REVOKED=$3
131 TAG=$4
132 $SSHKEYGEN -Qf $KRL $KEY >/dev/null
133 result=$?
134 if test "x$EXPECT_REVOKED" = "xyes" -a $result -eq 0 ; then
135 fatal "key $KEY not revoked by KRL $KRL: $TAG"
136 elif test "x$EXPECT_REVOKED" = "xno" -a $result -ne 0 ; then
137 fatal "key $KEY unexpectedly revoked by KRL $KRL: $TAG"
138 fi
139}
djm@openbsd.org86936ec2015-01-30 01:11:39 +0000140test_rev() {
Damien Millerebafebd2013-01-18 11:51:56 +1100141 FILES=$1
142 TAG=$2
143 KEYS_RESULT=$3
144 ALL_RESULT=$4
145 SERIAL_RESULT=$5
146 KEYID_RESULT=$6
147 CERTS_RESULT=$7
148 CA_RESULT=$8
djm@openbsd.org86936ec2015-01-30 01:11:39 +0000149 SERIAL_WRESULT=$9
150 KEYID_WRESULT=$10
Damien Millerebafebd2013-01-18 11:51:56 +1100151 verbose "$tid: checking revocations for $TAG"
152 for f in $FILES ; do
djm@openbsd.org86936ec2015-01-30 01:11:39 +0000153 check_krl $f $OBJ/krl-empty no "$TAG"
154 check_krl $f $OBJ/krl-keys $KEYS_RESULT "$TAG"
155 check_krl $f $OBJ/krl-all $ALL_RESULT "$TAG"
156 check_krl $f $OBJ/krl-serial $SERIAL_RESULT "$TAG"
157 check_krl $f $OBJ/krl-keyid $KEYID_RESULT "$TAG"
158 check_krl $f $OBJ/krl-cert $CERTS_RESULT "$TAG"
159 check_krl $f $OBJ/krl-ca $CA_RESULT "$TAG"
160 check_krl $f $OBJ/krl-serial-wild $SERIAL_WRESULT "$TAG"
161 check_krl $f $OBJ/krl-keyid-wild $KEYID_WRESULT "$TAG"
Damien Millerebafebd2013-01-18 11:51:56 +1100162 done
163}
djm@openbsd.org86936ec2015-01-30 01:11:39 +0000164
165test_all() {
166 # wildcard
167 # keys all sr# k.ID cert CA sr.# k.ID
168 test_rev "$RKEYS" "revoked keys" yes yes no no no no no no
169 test_rev "$UKEYS" "unrevoked keys" no no no no no no no no
170 test_rev "$RCERTS" "revoked certs" yes yes yes yes yes yes yes yes
171 test_rev "$UCERTS" "unrevoked certs" no no no no no yes no no
172}
173
174test_all
Damien Millerebafebd2013-01-18 11:51:56 +1100175
176# Check update. Results should be identical.
177verbose "$tid: testing KRL update"
178for f in $OBJ/krl-keys $OBJ/krl-cert $OBJ/krl-all \
djm@openbsd.org86936ec2015-01-30 01:11:39 +0000179 $OBJ/krl-ca $OBJ/krl-serial $OBJ/krl-keyid \
180 $OBJ/krl-serial-wild $OBJ/krl-keyid-wild; do
Damien Millerebafebd2013-01-18 11:51:56 +1100181 cp -f $OBJ/krl-empty $f
182 genkrls -u
183done
djm@openbsd.org86936ec2015-01-30 01:11:39 +0000184
185test_all