keytype.sh 2.4 KB

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