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>
227 lines
6.2 KiB
C
227 lines
6.2 KiB
C
/*
|
|
* mock_irecv_sym.c -- Interposed libirecovery entry points.
|
|
*/
|
|
|
|
#include "mock_irecv_internal.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
|
|
const char *irecv_strerror(irecv_error_t error)
|
|
{
|
|
switch ((int)error) {
|
|
case 0: return "Success";
|
|
case -1: return "No device found";
|
|
case -2: return "Out of memory";
|
|
case -3: return "Unable to connect";
|
|
default: return "Mock irecovery error";
|
|
}
|
|
}
|
|
|
|
const char *irecv_version(void)
|
|
{
|
|
return "mock-1.3.1";
|
|
}
|
|
|
|
void irecv_set_debug_level(int level)
|
|
{
|
|
(void)level;
|
|
}
|
|
|
|
irecv_error_t irecv_open_with_ecid(irecv_client_t *client, uint64_t ecid)
|
|
{
|
|
struct irecv_client_private *c;
|
|
int i;
|
|
|
|
mock_log_append("irecv_open_with_ecid(ecid=0x%llx)",
|
|
(unsigned long long)ecid);
|
|
|
|
if (!client)
|
|
return (irecv_error_t)-1;
|
|
|
|
/* FIFO of staged open errors -- consume one per call. */
|
|
for (i = 0; i < IRECV_OPEN_ERROR_SLOTS; i++) {
|
|
irecv_open_error_slot_t *s = &g_irecv_open_error_slots[i];
|
|
if (s->in_use && !s->consumed) {
|
|
s->consumed = 1;
|
|
*client = NULL;
|
|
return (irecv_error_t)s->error_code;
|
|
}
|
|
}
|
|
|
|
/* Sticky flag (backwards compat) still takes effect when FIFO is
|
|
* empty. Tests that called mock_irecv_set_open_error() continue to
|
|
* see errors on every subsequent call. */
|
|
if (g_irecv_open_error != 0) {
|
|
*client = NULL;
|
|
return (irecv_error_t)g_irecv_open_error;
|
|
}
|
|
c = calloc(1, sizeof(*c));
|
|
if (!c)
|
|
return (irecv_error_t)-2;
|
|
c->magic = IRECV_MAGIC;
|
|
c->info.pid = (uint16_t)g_irecv_info_pid;
|
|
c->info.ecid = ecid != 0 ? ecid : g_irecv_info_ecid;
|
|
c->info.cpid = 0x8020;
|
|
c->info.have_ecid = 1;
|
|
c->info.have_cpid = 1;
|
|
snprintf(c->serial_buf, sizeof(c->serial_buf), "%s",
|
|
g_irecv_info_serial);
|
|
c->info.serial_string = c->serial_buf;
|
|
*client = c;
|
|
return (irecv_error_t)0;
|
|
}
|
|
|
|
irecv_error_t irecv_open_with_ecid_and_attempts(irecv_client_t *client,
|
|
uint64_t ecid, int attempts)
|
|
{
|
|
(void)attempts;
|
|
return irecv_open_with_ecid(client, ecid);
|
|
}
|
|
|
|
irecv_error_t irecv_close(irecv_client_t client)
|
|
{
|
|
mock_log_append("irecv_close");
|
|
if (!client)
|
|
return (irecv_error_t)0;
|
|
client->magic = 0;
|
|
free(client);
|
|
return (irecv_error_t)0;
|
|
}
|
|
|
|
irecv_error_t irecv_reset(irecv_client_t client)
|
|
{
|
|
(void)client;
|
|
mock_log_append("irecv_reset");
|
|
return (irecv_error_t)0;
|
|
}
|
|
|
|
irecv_client_t irecv_reconnect(irecv_client_t client, int initial_pause)
|
|
{
|
|
(void)initial_pause;
|
|
mock_log_append("irecv_reconnect");
|
|
return client;
|
|
}
|
|
|
|
const struct irecv_device_info *irecv_get_device_info(irecv_client_t client)
|
|
{
|
|
mock_log_append("irecv_get_device_info");
|
|
if (!client)
|
|
return NULL;
|
|
return &client->info;
|
|
}
|
|
|
|
irecv_error_t irecv_send_command(irecv_client_t client, const char *command)
|
|
{
|
|
(void)client;
|
|
mock_log_append("irecv_send_command(%s)",
|
|
command ? command : "(null)");
|
|
|
|
if (g_irecv_cmd_expect_active) {
|
|
g_irecv_cmd_expect_active = 0;
|
|
if (!command || !strstr(command, g_irecv_cmd_expect)) {
|
|
mock_log_append("EXPECT-FAIL: expected command containing '%s'",
|
|
g_irecv_cmd_expect);
|
|
return (irecv_error_t)-1;
|
|
}
|
|
}
|
|
return (irecv_error_t)0;
|
|
}
|
|
|
|
irecv_error_t irecv_send_command_breq(irecv_client_t client,
|
|
const char *command, uint8_t b_request)
|
|
{
|
|
(void)b_request;
|
|
return irecv_send_command(client, command);
|
|
}
|
|
|
|
irecv_error_t irecv_send_file(irecv_client_t client, const char *filename,
|
|
unsigned int options)
|
|
{
|
|
struct stat st;
|
|
size_t size = 0;
|
|
int i;
|
|
|
|
(void)client; (void)options;
|
|
if (filename && stat(filename, &st) == 0)
|
|
size = (size_t)st.st_size;
|
|
|
|
mock_log_append("irecv_send_file(%s,%zu)",
|
|
filename ? filename : "(null)", size);
|
|
|
|
/* Phase 3: per-path staged errors take priority. Each slot fires at
|
|
* most once; path_needle is matched via strstr() on the filename. */
|
|
if (filename) {
|
|
for (i = 0; i < IRECV_SEND_FILE_STAGES; i++) {
|
|
irecv_send_file_stage_t *s = &g_irecv_send_file_stages[i];
|
|
if (!s->in_use || s->consumed)
|
|
continue;
|
|
if (s->path_needle[0] == '\0')
|
|
continue;
|
|
if (strstr(filename, s->path_needle) != NULL) {
|
|
s->consumed = 1;
|
|
return (irecv_error_t)s->error_code;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (g_irecv_file_upload_active) {
|
|
g_irecv_file_upload_active = 0;
|
|
if (g_irecv_file_upload_bytes_out)
|
|
*g_irecv_file_upload_bytes_out = size;
|
|
}
|
|
return (irecv_error_t)0;
|
|
}
|
|
|
|
irecv_error_t irecv_setenv(irecv_client_t client, const char *variable,
|
|
const char *value)
|
|
{
|
|
int i;
|
|
(void)client;
|
|
mock_log_append("irecv_setenv(%s=%s)",
|
|
variable ? variable : "(null)",
|
|
value ? value : "(null)");
|
|
|
|
if (variable) {
|
|
for (i = 0; i < MOCK_SETENV_SLOTS; i++) {
|
|
if (g_irecv_setenv_results[i].in_use &&
|
|
strcmp(g_irecv_setenv_results[i].var, variable) == 0) {
|
|
return (irecv_error_t)g_irecv_setenv_results[i].error;
|
|
}
|
|
}
|
|
}
|
|
return (irecv_error_t)g_irecv_setenv_default_error;
|
|
}
|
|
|
|
irecv_error_t irecv_setenv_np(irecv_client_t client, const char *variable,
|
|
const char *value)
|
|
{
|
|
return irecv_setenv(client, variable, value);
|
|
}
|
|
|
|
irecv_error_t irecv_getenv(irecv_client_t client, const char *variable,
|
|
char **value)
|
|
{
|
|
(void)client;
|
|
mock_log_append("irecv_getenv(%s)", variable ? variable : "(null)");
|
|
if (value)
|
|
*value = strdup("mockvalue");
|
|
return (irecv_error_t)0;
|
|
}
|
|
|
|
irecv_error_t irecv_saveenv(irecv_client_t client)
|
|
{
|
|
(void)client;
|
|
mock_log_append("irecv_saveenv");
|
|
return (irecv_error_t)0;
|
|
}
|
|
|
|
irecv_error_t irecv_reboot(irecv_client_t client)
|
|
{
|
|
(void)client;
|
|
mock_log_append("irecv_reboot");
|
|
return (irecv_error_t)0;
|
|
}
|