Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 1 | #!/bin/sh |
tb@openbsd.org | e65e25c | 2019-11-21 05:18:47 +0000 | [diff] [blame] | 2 | # $OpenBSD: ssh2putty.sh,v 1.5 2019/11/21 05:18:47 tb Exp $ |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 3 | |
| 4 | if test "x$1" = "x" -o "x$2" = "x" -o "x$3" = "x" ; then |
| 5 | echo "Usage: ssh2putty hostname port ssh-private-key" |
| 6 | exit 1 |
| 7 | fi |
| 8 | |
| 9 | HOST=$1 |
| 10 | PORT=$2 |
| 11 | KEYFILE=$3 |
| 12 | |
| 13 | # XXX - support DSA keys too |
Tim Rice | dce65cf | 2008-03-13 18:21:06 -0700 | [diff] [blame] | 14 | if grep "BEGIN RSA PRIVATE KEY" $KEYFILE >/dev/null 2>&1 ; then |
| 15 | : |
| 16 | else |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 17 | echo "Unsupported private key format" |
| 18 | exit 1 |
| 19 | fi |
| 20 | |
| 21 | public_exponent=` |
tb@openbsd.org | e65e25c | 2019-11-21 05:18:47 +0000 | [diff] [blame] | 22 | openssl rsa -noout -text -in $KEYFILE | grep ^publicExponent | |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 23 | sed 's/.*(//;s/).*//' |
| 24 | ` |
| 25 | test $? -ne 0 && exit 1 |
| 26 | |
| 27 | modulus=` |
djm@openbsd.org | 8377d50 | 2015-05-08 07:26:13 +0000 | [diff] [blame] | 28 | openssl rsa -noout -modulus -in $KEYFILE | grep ^Modulus= | |
Damien Miller | af78493 | 2008-03-13 00:17:00 +1100 | [diff] [blame] | 29 | sed 's/^Modulus=/0x/' | tr A-Z a-z |
| 30 | ` |
| 31 | test $? -ne 0 && exit 1 |
| 32 | |
| 33 | echo "rsa2@$PORT:$HOST $public_exponent,$modulus" |
| 34 | |