[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 | |
---|
[33af2b7] | 9 | %.template: $(srcdir)/%.template.in |
---|
[4b53371] | 10 | sed s/__HOSTNAME__/$(TEST_HOST)/ < $< > $@ |
---|
[a0161fe] | 11 | if test -n "$(OCSP_PORT)"; then \ |
---|
| 12 | sed -i -e 's/^### ocsp/ocsp/' \ |
---|
| 13 | -e s/__OCSP_PORT__/$(OCSP_PORT)/ $@; \ |
---|
| 14 | fi |
---|
[4b53371] | 15 | |
---|
[33af2b7] | 16 | %.uid: $(srcdir)/%.uid.in |
---|
[4b53371] | 17 | sed s/__HOSTNAME__/$(TEST_HOST)/ < $< > $@ |
---|
| 18 | |
---|
| 19 | %/secret.key: |
---|
| 20 | mkdir -p $(dir $@) |
---|
| 21 | chmod 0700 $(dir $@) |
---|
[298dc66] | 22 | certtool --outfile $@ --generate-privkey |
---|
[4b53371] | 23 | |
---|
[d70dd6e] | 24 | %/secret.pgp.raw: %.uid %/secret.key |
---|
| 25 | PEM2OPENPGP_EXPIRATION=86400 PEM2OPENPGP_USAGE_FLAGS=authenticate,certify,sign pem2openpgp "$$(cat $<)" < $(dir $@)secret.key > $@ |
---|
[4b53371] | 26 | |
---|
[d70dd6e] | 27 | %/secret.pgp: %/secret.pgp.raw pgpcrc |
---|
| 28 | (printf -- '-----BEGIN PGP PRIVATE KEY BLOCK-----\nVersion: test\n\n' && \ |
---|
| 29 | base64 < $< && \ |
---|
| 30 | printf -- '=' && \ |
---|
| 31 | ./pgpcrc < $< | base64 && \ |
---|
| 32 | printf -- '-----END PGP PRIVATE KEY BLOCK-----\n' ) > $@ |
---|
[3e800f9] | 33 | |
---|
[d70dd6e] | 34 | %/gpg.conf: %/secret.pgp |
---|
| 35 | rm -f $(dir $@)pubring.gpg $(dir $@)secring.gpg $(dir $@)trustdb.gpg $(dir $@)pubring.kbx $(dir $@)private-keys-v1.d/*.key |
---|
| 36 | GNUPGHOME=$(dir $@) gpg --import $< |
---|
| 37 | printf "%s:6:\n" "$$(GNUPGHOME=$(dir $@) gpg --with-colons --list-secret-keys --fingerprint | grep ^fpr: | cut -f 10 -d :)" | GNUPGHOME=$(dir $@) gpg --import-ownertrust |
---|
| 38 | printf "default-key %s\n" "$$(GNUPGHOME=$(dir $@) gpg --with-colons --list-secret-keys --fingerprint | grep ^fpr: | cut -f 10 -d :)" > $@ |
---|
[3e800f9] | 39 | |
---|
[d70dd6e] | 40 | %/minimal.pgp: %/gpg.conf |
---|
[2b80754] | 41 | if test -r $@; then rm $@; fi |
---|
[d70dd6e] | 42 | GNUPGHOME=$(dir $@) gpg --output $@ --armor --export "$$(GNUPGHOME=$(dir $@) gpg --with-colons --list-secret-keys --fingerprint | grep ^fpr: | cut -f 10 -d :)" |
---|
[3e800f9] | 43 | |
---|
[d92899e] | 44 | # Import and signing modify the shared keyring, which leads to race |
---|
[04addef] | 45 | # conditions with parallel make. Locking avoids this problem. Building |
---|
| 46 | # authority/minimal.pgp (instead of just authority/gpg.conf) before |
---|
| 47 | # */cert.pgp avoids having to lock for all */minimal.pgp, too. |
---|
| 48 | %/cert.pgp: %/minimal.pgp authority/minimal.pgp |
---|
[2b80754] | 49 | if test -r $@; then rm $@; fi |
---|
[ee94de5] | 50 | GNUPGHOME=authority/ $(GPG_FLOCK) gpg --import $< |
---|
| 51 | 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 :)" |
---|
| 52 | GNUPGHOME=authority/ $(GPG_FLOCK) gpg --output $@ --armor --export "$$(GNUPGHOME=$(dir $@) gpg --with-colons --list-secret-keys --fingerprint | grep ^fpr: | cut -f 10 -d :)" |
---|
[3e800f9] | 53 | |
---|
| 54 | # special cases for the authorities' root certs: |
---|
[4b53371] | 55 | authority/x509.pem: authority.template authority/secret.key |
---|
[298dc66] | 56 | certtool --outfile $@ --generate-self-signed --load-privkey authority/secret.key --template authority.template |
---|
[33af2b7] | 57 | rogueca/x509.pem: $(srcdir)/rogueca.template rogueca/secret.key |
---|
[298dc66] | 58 | certtool --outfile $@ --generate-self-signed --load-privkey rogueca/secret.key --template $(srcdir)/rogueca.template |
---|
[4b53371] | 59 | |
---|
[a63301f] | 60 | %/cert-request: %.template %/secret.key |
---|
[298dc66] | 61 | certtool --outfile $@ --generate-request --load-privkey $(dir $@)secret.key --template $< |
---|
[4b53371] | 62 | |
---|
[c0bb823] | 63 | # normal case: certificates signed by test CA |
---|
[a63301f] | 64 | %/x509.pem: %.template %/cert-request authority/secret.key authority/x509.pem |
---|
[42829ae] | 65 | certtool --outfile $@ --generate-certificate --load-ca-certificate authority/x509.pem --load-ca-privkey authority/secret.key --load-request $(dir $@)cert-request --template $< |
---|
[4b53371] | 66 | |
---|
[c0bb823] | 67 | # error case: certificates signed by rogue CA |
---|
| 68 | rogue%/x509.pem: rogue%.template rogue%/cert-request rogueca/x509.pem |
---|
[298dc66] | 69 | certtool --outfile $@ --generate-certificate --load-ca-certificate rogueca/x509.pem --load-ca-privkey rogueca/secret.key --load-request $(dir $@)cert-request --template $< |
---|
[c0bb823] | 70 | |
---|
[6f644fa] | 71 | %/softhsm.conf: %/secret.key |
---|
| 72 | echo "0:$(dir $@)softhsm.db" > $@ |
---|
| 73 | |
---|
| 74 | %/softhsm.db: %/x509.pem %/secret.key %/softhsm.conf |
---|
[5eb4544] | 75 | SOFTHSM="$(SOFTHSM)" \ |
---|
[6f644fa] | 76 | SOFTHSM_CONF="$(dir $@)softhsm.conf" \ |
---|
| 77 | $(srcdir)/softhsm.bash init $(dir $@)secret.key $(dir $@)x509.pem |
---|
[33af2b7] | 78 | |
---|
[b0e5dae] | 79 | %/softhsm2.conf: %/secret.key |
---|
| 80 | echo "objectstore.backend = file" > $@ |
---|
| 81 | echo "directories.tokendir = $(dir $@)softhsm2.db" >> $@ |
---|
| 82 | |
---|
| 83 | %/softhsm2.db: %/x509.pem %/secret.key %/softhsm2.conf |
---|
| 84 | mkdir -p $@ |
---|
[5725dca] | 85 | SOFTHSM="$(SOFTHSM)" \ |
---|
[b0e5dae] | 86 | SOFTHSM2_CONF="$(dir $@)softhsm2.conf" \ |
---|
| 87 | $(srcdir)/softhsm.bash init $(dir $@)secret.key $(dir $@)x509.pem |
---|
| 88 | |
---|
[33af2b7] | 89 | # Generate CRL revoking a certain certificate. Currently used to |
---|
| 90 | # revoke the server certificate and check if setting the CRL as |
---|
| 91 | # GnuTLSProxyCRLFile causes the connection to the back end server to |
---|
| 92 | # fail. |
---|
| 93 | %/crl.pem: %/x509.pem ${srcdir}/%-crl.template |
---|
| 94 | certtool --generate-crl \ |
---|
[298dc66] | 95 | --outfile $@ \ |
---|
[33af2b7] | 96 | --load-ca-privkey authority/secret.key \ |
---|
| 97 | --load-ca-certificate authority/x509.pem \ |
---|
| 98 | --load-certificate $< \ |
---|
[298dc66] | 99 | --template "${srcdir}/$(*)-crl.template" |
---|