xref: /openssl/test/certs/setup.sh (revision 2f0b4974)
1#! /bin/bash
2
3# Primary root: root-cert
4./mkcert.sh genroot "Root CA" root-key root-cert
5# root cert variants: CA:false, key2, DN2, expired
6./mkcert.sh genss "Root CA" root-key root-nonca
7./mkcert.sh genroot "Root CA" root-key2 root-cert2
8./mkcert.sh genroot "Root Cert 2" root-key root-name2
9DAYS=-1 ./mkcert.sh genroot "Root CA" root-key root-expired
10# cross root and root cross cert
11./mkcert.sh genroot "Cross Root" cross-key cross-root
12./mkcert.sh genca "Root CA" root-key root-cross-cert cross-key cross-root
13# trust variants: +serverAuth -serverAuth +clientAuth -clientAuth
14openssl x509 -in root-cert.pem -trustout \
15    -addtrust serverAuth -out root+serverAuth.pem
16openssl x509 -in root-cert.pem -trustout \
17    -addreject serverAuth -out root-serverAuth.pem
18openssl x509 -in root-cert.pem -trustout \
19    -addtrust clientAuth -out root+clientAuth.pem
20openssl x509 -in root-cert.pem -trustout \
21    -addreject clientAuth -out root-clientAuth.pem
22# trust variants: +anyEKU -anyEKU
23openssl x509 -in root-cert.pem -trustout \
24    -addtrust anyExtendedKeyUsage -out root+anyEKU.pem
25openssl x509 -in root-cert.pem -trustout \
26    -addreject anyExtendedKeyUsage -out root-anyEKU.pem
27# root-cert2 trust variants: +serverAuth -serverAuth +clientAuth
28openssl x509 -in root-cert2.pem -trustout \
29    -addtrust serverAuth -out root2+serverAuth.pem
30openssl x509 -in root-cert2.pem -trustout \
31    -addreject serverAuth -out root2-serverAuth.pem
32openssl x509 -in root-cert2.pem -trustout \
33    -addtrust clientAuth -out root2+clientAuth.pem
34# root-nonca trust variants: +serverAuth +anyEKU
35openssl x509 -in root-nonca.pem -trustout \
36    -addtrust serverAuth -out nroot+serverAuth.pem
37openssl x509 -in root-nonca.pem -trustout \
38    -addtrust anyExtendedKeyUsage -out nroot+anyEKU.pem
39
40# Root CA security level variants:
41# MD5 self-signature
42OPENSSL_SIGALG=md5 \
43./mkcert.sh genroot "Root CA" root-key root-cert-md5
44# 768-bit key
45OPENSSL_KEYBITS=768 \
46./mkcert.sh genroot "Root CA" root-key-768 root-cert-768
47
48# primary client-EKU root: croot-cert
49./mkcert.sh genroot "Root CA" root-key croot-cert clientAuth
50# trust variants: +serverAuth -serverAuth +clientAuth -clientAuth +anyEKU -anyEKU
51openssl x509 -in croot-cert.pem -trustout \
52    -addtrust serverAuth -out croot+serverAuth.pem
53openssl x509 -in croot-cert.pem -trustout \
54    -addreject serverAuth -out croot-serverAuth.pem
55openssl x509 -in croot-cert.pem -trustout \
56    -addtrust clientAuth -out croot+clientAuth.pem
57openssl x509 -in croot-cert.pem -trustout \
58    -addreject clientAuth -out croot-clientAuth.pem
59openssl x509 -in croot-cert.pem -trustout \
60    -addtrust anyExtendedKeyUsage -out croot+anyEKU.pem
61openssl x509 -in croot-cert.pem -trustout \
62    -addreject anyExtendedKeyUsage -out croot-anyEKU.pem
63
64# primary server-EKU root: sroot-cert
65./mkcert.sh genroot "Root CA" root-key sroot-cert serverAuth
66# trust variants: +serverAuth -serverAuth +clientAuth -clientAuth +anyEKU -anyEKU
67openssl x509 -in sroot-cert.pem -trustout \
68    -addtrust serverAuth -out sroot+serverAuth.pem
69openssl x509 -in sroot-cert.pem -trustout \
70    -addreject serverAuth -out sroot-serverAuth.pem
71openssl x509 -in sroot-cert.pem -trustout \
72    -addtrust clientAuth -out sroot+clientAuth.pem
73openssl x509 -in sroot-cert.pem -trustout \
74    -addreject clientAuth -out sroot-clientAuth.pem
75openssl x509 -in sroot-cert.pem -trustout \
76    -addtrust anyExtendedKeyUsage -out sroot+anyEKU.pem
77openssl x509 -in sroot-cert.pem -trustout \
78    -addreject anyExtendedKeyUsage -out sroot-anyEKU.pem
79
80# Primary intermediate ca: ca-cert
81./mkcert.sh genca "CA" ca-key ca-cert root-key root-cert
82# ca variants: CA:false, no bc, key2, DN2, issuer2, expired
83./mkcert.sh genee "CA" ca-key ca-nonca root-key root-cert
84./mkcert.sh gen_nonbc_ca "CA" ca-key ca-nonbc root-key root-cert
85./mkcert.sh genca "CA" ca-key2 ca-cert2 root-key root-cert
86./mkcert.sh genca "CA2" ca-key ca-name2 root-key root-cert
87./mkcert.sh genca "CA" ca-key ca-root2 root-key2 root-cert2
88DAYS=-1 ./mkcert.sh genca "CA" ca-key ca-expired root-key root-cert
89# trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth
90openssl x509 -in ca-cert.pem -trustout \
91    -addtrust serverAuth -out ca+serverAuth.pem
92openssl x509 -in ca-cert.pem -trustout \
93    -addreject serverAuth -out ca-serverAuth.pem
94openssl x509 -in ca-cert.pem -trustout \
95    -addtrust clientAuth -out ca+clientAuth.pem
96openssl x509 -in ca-cert.pem -trustout \
97    -addreject clientAuth -out ca-clientAuth.pem
98# trust variants: +anyEKU, -anyEKU
99openssl x509 -in ca-cert.pem -trustout \
100    -addtrust anyExtendedKeyUsage -out ca+anyEKU.pem
101openssl x509 -in ca-cert.pem -trustout \
102    -addreject anyExtendedKeyUsage -out ca-anyEKU.pem
103# ca-nonca trust variants: +serverAuth, +anyEKU
104openssl x509 -in ca-nonca.pem -trustout \
105    -addtrust serverAuth -out nca+serverAuth.pem
106openssl x509 -in ca-nonca.pem -trustout \
107    -addtrust anyExtendedKeyUsage -out nca+anyEKU.pem
108
109# Intermediate CA security variants:
110# MD5 issuer signature,
111OPENSSL_SIGALG=md5 \
112./mkcert.sh genca "CA" ca-key ca-cert-md5 root-key root-cert
113openssl x509 -in ca-cert-md5.pem -trustout \
114    -addtrust anyExtendedKeyUsage -out ca-cert-md5-any.pem
115# Issuer has 768-bit key
116./mkcert.sh genca "CA" ca-key ca-cert-768i root-key-768 root-cert-768
117# CA has 768-bit key
118OPENSSL_KEYBITS=768 \
119./mkcert.sh genca "CA" ca-key-768 ca-cert-768 root-key root-cert
120# EC cert with explicit curve
121./mkcert.sh genca "CA" ca-key-ec-explicit ca-cert-ec-explicit root-key root-cert
122# EC cert with named curve
123./mkcert.sh genca "CA" ca-key-ec-named ca-cert-ec-named root-key root-cert
124
125# client intermediate ca: cca-cert
126./mkcert.sh genca -p clientAuth "CA" ca-key cca-cert root-key root-cert
127# trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth, +anyEKU, -anyEKU
128openssl x509 -in cca-cert.pem -trustout \
129    -addtrust serverAuth -out cca+serverAuth.pem
130openssl x509 -in cca-cert.pem -trustout \
131    -addreject serverAuth -out cca-serverAuth.pem
132openssl x509 -in cca-cert.pem -trustout \
133    -addtrust clientAuth -out cca+clientAuth.pem
134openssl x509 -in cca-cert.pem -trustout \
135    -addreject clientAuth -out cca-clientAuth.pem
136openssl x509 -in cca-cert.pem -trustout \
137    -addtrust anyExtendedKeyUsage -out cca+anyEKU.pem
138openssl x509 -in cca-cert.pem -trustout \
139    -addreject anyExtendedKeyUsage -out cca-anyEKU.pem
140
141# server intermediate ca: sca-cert
142./mkcert.sh genca -p serverAuth "CA" ca-key sca-cert root-key root-cert
143# trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth, +anyEKU, -anyEKU
144openssl x509 -in sca-cert.pem -trustout \
145    -addtrust serverAuth -out sca+serverAuth.pem
146openssl x509 -in sca-cert.pem -trustout \
147    -addreject serverAuth -out sca-serverAuth.pem
148openssl x509 -in sca-cert.pem -trustout \
149    -addtrust clientAuth -out sca+clientAuth.pem
150openssl x509 -in sca-cert.pem -trustout \
151    -addreject clientAuth -out sca-clientAuth.pem
152openssl x509 -in sca-cert.pem -trustout \
153    -addtrust anyExtendedKeyUsage -out sca+anyEKU.pem
154openssl x509 -in sca-cert.pem -trustout \
155    -addreject anyExtendedKeyUsage -out sca-anyEKU.pem
156
157# Primary leaf cert: ee-cert with default purpose: serverAuth
158./mkcert.sh genee server.example ee-key ee-cert ca-key ca-cert
159# ee variants: expired, issuer-key2, issuer-name2, bad-pathlen
160./mkcert.sh genee server.example ee-key ee-expired ca-key ca-cert -days -1
161./mkcert.sh genee server.example ee-key ee-cert2 ca-key2 ca-cert2
162./mkcert.sh genee server.example ee-key ee-name2 ca-key ca-name2
163./mkcert.sh genee server.example ee-key ee-pathlen ca-key ca-cert \
164    -extfile <(echo "basicConstraints=CA:false,pathlen:0") # bash needed here
165# purpose variants: clientAuth
166./mkcert.sh genee -p clientAuth server.example ee-key ee-client ca-key ca-cert
167# trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth
168openssl x509 -in ee-cert.pem -trustout \
169    -addtrust serverAuth -out ee+serverAuth.pem
170openssl x509 -in ee-cert.pem -trustout \
171    -addreject serverAuth -out ee-serverAuth.pem
172openssl x509 -in ee-client.pem -trustout \
173    -addtrust clientAuth -out ee+clientAuth.pem
174openssl x509 -in ee-client.pem -trustout \
175    -addreject clientAuth -out ee-clientAuth.pem
176
177# time stamping certificates
178./mkcert.sh genee -p critical,timeStamping -k critical,digitalSignature server.example ee-key ee-timestampsign-CABforum ca-key ca-cert
179./mkcert.sh genee -p timeStamping -k critical,digitalSignature server.example ee-key ee-timestampsign-CABforum-noncritxku ca-key ca-cert
180./mkcert.sh genee -p critical,timeStamping,serverAuth -k critical,digitalSignature server.example ee-key ee-timestampsign-CABforum-serverauth ca-key ca-cert
181./mkcert.sh genee -p critical,timeStamping,2.5.29.37.0 -k critical,digitalSignature server.example ee-key ee-timestampsign-CABforum-anyextkeyusage ca-key ca-cert
182./mkcert.sh genee -p critical,timeStamping -k critical,digitalSignature,cRLSign server.example ee-key ee-timestampsign-CABforum-crlsign ca-key ca-cert
183./mkcert.sh genee -p critical,timeStamping -k critical,digitalSignature,keyCertSign server.example ee-key ee-timestampsign-CABforum-keycertsign ca-key ca-cert
184./mkcert.sh genee -p critical,timeStamping server.example ee-key ee-timestampsign-rfc3161 ca-key ca-cert
185./mkcert.sh genee -p timeStamping server.example ee-key ee-timestampsign-rfc3161-noncritxku ca-key ca-cert
186./mkcert.sh genee -p critical,timeStamping -k digitalSignature server.example ee-key ee-timestampsign-rfc3161-digsig ca-key ca-cert
187
188# code signing certificate
189./mkcert.sh genee -p codeSigning -k critical,digitalSignature server.example ee-key ee-codesign ca-key ca-cert
190./mkcert.sh genee -p codeSigning,serverAuth -k critical,digitalSignature server.example ee-key ee-codesign-serverauth ca-key ca-cert
191./mkcert.sh genee -p codeSigning,2.5.29.37.0 -k critical,digitalSignature server.example ee-key ee-codesign-anyextkeyusage ca-key ca-cert
192./mkcert.sh genee -p codeSigning -k critical,digitalSignature,cRLSign server.example ee-key ee-codesign-crlsign ca-key ca-cert
193./mkcert.sh genee -p codeSigning -k critical,digitalSignature,keyCertSign server.example ee-key ee-codesign-keycertsign ca-key ca-cert
194./mkcert.sh genee -p codeSigning -k digitalSignature server.example ee-key ee-codesign-noncritical ca-key ca-cert
195
196# Leaf cert security level variants
197# MD5 issuer signature
198OPENSSL_SIGALG=md5 \
199./mkcert.sh genee server.example ee-key ee-cert-md5 ca-key ca-cert
200# 768-bit issuer key
201./mkcert.sh genee server.example ee-key ee-cert-768i ca-key-768 ca-cert-768
202# 768-bit leaf key
203OPENSSL_KEYBITS=768 \
204./mkcert.sh genee server.example ee-key-768 ee-cert-768 ca-key ca-cert
205# EC cert with explicit curve signed by named curve ca
206./mkcert.sh genee server.example ee-key-ec-explicit ee-cert-ec-explicit ca-key-ec-named ca-cert-ec-named
207# EC cert with named curve signed by explicit curve ca
208./mkcert.sh genee server.example ee-key-ec-named-explicit \
209    ee-cert-ec-named-explicit ca-key-ec-explicit ca-cert-ec-explicit
210# EC cert with named curve signed by named curve ca
211./mkcert.sh genee server.example ee-key-ec-named-named \
212    ee-cert-ec-named-named ca-key-ec-named ca-cert-ec-named
213# 1024-bit leaf key
214OPENSSL_KEYBITS=1024 \
215./mkcert.sh genee server.example ee-key-1024 ee-cert-1024 ca-key ca-cert
216# 3072-bit leaf key
217OPENSSL_KEYBITS=3072 \
218./mkcert.sh genee server.example ee-key-3072 ee-cert-3072 ca-key ca-cert
219# 4096-bit leaf key
220OPENSSL_KEYBITS=4096 \
221./mkcert.sh genee server.example ee-key-4096 ee-cert-4096 ca-key ca-cert
222# 8192-bit leaf key
223OPENSSL_KEYBITS=8192 \
224./mkcert.sh genee server.example ee-key-8192 ee-cert-8192 ca-key ca-cert
225
226# self-signed end-entity cert with explicit keyUsage not including KeyCertSign
227openssl req -new -x509 -key ee-key.pem -subj /CN=ee-self-signed -out ee-self-signed.pem -addext keyUsage=digitalSignature -days 36525
228
229# self-signed end-entity cert signed with RSA-PSS
230openssl req -new -x509 -key ee-key.pem -subj /CN=ee-self-signed-pss -out ee-self-signed-pss.pem -days 36525 \
231    -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest
232
233# Proxy certificates, off of ee-client
234# Start with some good ones
235./mkcert.sh req pc1-key "0.CN = server.example" "1.CN = proxy 1" | \
236    ./mkcert.sh genpc pc1-key pc1-cert ee-key ee-client \
237                "language = id-ppl-anyLanguage" "pathlen = 1" "policy = text:AB"
238./mkcert.sh req pc2-key "0.CN = server.example" "1.CN = proxy 1" "2.CN = proxy 2" | \
239    ./mkcert.sh genpc pc2-key pc2-cert pc1-key pc1-cert \
240                "language = id-ppl-anyLanguage" "pathlen = 0" "policy = text:AB"
241# And now a couple of bad ones
242# pc3: incorrect CN
243./mkcert.sh req bad-pc3-key "0.CN = server.example" "1.CN = proxy 3" | \
244    ./mkcert.sh genpc bad-pc3-key bad-pc3-cert pc1-key pc1-cert \
245                "language = id-ppl-anyLanguage" "pathlen = 0" "policy = text:AB"
246# pc4: incorrect pathlen
247./mkcert.sh req bad-pc4-key "0.CN = server.example" "1.CN = proxy 1" "2.CN = proxy 4" | \
248    ./mkcert.sh genpc bad-pc4-key bad-pc4-cert pc1-key pc1-cert \
249                "language = id-ppl-anyLanguage" "pathlen = 1" "policy = text:AB"
250# pc5: no policy
251./mkcert.sh req pc5-key "0.CN = server.example" "1.CN = proxy 1" "2.CN = proxy 5" | \
252    ./mkcert.sh genpc pc5-key pc5-cert pc1-key pc1-cert \
253                "language = id-ppl-anyLanguage" "pathlen = 0"
254# pc6: incorrect CN (made into a component of a multivalue RDN)
255./mkcert.sh req bad-pc6-key "0.CN = server.example" "1.CN = proxy 1" "2.+CN = proxy 6" | \
256    ./mkcert.sh genpc bad-pc6-key bad-pc6-cert pc1-key pc1-cert \
257                "language = id-ppl-anyLanguage" "pathlen = 0" "policy = text:AB"
258
259# Name constraints test certificates.
260
261# NC CA1 only permits the host www.good.org and *.good.com email address
262# good@good.org and *@good.com and IP addresses 127.0.0.1 and
263# 192.168.0.0/16
264
265NC="permitted;DNS:www.good.org, permitted;DNS:good.com,"
266NC="$NC permitted;email:good@good.org, permitted;email:good.com,"
267NC="$NC permitted;IP:127.0.0.1/255.255.255.255, permitted;IP:192.168.0.0/255.255.0.0"
268
269NC=$NC ./mkcert.sh genca "Test NC CA 1" ncca1-key ncca1-cert root-key root-cert
270
271# NC CA2 allows anything apart from hosts www.bad.org and *.bad.com
272# and email addresses bad@bad.org and *@bad.com
273
274NC="excluded;DNS:www.bad.org, excluded;DNS:bad.com,"
275NC="$NC excluded;email:bad@bad.org, excluded;email:bad.com, "
276NC="$NC excluded;IP:10.0.0.0/255.0.0.0"
277
278NC=$NC ./mkcert.sh genca "Test NC CA 2" ncca2-key ncca2-cert root-key root-cert
279
280# Name constraints subordinate CA. Adds www.good.net (which should be
281# disallowed because parent CA doesn't permit it) adds ok.good.com
282# (which should be allowed because parent allows *.good.com
283# and now excludes bad.ok.good.com (allowed in permitted subtrees
284# but explicitly excluded).
285
286NC="permitted;DNS:www.good.net, permitted;DNS:ok.good.com, "
287NC="$NC excluded;DNS:bad.ok.good.com"
288NC=$NC ./mkcert.sh genca "Test NC sub CA" ncca3-key ncca3-cert \
289        ncca1-key ncca1-cert
290
291# all subjectAltNames allowed by CA1.  Some CNs are not!
292
293./mkcert.sh req alt1-key "O = Good NC Test Certificate 1" \
294    "1.CN=www.example.net" "2.CN=Joe Bloggs" | \
295    ./mkcert.sh geneealt alt1-key alt1-cert ncca1-key ncca1-cert \
296    "DNS.1 = www.good.org" "DNS.2 = any.good.com" \
297    "email.1 = good@good.org" "email.2 = any@good.com" \
298    "IP = 127.0.0.1" "IP = 192.168.0.1"
299
300# all DNS-like CNs allowed by CA1, no DNS SANs.
301
302./mkcert.sh req goodcn1-key "O = Good NC Test Certificate 1" \
303    "1.CN=www.good.org" "2.CN=any.good.com" \
304    "3.CN=not..dns" "4.CN=not@dns" "5.CN=not-.dns" "6.CN=not.dns." | \
305    ./mkcert.sh geneealt goodcn1-key goodcn1-cert ncca1-key ncca1-cert \
306    "IP = 127.0.0.1" "IP = 192.168.0.1"
307
308# all DNS-like CNs allowed by CA1, no SANs
309
310./mkcert.sh req goodcn2-key "O = Good NC Test Certificate 1" \
311    "CN=www.good.org" | \
312    ./mkcert.sh geneeconfig goodcn2-key goodcn2-cert ncca1-key ncca1-cert
313
314# Some DNS-like CNs not permitted by CA1, no DNS SANs.
315
316./mkcert.sh req badcn1-key "O = Good NC Test Certificate 1" \
317    "1.CN=www.good.org" "3.CN=bad.net" | \
318    ./mkcert.sh geneealt badcn1-key badcn1-cert ncca1-key ncca1-cert \
319    "IP = 127.0.0.1" "IP = 192.168.0.1"
320
321# no subjectAltNames excluded by CA2.
322
323./mkcert.sh req alt2-key "O = Good NC Test Certificate 2" | \
324    ./mkcert.sh geneealt alt2-key alt2-cert ncca2-key ncca2-cert \
325    "DNS.1 = www.anything.org" "DNS.2 = any.other.com" \
326    "email.1 = other@bad.org" "email.2 = any@something.com"
327
328# hostname other.good.org which is not allowed by CA1.
329
330./mkcert.sh req badalt1-key "O = Bad NC Test Certificate 1" | \
331    ./mkcert.sh geneealt badalt1-key badalt1-cert ncca1-key ncca1-cert \
332    "DNS.1 = other.good.org" "DNS.2 = any.good.com" \
333    "email.1 = good@good.org" "email.2 = any@good.com"
334
335# any.bad.com is excluded by CA2.
336
337./mkcert.sh req badalt2-key 'O = Bad NC Test Certificate 2' | \
338    ./mkcert.sh geneealt badalt2-key badalt2-cert ncca2-key ncca2-cert \
339    "DNS.1 = www.good.org" "DNS.2 = any.bad.com" \
340    "email.1 = good@good.org" "email.2 = any@good.com"
341
342# other@good.org not permitted by CA1
343
344./mkcert.sh req badalt3-key "O = Bad NC Test Certificate 3" | \
345    ./mkcert.sh geneealt badalt3-key badalt1-cert ncca1-key ncca1-cert \
346    "DNS.1 = www.good.org" "DNS.2 = any.good.com" \
347    "email.1 = other@good.org" "email.2 = any@good.com"
348
349# all subject alt names OK but subject email address not allowed by CA1.
350
351./mkcert.sh req badalt4-key 'O = Bad NC Test Certificate 4' \
352    "emailAddress = any@other.com" | \
353    ./mkcert.sh geneealt badalt4-key badalt4-cert ncca1-key ncca1-cert \
354    "DNS.1 = www.good.org" "DNS.2 = any.good.com" \
355    "email.1 = good@good.org" "email.2 = any@good.com"
356
357# IP address not allowed by CA1
358./mkcert.sh req badalt5-key "O = Bad NC Test Certificate 5" | \
359    ./mkcert.sh geneealt badalt5-key badalt5-cert ncca1-key ncca1-cert \
360    "DNS.1 = www.good.org" "DNS.2 = any.good.com" \
361    "email.1 = good@good.org" "email.2 = any@good.com" \
362    "IP = 127.0.0.2"
363
364# No DNS-ID SANs and subject CN not allowed by CA1.
365./mkcert.sh req badalt6-key "O = Bad NC Test Certificate 6" \
366    "1.CN=other.good.org" "2.CN=Joe Bloggs" "3.CN=any.good.com" | \
367    ./mkcert.sh geneealt badalt6-key badalt6-cert ncca1-key ncca1-cert \
368    "email.1 = good@good.org" "email.2 = any@good.com" \
369    "IP = 127.0.0.1" "IP = 192.168.0.1"
370
371# No DNS-ID SANS and subject CN not allowed by CA1, BMPSTRING
372REQMASK=MASK:0x800 ./mkcert.sh req badalt7-key "O = Bad NC Test Certificate 7" \
373    "1.CN=other.good.org" "2.CN=Joe Bloggs" "3.CN=any.good.com" | \
374    ./mkcert.sh geneealt badalt7-key badalt7-cert ncca1-key ncca1-cert \
375    "email.1 = good@good.org" "email.2 = any@good.com" \
376    "IP = 127.0.0.1" "IP = 192.168.0.1"
377
378# all subjectAltNames allowed by chain
379
380./mkcert.sh req alt3-key "O = Good NC Test Certificate 3" \
381    "1.CN=www.ok.good.com" "2.CN=Joe Bloggs" | \
382    ./mkcert.sh geneealt alt3-key alt3-cert ncca3-key ncca3-cert \
383    "DNS.1 = www.ok.good.com" \
384    "email.1 = good@good.org" "email.2 = any@good.com" \
385    "IP = 127.0.0.1" "IP = 192.168.0.1"
386
387# www.good.net allowed by parent CA but not parent of parent
388
389./mkcert.sh req badalt8-key "O = Bad NC Test Certificate 8" \
390    "1.CN=www.good.com" "2.CN=Joe Bloggs" | \
391    ./mkcert.sh geneealt badalt8-key badalt8-cert ncca3-key ncca3-cert \
392    "DNS.1 = www.ok.good.com" "DNS.2 = www.good.net" \
393    "email.1 = good@good.org" "email.2 = any@good.com" \
394    "IP = 127.0.0.1" "IP = 192.168.0.1"
395
396# other.good.com not allowed by parent CA but allowed by parent of parent
397
398./mkcert.sh req badalt9-key "O = Bad NC Test Certificate 9" \
399    "1.CN=www.good.com" "2.CN=Joe Bloggs" | \
400    ./mkcert.sh geneealt badalt9-key badalt9-cert ncca3-key ncca3-cert \
401    "DNS.1 = www.good.com" "DNS.2 = other.good.com" \
402    "email.1 = good@good.org" "email.2 = any@good.com" \
403    "IP = 127.0.0.1" "IP = 192.168.0.1"
404
405# www.bad.net excluded by parent CA.
406
407./mkcert.sh req badalt10-key "O = Bad NC Test Certificate 10" \
408    "1.CN=www.ok.good.com" "2.CN=Joe Bloggs" | \
409    ./mkcert.sh geneealt badalt10-key badalt10-cert ncca3-key ncca3-cert \
410    "DNS.1 = www.ok.good.com" "DNS.2 = bad.ok.good.com" \
411    "email.1 = good@good.org" "email.2 = any@good.com" \
412    "IP = 127.0.0.1" "IP = 192.168.0.1"
413
414# Certs for CVE-2022-4203 testcase
415
416NC="excluded;otherName:SRVName;UTF8STRING:foo@example.org" ./mkcert.sh genca \
417    "Test NC CA othername" nccaothername-key nccaothername-cert \
418    root-key root-cert
419
420./mkcert.sh req alt-email-key "O = NC email in othername Test Certificate" | \
421    ./mkcert.sh geneealt bad-othername-key bad-othername-cert \
422    nccaothername-key nccaothername-cert \
423    "otherName.1 = SRVName;UTF8STRING:foo@example.org"
424
425# RSA-PSS signatures
426# SHA1
427./mkcert.sh genee PSS-SHA1 ee-key ee-pss-sha1-cert ca-key ca-cert \
428    -sha1 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest
429# EE SHA256
430./mkcert.sh genee PSS-SHA256 ee-key ee-pss-sha256-cert ca-key ca-cert \
431            -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest
432# CA-PSS
433./mkcert.sh genca "CA-PSS" ca-pss-key ca-pss-cert root-key root-cert \
434            -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1
435./mkcert.sh genee "EE-PSS" ee-key ee-pss-cert ca-pss-key ca-pss-cert \
436            -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1
437# Should not have been possible to produce, see issue #13968:
438#./mkcert.sh genee "EE-PSS-wrong1.5" ee-key ee-pss-wrong1.5-cert ca-pss-key ca-pss-cert -sha256
439
440OPENSSL_KEYALG=ec OPENSSL_KEYBITS=brainpoolP256r1 ./mkcert.sh genee \
441    "Server ECDSA brainpoolP256r1 cert" server-ecdsa-brainpoolP256r1-key \
442    server-ecdsa-brainpoolP256r1-cert rootkey rootcert
443
444openssl req -new -noenc -subj "/CN=localhost" \
445    -newkey rsa-pss -keyout server-pss-restrict-key.pem \
446    -pkeyopt rsa_pss_keygen_md:sha256 -pkeyopt rsa_pss_keygen_saltlen:32 | \
447    ./mkcert.sh geneenocsr "Server RSA-PSS restricted cert" \
448    server-pss-restrict-cert rootkey rootcert
449
450openssl req -new -noenc -subj "/CN=Client-RSA-PSS" \
451    -newkey rsa-pss -keyout client-pss-restrict-key.pem \
452    -pkeyopt rsa_pss_keygen_md:sha256 -pkeyopt rsa_pss_keygen_saltlen:32 | \
453    ./mkcert.sh geneenocsr -p clientAuth "Client RSA-PSS restricted cert" \
454    client-pss-restrict-cert rootkey rootcert
455
456# CT entry
457./mkcert.sh genct server.example embeddedSCTs1-key embeddedSCTs1 embeddedSCTs1_issuer-key embeddedSCTs1_issuer ct-server-key
458
459OPENSSL_SIGALG= OPENSSL_KEYALG=ed448 ./mkcert.sh genroot "Root Ed448" \
460    root-ed448-key root-ed448-cert
461OPENSSL_SIGALG=ED448 OPENSSL_KEYALG=ed448 ./mkcert.sh genee ed448 \
462    server-ed448-key server-ed448-cert root-ed448-key root-ed448-cert
463
464# non-critical unknown extension
465./mkcert.sh geneeextra server.example ee-key ee-cert-noncrit-unknown-ext ca-key ca-cert "1.2.3.4=DER:05:00"
466
467# critical unknown extension
468./mkcert.sh geneeextra server.example ee-key ee-cert-crit-unknown-ext ca-key ca-cert "1.2.3.4=critical,DER:05:00"
469
470# critical id-pkix-ocsp-no-check extension
471./mkcert.sh geneeextra server.example ee-key ee-cert-ocsp-nocheck ca-key ca-cert "1.3.6.1.5.5.7.48.1.5=critical,DER:05:00"
472
473# certificatePolicies extension
474./mkcert.sh genca -c "1.3.6.1.4.1.16604.998855.1" "CA" ca-key ca-pol-cert root-key root-cert
475./mkcert.sh geneeextra server.example ee-key ee-cert-policies ca-key ca-cert "certificatePolicies=1.3.6.1.4.1.16604.998855.1"
476# We can create a cert with a duplicate policy oid - but its actually invalid!
477./mkcert.sh geneeextra server.example ee-key ee-cert-policies-bad ca-key ca-cert "certificatePolicies=1.3.6.1.4.1.16604.998855.1,1.3.6.1.4.1.16604.998855.1"
478
479# EC cert signed by curve ca with SHA3-224, SHA3-256, SHA3-384, SHA3-512
480OPENSSL_SIGALG="sha3-224" ./mkcert.sh genee server.example ee-key-ec-named-named ee-cert-ec-sha3-224 ca-key-ec-named ca-cert-ec-named
481OPENSSL_SIGALG="sha3-256" ./mkcert.sh genee server.example ee-key-ec-named-named ee-cert-ec-sha3-256 ca-key-ec-named ca-cert-ec-named
482OPENSSL_SIGALG="sha3-384" ./mkcert.sh genee server.example ee-key-ec-named-named ee-cert-ec-sha3-384 ca-key-ec-named ca-cert-ec-named
483OPENSSL_SIGALG="sha3-512" ./mkcert.sh genee server.example ee-key-ec-named-named ee-cert-ec-sha3-512 ca-key-ec-named ca-cert-ec-named
484