Debian Codegraph @

debian/tests/test-common

raw
1 # Create CA private key and certificate
2 openssl genrsa -out "$AUTOPKGTEST_TMP/ca.key.priv.pem" 2048
3 cat >"$AUTOPKGTEST_TMP/ca.openssl.cnf" <<EOF
4 [ req ]
5 distinguished_name = req_dn
6 string_mask = utf8only
7 prompt = no
8 x509_extensions = req_ext
9
10 [ req_dn ]
11 commonName = ktls-utils test CA
12
13 [ req_ext ]
14 subjectKeyIdentifier = hash
15 authorityKeyIdentifier = keyid:always,issuer:always
16 basicConstraints = critical, CA:true
17 EOF
18 openssl req -new -key "$AUTOPKGTEST_TMP/ca.key.priv.pem" \
19 -utf8 -nodes -batch -x509 \
20 -outform PEM -out "$AUTOPKGTEST_TMP/ca.x509.pem" \
21 -config "$AUTOPKGTEST_TMP/ca.openssl.cnf"
22
23 sed -i '/^\[authenticate\.client\]/,$ { /=/d }' \
24 /etc/tlshd/config
25
26 for role in server client; do
27 # Create private key and certificate for role
28 openssl genrsa -out "$AUTOPKGTEST_TMP/$role.key.priv.pem" 2048
29 cat >"$AUTOPKGTEST_TMP/$role.openssl.cnf" <<EOF
30 [ req ]
31 distinguished_name = req_dn
32 string_mask = utf8only
33 prompt = no
34 x509_extensions = req_ext
35
36 [ req_dn ]
37 commonName = $role.internal
38
39 [ req_ext ]
40 subjectKeyIdentifier = hash
41 authorityKeyIdentifier = keyid:always,issuer:always
42 basicConstraints = critical, CA:false
43 extendedKeyUsage = critical, ${role}Auth
44 EOF
45 openssl req -new -key "$AUTOPKGTEST_TMP/$role.key.priv.pem" \
46 -out "$AUTOPKGTEST_TMP/$role.req.pem" \
47 -config "$AUTOPKGTEST_TMP/$role.openssl.cnf"
48 openssl req -in "$AUTOPKGTEST_TMP/$role.req.pem" \
49 -copy_extensions copy \
50 -CA "$AUTOPKGTEST_TMP/ca.x509.pem" \
51 -CAkey "$AUTOPKGTEST_TMP/ca.key.priv.pem" \
52 -utf8 -nodes -batch -x509 \
53 -outform PEM -out "$AUTOPKGTEST_TMP/$role.x509.pem" \
54 -config "$AUTOPKGTEST_TMP/$role.openssl.cnf"
55
56 # Update tlshd config
57 sed -i '/^\[authenticate\.'$role'\]/a\
58 x509.truststore='"$AUTOPKGTEST_TMP/ca.x509.pem"'\
59 x509.certificate='"$AUTOPKGTEST_TMP/$role.x509.pem"'\
60 x509.private_key='"$AUTOPKGTEST_TMP/$role.key.priv.pem" \
61 /etc/tlshd/config
62 done
63
64 # Make server name resolvable
65 if ! grep -qw 'server\.internal' /etc/hosts; then
66 cat >>/etc/hosts <<EOF
67 ::1 server.internal
68 EOF
69 fi
70
71 # Restart tlshd with new config
72 systemctl restart tlshd