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