Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / net / data / ssl / scripts / generate-test-certs.sh
blob92d8f22868b191eeab7860a28e75f3ea09dba9f4
1 #!/bin/sh
3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # This script generates a set of test (end-entity, intermediate, root)
8 # certificates that can be used to test fetching of an intermediate via AIA.
10 try() {
11 "$@" || (e=$?; echo "$@" > /dev/stderr; exit $e)
14 try rm -rf out
15 try mkdir out
17 try /bin/sh -c "echo 01 > out/2048-sha256-root-serial"
18 touch out/2048-sha256-root-index.txt
20 # Generate the key
21 try openssl genrsa -out out/2048-sha256-root.key 2048
23 # Generate the root certificate
24 CA_COMMON_NAME="Test Root CA" \
25 try openssl req \
26 -new \
27 -key out/2048-sha256-root.key \
28 -out out/2048-sha256-root.req \
29 -config ca.cnf
31 CA_COMMON_NAME="Test Root CA" \
32 try openssl x509 \
33 -req -days 3650 \
34 -in out/2048-sha256-root.req \
35 -signkey out/2048-sha256-root.key \
36 -extfile ca.cnf \
37 -extensions ca_cert \
38 -text > out/2048-sha256-root.pem
40 # Generate the leaf certificate requests
41 try openssl req \
42 -new \
43 -keyout out/expired_cert.key \
44 -out out/expired_cert.req \
45 -config ee.cnf
47 try openssl req \
48 -new \
49 -keyout out/ok_cert.key \
50 -out out/ok_cert.req \
51 -config ee.cnf
53 SUBJECT_NAME=req_localhost_cn \
54 try openssl req \
55 -new \
56 -keyout out/localhost_cert.key \
57 -out out/localhost_cert.req \
58 -reqexts req_localhost_san \
59 -config ee.cnf
61 # Generate the leaf certificates
62 CA_COMMON_NAME="Test Root CA" \
63 try openssl ca \
64 -batch \
65 -extensions user_cert \
66 -startdate 060101000000Z \
67 -enddate 070101000000Z \
68 -in out/expired_cert.req \
69 -out out/expired_cert.pem \
70 -config ca.cnf
72 CA_COMMON_NAME="Test Root CA" \
73 try openssl ca \
74 -batch \
75 -extensions user_cert \
76 -days 3650 \
77 -in out/ok_cert.req \
78 -out out/ok_cert.pem \
79 -config ca.cnf
81 CA_COMMON_NAME="Test Root CA" \
82 try openssl ca \
83 -batch \
84 -extensions name_constraint_bad \
85 -subj "/CN=Leaf certificate/" \
86 -days 3650 \
87 -in out/ok_cert.req \
88 -out out/name_constraint_bad.pem \
89 -config ca.cnf
91 CA_COMMON_NAME="Test Root CA" \
92 try openssl ca \
93 -batch \
94 -extensions name_constraint_good \
95 -subj "/CN=Leaf Certificate/" \
96 -days 3650 \
97 -in out/ok_cert.req \
98 -out out/name_constraint_good.pem \
99 -config ca.cnf
101 CA_COMMON_NAME="Test Root CA" \
102 try openssl ca \
103 -batch \
104 -extensions user_cert \
105 -days 3650 \
106 -in out/localhost_cert.req \
107 -out out/localhost_cert.pem \
108 -config ca.cnf
110 try /bin/sh -c "cat out/ok_cert.key out/ok_cert.pem \
111 > ../certificates/ok_cert.pem"
112 try /bin/sh -c "cat out/localhost_cert.key out/localhost_cert.pem \
113 > ../certificates/localhost_cert.pem"
114 try /bin/sh -c "cat out/expired_cert.key out/expired_cert.pem \
115 > ../certificates/expired_cert.pem"
116 try /bin/sh -c "cat out/2048-sha256-root.key out/2048-sha256-root.pem \
117 > ../certificates/root_ca_cert.pem"
118 try /bin/sh -c "cat out/ok_cert.key out/name_constraint_bad.pem \
119 > ../certificates/name_constraint_bad.pem"
120 try /bin/sh -c "cat out/ok_cert.key out/name_constraint_good.pem \
121 > ../certificates/name_constraint_good.pem"
123 # Now generate the one-off certs
124 ## SHA-256 general test cert
125 try openssl req -x509 -days 3650 \
126 -config ../scripts/ee.cnf -newkey rsa:2048 -text \
127 -sha256 \
128 -out ../certificates/sha256.pem
130 ## Self-signed cert for SPDY/QUIC/HTTP2 pooling testing
131 try openssl req -x509 -days 3650 -extensions req_spdy_pooling \
132 -config ../scripts/ee.cnf -newkey rsa:2048 -text \
133 -out ../certificates/spdy_pooling.pem
135 ## SubjectAltName parsing
136 try openssl req -x509 -days 3650 -extensions req_san_sanity \
137 -config ../scripts/ee.cnf -newkey rsa:2048 -text \
138 -out ../certificates/subjectAltName_sanity_check.pem
140 ## Punycode handling
141 SUBJECT_NAME="req_punycode_dn" \
142 try openssl req -x509 -days 3650 -extensions req_punycode \
143 -config ../scripts/ee.cnf -newkey rsa:2048 -text \
144 -out ../certificates/punycodetest.pem
146 ## Reject intranet hostnames in "publicly" trusted certs
147 # 365 * 3 = 1095
148 SUBJECT_NAME="req_dn" \
149 try openssl req -x509 -days 1095 \
150 -config ../scripts/ee.cnf -newkey rsa:2048 -text \
151 -out ../certificates/reject_intranet_hosts.pem
153 ## Leaf certificate with a large key; Apple's certificate verifier rejects with
154 ## a fatal error if the key is bigger than 4096 bits.
155 try openssl req -x509 -days 3650 \
156 -config ../scripts/ee.cnf -newkey rsa:4104 -text \
157 -sha256 \
158 -out ../certificates/large_key.pem
160 ## Validity too long unit test support.
161 try openssl req -config ../scripts/ee.cnf \
162 -newkey rsa:2048 -text -out ../certificates/10_year_validity.req
163 CA_COMMON_NAME="Test Root CA" \
164 try openssl ca \
165 -batch \
166 -extensions user_cert \
167 -startdate 081030000000Z \
168 -enddate 181029000000Z \
169 -in ../certificates/10_year_validity.req \
170 -out ../certificates/10_year_validity.pem \
171 -config ca.cnf
172 # 365 * 11 = 4015
173 try openssl req -config ../scripts/ee.cnf \
174 -newkey rsa:2048 -text -out ../certificates/11_year_validity.req
175 CA_COMMON_NAME="Test Root CA" \
176 try openssl ca \
177 -batch \
178 -extensions user_cert \
179 -startdate 141030000000Z \
180 -days 4015 \
181 -in ../certificates/11_year_validity.req \
182 -out ../certificates/11_year_validity.pem \
183 -config ca.cnf
184 try openssl req -config ../scripts/ee.cnf \
185 -newkey rsa:2048 -text -out ../certificates/39_months_after_2015_04.req
186 CA_COMMON_NAME="Test Root CA" \
187 try openssl ca \
188 -batch \
189 -extensions user_cert \
190 -startdate 150402000000Z \
191 -enddate 180702000000Z \
192 -in ../certificates/39_months_after_2015_04.req \
193 -out ../certificates/39_months_after_2015_04.pem \
194 -config ca.cnf
195 try openssl req -config ../scripts/ee.cnf \
196 -newkey rsa:2048 -text -out ../certificates/40_months_after_2015_04.req
197 CA_COMMON_NAME="Test Root CA" \
198 try openssl ca \
199 -batch \
200 -extensions user_cert \
201 -startdate 150402000000Z \
202 -enddate 180801000000Z \
203 -in ../certificates/40_months_after_2015_04.req \
204 -out ../certificates/40_months_after_2015_04.pem \
205 -config ca.cnf
206 try openssl req -config ../scripts/ee.cnf \
207 -newkey rsa:2048 -text -out ../certificates/60_months_after_2012_07.req
208 CA_COMMON_NAME="Test Root CA" \
209 try openssl ca \
210 -batch \
211 -extensions user_cert \
212 -startdate 141030000000Z \
213 -enddate 190930000000Z \
214 -in ../certificates/60_months_after_2012_07.req \
215 -out ../certificates/60_months_after_2012_07.pem \
216 -config ca.cnf
217 try openssl req -config ../scripts/ee.cnf \
218 -newkey rsa:2048 -text -out ../certificates/61_months_after_2012_07.req
219 # 30 * 61 = 1830
220 CA_COMMON_NAME="Test Root CA" \
221 try openssl ca \
222 -batch \
223 -extensions user_cert \
224 -startdate 141030000000Z \
225 -days 1830 \
226 -in ../certificates/61_months_after_2012_07.req \
227 -out ../certificates/61_months_after_2012_07.pem \
228 -config ca.cnf
229 # start date after expiry date
230 try openssl req -config ../scripts/ee.cnf \
231 -newkey rsa:2048 -text -out ../certificates/start_after_expiry.req
232 CA_COMMON_NAME="Test Root CA" \
233 try openssl ca \
234 -batch \
235 -extensions user_cert \
236 -startdate 180901000000Z \
237 -enddate 150402000000Z \
238 -in ../certificates/start_after_expiry.req \
239 -out ../certificates/start_after_expiry.pem \
240 -config ca.cnf
241 try openssl req -config ../scripts/ee.cnf \
242 -newkey rsa:2048 -text -out ../certificates/start_after_expiry.req
243 # Issued pre-BRs, lifetime < 120 months, expires before 2019-07-01
244 try openssl req -config ../scripts/ee.cnf \
245 -newkey rsa:2048 -text -out ../certificates/pre_br_validity_ok.req
246 CA_COMMON_NAME="Test Root CA" \
247 try openssl ca \
248 -batch \
249 -extensions user_cert \
250 -startdate 080101000000Z \
251 -enddate 150101000000Z \
252 -in ../certificates/pre_br_validity_ok.req \
253 -out ../certificates/pre_br_validity_ok.pem \
254 -config ca.cnf
255 try openssl req -config ../scripts/ee.cnf \
256 -newkey rsa:2048 -text -out ../certificates/pre_br_validity_ok.req
257 # Issued pre-BRs, lifetime > 120 months, expires before 2019-07-01
258 try openssl req -config ../scripts/ee.cnf \
259 -newkey rsa:2048 -text -out ../certificates/pre_br_validity_bad_121.req
260 CA_COMMON_NAME="Test Root CA" \
261 try openssl ca \
262 -batch \
263 -extensions user_cert \
264 -startdate 080101000000Z \
265 -enddate 180501000000Z \
266 -in ../certificates/pre_br_validity_bad_121.req \
267 -out ../certificates/pre_br_validity_bad_121.pem \
268 -config ca.cnf
269 try openssl req -config ../scripts/ee.cnf \
270 -newkey rsa:2048 -text -out ../certificates/pre_br_validity_bad_121.req
271 # Issued pre-BRs, lifetime < 120 months, expires after 2019-07-01
272 try openssl req -config ../scripts/ee.cnf \
273 -newkey rsa:2048 -text -out ../certificates/pre_br_validity_bad_2020.req
274 CA_COMMON_NAME="Test Root CA" \
275 try openssl ca \
276 -batch \
277 -extensions user_cert \
278 -startdate 120501000000Z \
279 -enddate 190703000000Z \
280 -in ../certificates/pre_br_validity_bad_2020.req \
281 -out ../certificates/pre_br_validity_bad_2020.pem \
282 -config ca.cnf
283 try openssl req -config ../scripts/ee.cnf \
284 -newkey rsa:2048 -text -out ../certificates/pre_br_validity_bad_2020.req
286 # Regenerate CRLSets
287 ## Block a leaf cert directly by SPKI
288 try python crlsetutil.py -o ../certificates/crlset_by_leaf_spki.raw \
289 <<CRLBYLEAFSPKI
291 "BlockedBySPKI": ["../certificates/ok_cert.pem"]
293 CRLBYLEAFSPKI
295 ## Block a leaf cert by issuer-hash-and-serial (ok_cert.pem == serial 2, by
296 ## virtue of the serial file and ordering above.
297 try python crlsetutil.py -o ../certificates/crlset_by_root_serial.raw \
298 <<CRLBYROOTSERIAL
300 "BlockedByHash": {
301 "../certificates/root_ca_cert.pem": [2]
304 CRLBYROOTSERIAL
306 ## Block a leaf cert by issuer-hash-and-serial. However, this will be issued
307 ## from an intermediate CA issued underneath a root.
308 try python crlsetutil.py -o ../certificates/crlset_by_intermediate_serial.raw \
309 <<CRLSETBYINTERMEDIATESERIAL
311 "BlockedByHash": {
312 "../certificates/quic_intermediate.crt": [3]
315 CRLSETBYINTERMEDIATESERIAL