- README rewritten for a first-time reader: the gate and its rule order, quick start, all 45 tools by group, transports, proxy and rewrite rules, findings/ assets/traffic/reports, state layout, security model, limits, build and release targets, install layout, environment, source layout, 1.x promise. - License changed to CNCL 1.1 (Could Not Care Less License). LICENSE carries the unchanged text; README, SECURITY.md and the man page point at it. make dist and make install ship LICENSE. - Scope gap tests: deny_ip beats allow_ip, port range endpoints and neighbours, /25 boundary, IPv6 CIDR accept/refuse, apex vs subdomain vs wildcard matching (*.name not matching the apex), embedded host:port, trailing FQDN dot, and a failed scope_reload closing the gate. scope.c 75.9% -> 82.8%, total 79.4%. 397 checks, analyze clean, release-check green including distcheck 1.0.4.
208 lines
6.9 KiB
Makefile
208 lines
6.9 KiB
Makefile
CC ?= cc
|
|
CFLAGS ?= -std=c99 -O2 -Wall -Wextra -Wpedantic -Werror \
|
|
-D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE
|
|
LIBDIR ?= vendor/libmcp
|
|
PREFIX ?= /usr/local
|
|
BINDIR ?= $(PREFIX)/bin
|
|
DOCDIR ?= $(PREFIX)/share/doc/apex-twin
|
|
UNITDIR ?= $(PREFIX)/lib/systemd/system
|
|
MANDIR ?= $(PREFIX)/share/man/man1
|
|
SRC := $(wildcard src/*.c)
|
|
OBJ := $(SRC:.c=.o)
|
|
ASAN_BIN := apex-twin-asan
|
|
ASAN_OBJ := $(SRC:src/%.c=build-asan/%.o)
|
|
ASAN_FLAGS := -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer
|
|
FUZZBUG_BIN := apex-twin-asan-bug
|
|
FUZZBUG_OBJ := $(SRC:src/%.c=build-fuzzbug/%.o)
|
|
FUZZBUG_PROXY_BIN := apex-twin-asan-bug-proxy
|
|
FUZZBUG_PROXY_OBJ := $(SRC:src/%.c=build-fuzzbug-proxy/%.o)
|
|
FUZZBUG_HTTP_BIN := apex-twin-asan-bug-http
|
|
FUZZBUG_HTTP_OBJ := $(SRC:src/%.c=build-fuzzbug-http/%.o)
|
|
COV_BIN := apex-twin-cov
|
|
COV_OBJ := $(SRC:src/%.c=build-cov/%.o)
|
|
COV_FLAGS := -g -O0 --coverage
|
|
VERSION := $(shell sed -n 's/^#define APEX_VERSION "\(.*\)"/\1/p' src/apex.h)
|
|
DISTNAME := apex-twin-$(VERSION)
|
|
DIST := $(DISTNAME).tar.gz
|
|
|
|
all: apex-twin
|
|
|
|
apex-twin: $(OBJ)
|
|
$(CC) $(CFLAGS) -o $@ $(OBJ)
|
|
|
|
src/%.o: src/%.c src/apex.h $(LIBDIR)/mcp.h
|
|
$(CC) $(CFLAGS) -I$(LIBDIR) -Isrc -c -o $@ $<
|
|
|
|
test: apex-twin
|
|
./tests/run.sh
|
|
|
|
gate-audit:
|
|
python3 tests/gate_audit.py
|
|
|
|
version-check:
|
|
python3 tests/version_check.py
|
|
|
|
asan: $(ASAN_BIN)
|
|
|
|
test-asan: $(ASAN_BIN)
|
|
ASAN_OPTIONS=detect_leaks=0 UBSAN_OPTIONS=halt_on_error=1 \
|
|
APEX_BIN=$(CURDIR)/$(ASAN_BIN) ./tests/run.sh
|
|
|
|
fuzz: $(ASAN_BIN)
|
|
ASAN_OPTIONS=detect_leaks=0:halt_on_error=1 \
|
|
UBSAN_OPTIONS=halt_on_error=1 \
|
|
APEX_BIN=$(CURDIR)/$(ASAN_BIN) python3 tests/fuzz.py
|
|
|
|
fuzz-selftest:
|
|
python3 tests/fuzz.py --selftest
|
|
|
|
build-fuzzbug:
|
|
mkdir -p build-fuzzbug
|
|
|
|
build-fuzzbug/%.o: src/%.c src/apex.h $(LIBDIR)/mcp.h | build-fuzzbug
|
|
$(CC) $(CFLAGS) $(ASAN_FLAGS) -DAPEX_FUZZ_BUG -I$(LIBDIR) -Isrc -c -o $@ $<
|
|
|
|
$(FUZZBUG_BIN): $(FUZZBUG_OBJ)
|
|
$(CC) $(CFLAGS) $(ASAN_FLAGS) -o $@ $(FUZZBUG_OBJ)
|
|
|
|
# The red proof: build with a deliberate heap overflow and require the fuzzer to
|
|
# reject it. A green run here would mean the harness is blind.
|
|
fuzz-proxy: $(ASAN_BIN)
|
|
ASAN_OPTIONS=detect_leaks=0:halt_on_error=1 \
|
|
UBSAN_OPTIONS=halt_on_error=1 \
|
|
APEX_BIN=$(CURDIR)/$(ASAN_BIN) python3 tests/fuzz_proxy.py
|
|
|
|
build-fuzzbug-proxy:
|
|
mkdir -p build-fuzzbug-proxy
|
|
|
|
build-fuzzbug-proxy/%.o: src/%.c src/apex.h $(LIBDIR)/mcp.h | build-fuzzbug-proxy
|
|
$(CC) $(CFLAGS) $(ASAN_FLAGS) -DAPEX_FUZZ_BUG_PROXY -I$(LIBDIR) -Isrc -c -o $@ $<
|
|
|
|
$(FUZZBUG_PROXY_BIN): $(FUZZBUG_PROXY_OBJ)
|
|
$(CC) $(CFLAGS) $(ASAN_FLAGS) -o $@ $(FUZZBUG_PROXY_OBJ)
|
|
|
|
coverage: $(COV_BIN)
|
|
APEX_BIN=$(CURDIR)/$(COV_BIN) ./tests/run.sh
|
|
python3 tests/coverage.py
|
|
|
|
build-cov:
|
|
mkdir -p build-cov
|
|
|
|
build-cov/%.o: src/%.c src/apex.h $(LIBDIR)/mcp.h | build-cov
|
|
$(CC) $(CFLAGS) $(COV_FLAGS) -I$(LIBDIR) -Isrc -c -o $@ $<
|
|
|
|
$(COV_BIN): $(COV_OBJ)
|
|
$(CC) $(CFLAGS) $(COV_FLAGS) -o $@ $(COV_OBJ)
|
|
|
|
fuzz-http: $(ASAN_BIN)
|
|
ASAN_OPTIONS=detect_leaks=0:halt_on_error=1 \
|
|
UBSAN_OPTIONS=halt_on_error=1 \
|
|
APEX_BIN=$(CURDIR)/$(ASAN_BIN) python3 tests/fuzz_http.py
|
|
|
|
build-fuzzbug-http:
|
|
mkdir -p build-fuzzbug-http
|
|
|
|
build-fuzzbug-http/%.o: src/%.c src/apex.h $(LIBDIR)/mcp.h | build-fuzzbug-http
|
|
$(CC) $(CFLAGS) $(ASAN_FLAGS) -DAPEX_FUZZ_BUG_HTTP -I$(LIBDIR) -Isrc -c -o $@ $<
|
|
|
|
$(FUZZBUG_HTTP_BIN): $(FUZZBUG_HTTP_OBJ)
|
|
$(CC) $(CFLAGS) $(ASAN_FLAGS) -o $@ $(FUZZBUG_HTTP_OBJ)
|
|
|
|
fuzz-http-red: $(FUZZBUG_HTTP_BIN)
|
|
@if ASAN_OPTIONS=detect_leaks=0:halt_on_error=1 \
|
|
APEX_BIN=$(CURDIR)/$(FUZZBUG_HTTP_BIN) FUZZ_CASES=1 \
|
|
python3 tests/fuzz_http.py; then \
|
|
echo "fuzz-http-red FAILED: the broken HTTP face was reported green"; exit 1; \
|
|
else \
|
|
echo "fuzz-http-red PASSED: the harness caught the deliberate bug"; \
|
|
fi
|
|
|
|
fuzz-proxy-red: $(FUZZBUG_PROXY_BIN)
|
|
@if ASAN_OPTIONS=detect_leaks=0:halt_on_error=1 \
|
|
APEX_BIN=$(CURDIR)/$(FUZZBUG_PROXY_BIN) FUZZ_CASES=1 \
|
|
python3 tests/fuzz_proxy.py; then \
|
|
echo "fuzz-proxy-red FAILED: the broken proxy was reported green"; exit 1; \
|
|
else \
|
|
echo "fuzz-proxy-red PASSED: the harness caught the deliberate bug"; \
|
|
fi
|
|
|
|
fuzz-red: $(FUZZBUG_BIN)
|
|
@if ASAN_OPTIONS=detect_leaks=0:halt_on_error=1 \
|
|
APEX_BIN=$(CURDIR)/$(FUZZBUG_BIN) FUZZ_CASES=1 \
|
|
python3 tests/fuzz.py; then \
|
|
echo "fuzz-red FAILED: the broken binary was reported green"; exit 1; \
|
|
else \
|
|
echo "fuzz-red PASSED: the harness caught the deliberate bug"; \
|
|
fi
|
|
|
|
build-asan:
|
|
mkdir -p build-asan
|
|
|
|
build-asan/%.o: src/%.c src/apex.h $(LIBDIR)/mcp.h | build-asan
|
|
$(CC) $(CFLAGS) $(ASAN_FLAGS) -I$(LIBDIR) -Isrc -c -o $@ $<
|
|
|
|
$(ASAN_BIN): $(ASAN_OBJ)
|
|
$(CC) $(CFLAGS) $(ASAN_FLAGS) -o $@ $(ASAN_OBJ)
|
|
|
|
# Static analysis, one translation unit at a time. Warnings are expected to be
|
|
# read, not piped away; the target fails on a compiler error.
|
|
analyze:
|
|
@for f in $(SRC); do \
|
|
echo " ANALYZE $$f"; \
|
|
$(CC) $(CFLAGS) -fanalyzer -I$(LIBDIR) -Isrc -c -o /dev/null $$f || exit 1; \
|
|
done
|
|
|
|
dist:
|
|
@test -n "$(VERSION)" || { echo "dist: cannot read APEX_VERSION"; exit 1; }
|
|
rm -rf $(DISTNAME) $(DIST)
|
|
mkdir -p $(DISTNAME)
|
|
cp Makefile README.md SECURITY.md CHANGELOG.md LICENSE .gitignore $(DISTNAME)/
|
|
cp -a src vendor tests docs examples systemd $(DISTNAME)/
|
|
find $(DISTNAME) -type f \( -name '*.o' -o -name '*.gcda' -o -name '*.gcno' \
|
|
-o -name '*.gcov' \) -delete
|
|
find $(DISTNAME) -type d -name '__pycache__' -prune -exec rm -rf {} +
|
|
tar -czf $(DIST) $(DISTNAME)
|
|
rm -rf $(DISTNAME)
|
|
@echo "built $(DIST)"
|
|
|
|
distcheck: dist
|
|
@set -e; tmp=$$(mktemp -d); \
|
|
trap 'rm -rf "$$tmp"' EXIT; \
|
|
tar -xzf $(DIST) -C "$$tmp"; \
|
|
$(MAKE) -C "$$tmp/$(DISTNAME)"; \
|
|
$(MAKE) -C "$$tmp/$(DISTNAME)" test; \
|
|
echo "distcheck: $(DISTNAME) builds and passes from the tarball"
|
|
|
|
# The full release gate, fail-fast. Takes several minutes and needs the network
|
|
# for the example.com checks; it is not part of `make test`.
|
|
release-check:
|
|
$(MAKE) version-check
|
|
$(MAKE) gate-audit
|
|
$(MAKE) test
|
|
$(MAKE) test-asan
|
|
$(MAKE) analyze
|
|
$(MAKE) fuzz
|
|
$(MAKE) fuzz-proxy
|
|
$(MAKE) fuzz-http
|
|
$(MAKE) distcheck
|
|
|
|
install: apex-twin
|
|
mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(DOCDIR) $(DESTDIR)$(UNITDIR) \
|
|
$(DESTDIR)$(MANDIR)
|
|
install -m 0755 apex-twin $(DESTDIR)$(BINDIR)/apex-twin
|
|
install -m 0644 README.md CHANGELOG.md SECURITY.md LICENSE $(DESTDIR)$(DOCDIR)/
|
|
install -m 0644 docs/operations.md docs/artex-port.md $(DESTDIR)$(DOCDIR)/
|
|
install -m 0644 docs/apex-twin.1 $(DESTDIR)$(MANDIR)/apex-twin.1
|
|
install -m 0644 systemd/apex-twin.service $(DESTDIR)$(UNITDIR)/apex-twin.service
|
|
install -m 0644 systemd/apex-twin-proxy.service $(DESTDIR)$(UNITDIR)/apex-twin-proxy.service
|
|
|
|
clean:
|
|
rm -f apex-twin $(OBJ) $(ASAN_BIN) $(FUZZBUG_BIN) $(FUZZBUG_PROXY_BIN) \
|
|
$(FUZZBUG_HTTP_BIN) $(COV_BIN)
|
|
rm -rf build-asan build-fuzzbug build-fuzzbug-proxy build-fuzzbug-http \
|
|
build-cov
|
|
rm -f *.gcov
|
|
rm -rf $(DISTNAME) $(DIST)
|
|
|
|
.PHONY: all test gate-audit version-check asan test-asan fuzz fuzz-selftest fuzz-red fuzz-proxy fuzz-proxy-red fuzz-http fuzz-http-red coverage analyze dist distcheck release-check install clean
|