2023-01-16 05:11:29 +01:00
|
|
|
# $OpenBSD: krl.sh,v 1.12 2023/01/16 04:11:29 djm Exp $
|
2013-01-18 01:51:56 +01:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
tid="key revocation lists"
|
|
|
|
|
2019-07-25 11:17:35 +02:00
|
|
|
# Use ed25519 by default since it's fast and it's supported when building
|
|
|
|
# w/out OpenSSL. Populate ktype[2-4] with the other types if supported.
|
2019-11-27 00:43:10 +01:00
|
|
|
ktype1=ed25519; ktype2=ed25519; ktype3=ed25519;
|
|
|
|
ktype4=ed25519; ktype5=ed25519; ktype6=ed25519;
|
2019-12-16 03:39:05 +01:00
|
|
|
for t in $SSH_KEYTYPES; do
|
2019-07-25 11:17:35 +02:00
|
|
|
case "$t" in
|
|
|
|
ecdsa*) ktype2=ecdsa ;;
|
|
|
|
ssh-rsa) ktype3=rsa ;;
|
|
|
|
ssh-dss) ktype4=dsa ;;
|
2019-11-27 00:43:10 +01:00
|
|
|
sk-ssh-ed25519@openssh.com) ktype5=ed25519-sk ;;
|
|
|
|
sk-ecdsa-sha2-nistp256@openssh.com) ktype6=ecdsa-sk ;;
|
2019-07-25 11:17:35 +02:00
|
|
|
esac
|
|
|
|
done
|
2013-02-14 00:14:51 +01:00
|
|
|
|
2013-01-18 01:51:56 +01:00
|
|
|
# Do most testing with ssh-keygen; it uses the same verification code as sshd.
|
|
|
|
|
|
|
|
# Old keys will interfere with ssh-keygen.
|
|
|
|
rm -f $OBJ/revoked-* $OBJ/krl-*
|
|
|
|
|
|
|
|
# Generate a CA key
|
2019-07-25 11:17:35 +02:00
|
|
|
$SSHKEYGEN -t $ktype1 -f $OBJ/revoked-ca -C "" -N "" > /dev/null ||
|
2013-01-18 01:51:56 +01:00
|
|
|
fatal "$SSHKEYGEN CA failed"
|
2019-07-25 11:17:35 +02:00
|
|
|
$SSHKEYGEN -t $ktype2 -f $OBJ/revoked-ca2 -C "" -N "" > /dev/null ||
|
2014-11-17 01:21:40 +01:00
|
|
|
fatal "$SSHKEYGEN CA2 failed"
|
2013-01-18 01:51:56 +01:00
|
|
|
|
|
|
|
# A specification that revokes some certificates by serial numbers
|
|
|
|
# The serial pattern is chosen to ensure the KRL includes list, range and
|
|
|
|
# bitmap sections.
|
|
|
|
cat << EOF >> $OBJ/revoked-serials
|
|
|
|
serial: 1-4
|
|
|
|
serial: 10
|
|
|
|
serial: 15
|
|
|
|
serial: 30
|
|
|
|
serial: 50
|
2019-11-27 00:43:10 +01:00
|
|
|
serial: 90
|
2013-01-18 01:51:56 +01:00
|
|
|
serial: 999
|
|
|
|
# The following sum to 500-799
|
|
|
|
serial: 500
|
|
|
|
serial: 501
|
|
|
|
serial: 502
|
|
|
|
serial: 503-600
|
|
|
|
serial: 700-797
|
|
|
|
serial: 798
|
|
|
|
serial: 799
|
|
|
|
serial: 599-701
|
2014-07-02 09:02:03 +02:00
|
|
|
# Some multiple consecutive serial number ranges
|
|
|
|
serial: 10000-20000
|
|
|
|
serial: 30000-40000
|
2013-01-18 01:51:56 +01:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# A specification that revokes some certificated by key ID.
|
|
|
|
touch $OBJ/revoked-keyid
|
2019-11-27 00:43:10 +01:00
|
|
|
for n in 1 2 3 4 10 15 30 50 90 `jot 500 300` 999 1000 1001 1002; do
|
2015-01-19 18:31:13 +01:00
|
|
|
test "x$n" = "x499" && continue
|
2013-01-18 01:51:56 +01:00
|
|
|
# Fill in by-ID revocation spec.
|
|
|
|
echo "id: revoked $n" >> $OBJ/revoked-keyid
|
|
|
|
done
|
|
|
|
|
|
|
|
keygen() {
|
|
|
|
N=$1
|
|
|
|
f=$OBJ/revoked-`printf "%04d" $N`
|
2019-07-25 11:17:35 +02:00
|
|
|
# Vary the keytype. We use mostly ed25519 since this is fast and well
|
|
|
|
# supported.
|
|
|
|
keytype=$ktype1
|
2013-01-18 01:51:56 +01:00
|
|
|
case $N in
|
2019-11-27 00:43:10 +01:00
|
|
|
2 | 10 | 510 | 1001) keytype=$ktype2 ;;
|
|
|
|
4 | 30 | 520 | 1002) keytype=$ktype3 ;;
|
|
|
|
8 | 50 | 530 | 1003) keytype=$ktype4 ;;
|
|
|
|
16 | 70 | 540 | 1004) keytype=$ktype5 ;;
|
|
|
|
32 | 90 | 550 | 1005) keytype=$ktype6 ;;
|
2013-01-18 01:51:56 +01:00
|
|
|
esac
|
|
|
|
$SSHKEYGEN -t $keytype -f $f -C "" -N "" > /dev/null \
|
|
|
|
|| fatal "$SSHKEYGEN failed"
|
|
|
|
# Sign cert
|
|
|
|
$SSHKEYGEN -s $OBJ/revoked-ca -z $n -I "revoked $N" $f >/dev/null 2>&1 \
|
|
|
|
|| fatal "$SSHKEYGEN sign failed"
|
|
|
|
echo $f
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate some keys.
|
|
|
|
verbose "$tid: generating test keys"
|
2019-11-27 00:43:10 +01:00
|
|
|
REVOKED_SERIALS="1 4 10 50 90 500 510 520 550 799 999"
|
2013-01-18 01:51:56 +01:00
|
|
|
for n in $REVOKED_SERIALS ; do
|
|
|
|
f=`keygen $n`
|
2015-01-30 02:11:39 +01:00
|
|
|
RKEYS="$RKEYS ${f}.pub"
|
|
|
|
RCERTS="$RCERTS ${f}-cert.pub"
|
2013-01-18 01:51:56 +01:00
|
|
|
done
|
2015-01-19 18:31:13 +01:00
|
|
|
UNREVOKED_SERIALS="5 9 14 16 29 49 51 499 800 1010 1011"
|
|
|
|
UNREVOKED=""
|
|
|
|
for n in $UNREVOKED_SERIALS ; do
|
|
|
|
f=`keygen $n`
|
2015-01-30 02:11:39 +01:00
|
|
|
UKEYS="$UKEYS ${f}.pub"
|
|
|
|
UCERTS="$UCERTS ${f}-cert.pub"
|
2013-01-18 01:51:56 +01:00
|
|
|
done
|
|
|
|
|
2018-09-12 03:23:48 +02:00
|
|
|
# Specifications that revoke keys by hash.
|
|
|
|
touch $OBJ/revoked-sha1 $OBJ/revoked-sha256 $OBJ/revoked-hash
|
|
|
|
for rkey in $RKEYS; do
|
|
|
|
(printf "sha1: "; cat $rkey) >> $OBJ/revoked-sha1
|
|
|
|
(printf "sha256: "; cat $rkey) >> $OBJ/revoked-sha256
|
|
|
|
(printf "hash: "; $SSHKEYGEN -lf $rkey | \
|
|
|
|
awk '{ print $2 }') >> $OBJ/revoked-hash
|
|
|
|
done
|
|
|
|
|
2013-01-18 01:51:56 +01:00
|
|
|
genkrls() {
|
|
|
|
OPTS=$1
|
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-empty - </dev/null \
|
|
|
|
>/dev/null || fatal "$SSHKEYGEN KRL failed"
|
2015-01-30 02:11:39 +01:00
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-keys $RKEYS \
|
2013-01-18 01:51:56 +01:00
|
|
|
>/dev/null || fatal "$SSHKEYGEN KRL failed"
|
2015-01-30 02:11:39 +01:00
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-cert $RCERTS \
|
2013-01-18 01:51:56 +01:00
|
|
|
>/dev/null || fatal "$SSHKEYGEN KRL failed"
|
2015-01-30 02:11:39 +01:00
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-all $RKEYS $RCERTS \
|
2013-01-18 01:51:56 +01:00
|
|
|
>/dev/null || fatal "$SSHKEYGEN KRL failed"
|
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-ca $OBJ/revoked-ca.pub \
|
|
|
|
>/dev/null || fatal "$SSHKEYGEN KRL failed"
|
2018-09-12 03:23:48 +02:00
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-sha1 $OBJ/revoked-sha1 \
|
|
|
|
>/dev/null 2>&1 || fatal "$SSHKEYGEN KRL failed"
|
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-sha256 $OBJ/revoked-sha256 \
|
|
|
|
>/dev/null 2>&1 || fatal "$SSHKEYGEN KRL failed"
|
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-hash $OBJ/revoked-hash \
|
|
|
|
>/dev/null 2>&1 || fatal "$SSHKEYGEN KRL failed"
|
2014-11-17 01:21:40 +01:00
|
|
|
# This should fail as KRLs from serial/key-id spec need the CA specified.
|
2013-01-18 01:51:56 +01:00
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-serial $OBJ/revoked-serials \
|
|
|
|
>/dev/null 2>&1 && fatal "$SSHKEYGEN KRL succeeded unexpectedly"
|
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-keyid $OBJ/revoked-keyid \
|
|
|
|
>/dev/null 2>&1 && fatal "$SSHKEYGEN KRL succeeded unexpectedly"
|
2015-01-30 02:11:39 +01:00
|
|
|
# These should succeed; they specify an explicit CA key.
|
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-serial -s $OBJ/revoked-ca \
|
|
|
|
$OBJ/revoked-serials >/dev/null || fatal "$SSHKEYGEN KRL failed"
|
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-keyid -s $OBJ/revoked-ca.pub \
|
|
|
|
$OBJ/revoked-keyid >/dev/null || fatal "$SSHKEYGEN KRL failed"
|
|
|
|
# These should succeed; they specify an wildcard CA key.
|
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-serial-wild -s NONE $OBJ/revoked-serials \
|
|
|
|
>/dev/null || fatal "$SSHKEYGEN KRL failed"
|
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-keyid-wild -s NONE $OBJ/revoked-keyid \
|
2013-01-18 01:51:56 +01:00
|
|
|
>/dev/null || fatal "$SSHKEYGEN KRL failed"
|
2014-11-17 01:21:40 +01:00
|
|
|
# Revoke the same serials with the second CA key to ensure a multi-CA
|
|
|
|
# KRL is generated.
|
|
|
|
$SSHKEYGEN $OPTS -kf $OBJ/krl-serial -u -s $OBJ/revoked-ca2 \
|
|
|
|
$OBJ/revoked-serials >/dev/null || fatal "$SSHKEYGEN KRL failed"
|
2013-01-18 01:51:56 +01:00
|
|
|
}
|
|
|
|
|
2013-11-21 04:24:42 +01:00
|
|
|
## XXX dump with trace and grep for set cert serials
|
|
|
|
## XXX test ranges near (u64)-1, etc.
|
|
|
|
|
2013-01-18 01:51:56 +01:00
|
|
|
verbose "$tid: generating KRLs"
|
|
|
|
genkrls
|
|
|
|
|
|
|
|
check_krl() {
|
|
|
|
KEY=$1
|
|
|
|
KRL=$2
|
|
|
|
EXPECT_REVOKED=$3
|
|
|
|
TAG=$4
|
|
|
|
$SSHKEYGEN -Qf $KRL $KEY >/dev/null
|
|
|
|
result=$?
|
2018-09-12 03:23:48 +02:00
|
|
|
if test "x$EXPECT_REVOKED" = "xy" -a $result -eq 0 ; then
|
2013-01-18 01:51:56 +01:00
|
|
|
fatal "key $KEY not revoked by KRL $KRL: $TAG"
|
2018-09-12 03:23:48 +02:00
|
|
|
elif test "x$EXPECT_REVOKED" = "xn" -a $result -ne 0 ; then
|
2013-01-18 01:51:56 +01:00
|
|
|
fatal "key $KEY unexpectedly revoked by KRL $KRL: $TAG"
|
|
|
|
fi
|
|
|
|
}
|
2015-01-30 02:11:39 +01:00
|
|
|
test_rev() {
|
2013-01-18 01:51:56 +01:00
|
|
|
FILES=$1
|
|
|
|
TAG=$2
|
|
|
|
KEYS_RESULT=$3
|
|
|
|
ALL_RESULT=$4
|
2018-09-12 03:23:48 +02:00
|
|
|
HASH_RESULT=$5
|
|
|
|
SERIAL_RESULT=$6
|
|
|
|
KEYID_RESULT=$7
|
|
|
|
CERTS_RESULT=$8
|
|
|
|
CA_RESULT=$9
|
2023-01-16 05:11:29 +01:00
|
|
|
SERIAL_WRESULT=${10}
|
|
|
|
KEYID_WRESULT=${11}
|
2013-01-18 01:51:56 +01:00
|
|
|
verbose "$tid: checking revocations for $TAG"
|
|
|
|
for f in $FILES ; do
|
2015-01-30 02:11:39 +01:00
|
|
|
check_krl $f $OBJ/krl-empty no "$TAG"
|
|
|
|
check_krl $f $OBJ/krl-keys $KEYS_RESULT "$TAG"
|
|
|
|
check_krl $f $OBJ/krl-all $ALL_RESULT "$TAG"
|
2018-09-12 03:23:48 +02:00
|
|
|
check_krl $f $OBJ/krl-sha1 $HASH_RESULT "$TAG"
|
|
|
|
check_krl $f $OBJ/krl-sha256 $HASH_RESULT "$TAG"
|
|
|
|
check_krl $f $OBJ/krl-hash $HASH_RESULT "$TAG"
|
2015-01-30 02:11:39 +01:00
|
|
|
check_krl $f $OBJ/krl-serial $SERIAL_RESULT "$TAG"
|
|
|
|
check_krl $f $OBJ/krl-keyid $KEYID_RESULT "$TAG"
|
|
|
|
check_krl $f $OBJ/krl-cert $CERTS_RESULT "$TAG"
|
|
|
|
check_krl $f $OBJ/krl-ca $CA_RESULT "$TAG"
|
|
|
|
check_krl $f $OBJ/krl-serial-wild $SERIAL_WRESULT "$TAG"
|
|
|
|
check_krl $f $OBJ/krl-keyid-wild $KEYID_WRESULT "$TAG"
|
2013-01-18 01:51:56 +01:00
|
|
|
done
|
|
|
|
}
|
2015-01-30 02:11:39 +01:00
|
|
|
|
|
|
|
test_all() {
|
2018-09-12 03:23:48 +02:00
|
|
|
# wildcard
|
|
|
|
# keys all hash sr# ID cert CA srl ID
|
|
|
|
test_rev "$RKEYS" "revoked keys" y y y n n n n n n
|
|
|
|
test_rev "$UKEYS" "unrevoked keys" n n n n n n n n n
|
|
|
|
test_rev "$RCERTS" "revoked certs" y y y y y y y y y
|
|
|
|
test_rev "$UCERTS" "unrevoked certs" n n n n n n y n n
|
2015-01-30 02:11:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
test_all
|
2013-01-18 01:51:56 +01:00
|
|
|
|
|
|
|
# Check update. Results should be identical.
|
|
|
|
verbose "$tid: testing KRL update"
|
|
|
|
for f in $OBJ/krl-keys $OBJ/krl-cert $OBJ/krl-all \
|
2015-01-30 02:11:39 +01:00
|
|
|
$OBJ/krl-ca $OBJ/krl-serial $OBJ/krl-keyid \
|
|
|
|
$OBJ/krl-serial-wild $OBJ/krl-keyid-wild; do
|
2013-01-18 01:51:56 +01:00
|
|
|
cp -f $OBJ/krl-empty $f
|
|
|
|
genkrls -u
|
|
|
|
done
|
2015-01-30 02:11:39 +01:00
|
|
|
|
|
|
|
test_all
|