Debian Codegraph @

tests/certs/generate

raw symbols SCIP
1 #!/bin/sh
2
3 set -ue
4 PATH="/usr/bin:/bin"
5 export PATH
6
7 BASEDIR="$(dirname -- "$0")"
8 OU="InterIMAP test suite"
9 cd "$BASEDIR"
10
11 OPENSSL_CONF="./openssl.cnf"
12 export OPENSSL_CONF
13
14 cadir="$(mktemp --tmpdir --directory)"
15 trap 'rm -rf -- "$cadir"' EXIT INT TERM
16 genpkey() {
17 local key="$1"
18 shift
19 openssl genpkey -out "$key" "$@" 2>&1
20 }
21
22 # generate CA (we intentionally throw away the private key and serial
23 # file to avoid reuse)
24 genpkey "$cadir/ca.key" -algorithm RSA
25 openssl req -new -x509 -rand /dev/urandom \
26 -subj "/OU=$OU/CN=Fake Root CA" \
27 -addext subjectKeyIdentifier="hash" \
28 -addext authorityKeyIdentifier="keyid:always,issuer" \
29 -addext basicConstraints="critical,CA:TRUE" \
30 -key "$cadir/ca.key" -out ./ca.crt
31
32 SERIAL=1
33 new() {
34 local key="$1" cn="$2"
35 openssl req -new -rand /dev/urandom -key "$key" \
36 -subj "/OU=$OU/CN=$cn" ${3+-addext subjectAltName="$3"} \
37 -out "$cadir/new.csr"
38 cat >"$cadir/new-ext.cnf" <<-EOF
39 basicConstraints = critical, CA:FALSE
40 keyUsage = critical, digitalSignature, keyEncipherment
41 extendedKeyUsage = critical, serverAuth
42 EOF
43 if [ -n "${3+x}" ]; then
44 printf "subjectAltName = %s\\n" "$3" >>"$cadir/new-ext.cnf"
45 fi
46 openssl x509 -req -in "$cadir/new.csr" -CA ./ca.crt -CAkey "$cadir/ca.key" \
47 -CAserial "$cadir/ca.srl" -CAcreateserial -extfile "$cadir/new-ext.cnf" 2>&1
48 }
49
50 genpkey ./dovecot.rsa.key -algorithm RSA
51 new ./dovecot.rsa.key "localhost" "DNS:localhost,DNS:ip6-localhost,IP:127.0.0.1,IP:::1" >./dovecot.rsa.crt
52
53 genpkey ./dovecot.ecdsa.key -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -pkeyopt ec_param_enc:named_curve
54 new ./dovecot.ecdsa.key "localhost" >./dovecot.ecdsa.crt
55
56 genpkey ./dovecot.rsa2.key -algorithm RSA
57 new ./dovecot.rsa2.key "imap.example.net" "DNS:imap.example.net,DNS:localhost" >./dovecot.rsa2.crt