isaacpittman-hitachi / rpms / openssl

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