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