-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.sh
More file actions
executable file
·75 lines (62 loc) · 1.74 KB
/
generate.sh
File metadata and controls
executable file
·75 lines (62 loc) · 1.74 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# need domain as first argument
DOMAIN=$1
# make sure that domain is given
if [ "${DOMAIN}x" == "x" ]; then
echo "Usage: ${0} domain"
exit 1
fi
# need year
YEAR=`date "+%Y"`
# need username
ME=`whoami`
# directory to hold files
DIR=${DOMAIN}_${YEAR}
# name for CSR file
CSR=${DIR}/${DOMAIN}_${YEAR}.csr
# name for key
KEY=${DIR}/${DOMAIN}_${YEAR}.key
# name for ssl.conf
SSL=${DIR}/ssl.conf
# domain without www.
NOWWW=`echo ${DOMAIN} | sed -e "s/^www\.//"`
# create directory to hold files
mkdir -p ${DIR}
# generate key
openssl genrsa -out ${KEY}
# generate SSL conf
cat << EOF > ${SSL}
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
[req_distinguished_name]
countryName = Country Name (2 letter code)
countryName_default = GB
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = Fife
localityName = Locality Name (eg, city)
localityName_default = St Andrews
0.organizationName = Organization Name (company)
0.organizationName_default = University of St Andrews
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = IT Services
emailAddress = Email address
emailAddress_default = ${ME}@st-andrews.ac.uk
commonName = Put domain name here
commonName_default = ${DOMAIN}
commonName_max = 64
[ v3_req ]
# Extensions to add to a certificate request
#basicConstraints = CA:FALSE
#keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = ${DOMAIN}
EOF
# domain has leading www., so add domain without it
if [ ${DOMAIN} != ${NOWWW} ]; then
echo "DNS.2 = ${NOWWW}" >> ${SSL}
fi
# generate CSR
openssl req -batch -new -sha256 -key ${KEY} -out ${CSR} -config ${SSL}
echo "Your CSR is here:" `pwd`/${CSR}