source: mod_gnutls/test/test_ca.mk @ af9e3a5

debian/master
Last change on this file since af9e3a5 was b47dc70, checked in by Fiona Klute <fiona.klute@…>, 14 months ago

Test suite: Simplify certificate template creation

  • Property mode set to 100644
File size: 4.6 KB
Line 
1#!/usr/bin/make -f
2# Authors:
3# Daniel Kahn Gillmor <dkg@fifthhorseman.net>
4# Fiona Klute <fiona.klute@gmx.de>
5
6# General rules to set up a miniature CA & server & client environment
7# for the test suite
8
9%.template: $(srcdir)/%.template.in
10        sed s/__HOSTNAME__/$(TEST_HOST)/ < $< > $@
11        sed -i -e "s,__OCSP_URI__,$(OCSP_URI_TEMPLATE)," $@
12        for i in $(patsubst [%],%,$(TEST_IP)); do \
13                IP_ADDRS="$${IP_ADDRS}\nip_address = $${i}"; \
14        done; \
15        sed -i -e "s,__IP_ADDRESSES__,$${IP_ADDRS#\\n}," $@
16
17%.uid: $(srcdir)/%.uid.in
18        sed s/__HOSTNAME__/$(TEST_HOST)/ < $< > $@
19
20%/secret.key:
21        mkdir -p $(dir $@)
22        chmod 0700 $(dir $@)
23        certtool --outfile $@ --generate-privkey
24
25%/secret.pgp.raw: %.uid %/secret.key
26        PEM2OPENPGP_USAGE_FLAGS=authenticate,certify,sign pem2openpgp "$$(cat $<)" < $(dir $@)secret.key > $@
27
28%/secret.pgp: %/secret.pgp.raw pgpcrc
29        (printf -- '-----BEGIN PGP PRIVATE KEY BLOCK-----\nVersion: test\n\n' && \
30        base64 < $< && \
31        printf -- '=' && \
32        ./pgpcrc < $< | base64 && \
33        printf -- '-----END PGP PRIVATE KEY BLOCK-----\n' ) > $@
34
35%/gpg.conf: %/secret.pgp
36        rm -f $(dir $@)pubring.gpg $(dir $@)secring.gpg $(dir $@)trustdb.gpg $(dir $@)pubring.kbx $(dir $@)private-keys-v1.d/*.key
37        GNUPGHOME=$(dir $@) gpg --import $<
38        printf "%s:6:\n" "$$(GNUPGHOME=$(dir $@) gpg --with-colons --list-secret-keys --fingerprint | grep ^fpr: | cut -f 10 -d :)" | GNUPGHOME=$(dir $@) gpg --import-ownertrust
39        printf "default-key %s\n" "$$(GNUPGHOME=$(dir $@) gpg --with-colons --list-secret-keys --fingerprint | grep ^fpr: | cut -f 10 -d :)" > $@
40
41%/minimal.pgp: %/gpg.conf
42        if test -r $@; then rm $@; fi
43        GNUPGHOME=$(dir $@) gpg --output $@ --armor --export "$$(GNUPGHOME=$(dir $@) gpg --with-colons --list-secret-keys --fingerprint | grep ^fpr: | cut -f 10 -d :)"
44
45# Import and signing modify the shared keyring, which leads to race
46# conditions with parallel make. Locking avoids this problem. Building
47# authority/minimal.pgp (instead of just authority/gpg.conf) before
48# */cert.pgp avoids having to lock for all */minimal.pgp, too.
49%/cert.pgp: %/minimal.pgp authority/minimal.pgp
50        if test -r $@; then rm $@; fi
51        GNUPGHOME=authority/ $(GPG_FLOCK) gpg --import $<
52        GNUPGHOME=authority/ $(GPG_FLOCK) gpg --batch --sign-key --no-tty --yes "$$(GNUPGHOME=$(dir $@) gpg --with-colons --list-secret-keys --fingerprint | grep ^fpr: | cut -f 10 -d :)"
53        GNUPGHOME=authority/ $(GPG_FLOCK) gpg --output $@ --armor --export "$$(GNUPGHOME=$(dir $@) gpg --with-colons --list-secret-keys --fingerprint | grep ^fpr: | cut -f 10 -d :)"
54
55# special cases for the authorities' root certs:
56authority/x509.pem: authority.template authority/secret.key
57        certtool --outfile $@ --generate-self-signed --load-privkey authority/secret.key --template authority.template
58rogueca/x509.pem: $(srcdir)/rogueca.template rogueca/secret.key
59        certtool --outfile $@ --generate-self-signed --load-privkey rogueca/secret.key --template $(srcdir)/rogueca.template
60
61%/cert-request: %.template %/secret.key
62        certtool --outfile $@ --generate-request --load-privkey $(dir $@)secret.key --template $<
63
64# normal case: certificates signed by test CA
65%/x509.pem: %.template %/cert-request authority/secret.key authority/x509.pem
66        certtool --outfile $@ --generate-certificate --load-ca-certificate authority/x509.pem --load-ca-privkey authority/secret.key --load-request $(dir $@)cert-request --template $<
67
68# error case: certificates signed by rogue CA
69rogue%/x509.pem: rogue%.template rogue%/cert-request rogueca/x509.pem
70        certtool --outfile $@ --generate-certificate --load-ca-certificate rogueca/x509.pem --load-ca-privkey rogueca/secret.key --load-request $(dir $@)cert-request --template $<
71
72%/softhsm.conf: %/secret.key
73        echo "0:$(dir $@)softhsm.db" > $@
74
75%/softhsm.db: %/x509.pem %/secret.key %/softhsm.conf
76        SOFTHSM="$(SOFTHSM)" \
77        SOFTHSM_CONF="$(dir $@)softhsm.conf" \
78        $(srcdir)/softhsm.bash init $(dir $@)secret.key $(dir $@)x509.pem
79
80%/softhsm2.conf: %/secret.key
81        echo "objectstore.backend = file" > $@
82        echo "directories.tokendir = $(dir $@)softhsm2.db" >> $@
83
84%/softhsm2.db: %/x509.pem %/secret.key %/softhsm2.conf
85        mkdir -p $@
86        SOFTHSM="$(SOFTHSM)" \
87        SOFTHSM2_CONF="$(dir $@)softhsm2.conf" \
88        $(srcdir)/softhsm.bash init $(dir $@)secret.key $(dir $@)x509.pem
89
90# Generate CRL revoking a certain certificate. Currently used to
91# revoke the server certificate and check if setting the CRL as
92# GnuTLSProxyCRLFile causes the connection to the back end server to
93# fail.
94%/crl.pem: %/x509.pem ${srcdir}/%-crl.template
95        certtool --generate-crl \
96                --outfile $@ \
97                --load-ca-privkey authority/secret.key \
98                --load-ca-certificate authority/x509.pem \
99                --load-certificate $< \
100                --template "${srcdir}/$(*)-crl.template"
Note: See TracBrowser for help on using the repository browser.