1# $OpenBSD: keytype.sh,v 1.7 2018/03/12 00:54:04 djm Exp $ 2# Placed in the Public Domain. 3 4tid="login with different key types" 5 6cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak 7cp $OBJ/ssh_proxy $OBJ/ssh_proxy_bak 8 9# Traditional and builtin key types. 10ktypes="dsa-1024 rsa-2048 rsa-3072 ed25519-512" 11# Types not present in all OpenSSL versions. 12for i in `$SSH -Q key`; do 13 case "$i" in 14 ecdsa-sha2-nistp256) ktypes="$ktypes ecdsa-256" ;; 15 ecdsa-sha2-nistp384) ktypes="$ktypes ecdsa-384" ;; 16 ecdsa-sha2-nistp521) ktypes="$ktypes ecdsa-521" ;; 17 esac 18done 19 20for kt in $ktypes; do 21 rm -f $OBJ/key.$kt 22 bits=`echo ${kt} | awk -F- '{print $2}'` 23 type=`echo ${kt} | awk -F- '{print $1}'` 24 verbose "keygen $type, $bits bits" 25 ${SSHKEYGEN} -b $bits -q -N '' -t $type -f $OBJ/key.$kt ||\ 26 fail "ssh-keygen for type $type, $bits bits failed" 27done 28 29tries="1 2 3" 30for ut in $ktypes; do 31 htypes=$ut 32 #htypes=$ktypes 33 for ht in $htypes; do 34 case $ht in 35 dsa-1024) t=ssh-dss;; 36 ecdsa-256) t=ecdsa-sha2-nistp256;; 37 ecdsa-384) t=ecdsa-sha2-nistp384;; 38 ecdsa-521) t=ecdsa-sha2-nistp521;; 39 ed25519-512) t=ssh-ed25519;; 40 rsa-*) t=rsa-sha2-512,rsa-sha2-256,ssh-rsa;; 41 esac 42 trace "ssh connect, userkey $ut, hostkey $ht" 43 ( 44 grep -v HostKey $OBJ/sshd_proxy_bak 45 echo HostKey $OBJ/key.$ht 46 echo PubkeyAcceptedKeyTypes $t 47 echo HostKeyAlgorithms $t 48 ) > $OBJ/sshd_proxy 49 ( 50 grep -v IdentityFile $OBJ/ssh_proxy_bak 51 echo IdentityFile $OBJ/key.$ut 52 echo PubkeyAcceptedKeyTypes $t 53 echo HostKeyAlgorithms $t 54 ) > $OBJ/ssh_proxy 55 ( 56 printf 'localhost-with-alias,127.0.0.1,::1 ' 57 cat $OBJ/key.$ht.pub 58 ) > $OBJ/known_hosts 59 cat $OBJ/key.$ut.pub > $OBJ/authorized_keys_$USER 60 for i in $tries; do 61 verbose "userkey $ut, hostkey ${ht}" 62 ${SSH} -F $OBJ/ssh_proxy 999.999.999.999 true 63 if [ $? -ne 0 ]; then 64 fail "ssh userkey $ut, hostkey $ht failed" 65 fi 66 done 67 done 68done 69