tr4mpass/tests/integration/integration_helpers.h
tr4m0ryp 30807c8ef6 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>
2026-04-18 17:43:30 +02:00

90 lines
2.9 KiB
C

/*
* integration_helpers.h -- Shared fixtures for Path A / Path B E2E tests.
*
* Each E2E test needs a synthetic device_info_t, a set of readable temp
* files for the iBSS/iBEC/devicetree/ramdisk/patched-mad stages, and a
* consistent set of TR4MPASS_* environment variables so path_a_*.c and
* path_b_*.c accept the inputs without reaching real hardware.
*
* All paths live under /tmp/tr4mpass_e2e_<pid>/ so concurrent test runs
* do not collide. Tests call e2e_fixture_init() in setUp and
* e2e_fixture_teardown() in tearDown; mock_reset_all() must still be
* invoked explicitly (the helpers never touch mock state).
*/
#ifndef TR4MPASS_E2E_INTEGRATION_HELPERS_H
#define TR4MPASS_E2E_INTEGRATION_HELPERS_H
#include <stddef.h>
#include <stdint.h>
#include "device/device.h"
#define E2E_PATH_MAX 160
typedef struct {
char base_dir[E2E_PATH_MAX];
char ibss[E2E_PATH_MAX];
char ibec[E2E_PATH_MAX];
char devtree[E2E_PATH_MAX];
char trustcache[E2E_PATH_MAX];
char ramdisk[E2E_PATH_MAX];
char patched_mad[E2E_PATH_MAX];
} e2e_fixture_t;
/*
* e2e_fixture_init -- Create a fresh /tmp/tr4mpass_e2e_<pid>/ directory
* populated with minimal placeholder files for each Path A stage. The
* TR4MPASS_* environment variables are set to point at those files.
*
* Returns 0 on success, -1 on any I/O failure. On success the caller
* must call e2e_fixture_teardown() to remove the temp files and unset
* the environment variables.
*/
int e2e_fixture_init(e2e_fixture_t *fx);
/*
* e2e_fixture_teardown -- Delete temp files and unset env vars. Safe to
* call even when e2e_fixture_init() failed partway through.
*/
void e2e_fixture_teardown(e2e_fixture_t *fx);
/*
* e2e_make_device_path_a -- Populate a device_info_t for a Path A
* (checkm8-vulnerable) device with all identity fields filled in. The
* device is returned by value so the caller owns the storage.
*/
device_info_t e2e_make_device_path_a(void);
/*
* e2e_make_device_path_b_cellular -- A12+ cellular device fixture
* (checkm8_vulnerable=0, IMEI populated).
*/
device_info_t e2e_make_device_path_b_cellular(void);
/*
* e2e_make_device_path_b_wifi -- A12+ WiFi-only device fixture
* (checkm8_vulnerable=0, IMEI and MEID empty).
*/
device_info_t e2e_make_device_path_b_wifi(void);
/*
* e2e_unset_all_env -- Clear every TR4MPASS_* env var this fixture
* touches. Used by the "missing env" test case that wants a completely
* unconfigured environment.
*/
void e2e_unset_all_env(void);
/*
* e2e_first_index_of -- Return the index of the first call-log entry
* containing needle, or -1 if none. Used by ordering assertions.
*/
int e2e_first_index_of(const char *needle);
/*
* e2e_ordering_ok -- Shorthand for "a appears before b in the call log".
* Returns 1 if both are present and a comes first, 0 otherwise.
*/
int e2e_ordering_ok(const char *needle_a, const char *needle_b);
#endif /* TR4MPASS_E2E_INTEGRATION_HELPERS_H */