xref: /freebsd/crypto/openssh/regress/ssh2putty.sh (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1#!/bin/sh
2#	$OpenBSD: ssh2putty.sh,v 1.9 2021/07/25 12:13:03 dtucker 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
13OPENSSL_BIN="${OPENSSL_BIN:-openssl}"
14
15# XXX - support DSA keys too
16if grep "BEGIN RSA PRIVATE KEY" $KEYFILE >/dev/null 2>&1 ; then
17	:
18else
19	echo "Unsupported private key format"
20	exit 1
21fi
22
23public_exponent=`
24	$OPENSSL_BIN rsa -noout -text -in $KEYFILE | grep ^publicExponent |
25	sed 's/.*(//;s/).*//'
26`
27test $? -ne 0 && exit 1
28
29modulus=`
30	$OPENSSL_BIN rsa -noout -modulus -in $KEYFILE | grep ^Modulus= |
31	sed 's/^Modulus=/0x/' | tr A-Z a-z
32`
33test $? -ne 0 && exit 1
34
35echo "rsa2@$PORT:$HOST $public_exponent,$modulus"
36
37