@@ -22,17 +22,17 @@ CN_CA=${CN_CA:0:64}
22
22
CN_IA=${CN_IA: 0: 64}
23
23
CN_WEB=${CN_WEB: 0: 64}
24
24
25
- mkdir -p /certs /ca
25
+ mkdir -p /ca /certs
26
26
cd /ca
27
27
28
28
CA_KEY_FILE=${CA_KEY_FILE:-/ ca/ ca.key}
29
29
CA_CRT_FILE=${CA_CRT_FILE:-/ ca/ ca.crt}
30
30
CA_SRL_FILE=${CA_SRL_FILE:-/ ca/ ca.srl}
31
31
32
- if [ -f " $CA_CRT_FILE " ] ; then
32
+ if [ -f " $CA_CRT_FILE " ]; then
33
33
logInfo " CA already exists. Good. We'll reuse it."
34
- if [ ! -f " $CA_SRL_FILE " ] ; then
35
- echo 01 > ${CA_SRL_FILE}
34
+ if [ ! -f " $CA_SRL_FILE " ]; then
35
+ echo 01 > ${CA_SRL_FILE}
36
36
fi
37
37
else
38
38
logInfo " No CA was found. Generating one."
42
42
43
43
logInfo " generate CA cert with key and self sign it: ${CAID} "
44
44
openssl req -new -x509 -days 1300 -sha256 -key ${CA_KEY_FILE} -out ${CA_CRT_FILE} -passin pass:foobar -subj " /C=NL/ST=Noord Holland/L=Amsterdam/O=ME/OU=IT/CN=${CN_CA} " -extensions IA -config <(
45
- cat << -EOF
45
+ cat << -EOF
46
46
[req]
47
47
distinguished_name = dn
48
48
[dn]
@@ -51,23 +51,24 @@ basicConstraints = critical,CA:TRUE
51
51
keyUsage = critical, digitalSignature, cRLSign, keyCertSign
52
52
subjectKeyIdentifier = hash
53
53
EOF
54
- )
54
+ )
55
55
56
56
[[ ${DEBUG} -gt 0 ]] && logInfo " show the CA cert details"
57
57
[[ ${DEBUG} -gt 0 ]] && openssl x509 -noout -text -in ${CA_CRT_FILE}
58
58
59
- echo 01 > ${CA_SRL_FILE}
59
+ echo 01 > ${CA_SRL_FILE}
60
60
61
61
fi
62
62
63
63
cd /certs
64
64
65
- logInfo " Generate IA key"
66
- openssl genrsa -des3 -passout pass:foobar -out ia.key 4096 & > /dev/null
65
+ if [ -f " fullchain_with_key.pem" ]; then
66
+ logInfo " Generate IA key"
67
+ openssl genrsa -des3 -passout pass:foobar -out ia.key 4096 & > /dev/null
67
68
68
- logInfo " Create a signing request for the IA: ${CAID} "
69
- openssl req -new -key ia.key -out ia.csr -passin pass:foobar -subj " /C=NL/ST=Noord Holland/L=Amsterdam/O=ME/OU=IT/CN=${CN_IA} " -reqexts IA -config <(
70
- cat << -EOF
69
+ logInfo " Create a signing request for the IA: ${CAID} "
70
+ openssl req -new -key ia.key -out ia.csr -passin pass:foobar -subj " /C=NL/ST=Noord Holland/L=Amsterdam/O=ME/OU=IT/CN=${CN_IA} " -reqexts IA -config <(
71
+ cat << -EOF
71
72
[req]
72
73
distinguished_name = dn
73
74
[dn]
@@ -76,14 +77,14 @@ basicConstraints = critical,CA:TRUE,pathlen:0
76
77
keyUsage = critical, digitalSignature, cRLSign, keyCertSign
77
78
subjectKeyIdentifier = hash
78
79
EOF
79
- )
80
+ )
80
81
81
- [[ ${DEBUG} -gt 0 ]] && logInfo " Show the singing request, to make sure extensions are there"
82
- [[ ${DEBUG} -gt 0 ]] && openssl req -in ia.csr -noout -text
82
+ [[ ${DEBUG} -gt 0 ]] && logInfo " Show the singing request, to make sure extensions are there"
83
+ [[ ${DEBUG} -gt 0 ]] && openssl req -in ia.csr -noout -text
83
84
84
- logInfo " Sign the IA request with the CA cert and key, producing the IA cert"
85
- openssl x509 -req -days 730 -in ia.csr -CA ${CA_CRT_FILE} -CAkey ${CA_KEY_FILE} -CAserial ${CA_SRL_FILE} -out ia.crt -passin pass:foobar -extensions IA -extfile <(
86
- cat << -EOF
85
+ logInfo " Sign the IA request with the CA cert and key, producing the IA cert"
86
+ openssl x509 -req -days 730 -in ia.csr -CA ${CA_CRT_FILE} -CAkey ${CA_KEY_FILE} -CAserial ${CA_SRL_FILE} -out ia.crt -passin pass:foobar -extensions IA -extfile <(
87
+ cat << -EOF
87
88
[req]
88
89
distinguished_name = dn
89
90
[dn]
@@ -92,33 +93,33 @@ basicConstraints = critical,CA:TRUE,pathlen:0
92
93
keyUsage = critical, digitalSignature, cRLSign, keyCertSign
93
94
subjectKeyIdentifier = hash
94
95
EOF
95
- ) & > /dev/null
96
+ ) & > /dev/null
96
97
98
+ [[ ${DEBUG} -gt 0 ]] && logInfo " show the IA cert details"
99
+ [[ ${DEBUG} -gt 0 ]] && openssl x509 -noout -text -in ia.crt
97
100
98
- [[ ${DEBUG} -gt 0 ]] && logInfo " show the IA cert details "
99
- [[ ${DEBUG} -gt 0 ]] && openssl x509 -noout -text -in ia.crt
101
+ logInfo " Initialize the serial number for signed certificates "
102
+ echo 01 > ia.srl
100
103
101
- logInfo " Initialize the serial number for signed certificates"
102
- echo 01 > ia.srl
104
+ logInfo " Create the key (w/o passphrase..)"
105
+ openssl genrsa -des3 -passout pass:foobar -out web.orig.key 2048 & > /dev/null
106
+ openssl rsa -passin pass:foobar -in web.orig.key -out web.key & > /dev/null
103
107
104
- logInfo " Create the key (w/o passphrase..)"
105
- openssl genrsa -des3 -passout pass:foobar -out web.orig.key 2048 & > /dev/null
106
- openssl rsa -passin pass:foobar -in web.orig.key -out web.key & > /dev/null
108
+ logInfo " Create the signing request, using extensions"
109
+ openssl req -new -key web.key -sha256 -out web.csr -passin pass:foobar -subj " /C=NL/ST=Noord Holland/L=Amsterdam/O=ME/OU=IT/CN=${CN_WEB} " -reqexts SAN -config <( cat <( printf " [req]\ndistinguished_name = dn\n[dn]\n[SAN]\nsubjectAltName=${ALLDOMAINS} " ) )
107
110
108
- logInfo " Create the signing request, using extensions"
109
- openssl req -new -key web.key -sha256 -out web.csr -passin pass:foobar -subj " /C=NL/ST=Noord Holland/L=Amsterdam/O=ME/OU=IT/CN= ${CN_WEB} " -reqexts SAN -config <( cat <( printf " [ req]\ndistinguished_name = dn\n[dn]\n[SAN]\nsubjectAltName= ${ALLDOMAINS} " ) )
111
+ [[ ${DEBUG} -gt 0 ]] && logInfo " Show the singing request, to make sure extensions are there "
112
+ [[ ${DEBUG} -gt 0 ]] && openssl req -in web.csr -noout -text
110
113
111
- [[ ${DEBUG} -gt 0 ]] && logInfo " Show the singing request, to make sure extensions are there "
112
- [[ ${DEBUG} -gt 0 ]] && openssl req -in web.csr -noout -text
114
+ logInfo " Sign the request, using the intermediate cert and key "
115
+ openssl x509 - req -days 365 - in web.csr -CA ia.crt -CAkey ia.key -out web.crt -passin pass:foobar -extensions SAN -extfile <( cat <( printf " [req]\ndistinguished_name = dn\n[dn]\n[SAN]\nsubjectAltName= ${ALLDOMAINS} " ) ) & > /dev/null
113
116
114
- logInfo " Sign the request, using the intermediate cert and key "
115
- openssl x509 -req -days 365 -in web.csr -CA ia.crt -CAkey ia.key -out web.crt -passin pass:foobar -extensions SAN -extfile <( cat <( printf " [req]\ndistinguished_name = dn\n[dn]\n[SAN]\nsubjectAltName= ${ALLDOMAINS} " ) ) & > /dev/null
117
+ [[ ${DEBUG} -gt 0 ]] && logInfo " Show the final cert details "
118
+ [[ ${DEBUG} -gt 0 ]] && openssl x509 -noout -text -in web.crt
116
119
117
- [[ ${DEBUG} -gt 0 ]] && logInfo " Show the final cert details "
118
- [[ ${DEBUG} -gt 0 ]] && openssl x509 -noout -text -in web.crt
120
+ logInfo " Concatenating fullchain.pem... "
121
+ cat web.crt ia.crt ${CA_CRT_FILE} > fullchain.pem
119
122
120
- logInfo " Concatenating fullchain.pem..."
121
- cat web.crt ia.crt ${CA_CRT_FILE} > fullchain.pem
122
-
123
- logInfo " Concatenating fullchain_with_key.pem"
124
- cat fullchain.pem web.key > fullchain_with_key.pem
123
+ logInfo " Concatenating fullchain_with_key.pem"
124
+ cat fullchain.pem web.key > fullchain_with_key.pem
125
+ fi
0 commit comments