aboutsummaryrefslogtreecommitdiff
path: root/crypto/openssh/regress/cert-hostkey.sh
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssh/regress/cert-hostkey.sh')
-rw-r--r--[-rwxr-xr-x]crypto/openssh/regress/cert-hostkey.sh116
1 files changed, 60 insertions, 56 deletions
diff --git a/crypto/openssh/regress/cert-hostkey.sh b/crypto/openssh/regress/cert-hostkey.sh
index d2ecd318beae..a3414e1a5c50 100755..100644
--- a/crypto/openssh/regress/cert-hostkey.sh
+++ b/crypto/openssh/regress/cert-hostkey.sh
@@ -1,4 +1,4 @@
-# $OpenBSD: cert-hostkey.sh,v 1.16 2018/07/03 11:43:49 djm Exp $
+# $OpenBSD: cert-hostkey.sh,v 1.27 2021/09/30 05:26:26 dtucker Exp $
# Placed in the Public Domain.
tid="certified host keys"
@@ -7,8 +7,9 @@ rm -f $OBJ/known_hosts-cert* $OBJ/host_ca_key* $OBJ/host_revoked_*
rm -f $OBJ/cert_host_key* $OBJ/host_krl_*
# Allow all hostkey/pubkey types, prefer certs for the client
+rsa=0
types=""
-for i in `$SSH -Q key`; do
+for i in `$SSH -Q key | maybe_filter_sk`; do
if [ -z "$types" ]; then
types="$i"
continue
@@ -19,6 +20,7 @@ for i in `$SSH -Q key`; do
types="rsa-sha2-256-cert-v01@openssh.com,$i,$types"
types="rsa-sha2-512-cert-v01@openssh.com,$types";;
*rsa*)
+ rsa=1
types="$types,rsa-sha2-512,rsa-sha2-256,$i";;
# Prefer certificate to plain keys.
*cert*) types="$i,$types";;
@@ -27,12 +29,12 @@ for i in `$SSH -Q key`; do
done
(
echo "HostKeyAlgorithms ${types}"
- echo "PubkeyAcceptedKeyTypes *"
+ echo "PubkeyAcceptedAlgorithms *"
) >> $OBJ/ssh_proxy
cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
(
echo "HostKeyAlgorithms *"
- echo "PubkeyAcceptedKeyTypes *"
+ echo "PubkeyAcceptedAlgorithms *"
) >> $OBJ/sshd_proxy_bak
HOSTS='localhost-with-alias,127.0.0.1,::1'
@@ -51,10 +53,12 @@ kh_revoke() {
}
# Create a CA key and add it to known hosts. Ed25519 chosen for speed.
-# RSA for testing RSA/SHA2 signatures.
+# RSA for testing RSA/SHA2 signatures if supported.
+ktype2=ed25519
+[ "x$rsa" = "x1" ] && ktype2=rsa
${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/host_ca_key ||\
fail "ssh-keygen of host_ca_key failed"
-${SSHKEYGEN} -q -N '' -t rsa -f $OBJ/host_ca_key2 ||\
+${SSHKEYGEN} -q -N '' -t $ktype2 -f $OBJ/host_ca_key2 ||\
fail "ssh-keygen of host_ca_key failed"
kh_ca host_ca_key.pub host_ca_key2.pub > $OBJ/known_hosts-cert.orig
@@ -66,7 +70,7 @@ touch $OBJ/host_revoked_plain
touch $OBJ/host_revoked_cert
cat $OBJ/host_ca_key.pub $OBJ/host_ca_key2.pub > $OBJ/host_revoked_ca
-PLAIN_TYPES=`$SSH -Q key-plain | sed 's/^ssh-dss/ssh-dsa/g;s/^ssh-//'`
+PLAIN_TYPES=`echo "$SSH_KEYTYPES" | sed 's/^ssh-dss/ssh-dsa/g;s/^ssh-//'`
if echo "$PLAIN_TYPES" | grep '^rsa$' >/dev/null 2>&1 ; then
PLAIN_TYPES="$PLAIN_TYPES rsa-sha2-256 rsa-sha2-512"
@@ -127,35 +131,32 @@ attempt_connect() {
}
# Basic connect and revocation tests.
-for privsep in yes no ; do
- for ktype in $PLAIN_TYPES ; do
- verbose "$tid: host ${ktype} cert connect privsep $privsep"
- (
- cat $OBJ/sshd_proxy_bak
- echo HostKey $OBJ/cert_host_key_${ktype}
- echo HostCertificate $OBJ/cert_host_key_${ktype}-cert.pub
- echo UsePrivilegeSeparation $privsep
- ) > $OBJ/sshd_proxy
+for ktype in $PLAIN_TYPES ; do
+ verbose "$tid: host ${ktype} cert connect"
+ (
+ cat $OBJ/sshd_proxy_bak
+ echo HostKey $OBJ/cert_host_key_${ktype}
+ echo HostCertificate $OBJ/cert_host_key_${ktype}-cert.pub
+ ) > $OBJ/sshd_proxy
- # test name expect success
- attempt_connect "$ktype basic connect" "yes"
- attempt_connect "$ktype empty KRL" "yes" \
- -oRevokedHostKeys=$OBJ/host_krl_empty
- attempt_connect "$ktype KRL w/ plain key revoked" "no" \
- -oRevokedHostKeys=$OBJ/host_krl_plain
- attempt_connect "$ktype KRL w/ cert revoked" "no" \
- -oRevokedHostKeys=$OBJ/host_krl_cert
- attempt_connect "$ktype KRL w/ CA revoked" "no" \
- -oRevokedHostKeys=$OBJ/host_krl_ca
- attempt_connect "$ktype empty plaintext revocation" "yes" \
- -oRevokedHostKeys=$OBJ/host_revoked_empty
- attempt_connect "$ktype plain key plaintext revocation" "no" \
- -oRevokedHostKeys=$OBJ/host_revoked_plain
- attempt_connect "$ktype cert plaintext revocation" "no" \
- -oRevokedHostKeys=$OBJ/host_revoked_cert
- attempt_connect "$ktype CA plaintext revocation" "no" \
- -oRevokedHostKeys=$OBJ/host_revoked_ca
- done
+ # test name expect success
+ attempt_connect "$ktype basic connect" "yes"
+ attempt_connect "$ktype empty KRL" "yes" \
+ -oRevokedHostKeys=$OBJ/host_krl_empty
+ attempt_connect "$ktype KRL w/ plain key revoked" "no" \
+ -oRevokedHostKeys=$OBJ/host_krl_plain
+ attempt_connect "$ktype KRL w/ cert revoked" "no" \
+ -oRevokedHostKeys=$OBJ/host_krl_cert
+ attempt_connect "$ktype KRL w/ CA revoked" "no" \
+ -oRevokedHostKeys=$OBJ/host_krl_ca
+ attempt_connect "$ktype empty plaintext revocation" "yes" \
+ -oRevokedHostKeys=$OBJ/host_revoked_empty
+ attempt_connect "$ktype plain key plaintext revocation" "no" \
+ -oRevokedHostKeys=$OBJ/host_revoked_plain
+ attempt_connect "$ktype cert plaintext revocation" "no" \
+ -oRevokedHostKeys=$OBJ/host_revoked_cert
+ attempt_connect "$ktype CA plaintext revocation" "no" \
+ -oRevokedHostKeys=$OBJ/host_revoked_ca
done
# Revoked certificates with key present
@@ -165,24 +166,21 @@ for ktype in $PLAIN_TYPES ; do
kh_revoke cert_host_key_${ktype}.pub >> $OBJ/known_hosts-cert.orig
done
cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
-for privsep in yes no ; do
- for ktype in $PLAIN_TYPES ; do
- verbose "$tid: host ${ktype} revoked cert privsep $privsep"
- (
- cat $OBJ/sshd_proxy_bak
- echo HostKey $OBJ/cert_host_key_${ktype}
- echo HostCertificate $OBJ/cert_host_key_${ktype}-cert.pub
- echo UsePrivilegeSeparation $privsep
- ) > $OBJ/sshd_proxy
+for ktype in $PLAIN_TYPES ; do
+ verbose "$tid: host ${ktype} revoked cert"
+ (
+ cat $OBJ/sshd_proxy_bak
+ echo HostKey $OBJ/cert_host_key_${ktype}
+ echo HostCertificate $OBJ/cert_host_key_${ktype}-cert.pub
+ ) > $OBJ/sshd_proxy
- cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
- ${SSH} -oUserKnownHostsFile=$OBJ/known_hosts-cert \
- -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
- -F $OBJ/ssh_proxy somehost true >/dev/null 2>&1
- if [ $? -eq 0 ]; then
- fail "ssh cert connect succeeded unexpectedly"
- fi
- done
+ cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
+ ${SSH} -oUserKnownHostsFile=$OBJ/known_hosts-cert \
+ -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
+ -F $OBJ/ssh_proxy somehost true >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ fail "ssh cert connect succeeded unexpectedly"
+ fi
done
# Revoked CA
@@ -214,7 +212,7 @@ test_one() {
result=$2
sign_opts=$3
- for kt in rsa ed25519 ; do
+ for kt in $PLAIN_TYPES; do
case $ktype in
rsa-sha2-*) tflag="-t $ktype"; ca="$OBJ/host_ca_key2" ;;
*) tflag=""; ca="$OBJ/host_ca_key" ;;
@@ -248,7 +246,7 @@ test_one() {
test_one "user-certificate" failure "-n $HOSTS"
test_one "empty principals" success "-h"
test_one "wrong principals" failure "-h -n foo"
-test_one "cert not yet valid" failure "-h -V20200101:20300101"
+test_one "cert not yet valid" failure "-h -V20300101:20320101"
test_one "cert expired" failure "-h -V19800101:19900101"
test_one "cert valid interval" success "-h -V-1w:+2w"
test_one "cert has constraints" failure "-h -Oforce-command=false"
@@ -279,11 +277,17 @@ for ktype in $PLAIN_TYPES ; do
) > $OBJ/sshd_proxy
${SSH} -oUserKnownHostsFile=$OBJ/known_hosts-cert \
- -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
- -F $OBJ/ssh_proxy somehost true
+ -oGlobalKnownHostsFile=none -F $OBJ/ssh_proxy somehost true
if [ $? -ne 0 ]; then
fail "ssh cert connect failed"
fi
+ # Also check that it works when the known_hosts file is not in the
+ # first array position.
+ ${SSH} -oUserKnownHostsFile="/dev/null $OBJ/known_hosts-cert" \
+ -oGlobalKnownHostsFile=none -F $OBJ/ssh_proxy somehost true
+ if [ $? -ne 0 ]; then
+ fail "ssh cert connect failed known_hosts 2nd"
+ fi
done
# Wrong certificate