source: mod_gnutls/test/Makefile.am @ b6ce8ad

main mod_gnutls/0.12.0
Last change on this file since b6ce8ad was eb21e89, checked in by Fiona Klute <fiona.klute@…>, 20 months ago

Fix server_rec references in mgs_get_ocsp_response()

During the handshake the base_server of the relevant conn_rec is
always the first vhost matching the host/port combination of the
incoming connection. By the time an OCSP response is requested
mod_gnutls may already have selected another server based on SNI, but
Apache hasn't updated the conn_rec yet. In that case c->base_server
does not refer to the right server, and if that server reference is
used to get the mod_gnutls configuration it'll be the wrong one.

That behavior caused a bug where caching a fresh OCSP response during
handshake failed if the initial vhost had OCSP stapling disabled,
because with stapling disabled the cache lifetime is set to -1. In
other cases a wrong cache lifetime might have been used.

The bug is fixed by using the mod_gnutls server configuration
referenced by the mod_gnutls connection structure, which has already
been updated by the SNI parsing code. It contains a reference to the
correct server_rec.

This commit also contains a regression test.

  • Property mode set to 100644
File size: 13.4 KB
Line 
1SUBDIRS = tests
2
3VALGRIND_SUPPRESS = suppressions.valgrind
4EXTRA_DIST = $(VALGRIND_SUPPRESS)
5
6if ENABLE_VALGRIND
7valgrind = --valgrind \
8        $(foreach supp,$(VALGRIND_SUPPRESS),--valgrind-suppressions "$(srcdir)/$(supp)")
9else
10valgrind =
11endif
12
13# Generate the test scripts
14test-%.bash: test-template.bash.in | tests/%/
15        testname="$(*)"; \
16        sed -e s/_NUM_/$${testname%%_*}/ -e 's,_VALGRIND_,$(valgrind),' < $< > $@
17        chmod a+x $@
18
19test_scripts = test-00_basic.bash \
20        test-01_priorities_config.bash \
21        test-02_cache_in_vhost.bash \
22        test-03_cachetimeout_in_vhost.bash \
23        test-04_name_based_vhosts.bash \
24        test-05_client_handshake_error.bash \
25        test-06_invalid_plaintext.bash \
26        test-10_client_verification.bash \
27        test-12_cgi_variables.bash \
28        test-14_resume_session.bash \
29        test-15_basic_msva.bash \
30        test-16_view-status.bash \
31        test-17_cgi_vars_large_cert.bash \
32        test-19_TLS_reverse_proxy.bash \
33        test-20_TLS_reverse_proxy_client_auth.bash \
34        test-21_TLS_reverse_proxy_wrong_cert.bash \
35        test-22_TLS_reverse_proxy_crl_revoke.bash \
36        test-23_TLS_reverse_proxy_mismatched_priorities.bash \
37        test-24_pkcs11_cert.bash \
38        test-26_redirect_HTTP_to_HTTPS.bash \
39        test-27_OCSP_server.bash \
40        test-28_HTTP2_support.bash \
41        test-29_OCSP_server_no_async.bash \
42        test-30_ip_based_vhosts.bash \
43        test-34_TLS_reverse_proxy_h2.bash \
44        test-35_client_reauth.bash \
45        test-36_OCSP_server_nonce.bash \
46        test-37_TLS_reverse_proxy_resume_session.bash
47
48MOSTLYCLEANFILES = $(test_scripts)
49dist_check_SCRIPTS = netns_py.bash test-template.bash.in
50
51TEST_EXTENSIONS = .bash .py
52PY_LOG_COMPILER = $(PYTHON)
53TESTS = doctest-mgstest.py unittest-mgstest.py $(test_scripts)
54
55check_PROGRAMS = pgpcrc
56pgpcrc_SOURCES = pgpcrc.c
57
58# build OCSP database tool
59if ENABLE_OCSP_TEST
60check_PROGRAMS += gen_ocsp_index
61gen_ocsp_index_SOURCES = gen_ocsp_index.c cert_helper.c
62gen_ocsp_index_CFLAGS = $(LIBGNUTLS_CFLAGS)
63gen_ocsp_index_LDFLAGS = $(LIBGNUTLS_LIBS)
64noinst_HEADERS = cert_helper.h
65endif
66
67# Python tools for tests
68noinst_PYTHON = https-test-client.py mgstest/http.py mgstest/__init__.py \
69        mgstest/hooks.py mgstest/ocsp.py mgstest/services.py \
70        mgstest/softhsm.py mgstest/tests.py mgstest/valgrind.py \
71        mgstest/test_tests.py runtest.py \
72        softhsm-init.py doctest-mgstest.py unittest-mgstest.py \
73        required-modules.py data/ocsp.py check_test_ips.py
74
75# Identities in the miniature CA, server, and client environment for
76# the test suite
77shared_identities = authority authority/client
78pgp_identities = $(shared_identities)
79x509_only_identities = authority/server authority/meow.test \
80        authority/subca authority/subca/server \
81        rogueca rogueca/imposter rogueca/rogueclient
82if ENABLE_OCSP_TEST
83x509_only_identities += authority/ocsp-responder authority/subca/ocsp-responder
84endif
85x509_identities = $(shared_identities) $(x509_only_identities)
86identities = $(shared_identities) $(x509_only_identities)
87# Append strings after ":=" to each identity to generate a list of
88# necessary files
89pgp_tokens = $(pgp_identities:=/cert.pgp) \
90        $(pgp_identities:=/secret.pgp)
91x509_keys = $(x509_identities:=/secret.key)
92x509_certs = $(x509_identities:=/x509.pem)
93x509_tokens = $(x509_certs) $(x509_keys)
94tokens = $(x509_tokens)
95if USE_MSVA
96tokens += $(pgp_tokens)
97endif
98
99if !DISABLE_FLOCK
100# flock command for write access to the authority keyring
101GPG_FLOCK = @FLOCK@ authority/lock
102endif
103
104include $(srcdir)/test_ca.mk
105
106# Test cases trying to create keys and certificates in parallel causes
107# race conditions. Ensure that all keys and certificates are generated
108# before tests get to run.
109#
110# NOTE: Once the support files have been generated, test cases can be
111# run with multiple jobs, but real parallelization would require
112# dynamic port assignments. At the moment, lock files ensure that only
113# one Apache instance (possibly plus a proxy back end instance) is
114# running at any time, so test cases actually have to wait for each
115# other - just not in any particular order.
116check_DATA = $(tokens) authority/server/crl.pem
117
118MOSTLYCLEANFILES += cache/* logs/* outputs/* authority/server/crl.pem
119
120cert_templates = authority/template.in authority/client/template.in \
121        authority/meow.test/template.in authority/ocsp-responder/template \
122        authority/server/template.in \
123        authority/subca/template.in authority/subca/server/template.in \
124        authority/subca/ocsp-responder/template \
125        rogueca/template rogueca/imposter/template.in \
126        rogueca/rogueclient/template.in
127generated_templates = authority/template authority/client/template \
128        authority/meow.test/template authority/server/template \
129        rogueca/imposter/template rogueca/rogueclient/template
130
131# Delete X.509 private keys on full clean. Note that unless you need
132# to generate fresh keys, the "mostlyclean" target should be
133# sufficient (see below).
134CLEANFILES = $(x509_keys)
135
136# Delete X.509 certificates and generated templates on "mostlyclean"
137# target. Certificates can be rebuilt without generating new key
138# pairs, and regenerating them makes it possible to change identities
139# (e.g. host names) without wasting time on new keys (which would
140# happen after "clean").
141MOSTLYCLEANFILES += $(x509_certs) $(generated_templates) $(identities:=/uid)
142
143
144# Delete PGP keyrings on "mostlyclean" target. They are created from
145# the X.509 private keys and certificates with an expiration time of
146# one day, so regenerating them is both fast and frequently
147# necessary.
148pgp_patterns = /*.pgp /*.pgp.raw /*.gpg /*.gpg~ /gpg.conf \
149        /*.kbx /*.kbx~ /S.gpg-agent /private-keys-v1.d/*
150MOSTLYCLEANFILES += $(foreach pat,$(pgp_patterns),$(pgp_identities:=$(pat))) \
151        authority/lock authority/tofu.db
152# GnuPG random pool, no need to regenerate on every build
153CLEANFILES += authority/random_seed
154
155# GnuPG 2 starts gpg-agent processes per GNUPGHOME (one for every PGP
156# identity) while creating the PGP certificates. This target is called
157# by both "check-local" and "mostlyclean-local": The former because
158# agent processes are started while preparing for "check" and are no
159# longer needed afterwards, the latter to make sure they are gone
160# along with their certificates.
161stop-gnupg-agent:
162        for id in $(pgp_identities) $(msva_home); do \
163                GNUPGHOME=$$id/ gpgconf --kill gpg-agent || true; \
164        done
165
166check-local: stop-gnupg-agent
167
168# Delete lock files for test servers on "mostlyclean" target.
169MOSTLYCLEANFILES += *.lock
170
171# Build certificate chain files. Note that intermediate tokens must be
172# listed explicitly, or the dependency chain will be broken because
173# the higher level pattern matches, too.
174chain_tokens = authority/server/x509-chain.pem \
175        authority/subca/x509-chain.pem \
176        authority/subca/server/x509-chain.pem
177check_DATA += $(chain_tokens)
178MOSTLYCLEANFILES += $(chain_tokens) authority/x509-chain.pem
179
180# rule to build MSVA trust database
181if USE_MSVA
182msva_home = msva.gnupghome
183check_DATA += $(msva_home)/trustdb.gpg authority/client/uid
184MOSTLYCLEANFILES += $(foreach pat,$(pgp_patterns),$(msva_home)$(pat))
185$(msva_home)/trustdb.gpg: authority/minimal.pgp authority/client/cert.pgp
186        mkdir -p -m 0700 $(dir $@)
187        GNUPGHOME=$(dir $@) gpg --import < $<
188        printf "%s:6:\n" "$$(GNUPGHOME=authority/ gpg --with-colons --list-secret-keys --fingerprint | grep ^fpr: | cut -f 10 -d :)" | GNUPGHOME=$(dir $@) gpg --import-ownertrust
189        GNUPGHOME=$(dir $@) gpg --import < authority/client/cert.pgp
190        printf "keyserver does-not-exist.example\n" > $(msva_home)/gpg.conf
191endif
192
193if ENABLE_OCSP_TEST
194# rules to build OCSP database
195ocsp_index_data = authority/ocsp_index.txt authority/ocsp_index.txt.attr \
196        authority/subca/ocsp_index.txt authority/subca/ocsp_index.txt.attr
197check_DATA += $(ocsp_index_data)
198MOSTLYCLEANFILES += $(ocsp_index_data)
199
200# The "find" command builds a list of all certificates directly below
201# the CA that aren't for the ocsp-responder.
202%/ocsp_index.txt: $(x509_tokens) gen_ocsp_index
203        ./gen_ocsp_index $$(find $(*) -mindepth 2 -maxdepth 2 ! -path '*/ocsp-responder/*' -name x509.pem) > $@
204
205%/ocsp_index.txt.attr:
206        @mkdir -m 0700 -p $(dir $@)
207        echo "unique_subject = no" > $@
208endif
209
210# SoftHSM token, note that the SoftHSM 2 token is a directory
211SOFTHSM2_TOKEN = authority/server/softhsm2.db
212# included in mostlyclean-local below
213clean-softhsm2-db:
214        -rm -rf $(SOFTHSM2_TOKEN)
215
216if HAVE_SOFTHSM
217check_DATA += $(SOFTHSM2_TOKEN)
218endif HAVE_SOFTHSM
219
220check_DATA += make-test-dirs
221extra_dirs = logs cache outputs
222make-test-dirs:
223        mkdir -p $(extra_dirs)
224
225.PHONY: make-test-dirs clean-softhsm2-db stop-gnupg-agent
226
227
228if ENABLE_COVERAGE
229coverage_raw_dir = outputs/coverage
230coverage_out = coverage
231MOSTLYCLEANFILES += $(coverage_raw_dir)/*
232endif
233
234mostlyclean-local: clean-softhsm2-db stop-gnupg-agent
235        -rmdir $(pgp_identities:=/private-keys-v1.d) || true
236if USE_MSVA
237        -rmdir $(msva_home)/private-keys-v1.d || true
238endif
239
240# Delete test data directories, and wait for test services to
241# exit. The reason for the wait is that Apache instances may take some
242# time to exit and delete their PID files. Occasionally some PID files
243# where still around during "distcheck" runs by the time the target
244# checked if the build directory was really empty after "distclean",
245# breaking the build. Delaying "clean-local" until PID files are gone
246# avoids this issue, and the timeout will expose actually unclean
247# stops.
248clean-local:
249if ENABLE_COVERAGE
250        -rmdir $(coverage_raw_dir) || true
251        -rm -rf $(coverage_out) || true
252endif
253        -rmdir $(extra_dirs) || true
254if USE_MSVA
255        -rmdir $(msva_home) || true
256endif
257        wait=0; \
258        while ls *.pid && test "$$wait" -lt "@TEST_LOCK_WAIT@"; do \
259                wait=$$(($$wait + 1)); \
260                echo "waiting for test services to exit ($$wait seconds)"; \
261                sleep 1; \
262        done
263
264# Apache configuration and data files
265apache_data = base_apache.conf cgi_module.conf data/dump.cgi \
266        data/test.txt data/secret/mirror.cgi data/secret/test.txt \
267        mime.types proxy_mods.conf
268
269# Which modules are compiled into the Apache binary varies between
270# distributions. required-modules.py creates additional LoadModule
271# directives if needed.
272check_DATA += apache-conf/required-modules.conf
273MOSTLYCLEANFILES += apache-conf/required-modules.conf
274apache-conf/required-modules.conf: required-modules.py
275        APACHE2=@APACHE2@ AP_LIBEXECDIR=@AP_LIBEXECDIR@ $(PYTHON) $< >$@
276
277# Documentation for the test system
278test_doc = README.md sample_fail.yaml sample_test.yaml
279
280EXTRA_DIST += $(apache_data) $(cert_templates) $(shared_identities:=/uid.in) \
281        authority/server/crl.template $(test_doc)
282
283# Lockfile for the main Apache process
284test_lockfile = ./test.lock
285# Lockfile for the proxy backend Apache process (if any)
286backend_lockfile = ./backend.lock
287# Lockfile for the OCSP server Apache process (if any)
288ocsp_lockfile = ./ocsp.lock
289
290# port for the main Apache server
291TEST_PORT ?= 9932
292# port for MSVA in test cases that use it
293MSVA_PORT ?= 9933
294# port for TLS proxy backend server
295BACKEND_PORT ?= 9934
296# port for plain HTTP server
297TEST_HTTP_PORT ?= 9935
298# port for the OCSP responder
299if ENABLE_OCSP_TEST
300OCSP_PORT ?= 9936
301OCSP_URI_TEMPLATE = ocsp_uri = http://$(TEST_HOST):$(OCSP_PORT)/ocsp/
302endif
303# maximum time to wait for service startup (seconds)
304TEST_SERVICE_MAX_WAIT ?= 10
305# wait loop time for service startup (seconds)
306TEST_SERVICE_WAIT ?= 0.3
307
308AM_TESTS_ENVIRONMENT = export APACHE2=@APACHE2@; \
309        export AP_LIBEXECDIR=@AP_LIBEXECDIR@; \
310        export PYTHON="@PYTHON@"; \
311        export TEST_LOCK_WAIT="@TEST_LOCK_WAIT@"; \
312        export TEST_IP="@TEST_IP@"; \
313        export TEST_HOST="@TEST_HOST@"; \
314        export TEST_PORT="$(TEST_PORT)"; \
315        export TEST_SERVICE_MAX_WAIT="$(TEST_SERVICE_MAX_WAIT)"; \
316        export TEST_SERVICE_WAIT="$(TEST_SERVICE_WAIT)"; \
317        export TEST_QUERY_TIMEOUT="@TEST_QUERY_TIMEOUT@"; \
318        export BACKEND_HOST="@TEST_HOST@"; \
319        export BACKEND_PORT="$(BACKEND_PORT)"; \
320        export TEST_HTTP_PORT="$(TEST_HTTP_PORT)"; \
321        export HTTP_CLI="@HTTP_CLI@";
322
323if USE_MSVA
324AM_TESTS_ENVIRONMENT += export MSVA_PORT="$(MSVA_PORT)";
325endif
326
327if HAVE_SOFTHSM
328AM_TESTS_ENVIRONMENT += export SOFTHSM="@SOFTHSM@"; \
329        export SOFTHSM_LIB="@SOFTHSM_LIB@";
330endif
331
332if ENABLE_OCSP_TEST
333AM_TESTS_ENVIRONMENT += export OPENSSL="@OPENSSL@"; \
334        export OCSP_PORT="$(OCSP_PORT)";
335endif
336
337if ENABLE_VALGRIND
338AM_TESTS_ENVIRONMENT += export VALGRIND="@VALGRIND@";
339endif
340
341if ENABLE_NETNS
342AM_TESTS_ENVIRONMENT += export UNSHARE="@UNSHARE@"; \
343        export USE_TEST_NAMESPACE=1;
344endif
345# Without flock tests must not run in parallel, and PID files are used
346# to prevent conflicts between server instances. Otherwise set lock
347# files for flock.
348if DISABLE_FLOCK
349AM_TESTS_ENVIRONMENT += export TEST_LOCK="apache2.pid"; \
350        export BACKEND_LOCK="backend.pid"; \
351        export OCSP_LOCK="ocsp.pid";
352.NOTPARALLEL:
353else
354AM_TESTS_ENVIRONMENT += export FLOCK="@FLOCK@"; \
355        export TEST_LOCK="$(test_lockfile)"; \
356        export BACKEND_LOCK="$(backend_lockfile)"; \
357        export OCSP_LOCK="$(ocsp_lockfile)";
358endif
359
360if ENABLE_COVERAGE
361AM_TESTS_ENVIRONMENT += export LLVM_PROFILE_FILE="$(coverage_raw_dir)/%p-%3m.profraw";
362
363outputs/coverage.profdata: $(coverage_raw_dir)/*.profraw
364        llvm-profdata merge -sparse $^ -o $@
365
366coverage/index.html: outputs/coverage.profdata
367        llvm-cov show ../src/.libs/mod_gnutls.so -instr-profile=$< -format=html $(srcdir)/../src/*.c $(srcdir)/../src/*.h $(srcdir)/../include/*.h -output-dir=$(dir $@)/
368
369coverage: coverage/index.html
370endif
371
372# Echo AM_TESTS_ENVIRONMENT. This can be useful for debugging, e.g. if
373# you want to manually run an Apache instance with Valgrind using the
374# same configuration as a test case.
375show-test-env: export TEST_ENV=$(AM_TESTS_ENVIRONMENT)
376show-test-env:
377        @echo "$${TEST_ENV}"
378
379# Build the test suite README as HTML if pandoc is available.
380if USE_PANDOC
381noinst_DATA = README.html
382MOSTLYCLEANFILES += $(noinst_DATA)
383%.html: %.md $(srcdir)/../doc/style.css
384        $(PANDOC) --css $(filter %.css,$^) --metadata pagetitle="$(<)" --self-contained -f markdown -o $@ $<
385endif
Note: See TracBrowser for help on using the repository browser.