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>
87 lines
2.4 KiB
C
87 lines
2.4 KiB
C
/*
|
|
* test_parsing.c -- DFU serial CPID/ECID parsing tests.
|
|
*
|
|
* Inline copy of parse_hex_field logic from src/device/usb_dfu.c, tested
|
|
* independently of the hardware-dependent USB code.
|
|
*/
|
|
|
|
#include "test_framework.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static int test_parse_hex_field(const char *serial, const char *key,
|
|
uint64_t *out)
|
|
{
|
|
const char *p;
|
|
char *endptr;
|
|
|
|
if (!serial || !key || !out)
|
|
return -1;
|
|
p = strstr(serial, key);
|
|
if (!p)
|
|
return -1;
|
|
endptr = NULL;
|
|
*out = strtoull(p + strlen(key), &endptr, 16);
|
|
if (!endptr || endptr == p + strlen(key)) {
|
|
*out = 0;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void test_parse_cpid_normal(void)
|
|
{
|
|
const char *serial = "CPID:8015 CPRV:11 BDID:0C ECID:001A2B3C4D5E6F70 "
|
|
"IBFL:3C SRTG:[iBoot-4142.0.0.0.1]";
|
|
uint64_t cpid = 0, ecid = 0;
|
|
|
|
ASSERT_EQ(test_parse_hex_field(serial, "CPID:", &cpid), 0);
|
|
ASSERT_EQ(cpid, (uint64_t)0x8015);
|
|
|
|
ASSERT_EQ(test_parse_hex_field(serial, "ECID:", &ecid), 0);
|
|
ASSERT_EQ(ecid, (uint64_t)0x001A2B3C4D5E6F70ULL);
|
|
}
|
|
|
|
static void test_parse_cpid_a9_samsung(void)
|
|
{
|
|
const char *serial = "CPID:8003 CPRV:10 BDID:02 ECID:AABB112233445566";
|
|
uint64_t cpid = 0;
|
|
|
|
ASSERT_EQ(test_parse_hex_field(serial, "CPID:", &cpid), 0);
|
|
ASSERT_EQ(cpid, (uint64_t)0x8003);
|
|
}
|
|
|
|
static void test_parse_cpid_empty_serial(void)
|
|
{
|
|
/* Bare DFU string -- no CPID/ECID fields */
|
|
const char *serial = "Apple Mobile Device (DFU Mode)";
|
|
uint64_t cpid = 0xDEAD, ecid = 0xDEAD;
|
|
|
|
ASSERT_EQ(test_parse_hex_field(serial, "CPID:", &cpid), -1);
|
|
ASSERT_EQ(test_parse_hex_field(serial, "ECID:", &ecid), -1);
|
|
/* Outputs unchanged on failure */
|
|
ASSERT_EQ(cpid, (uint64_t)0xDEAD);
|
|
ASSERT_EQ(ecid, (uint64_t)0xDEAD);
|
|
}
|
|
|
|
static void test_parse_cpid_partial(void)
|
|
{
|
|
/* CPID present, ECID absent */
|
|
const char *serial = "CPID:8960 CPRV:01";
|
|
uint64_t cpid = 0, ecid = 0xBEEF;
|
|
|
|
ASSERT_EQ(test_parse_hex_field(serial, "CPID:", &cpid), 0);
|
|
ASSERT_EQ(cpid, (uint64_t)0x8960);
|
|
ASSERT_EQ(test_parse_hex_field(serial, "ECID:", &ecid), -1);
|
|
ASSERT_EQ(ecid, (uint64_t)0xBEEF); /* unchanged */
|
|
}
|
|
|
|
void run_serial_parse_tests(void)
|
|
{
|
|
printf("--- Section 1: DFU serial parsing ---\n");
|
|
test_parse_cpid_normal();
|
|
test_parse_cpid_a9_samsung();
|
|
test_parse_cpid_empty_serial();
|
|
test_parse_cpid_partial();
|
|
}
|