summaryrefslogtreecommitdiff
path: root/regress/limit-keytype.sh
diff options
context:
space:
mode:
authordtucker@openbsd.org <dtucker@openbsd.org>2019-07-26 04:22:21 +0000
committerDarren Tucker <dtucker@dtucker.net>2019-07-26 14:51:25 +1000
commitd31e7c937ba0b97534f373cf5dea34675bcec602 (patch)
treecc0d31a08bebcc92657d8abe7a949f3ca8d86eb8 /regress/limit-keytype.sh
parent0967a233b8a28907ae8a4a6773c89f21d2ace11b (diff)
upstream: Restrict limit-keytype to types supported by build. This
means we have to skip a couple tests when only one key type is supported. OpenBSD-Regress-ID: 22d05befb9c7ce21ce8dc22acf1ffe9e2ef2e95e
Diffstat (limited to 'regress/limit-keytype.sh')
-rw-r--r--regress/limit-keytype.sh56
1 files changed, 40 insertions, 16 deletions
diff --git a/regress/limit-keytype.sh b/regress/limit-keytype.sh
index 04f11977e..5c30af006 100644
--- a/regress/limit-keytype.sh
+++ b/regress/limit-keytype.sh
@@ -1,4 +1,4 @@
1# $OpenBSD: limit-keytype.sh,v 1.5 2018/03/12 00:52:57 djm Exp $ 1# $OpenBSD: limit-keytype.sh,v 1.6 2019/07/26 04:22:21 dtucker Exp $
2# Placed in the Public Domain. 2# Placed in the Public Domain.
3 3
4tid="restrict pubkey type" 4tid="restrict pubkey type"
@@ -9,18 +9,27 @@ rm -f $OBJ/authorized_principals_$USER $OBJ/cert_user_key*
9mv $OBJ/sshd_proxy $OBJ/sshd_proxy.orig 9mv $OBJ/sshd_proxy $OBJ/sshd_proxy.orig
10mv $OBJ/ssh_proxy $OBJ/ssh_proxy.orig 10mv $OBJ/ssh_proxy $OBJ/ssh_proxy.orig
11 11
12ktype1=ed25519; ktype2=$ktype1; ktype3=$ktype1; ktype4=$ktype1
13for t in `${SSH} -Q key-plain`; do
14 case "$t" in
15 ssh-rsa) ktype2=rsa ;;
16 ecdsa*) ktype3=ecdsa ;; # unused
17 ssh-dss) ktype4=dsa ;;
18 esac
19done
20
12# Create a CA key 21# Create a CA key
13${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/user_ca_key ||\ 22${SSHKEYGEN} -q -N '' -t $ktype1 -f $OBJ/user_ca_key ||\
14 fatal "ssh-keygen failed" 23 fatal "ssh-keygen failed"
15 24
16# Make some keys and a certificate. 25# Make some keys and a certificate.
17${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/user_key1 || \ 26${SSHKEYGEN} -q -N '' -t $ktype1 -f $OBJ/user_key1 || \
18 fatal "ssh-keygen failed" 27 fatal "ssh-keygen failed"
19${SSHKEYGEN} -q -N '' -t rsa -f $OBJ/user_key2 || \ 28${SSHKEYGEN} -q -N '' -t $ktype2 -f $OBJ/user_key2 || \
20 fatal "ssh-keygen failed" 29 fatal "ssh-keygen failed"
21${SSHKEYGEN} -q -N '' -t rsa -f $OBJ/user_key3 || \ 30${SSHKEYGEN} -q -N '' -t $ktype2 -f $OBJ/user_key3 || \
22 fatal "ssh-keygen failed" 31 fatal "ssh-keygen failed"
23${SSHKEYGEN} -q -N '' -t dsa -f $OBJ/user_key4 || \ 32${SSHKEYGEN} -q -N '' -t $ktype4 -f $OBJ/user_key4 || \
24 fatal "ssh-keygen failed" 33 fatal "ssh-keygen failed"
25${SSHKEYGEN} -q -s $OBJ/user_ca_key -I "regress user key for $USER" \ 34${SSHKEYGEN} -q -s $OBJ/user_ca_key -I "regress user key for $USER" \
26 -z $$ -n ${USER},mekmitasdigoat $OBJ/user_key3 || 35 -z $$ -n ${USER},mekmitasdigoat $OBJ/user_key3 ||
@@ -51,6 +60,17 @@ prepare_config() {
51 ) > $OBJ/sshd_proxy 60 ) > $OBJ/sshd_proxy
52} 61}
53 62
63# Return the required parameter for PubkeyAcceptedKeyTypes corresponding to
64# the supplied key type.
65keytype() {
66 case "$1" in
67 ecdsa) printf "ecdsa-sha2-*" ;;
68 ed25519) printf "ssh-ed25519" ;;
69 dsa) printf "ssh-dss" ;;
70 rsa) printf "rsa-sha2-256,rsa-sha2-512,ssh-rsa" ;;
71 esac
72}
73
54prepare_config 74prepare_config
55 75
56# Check we can log in with all key types. 76# Check we can log in with all key types.
@@ -59,19 +79,21 @@ ${SSH} $opts -i $OBJ/user_key1 proxy true || fatal "key1 failed"
59${SSH} $opts -i $OBJ/user_key2 proxy true || fatal "key2 failed" 79${SSH} $opts -i $OBJ/user_key2 proxy true || fatal "key2 failed"
60 80
61# Allow plain Ed25519 and RSA. The certificate should fail. 81# Allow plain Ed25519 and RSA. The certificate should fail.
62verbose "allow rsa,ed25519" 82verbose "allow $ktype2,$ktype1"
63prepare_config \ 83prepare_config \
64 "PubkeyAcceptedKeyTypes rsa-sha2-256,rsa-sha2-512,ssh-rsa,ssh-ed25519" 84 "PubkeyAcceptedKeyTypes `keytype $ktype2`,`keytype $ktype1`"
65${SSH} $certopts proxy true && fatal "cert succeeded" 85${SSH} $certopts proxy true && fatal "cert succeeded"
66${SSH} $opts -i $OBJ/user_key1 proxy true || fatal "key1 failed" 86${SSH} $opts -i $OBJ/user_key1 proxy true || fatal "key1 failed"
67${SSH} $opts -i $OBJ/user_key2 proxy true || fatal "key2 failed" 87${SSH} $opts -i $OBJ/user_key2 proxy true || fatal "key2 failed"
68 88
69# Allow Ed25519 only. 89# Allow Ed25519 only.
70verbose "allow ed25519" 90verbose "allow $ktype1"
71prepare_config "PubkeyAcceptedKeyTypes ssh-ed25519" 91prepare_config "PubkeyAcceptedKeyTypes `keytype $ktype1`"
72${SSH} $certopts proxy true && fatal "cert succeeded" 92${SSH} $certopts proxy true && fatal "cert succeeded"
73${SSH} $opts -i $OBJ/user_key1 proxy true || fatal "key1 failed" 93${SSH} $opts -i $OBJ/user_key1 proxy true || fatal "key1 failed"
74${SSH} $opts -i $OBJ/user_key2 proxy true && fatal "key2 succeeded" 94if [ "$ktype1" != "$ktype2" ]; then
95 ${SSH} $opts -i $OBJ/user_key2 proxy true && fatal "key2 succeeded"
96fi
75 97
76# Allow all certs. Plain keys should fail. 98# Allow all certs. Plain keys should fail.
77verbose "allow cert only" 99verbose "allow cert only"
@@ -82,16 +104,18 @@ ${SSH} $opts -i $OBJ/user_key2 proxy true && fatal "key2 succeeded"
82 104
83# Allow RSA in main config, Ed25519 for non-existent user. 105# Allow RSA in main config, Ed25519 for non-existent user.
84verbose "match w/ no match" 106verbose "match w/ no match"
85prepare_config "PubkeyAcceptedKeyTypes rsa-sha2-256,rsa-sha2-512,ssh-rsa" \ 107prepare_config "PubkeyAcceptedKeyTypes `keytype $ktype2`" \
86 "Match user x$USER" "PubkeyAcceptedKeyTypes +ssh-ed25519" 108 "Match user x$USER" "PubkeyAcceptedKeyTypes +`keytype $ktype1`"
87${SSH} $certopts proxy true && fatal "cert succeeded" 109${SSH} $certopts proxy true && fatal "cert succeeded"
88${SSH} $opts -i $OBJ/user_key1 proxy true && fatal "key1 succeeded" 110if [ "$ktype1" != "$ktype2" ]; then
111 ${SSH} $opts -i $OBJ/user_key1 proxy true && fatal "key1 succeeded"
112fi
89${SSH} $opts -i $OBJ/user_key2 proxy true || fatal "key2 failed" 113${SSH} $opts -i $OBJ/user_key2 proxy true || fatal "key2 failed"
90 114
91# Allow only DSA in main config, Ed25519 for user. 115# Allow only DSA in main config, Ed25519 for user.
92verbose "match w/ matching" 116verbose "match w/ matching"
93prepare_config "PubkeyAcceptedKeyTypes ssh-dss" \ 117prepare_config "PubkeyAcceptedKeyTypes `keytype $ktype4`" \
94 "Match user $USER" "PubkeyAcceptedKeyTypes +ssh-ed25519" 118 "Match user $USER" "PubkeyAcceptedKeyTypes +`keytype $ktype1`"
95${SSH} $certopts proxy true || fatal "cert failed" 119${SSH} $certopts proxy true || fatal "cert failed"
96${SSH} $opts -i $OBJ/user_key1 proxy true || fatal "key1 failed" 120${SSH} $opts -i $OBJ/user_key1 proxy true || fatal "key1 failed"
97${SSH} $opts -i $OBJ/user_key4 proxy true && fatal "key4 succeeded" 121${SSH} $opts -i $OBJ/user_key4 proxy true && fatal "key4 succeeded"