e2e: strict-X.509-compatible test CA

This commit is contained in:
grabowski committed 2026-10-23 10:16:55 +07:00
1 parent cbd85c1e30
commit 07ff88c18d
1 file changed
+24 -3
+24 -3
View File
@@ -7,14 +7,35 @@
{ mailmig, nixos-mailserver }: { mailmig, nixos-mailserver }:
{ pkgs, lib, ... }: { pkgs, lib, ... }:
let let
# Python 3.13 verifies strictly (VERIFY_X509_STRICT): the CA needs keyUsage,
# leaves need SKI/AKI.
certs = pkgs.runCommand "mailmig-test-certs" { nativeBuildInputs = [ pkgs.openssl ]; } '' certs = pkgs.runCommand "mailmig-test-certs" { nativeBuildInputs = [ pkgs.openssl ]; } ''
mkdir $out && cd $out mkdir $out && cd $out
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \ cat > ca.cnf <<EOF
-keyout ca.key -out ca.crt -days 3650 -subj "/CN=mailmig test CA" [req]
distinguished_name = dn
x509_extensions = v3_ca
prompt = no
[dn]
CN = mailmig test CA
[v3_ca]
basicConstraints = critical,CA:TRUE
keyUsage = critical,keyCertSign,cRLSign
subjectKeyIdentifier = hash
EOF
openssl req -x509 -config ca.cnf -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \
-keyout ca.key -out ca.crt -days 3650
for h in old new; do for h in old new; do
openssl req -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \ openssl req -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \
-keyout $h.key -out $h.csr -subj "/CN=$h.test" -keyout $h.key -out $h.csr -subj "/CN=$h.test"
printf 'subjectAltName=DNS:%s.test\nextendedKeyUsage=serverAuth\nkeyUsage=digitalSignature\nbasicConstraints=CA:FALSE\n' $h > $h.ext cat > $h.ext <<EOF
subjectAltName = DNS:$h.test
extendedKeyUsage = serverAuth
keyUsage = critical,digitalSignature
basicConstraints = critical,CA:FALSE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid
EOF
openssl x509 -req -in $h.csr -CA ca.crt -CAkey ca.key -CAcreateserial \ openssl x509 -req -in $h.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
-out $h.crt -days 3650 -extfile $h.ext -out $h.crt -days 3650 -extfile $h.ext
done done