blob: dcb975d952f668d0ff6d0c5836c5ba7ffef46b18 [file] [log] [blame]
Damien Milleraf784932008-03-13 00:17:00 +11001#!/bin/sh
tb@openbsd.orge65e25c2019-11-21 05:18:47 +00002# $OpenBSD: ssh2putty.sh,v 1.5 2019/11/21 05:18:47 tb Exp $
Damien Milleraf784932008-03-13 00:17:00 +11003
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
Tim Ricedce65cf2008-03-13 18:21:06 -070014if grep "BEGIN RSA PRIVATE KEY" $KEYFILE >/dev/null 2>&1 ; then
15 :
16else
Damien Milleraf784932008-03-13 00:17:00 +110017 echo "Unsupported private key format"
18 exit 1
19fi
20
21public_exponent=`
tb@openbsd.orge65e25c2019-11-21 05:18:47 +000022 openssl rsa -noout -text -in $KEYFILE | grep ^publicExponent |
Damien Milleraf784932008-03-13 00:17:00 +110023 sed 's/.*(//;s/).*//'
24`
25test $? -ne 0 && exit 1
26
27modulus=`
djm@openbsd.org8377d502015-05-08 07:26:13 +000028 openssl rsa -noout -modulus -in $KEYFILE | grep ^Modulus= |
Damien Milleraf784932008-03-13 00:17:00 +110029 sed 's/^Modulus=/0x/' | tr A-Z a-z
30`
31test $? -ne 0 && exit 1
32
33echo "rsa2@$PORT:$HOST $public_exponent,$modulus"
34