source: mod_gnutls/test/test_ca.mk @ 2b80754

debian/masterdebian/stretch-backportsjessie-backportsupstream
Last change on this file since 2b80754 was 2b80754, checked in by Thomas Klute <thomas2.klute@…>, 3 years ago

Delete target files before exporting PGP certificates

GnuPG promts or (with --batch) fails if the target file exists.

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