From 67f1459efd2e85bf03d032539283fa8107218936 Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Mon, 2 May 2016 09:52:00 +0000 Subject: upstream commit unit and regress tests for SHA256/512; ok markus Upstream-Regress-ID: a0cd1a92dc824067076a5fcef83c18df9b0bf2c6 --- regress/cert-userkey.sh | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'regress/cert-userkey.sh') diff --git a/regress/cert-userkey.sh b/regress/cert-userkey.sh index c38c00a02..096d9e47a 100644 --- a/regress/cert-userkey.sh +++ b/regress/cert-userkey.sh @@ -1,4 +1,4 @@ -# $OpenBSD: cert-userkey.sh,v 1.14 2015/07/10 06:23:25 markus Exp $ +# $OpenBSD: cert-userkey.sh,v 1.15 2016/05/02 09:52:00 djm Exp $ # Placed in the Public Domain. tid="certified user keys" @@ -9,9 +9,16 @@ cp $OBJ/ssh_proxy $OBJ/ssh_proxy_bak PLAIN_TYPES=`$SSH -Q key-plain | sed 's/^ssh-dss/ssh-dsa/;s/^ssh-//'` +if echo "$PLAIN_TYPES" | grep '^rsa$' >/dev/null 2>&1 ; then + PLAIN_TYPES="$PLAIN_TYPES rsa-sha2-256 rsa-sha2-512" +fi + kname() { - n=`echo "$1" | sed 's/^dsa/ssh-dss/;s/^rsa/ssh-rsa/;s/^ed/ssh-ed/'` - echo "$n*,ssh-rsa*,ssh-ed25519*" + case $ktype in + rsa-sha2-*) ;; + *) printf $1 | sed 's/^dsa/ssh-dss/;s/^rsa/ssh-rsa/;s/^ed/ssh-ed/' ;; + esac + echo "*,ssh-rsa*,ssh-ed25519*" } # Create a CA key @@ -19,18 +26,24 @@ ${SSHKEYGEN} -q -N '' -t rsa -f $OBJ/user_ca_key ||\ fail "ssh-keygen of user_ca_key failed" # Generate and sign user keys -for ktype in $PLAIN_TYPES ; do +for ktype in $PLAIN_TYPES $EXTRA_TYPES ; do verbose "$tid: sign user ${ktype} cert" ${SSHKEYGEN} -q -N '' -t ${ktype} \ -f $OBJ/cert_user_key_${ktype} || \ - fail "ssh-keygen of cert_user_key_${ktype} failed" - ${SSHKEYGEN} -q -s $OBJ/user_ca_key -I "regress user key for $USER" \ - -z $$ -n ${USER},mekmitasdigoat $OBJ/cert_user_key_${ktype} || - fail "couldn't sign cert_user_key_${ktype}" + fatal "ssh-keygen of cert_user_key_${ktype} failed" + # Generate RSA/SHA2 certs for rsa-sha2* keys. + case $ktype in + rsa-sha2-*) tflag="-t $ktype" ;; + *) tflag="" ;; + esac + ${SSHKEYGEN} -q -s $OBJ/user_ca_key -z $$ \ + -I "regress user key for $USER" \ + -n ${USER},mekmitasdigoat $tflag $OBJ/cert_user_key_${ktype} || \ + fatal "couldn't sign cert_user_key_${ktype}" done # Test explicitly-specified principals -for ktype in $PLAIN_TYPES ; do +for ktype in $EXTRA_TYPES $PLAIN_TYPES ; do t=$(kname $ktype) for privsep in yes no ; do _prefix="${ktype} privsep $privsep" @@ -67,7 +80,7 @@ for ktype in $PLAIN_TYPES ; do if [ $? -eq 0 ]; then fail "ssh cert connect succeeded unexpectedly" fi - + # Wrong authorized_principals verbose "$tid: ${_prefix} wrong authorized_principals" echo gregorsamsa > $OBJ/authorized_principals_$USER @@ -166,8 +179,8 @@ basic_tests() { echo > $OBJ/authorized_keys_$USER extra_sshd="TrustedUserCAKeys $OBJ/user_ca_key.pub" fi - - for ktype in $PLAIN_TYPES ; do + + for ktype in $PLAIN_TYPES ; do t=$(kname $ktype) for privsep in yes no ; do _prefix="${ktype} privsep $privsep $auth" @@ -183,7 +196,7 @@ basic_tests() { cat $OBJ/ssh_proxy_bak echo "PubkeyAcceptedKeyTypes ${t}" ) > $OBJ/ssh_proxy - + ${SSH} -2i $OBJ/cert_user_key_${ktype} \ -F $OBJ/ssh_proxy somehost true if [ $? -ne 0 ]; then @@ -223,7 +236,7 @@ basic_tests() { fail "ssh cert connect failed" fi done - + # Revoked CA verbose "$tid: ${ktype} $auth revoked CA key" ( @@ -238,7 +251,7 @@ basic_tests() { fail "ssh cert connect succeeded unexpecedly" fi done - + verbose "$tid: $auth CA does not authenticate" ( cat $OBJ/sshd_proxy_bak @@ -286,7 +299,7 @@ test_one() { echo $auth_opt >> $OBJ/sshd_proxy fi fi - + verbose "$tid: $ident auth $auth expect $result $ktype" ${SSHKEYGEN} -q -s $OBJ/user_ca_key \ -I "regress user key for $USER" \ @@ -342,13 +355,13 @@ test_one "principals key option no principals" failure "" \ # Wrong certificate cat $OBJ/sshd_proxy_bak > $OBJ/sshd_proxy -for ktype in $PLAIN_TYPES ; do +for ktype in $PLAIN_TYPES ; do t=$(kname $ktype) # Self-sign ${SSHKEYGEN} -q -s $OBJ/cert_user_key_${ktype} -I \ "regress user key for $USER" \ -n $USER $OBJ/cert_user_key_${ktype} || - fail "couldn't sign cert_user_key_${ktype}" + fatal "couldn't sign cert_user_key_${ktype}" verbose "$tid: user ${ktype} connect wrong cert" ${SSH} -2i $OBJ/cert_user_key_${ktype} -F $OBJ/ssh_proxy \ somehost true >/dev/null 2>&1 -- cgit v1.2.3