feat: real Path A implementation, cert extraction, mock test harness

Converts the Path A pipeline from stubs to a working implementation for
A5-A11 devices, adds real certificate extraction via lockdownd and ECDSA
P-256 signing, and introduces a comprehensive mock-based test suite.

Activation
- cert_extract: lockdownd-backed DeviceCertificate,
  AccountTokenCertificate, UniqueDeviceCertificate with base64 decode
  and CertificateChain array fallback.
- signer: OpenSSL EVP ECDSA P-256 sign/verify with DER-encoded
  signatures plus a test keypair generator.
- record.c: 3 of 6 cert fields now populate from live device data.
  AccountTokenSignature signs when TR4MPASS_SIGNING_KEY is set.
  FairPlayKeyData, RKCData, SepNonce remain documented stubs
  (SEP-blocked per 26.3-vulnerability.md).

Path A bypass
- path_a_ramdisk: iBSS/iBEC/devicetree/trustcache/ramdisk upload via
  libirecovery, reconnect handling between DFU and recovery stages,
  iBoot go/bootx commands, SSH readiness poll.
- path_a_ssh: libssh2 + SCP. Mounts rootfs rw (apfs then hfs), runs
  AMFI patcher, backs up and replaces /usr/libexec/mobileactivationd
  with a user-supplied patched binary, verifies mode.

Build, CLI, config
- Makefile: add libssh2 dependency, split test targets into
  hw-independent (make test) and full mock (make test-mocks).
- env_config + cli_flags: 12 new --flags for ramdisk, SSH, signing
  paths; flags map to TR4MPASS_* env vars. --verbose prints summary.
- start.sh slimmed; helpers extracted to start-helpers.sh.

Test suite (20 to 248 tests)
- Mock framework under tests/mocks/ intercepts libimobiledevice,
  libirecovery, libusb, libssh2, libcurl, plus mobileactivation and
  afc. Staging API in mock_control.h.
- Unit tests per module: cert_extract, signer, ramdisk, SSH jailbreak,
  env_config.
- Integration tests in tests/integration/: 6 Path A E2E scenarios
  (happy path, exploit fail, reconnect timeout, SSH auth fail, SCP
  fail, missing env) and 3 Path B scenarios (identity manipulation
  works, nonce barrier rejection is handled cleanly, signal
  detection). Path B tests verify the tool reports the SEP barrier
  failure rather than misclaiming success.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
tr4m0ryp 2026-04-18 17:43:30 +02:00
parent 5b758931ac
commit 30807c8ef6
58 changed files with 7967 additions and 1210 deletions

View file

@ -4,7 +4,7 @@ LDFLAGS =
# Library discovery via pkg-config (warn but do not fail if missing)
PKG_LIBS = libimobiledevice-1.0 libirecovery-1.0 libusb-1.0 \
libplist-2.0 openssl libcurl
libplist-2.0 openssl libcurl libssh2
CFLAGS += $(shell pkg-config --cflags $(PKG_LIBS) 2>/dev/null)
LDFLAGS += $(shell pkg-config --libs $(PKG_LIBS) 2>/dev/null)
@ -26,20 +26,78 @@ $(TARGET): $(OBJS)
clean:
find src -name '*.o' -delete
rm -f $(TARGET) $(TEST_TARGET)
rm -f $(TARGET) $(TEST_TARGET) $(MOCK_TARGET)
find tests -name '*.o' -delete 2>/dev/null || true
# ------------------------------------------------------------------ #
# Test target: compile only hardware-independent units #
# No mocks, no real library linkage required for the SUT code. #
# ------------------------------------------------------------------ #
TEST_UNITS = src/device/chip_db.c src/bypass/bypass.c src/util/log.c
TEST_TARGET = tests/run_tests
TEST_CFLAGS = $(CFLAGS) -Iinclude -DUNIT_TEST
TEST_UNITS = src/device/chip_db.c src/bypass/bypass.c src/util/log.c \
src/util/env_config.c
# Sections linked by both `make test` (hw-independent) and `make test-mocks`.
TEST_SECT_CORE = tests/test_main.c tests/test_parsing.c tests/test_chip_db.c \
tests/test_bypass_probe.c tests/test_constants.c \
tests/test_cert_extract.c tests/test_signer.c \
tests/test_env_config.c
# Sections that require the mocked hardware libraries -- only used by
# `make test-mocks`. Include stub definitions of their entry points in
# TEST_SECT_STUBS so the hw-independent target still links.
TEST_SECT_MOCK = tests/test_ramdisk.c tests/test_ssh_jailbreak.c
# Aggregate for the mock build: real section bodies.
TEST_SECT = $(TEST_SECT_CORE) $(TEST_SECT_MOCK)
TEST_TARGET = tests/run_tests
TEST_CFLAGS = $(CFLAGS) -Iinclude -Itests -DUNIT_TEST
test: $(TEST_TARGET)
./$(TEST_TARGET)
$(TEST_TARGET): tests/test_sections.c $(TEST_UNITS)
# The hw-independent target replaces the mock-only sections with empty
# stubs so run_tests still finds run_ramdisk_tests / run_ssh_jailbreak_tests.
$(TEST_TARGET): $(TEST_SECT_CORE) $(TEST_UNITS) tests/mock_section_stubs.c
$(CC) $(TEST_CFLAGS) -o $@ $^
.PHONY: all clean test
# ------------------------------------------------------------------ #
# Mock test target: full suite against mocked hardware libraries. #
# #
# Links the test sections + all tests/mocks/*.c + the production #
# sources we want to exercise (everything under src/ except main.c #
# and the hardware-specific checkm8/dfu exploit code). The real #
# hardware libs (libimobiledevice/libirecovery/libusb/libssh2/curl) #
# are NOT linked -- the mocks satisfy those symbols. libplist, #
# openssl, and pthread remain real. #
# ------------------------------------------------------------------ #
MOCK_SRCS = $(shell find tests/mocks -name '*.c')
# Phase 3: pick up end-to-end integration test sources. `find` is
# guarded so `make` still works before the directory exists.
INT_SRCS = $(shell find tests/integration -name '*.c' 2>/dev/null)
# Production sources to include in the mock build. We exclude:
# - src/main.c (has its own main())
# - src/exploit/* and src/device/usb_dfu.c (direct DFU/checkm8 h/w code)
MOCK_SUT_SRCS = $(shell find src -name '*.c' \
-not -path 'src/main.c' \
-not -path 'src/exploit/*' \
-not -path 'src/device/usb_dfu.c')
MOCK_ALL_SRCS = $(TEST_SECT) $(MOCK_SRCS) $(INT_SRCS) $(MOCK_SUT_SRCS)
MOCK_TARGET = tests/run_mock_tests
# Only link libs that the SUT still needs at runtime and we did NOT mock.
MOCK_PKG_LIBS = libplist-2.0 openssl
MOCK_CFLAGS = -Wall -Wextra -std=c99 -D_GNU_SOURCE -O2 \
$(shell pkg-config --cflags $(MOCK_PKG_LIBS) 2>/dev/null) \
-Iinclude -Itests -Itests/integration -Itests/mocks \
-DTEST_MODE -DUNIT_TEST
MOCK_LDFLAGS = $(shell pkg-config --libs $(MOCK_PKG_LIBS) 2>/dev/null)
test-mocks: $(MOCK_TARGET)
./$(MOCK_TARGET)
$(MOCK_TARGET): $(MOCK_ALL_SRCS)
$(CC) $(MOCK_CFLAGS) -o $@ $^ $(MOCK_LDFLAGS)
.PHONY: all clean test test-mocks