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