1# $OpenBSD: keytype.sh,v 1.11 2021/02/25 03:27:34 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# Construct list of key types based on what the built binaries support. 10ktypes="" 11for i in ${SSH_KEYTYPES}; do 12 case "$i" in 13 ssh-dss) ktypes="$ktypes dsa-1024" ;; 14 ssh-rsa) ktypes="$ktypes rsa-2048 rsa-3072" ;; 15 ssh-ed25519) ktypes="$ktypes ed25519-512" ;; 16 ecdsa-sha2-nistp256) ktypes="$ktypes ecdsa-256" ;; 17 ecdsa-sha2-nistp384) ktypes="$ktypes ecdsa-384" ;; 18 ecdsa-sha2-nistp521) ktypes="$ktypes ecdsa-521" ;; 19 sk-ssh-ed25519*) ktypes="$ktypes ed25519-sk" ;; 20 sk-ecdsa-sha2-nistp256*) ktypes="$ktypes ecdsa-sk" ;; 21 esac 22done 23 24for kt in $ktypes; do 25 rm -f $OBJ/key.$kt 26 case "$kt" in 27 *sk) type="$kt"; bits="n/a"; bits_arg="";; 28 *) type=${kt%-*}; bits=${kt#*-}; bits_arg="-b $bits";; 29 esac 30 verbose "keygen $type, $bits bits" 31 ${SSHKEYGEN} $bits_arg -q -N '' -t $type -f $OBJ/key.$kt || \ 32 fail "ssh-keygen for type $type, $bits bits failed" 33done 34 35kname_to_ktype() { 36 case $1 in 37 dsa-1024) echo ssh-dss;; 38 ecdsa-256) echo ecdsa-sha2-nistp256;; 39 ecdsa-384) echo ecdsa-sha2-nistp384;; 40 ecdsa-521) echo ecdsa-sha2-nistp521;; 41 ed25519-512) echo ssh-ed25519;; 42 rsa-*) echo rsa-sha2-512,rsa-sha2-256,ssh-rsa;; 43 ed25519-sk) echo sk-ssh-ed25519@openssh.com;; 44 ecdsa-sk) echo sk-ecdsa-sha2-nistp256@openssh.com;; 45 esac 46} 47 48tries="1 2 3" 49for ut in $ktypes; do 50 user_type=`kname_to_ktype "$ut"` 51 htypes="$ut" 52 #htypes=$ktypes 53 for ht in $htypes; do 54 host_type=`kname_to_ktype "$ht"` 55 trace "ssh connect, userkey $ut, hostkey $ht" 56 ( 57 grep -v HostKey $OBJ/sshd_proxy_bak 58 echo HostKey $OBJ/key.$ht 59 echo PubkeyAcceptedAlgorithms $user_type 60 echo HostKeyAlgorithms $host_type 61 ) > $OBJ/sshd_proxy 62 ( 63 grep -v IdentityFile $OBJ/ssh_proxy_bak 64 echo IdentityFile $OBJ/key.$ut 65 echo PubkeyAcceptedAlgorithms $user_type 66 echo HostKeyAlgorithms $host_type 67 ) > $OBJ/ssh_proxy 68 ( 69 printf 'localhost-with-alias,127.0.0.1,::1 ' 70 cat $OBJ/key.$ht.pub 71 ) > $OBJ/known_hosts 72 cat $OBJ/key.$ut.pub > $OBJ/authorized_keys_$USER 73 for i in $tries; do 74 verbose "userkey $ut, hostkey ${ht}" 75 ${SSH} -F $OBJ/ssh_proxy 999.999.999.999 true 76 if [ $? -ne 0 ]; then 77 fail "ssh userkey $ut, hostkey $ht failed" 78 fi 79 done 80 done 81done 82