import of openssh-5.8p1
[openssh.git] / regress / ssh2putty.sh
1 #!/bin/sh
2 #       $OpenBSD: ssh2putty.sh,v 1.2 2009/10/06 23:51:49 dtucker Exp $
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
14 if grep "BEGIN RSA PRIVATE KEY" $KEYFILE >/dev/null 2>&1 ; then
15         :
16 else
17         echo "Unsupported private key format"
18         exit 1
19 fi
20
21 public_exponent=`
22         openssl rsa -noout -text -in $KEYFILE | grep ^publicExponent | 
23         sed 's/.*(//;s/).*//'
24 `
25 test $? -ne 0 && exit 1
26
27 modulus=`
28         openssl rsa -noout -modulus -in $KEYFILE | grep ^Modulus= | 
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