|
15 | 15 | # This file include the script to generate testing certificates for CRL testing. |
16 | 16 | # The generated files are: |
17 | 17 | # - certchain_with_crl.pem: the fullchain file that includes the leaf |
18 | | -# certificate with CRL and the root certificate. |
| 18 | +# certificate with CRL, intermediate certificate with invalid OCSP and valid |
| 19 | +# CRL, and the root certificate. |
19 | 20 | # - leaf.crl: the CRL file that includes the revoked leaf certificate. |
20 | 21 | # - leaf.key: the private key of the leaf certificate. |
21 | 22 | # - leaf_revoked.crl: the CRL file that includes the revoked leaf certificate. |
| 23 | +# - intermediate.crl: the CRL file that includes the intermediate certificate. |
| 24 | +# - intermediate_revoked.crl: the CRL file that includes the revoked intermediate |
22 | 25 | # - root.crt: the root certificate. |
23 | 26 | # |
24 | 27 | # Note: The script will not run in the pipeline, but we need to keep it for |
@@ -78,14 +81,90 @@ authorityKeyIdentifier = keyid:always,issuer:always |
78 | 81 | authorityKeyIdentifier = keyid:always |
79 | 82 | EOF |
80 | 83 |
|
| 84 | +# Set up OpenSSL CA directory structure |
| 85 | +mkdir -p demoCA/newcerts |
| 86 | +touch demoCA/index.txt |
| 87 | +echo '1002' > demoCA/serial |
| 88 | +echo '1002' > demoCA/crlnumber |
| 89 | + |
81 | 90 | # Generate root private key |
82 | 91 | openssl genrsa -out root.key 2048 |
83 | 92 |
|
84 | 93 | # Generate self-signed root certificate with extensions |
85 | 94 | openssl req -x509 -new -key root.key -sha256 -days 36500 -out root.crt \ |
86 | 95 | -config root.cnf -extensions v3_ca |
87 | 96 |
|
88 | | -# Create leaf certificate configuration file |
| 97 | +# Update intermediate.cnf to include [ca] and [CA_default] sections |
| 98 | +cat > intermediate.cnf <<EOF |
| 99 | +[ req ] |
| 100 | +default_bits = 2048 |
| 101 | +prompt = no |
| 102 | +distinguished_name = intermediate_distinguished_name |
| 103 | +x509_extensions = v3_intermediate_ca |
| 104 | +
|
| 105 | +[ intermediate_distinguished_name ] |
| 106 | +C = US |
| 107 | +ST = State |
| 108 | +L = City |
| 109 | +O = Organization |
| 110 | +OU = OrgUnit |
| 111 | +CN = IntermediateCA |
| 112 | +
|
| 113 | +[ ca ] |
| 114 | +default_ca = CA_default |
| 115 | +
|
| 116 | +[ CA_default ] |
| 117 | +dir = ./intermediateCA |
| 118 | +new_certs_dir = \$dir/newcerts |
| 119 | +database = \$dir/index.txt |
| 120 | +serial = \$dir/serial |
| 121 | +private_key = ./intermediate.key |
| 122 | +certificate = ./intermediate.crt |
| 123 | +default_md = sha256 |
| 124 | +policy = policy_any |
| 125 | +x509_extensions = usr_cert |
| 126 | +copy_extensions = copy |
| 127 | +default_days = 36500 |
| 128 | +default_crl_days = 36500 |
| 129 | +crlnumber = \$dir/crlnumber |
| 130 | +crl_extensions = crl_ext |
| 131 | +
|
| 132 | +[ policy_any ] |
| 133 | +countryName = optional |
| 134 | +stateOrProvinceName = optional |
| 135 | +localityName = optional |
| 136 | +organizationName = optional |
| 137 | +organizationalUnitName = optional |
| 138 | +commonName = supplied |
| 139 | +
|
| 140 | +[ v3_intermediate_ca ] |
| 141 | +basicConstraints = critical,CA:TRUE,pathlen:0 |
| 142 | +keyUsage = critical,keyCertSign,cRLSign |
| 143 | +subjectKeyIdentifier = hash |
| 144 | +authorityKeyIdentifier = keyid:always,issuer:always |
| 145 | +crlDistributionPoints = URI:http://localhost:10086/intermediate.crl |
| 146 | +authorityInfoAccess = OCSP;URI:http://localhost.test/ocsp |
| 147 | +
|
| 148 | +[ crl_ext ] |
| 149 | +authorityKeyIdentifier = keyid:always |
| 150 | +EOF |
| 151 | + |
| 152 | +# Set up OpenSSL CA directory structure for intermediate CA |
| 153 | +mkdir -p intermediateCA/newcerts |
| 154 | +touch intermediateCA/index.txt |
| 155 | +echo '1000' > intermediateCA/serial |
| 156 | +echo '1000' > intermediateCA/crlnumber |
| 157 | + |
| 158 | +# Generate intermediate private key |
| 159 | +openssl genrsa -out intermediate.key 2048 |
| 160 | + |
| 161 | +# Generate intermediate CSR |
| 162 | +openssl req -new -key intermediate.key -out intermediate.csr -config intermediate.cnf |
| 163 | + |
| 164 | +# Sign intermediate certificate with root CA |
| 165 | +openssl ca -config root.cnf -in intermediate.csr -out intermediate.crt -batch -extensions v3_intermediate_ca -extfile intermediate.cnf -notext |
| 166 | + |
| 167 | +# Update leaf.cnf to remove OCSP server |
89 | 168 | cat > leaf.cnf <<EOF |
90 | 169 | [ req ] |
91 | 170 | default_bits = 2048 |
@@ -113,31 +192,40 @@ openssl genrsa -out leaf.key 2048 |
113 | 192 | # Generate leaf certificate signing request (CSR) |
114 | 193 | openssl req -new -key leaf.key -out leaf.csr -config leaf.cnf |
115 | 194 |
|
116 | | -# Set up OpenSSL CA directory structure |
117 | | -mkdir -p demoCA/newcerts |
118 | | -touch demoCA/index.txt |
119 | | -echo '1000' > demoCA/serial |
120 | | -echo '1000' > demoCA/crlnumber |
| 195 | +# Sign leaf certificate with intermediate CA |
| 196 | +openssl ca -config intermediate.cnf -in leaf.csr -out leaf.crt -batch -extensions v3_req -extfile leaf.cnf -notext |
| 197 | + |
| 198 | +# Generate intermediate CRL using root.cnf (before revocation) |
| 199 | +openssl ca -config root.cnf -gencrl -out intermediate.crl |
| 200 | + |
| 201 | +# Convert root CRL to DER format |
| 202 | +openssl crl -in intermediate.crl -outform der -out intermediate.crl |
| 203 | + |
| 204 | +# Revoke intermediate certificate using root CA |
| 205 | +openssl ca -config root.cnf -revoke intermediate.crt |
| 206 | + |
| 207 | +# Generate intermediate CRL including revoked intermediate certificate |
| 208 | +openssl ca -config root.cnf -gencrl -out intermediate_revoked.crl |
121 | 209 |
|
122 | | -# Sign leaf certificate with root CA |
123 | | -openssl ca -config root.cnf -in leaf.csr -out leaf.crt -batch -extensions v3_req -extfile leaf.cnf -notext |
| 210 | +# Convert intermediate CRL to DER format |
| 211 | +openssl crl -in intermediate_revoked.crl -outform der -out intermediate_revoked.crl |
124 | 212 |
|
125 | | -# Generate the CRL |
126 | | -openssl ca -config root.cnf -gencrl -out leaf.crl |
| 213 | +# Generate leaf CRL |
| 214 | +openssl ca -config intermediate.cnf -gencrl -out leaf.crl |
127 | 215 |
|
128 | | -# Convert the CRL to DER format |
| 216 | +# Convert leaf CRL to DER format |
129 | 217 | openssl crl -in leaf.crl -outform der -out leaf.crl |
130 | 218 |
|
131 | | -# Revoke the leaf certificate |
132 | | -openssl ca -config root.cnf -revoke leaf.crt |
| 219 | +# Revoke leaf certificate |
| 220 | +openssl ca -config intermediate.cnf -revoke leaf.crt |
133 | 221 |
|
134 | | -# Generate the CRL including the revoked leaf certificate |
135 | | -openssl ca -config root.cnf -gencrl -out leaf_revoked.crl |
| 222 | +# Generate leaf CRL including revoked leaf certificate |
| 223 | +openssl ca -config intermediate.cnf -gencrl -out leaf_revoked.crl |
136 | 224 |
|
137 | | -# Convert the updated CRL to DER format |
| 225 | +# Convert leaf CRL to DER format |
138 | 226 | openssl crl -in leaf_revoked.crl -outform der -out leaf_revoked.crl |
139 | 227 |
|
140 | 228 | # merge leaf cert and root cert to create fullchain file |
141 | | -cat leaf.crt root.crt > certchain_with_crl.pem |
| 229 | +cat leaf.crt intermediate.crt root.crt > certchain_with_crl.pem |
142 | 230 |
|
143 | | -rm -rf leaf.csr leaf.crt leaf.cnf root.srl root.cnf root.key demoCA |
| 231 | +rm -rf leaf.csr leaf.crt leaf.cnf root.srl root.cnf root.key root.crl demoCA intermediate.csr intermediate.cnf intermediate.key intermediate.crt intermediateCA |
0 commit comments