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