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>
101 lines
2.2 KiB
C
101 lines
2.2 KiB
C
/*
|
|
* mock_core.c -- Cross-cutting mock machinery: call log, reset, helpers.
|
|
*/
|
|
|
|
#include "mock_internal.h"
|
|
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
mock_log_t g_mock_log;
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Call log */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
void mock_log_reset(void)
|
|
{
|
|
g_mock_log.count = 0;
|
|
/* No need to clear individual entries; count gates access. */
|
|
}
|
|
|
|
void mock_log_append(const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
if (g_mock_log.count >= MOCK_LOG_MAX)
|
|
return;
|
|
|
|
va_start(ap, fmt);
|
|
vsnprintf(g_mock_log.entries[g_mock_log.count],
|
|
MOCK_LOG_ENTRY_LEN, fmt, ap);
|
|
va_end(ap);
|
|
g_mock_log.count++;
|
|
}
|
|
|
|
size_t mock_get_call_count(void)
|
|
{
|
|
return g_mock_log.count;
|
|
}
|
|
|
|
const char *mock_get_call_log(size_t index)
|
|
{
|
|
if (index >= g_mock_log.count)
|
|
return NULL;
|
|
return g_mock_log.entries[index];
|
|
}
|
|
|
|
int mock_call_log_contains(const char *needle)
|
|
{
|
|
size_t i;
|
|
|
|
if (!needle)
|
|
return 0;
|
|
for (i = 0; i < g_mock_log.count; i++) {
|
|
if (strstr(g_mock_log.entries[i], needle))
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Global reset */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
void mock_reset_all(void)
|
|
{
|
|
mock_log_reset();
|
|
mock_lockdownd_reset();
|
|
mock_irecv_reset();
|
|
mock_libusb_reset();
|
|
mock_ssh_reset();
|
|
mock_curl_reset();
|
|
mock_checkm8_reset();
|
|
mock_afc_mobileactivation_reset();
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Small helpers */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
void *mock_memdup(const void *src, size_t len)
|
|
{
|
|
void *copy;
|
|
|
|
if (!src || len == 0)
|
|
return NULL;
|
|
copy = malloc(len);
|
|
if (!copy)
|
|
return NULL;
|
|
memcpy(copy, src, len);
|
|
return copy;
|
|
}
|
|
|
|
char *mock_strdup_safe(const char *src)
|
|
{
|
|
if (!src)
|
|
return NULL;
|
|
return strdup(src);
|
|
}
|