source: mod_gnutls/test/test_ca.mk @ b712429

proxy-ticket
Last change on this file since b712429 was b712429, checked in by Fiona Klute <fiona.klute@…>, 15 months ago

Test suite: Unify rules for X.509 root certificate generation

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