Debian Codegraph @

tests/cert-extensions

raw
1 # X509v3 certificate extension, cf. x509v3_config(5ssl)
2
3 x509_check() {
4 local cert="$1" ext out
5 out="$(mktemp --tmpdir)"
6 ext="basicConstraints,subjectAltName,keyUsage,extendedKeyUsage,tlsfeature"
7 openssl x509 -in "$cert" -noout -subject -ext "$ext" -nameopt compat >"$out"
8 diff --unified --color=auto -b --label="a/${cert#/}" --label="b/${cert#/}" -- - "$out"
9 }
10
11 # default settings (the ACME server adds a subjectAltName with the Common Name)
12 openssl genpkey -algorithm RSA -out /etc/lacme/test1.key
13 commonName="$(head -c10 /dev/urandom | base32 -w0 | tr "A-Z" "a-z").$DOMAINNAME"
14 cat >"/etc/lacme/lacme-certs.conf.d/test1.conf" <<- EOF
15 [test1]
16 certificate-key = /etc/lacme/test1.key
17 certificate-chain = /etc/lacme/test1.crt
18 subject = /CN=$commonName
19 EOF
20
21 lacme newOrder test1
22 test /etc/lacme/test1.crt -nt /etc/lacme/test1.key
23 x509_check /etc/lacme/test1.crt <<-EOF
24 subject=/CN=$commonName
25 X509v3 Key Usage: critical
26 Digital Signature, Key Encipherment
27 X509v3 Extended Key Usage:
28 TLS Web Server Authentication, TLS Web Client Authentication
29 X509v3 Basic Constraints: critical
30 CA:FALSE
31 X509v3 Subject Alternative Name:
32 DNS:$commonName
33 EOF
34
35 # subjectAltName
36 openssl genpkey -algorithm RSA -out /etc/lacme/test2.key
37 commonName="$(head -c10 /dev/urandom | base32 -w0 | tr "A-Z" "a-z").$DOMAINNAME"
38 subjectAltName=""
39 for i in $(seq 1 8); do
40 subjectAltName="${subjectAltName:+"$subjectAltName "}$(head -c10 /dev/urandom | base32 -w0 | tr "A-Z" "a-z").$DOMAINNAME"
41 done
42 cat >"/etc/lacme/lacme-certs.conf.d/test2.conf" <<- EOF
43 [test2]
44 certificate-key = /etc/lacme/test2.key
45 certificate-chain = /etc/lacme/test2.crt
46 subject = /CN=$commonName
47 subjectAltName = DNS:$(echo "$subjectAltName" | sed -r "s/ /, DNS:/g")
48 EOF
49
50 lacme newOrder test2
51 test /etc/lacme/test2.crt -nt /etc/lacme/test2.key
52 x509_check /etc/lacme/test2.crt <<-EOF
53 subject=/CN=$commonName
54 X509v3 Key Usage: critical
55 Digital Signature, Key Encipherment
56 X509v3 Extended Key Usage:
57 TLS Web Server Authentication, TLS Web Client Authentication
58 X509v3 Basic Constraints: critical
59 CA:FALSE
60 X509v3 Subject Alternative Name:
61 DNS:$(echo "$commonName" "$subjectAltName" | tr " " "\\n" | sort -u | paste -sd" " | sed -r "s/ /, DNS:/g")
62 EOF
63
64 # tlsfeature
65 openssl genpkey -algorithm RSA -out /etc/lacme/test3.key
66 commonName="$(head -c10 /dev/urandom | base32 -w0 | tr "A-Z" "a-z").$DOMAINNAME"
67 cat >"/etc/lacme/lacme-certs.conf.d/test3.conf" <<- EOF
68 [test3]
69 certificate-key = /etc/lacme/test3.key
70 certificate-chain = /etc/lacme/test3.crt
71 subject = /CN=$commonName
72 tlsfeature = status_request
73 EOF
74
75 lacme newOrder test3
76 test /etc/lacme/test3.crt -nt /etc/lacme/test3.key
77 x509_check /etc/lacme/test3.crt <<-EOF
78 subject=/CN=$commonName
79 X509v3 Key Usage: critical
80 Digital Signature, Key Encipherment
81 X509v3 Extended Key Usage:
82 TLS Web Server Authentication, TLS Web Client Authentication
83 X509v3 Basic Constraints: critical
84 CA:FALSE
85 X509v3 Subject Alternative Name:
86 DNS:$commonName
87 TLS Feature:
88 status_request
89 EOF
90
91 # vim: set filetype=sh :