2871ff
#!/bin/bash
2871ff
2871ff
if [ $# -eq 0 ]; then
2871ff
	echo $"Usage: `basename $0` filename" 1>&2
2871ff
	exit 1
2871ff
fi
2871ff
2871ff
PEM=$1
2871ff
REQ=`/bin/mktemp /tmp/openssl.XXXXXX`
2871ff
KEY=`/bin/mktemp /tmp/openssl.XXXXXX`
2871ff
CRT=`/bin/mktemp /tmp/openssl.XXXXXX`
2871ff
NEW=${PEM}_
2871ff
2871ff
trap "rm -f $REQ $KEY $CRT $NEW" SIGINT
2871ff
2871ff
if [ ! -f $PEM ]; then
2871ff
	echo "$PEM: file not found" 1>&2
2871ff
	exit 1
2871ff
fi
2871ff
2871ff
umask 077
2871ff
2871ff
OWNER=`ls -l $PEM | awk '{ printf "%s.%s", $3, $4; }'`
2871ff
2871ff
openssl rsa -inform pem -in $PEM -out $KEY
2871ff
openssl x509 -x509toreq -in $PEM -signkey $KEY -out $REQ
2871ff
openssl x509 -req -in $REQ -signkey $KEY -days 365 \
2871ff
	-extfile /etc/pki/tls/openssl.cnf -extensions v3_ca -out $CRT
2871ff
2871ff
(cat $KEY ; echo "" ; cat $CRT) > $NEW
2871ff
2871ff
chown $OWNER $NEW
2871ff
2871ff
mv -f $NEW $PEM
2871ff
2871ff
rm -f $REQ $KEY $CRT
2871ff
2871ff
exit 0
2871ff