-
Notifications
You must be signed in to change notification settings - Fork 0
/
lighttpd_gencert.sh
52 lines (47 loc) · 1.37 KB
/
lighttpd_gencert.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
# Generated self-signed certificate SSL for web-server use that script.
#
# For generate personal key on client side example:
#
# ssh-keygen -b 1024 -t dsa -N passphrase -f mykey -C "[email protected]"
# cat mykey.pub > ~/.ssh/authorized_keys
# chmod 0600 ~/.ssh/authorized_keys
set -e
tmpdir="/tmp"
certdir="/etc/lighttpd"
if [ -f $certdir/server.pem ] ; then
echo "certificate already exists."
echo "To recreate the certificate, delete the file $certdir/server.pem"
exit 0
fi
#generate https certificate
cat > $tmpdir/cert.cnf << "EOF"
RANDFILE = /dev/urandom
[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no
[ req_dn ]
C=ES
ST=ESPAIN
L=Madrid
O=Msp
OU=Msp
CN=msp.tk
[ cert_type ]
basicConstraints = critical,CA:FALSE
nsCertType = server
nsComment = "MSP SSL Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer:always
issuerAltName = issuer:copy
keyUsage = keyEncipherment, digitalSignature
extendedKeyUsage = serverAuth
EOF
openssl req -new -outform PEM -config $tmpdir/cert.cnf -out $tmpdir/server.pem -newkey rsa:2048 -nodes -keyout $tmpdir/server.key -keyform PEM -days 9999 -x509
cat $tmpdir/server.pem $tmpdir/server.key > $certdir/server.pem
rm -f $tmpdir/cert.cnf $tmpdir/server.pem $tmpdir/server.key
echo "Successfully generated self-signed certificate"