1 |
#!/bin/bash |
2 |
|
3 |
if [ $# -eq 0 ]; then |
4 |
echo $"Usage: `basename $0` filename" 1>&2 |
5 |
exit 1 |
6 |
fi |
7 |
|
8 |
PEM=$1 |
9 |
REQ=`/bin/mktemp /tmp/openssl.XXXXXX` |
10 |
KEY=`/bin/mktemp /tmp/openssl.XXXXXX` |
11 |
CRT=`/bin/mktemp /tmp/openssl.XXXXXX` |
12 |
NEW=${PEM}_ |
13 |
|
14 |
trap "rm -f $REQ $KEY $CRT $NEW" SIGINT |
15 |
|
16 |
if [ ! -f $PEM ]; then |
17 |
echo "$PEM: file not found" 1>&2 |
18 |
exit 1 |
19 |
fi |
20 |
|
21 |
umask 077 |
22 |
|
23 |
OWNER=`ls -l $PEM | awk '{ printf "%s.%s", $3, $4; }'` |
24 |
|
25 |
openssl rsa -inform pem -in $PEM -out $KEY |
26 |
openssl x509 -x509toreq -in $PEM -signkey $KEY -out $REQ |
27 |
openssl x509 -req -in $REQ -signkey $KEY -days 365 \ |
28 |
-extfile /etc/pki/tls/openssl.cnf -extensions v3_ca -out $CRT |
29 |
|
30 |
(cat $KEY ; echo "" ; cat $CRT) > $NEW |
31 |
|
32 |
chown $OWNER $NEW |
33 |
|
34 |
mv -f $NEW $PEM |
35 |
|
36 |
rm -f $REQ $KEY $CRT |
37 |
|
38 |
exit 0 |
39 |
|