xref: /openbsd-src/regress/usr.bin/ssh/ssh2putty.sh (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1#!/bin/sh
2
3if 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
6fi
7
8HOST=$1
9PORT=$2
10KEYFILE=$3
11
12# XXX - support DSA keys too
13if ! grep -q "BEGIN RSA PRIVATE KEY" $KEYFILE ; then
14	echo "Unsupported private key format"
15	exit 1
16fi
17
18public_exponent=`
19	openssl rsa -noout -text -in $KEYFILE | grep ^publicExponent |
20	sed 's/.*(//;s/).*//'
21`
22test $? -ne 0 && exit 1
23
24modulus=`
25	openssl rsa -noout -modulus -in $KEYFILE | grep ^Modulus= |
26	sed 's/^Modulus=/0x/' | tr A-Z a-z
27`
28test $? -ne 0 && exit 1
29
30echo "rsa2@$PORT:$HOST $public_exponent,$modulus"
31
32