tr4mpass/tests/test_bypass_probe.c
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

141 lines
3.8 KiB
C

/*
* test_bypass_probe.c -- Bypass module probe selection logic.
*
* Tests the probe selection against mock modules that replicate path_a
* and path_b probe conditions without requiring any hardware linkage.
*/
#include "test_framework.h"
#include "bypass/bypass.h"
#include "device/device.h"
#include <string.h>
/* ------------------------------------------------------------------ */
/* Mock bypass modules */
/* ------------------------------------------------------------------ */
static int mock_probe_path_a(device_info_t *dev)
{
if (!dev) return -1;
if (dev->checkm8_vulnerable != 1) return 0;
if (dev->is_dfu_mode != 1) return 0;
return 1;
}
static int mock_probe_path_b(device_info_t *dev)
{
if (!dev) return -1;
if (dev->checkm8_vulnerable != 0) return 0;
if (dev->is_dfu_mode != 1) return 0;
return 1;
}
static int mock_execute_noop(device_info_t *dev) { (void)dev; return 0; }
static const bypass_module_t mock_path_a = {
.name = "mock_path_a",
.description = "Mock Path A for testing",
.probe = mock_probe_path_a,
.execute = mock_execute_noop
};
static const bypass_module_t mock_path_b = {
.name = "mock_path_b",
.description = "Mock Path B for testing",
.probe = mock_probe_path_b,
.execute = mock_execute_noop
};
static device_info_t make_dev(int checkm8_vuln, int is_dfu)
{
device_info_t dev;
memset(&dev, 0, sizeof(dev));
dev.checkm8_vulnerable = checkm8_vuln;
dev.is_dfu_mode = is_dfu;
return dev;
}
/* ------------------------------------------------------------------ */
/* Cases */
/* ------------------------------------------------------------------ */
static void test_probe_path_a_compatible(void)
{
device_info_t dev = make_dev(1, 1);
ASSERT_EQ(mock_probe_path_a(&dev), 1);
}
static void test_probe_path_a_not_dfu(void)
{
device_info_t dev = make_dev(1, 0);
ASSERT_EQ(mock_probe_path_a(&dev), 0);
}
static void test_probe_path_a_a12(void)
{
device_info_t dev = make_dev(0, 1);
ASSERT_EQ(mock_probe_path_a(&dev), 0);
}
static void test_probe_path_b_compatible(void)
{
device_info_t dev = make_dev(0, 1);
ASSERT_EQ(mock_probe_path_b(&dev), 1);
}
static void test_probe_path_b_a11(void)
{
device_info_t dev = make_dev(1, 1);
ASSERT_EQ(mock_probe_path_b(&dev), 0);
}
static void test_probe_path_b_not_dfu(void)
{
device_info_t dev = make_dev(0, 0);
ASSERT_EQ(mock_probe_path_b(&dev), 0);
}
static void test_probe_select_prefers_a(void)
{
/* Both modules registered; checkm8-vulnerable device -> Path A selected */
bypass_register(&mock_path_a);
bypass_register(&mock_path_b);
device_info_t dev = make_dev(1, 1);
const bypass_module_t *sel = bypass_select(&dev);
ASSERT_NOTNULL(sel);
ASSERT_EQ(strcmp(sel->name, "mock_path_a"), 0);
}
static void test_probe_select_falls_to_b(void)
{
/* A12+ device -> Path A probe returns 0, Path B selected */
device_info_t dev = make_dev(0, 1);
const bypass_module_t *sel = bypass_select(&dev);
ASSERT_NOTNULL(sel);
ASSERT_EQ(strcmp(sel->name, "mock_path_b"), 0);
}
static void test_probe_select_no_match(void)
{
/* Normal mode A12+ device -> neither probe matches */
device_info_t dev = make_dev(0, 0);
ASSERT_NULL(bypass_select(&dev));
}
void run_bypass_probe_tests(void)
{
printf("--- Section 3: Bypass probe logic ---\n");
test_probe_path_a_compatible();
test_probe_path_a_not_dfu();
test_probe_path_a_a12();
test_probe_path_b_compatible();
test_probe_path_b_a11();
test_probe_path_b_not_dfu();
/* These three share a module registry -- must run after the others */
test_probe_select_prefers_a();
test_probe_select_falls_to_b();
test_probe_select_no_match();
}