ssh2putty.sh 702 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env sh
  2. # $OpenBSD: ssh2putty.sh,v 1.5 2019/11/21 05:18:47 tb Exp $
  3. if test "x$1" = "x" -o "x$2" = "x" -o "x$3" = "x"; then
  4. echo "Usage: ssh2putty hostname port ssh-private-key"
  5. exit 1
  6. fi
  7. HOST=$1
  8. PORT=$2
  9. KEYFILE=$3
  10. # XXX - support DSA keys too
  11. if grep "BEGIN RSA PRIVATE KEY" $KEYFILE > /dev/null 2>&1; then
  12. :
  13. else
  14. echo "Unsupported private key format"
  15. exit 1
  16. fi
  17. public_exponent=$(
  18. openssl rsa -noout -text -in $KEYFILE | grep ^publicExponent |
  19. sed 's/.*(//;s/).*//'
  20. )
  21. test $? -ne 0 && exit 1
  22. modulus=$(
  23. openssl rsa -noout -modulus -in $KEYFILE | grep ^Modulus= |
  24. sed 's/^Modulus=/0x/' | tr A-Z a-z
  25. )
  26. test $? -ne 0 && exit 1
  27. echo "rsa2@$PORT:$HOST $public_exponent,$modulus"