-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_certificates.sh
executable file
·35 lines (29 loc) · 1.02 KB
/
gen_certificates.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
PATH="/etc/httpd/conf"
SERVER_KEY="$PATH/server.key"
SERVER_CSR="$PATH/server.csr"
SERVER_CRT="$PATH/server.crt"
EXTFILE="$PATH/cert_ext.cnf"
OPENSSL_CMD="/usr/bin/openssl"
COMMON_NAME=`/bin/cat /etc/hostname`
# generating server key
echo "Generating private key"
$OPENSSL_CMD genrsa -out $SERVER_KEY 4096 2>/dev/null
if [ $? -ne 0 ] ; then
echo "ERROR: Failed to generate $SERVER_KEY"
exit 1
fi
## Update Common Name in External File
/bin/echo "commonName = $COMMON_NAME" >> $EXTFILE
# Generating Certificate Signing Request using config file
echo "Generating Certificate Signing Request"
$OPENSSL_CMD req -new -key $SERVER_KEY -out $SERVER_CSR -config $EXTFILE 2>/dev/null
if [ $? -ne 0 ] ; then
echo "ERROR: Failed to generate $SERVER_CSR"
exit 1
fi
echo "Generating self signed certificate"
$OPENSSL_CMD x509 -req -days 3650 -in $SERVER_CSR -signkey $SERVER_KEY -out $SERVER_CRT 2>/dev/null
if [ $? -ne 0 ] ; then
echo "ERROR: Failed to generate self-signed certificate file $SERVER_CRT"
fi