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>
296 lines
9 KiB
C
296 lines
9 KiB
C
/*
|
|
* mock_afc_mobileactivation.c -- Mocks for libimobiledevice's AFC and
|
|
* mobileactivation service APIs. Staging + reset lives in the sibling
|
|
* file mock_afc_mobileactivation_ctl.c; only the interposed symbols
|
|
* remain here.
|
|
*/
|
|
|
|
#include "mock_internal.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <libimobiledevice/libimobiledevice.h>
|
|
#include <libimobiledevice/lockdown.h>
|
|
#include <libimobiledevice/mobileactivation.h>
|
|
#include <libimobiledevice/afc.h>
|
|
#include <plist/plist.h>
|
|
|
|
/* Shared staging state (see mock_afc_mobileactivation_ctl.c). */
|
|
extern int g_ma_activate_error;
|
|
extern int g_ma_create_info_error;
|
|
extern char g_ma_state[64];
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* mobileactivation_* */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
struct mobileactivation_client_private {
|
|
uint32_t magic;
|
|
};
|
|
|
|
#define MA_MAGIC 0x4D414354u /* "MACT" */
|
|
|
|
mobileactivation_error_t
|
|
mobileactivation_client_start_service(idevice_t device,
|
|
mobileactivation_client_t *client,
|
|
const char *label)
|
|
{
|
|
struct mobileactivation_client_private *c;
|
|
(void)device; (void)label;
|
|
mock_log_append("mobileactivation_client_start_service");
|
|
if (!client) return MOBILEACTIVATION_E_INVALID_ARG;
|
|
c = calloc(1, sizeof(*c));
|
|
if (!c) return MOBILEACTIVATION_E_UNKNOWN_ERROR;
|
|
c->magic = MA_MAGIC;
|
|
*client = c;
|
|
return MOBILEACTIVATION_E_SUCCESS;
|
|
}
|
|
|
|
mobileactivation_error_t
|
|
mobileactivation_client_new(idevice_t device,
|
|
lockdownd_service_descriptor_t service,
|
|
mobileactivation_client_t *client)
|
|
{
|
|
(void)service;
|
|
return mobileactivation_client_start_service(device, client, "mock");
|
|
}
|
|
|
|
mobileactivation_error_t
|
|
mobileactivation_client_free(mobileactivation_client_t client)
|
|
{
|
|
mock_log_append("mobileactivation_client_free");
|
|
if (!client) return MOBILEACTIVATION_E_SUCCESS;
|
|
client->magic = 0;
|
|
free(client);
|
|
return MOBILEACTIVATION_E_SUCCESS;
|
|
}
|
|
|
|
mobileactivation_error_t
|
|
mobileactivation_get_activation_state(mobileactivation_client_t client,
|
|
plist_t *state)
|
|
{
|
|
(void)client;
|
|
mock_log_append("mobileactivation_get_activation_state");
|
|
if (!state) return MOBILEACTIVATION_E_INVALID_ARG;
|
|
*state = plist_new_string(g_ma_state);
|
|
return MOBILEACTIVATION_E_SUCCESS;
|
|
}
|
|
|
|
mobileactivation_error_t
|
|
mobileactivation_create_activation_session_info(mobileactivation_client_t client,
|
|
plist_t *blob)
|
|
{
|
|
(void)client;
|
|
mock_log_append("mobileactivation_create_activation_session_info");
|
|
if (!blob) return MOBILEACTIVATION_E_INVALID_ARG;
|
|
/* Return an empty dict: tests can replace via Phase 2 helpers. */
|
|
*blob = plist_new_dict();
|
|
return MOBILEACTIVATION_E_SUCCESS;
|
|
}
|
|
|
|
mobileactivation_error_t
|
|
mobileactivation_create_activation_info(mobileactivation_client_t client,
|
|
plist_t *info)
|
|
{
|
|
(void)client;
|
|
mock_log_append("mobileactivation_create_activation_info");
|
|
if (!info) return MOBILEACTIVATION_E_INVALID_ARG;
|
|
if (g_ma_create_info_error != 0) {
|
|
*info = NULL;
|
|
return (mobileactivation_error_t)g_ma_create_info_error;
|
|
}
|
|
*info = plist_new_dict();
|
|
return MOBILEACTIVATION_E_SUCCESS;
|
|
}
|
|
|
|
mobileactivation_error_t
|
|
mobileactivation_create_activation_info_with_session(mobileactivation_client_t client,
|
|
plist_t handshake_response,
|
|
plist_t *info)
|
|
{
|
|
(void)client; (void)handshake_response;
|
|
mock_log_append("mobileactivation_create_activation_info_with_session");
|
|
if (!info) return MOBILEACTIVATION_E_INVALID_ARG;
|
|
if (g_ma_create_info_error != 0) {
|
|
*info = NULL;
|
|
return (mobileactivation_error_t)g_ma_create_info_error;
|
|
}
|
|
*info = plist_new_dict();
|
|
return MOBILEACTIVATION_E_SUCCESS;
|
|
}
|
|
|
|
mobileactivation_error_t
|
|
mobileactivation_activate(mobileactivation_client_t client,
|
|
plist_t activation_record)
|
|
{
|
|
(void)client; (void)activation_record;
|
|
mock_log_append("mobileactivation_activate");
|
|
if (g_ma_activate_error != 0)
|
|
return (mobileactivation_error_t)g_ma_activate_error;
|
|
return MOBILEACTIVATION_E_SUCCESS;
|
|
}
|
|
|
|
mobileactivation_error_t
|
|
mobileactivation_activate_with_session(mobileactivation_client_t client,
|
|
plist_t activation_record,
|
|
plist_t headers)
|
|
{
|
|
(void)client; (void)activation_record; (void)headers;
|
|
mock_log_append("mobileactivation_activate_with_session");
|
|
if (g_ma_activate_error != 0)
|
|
return (mobileactivation_error_t)g_ma_activate_error;
|
|
return MOBILEACTIVATION_E_SUCCESS;
|
|
}
|
|
|
|
mobileactivation_error_t
|
|
mobileactivation_deactivate(mobileactivation_client_t client)
|
|
{
|
|
(void)client;
|
|
mock_log_append("mobileactivation_deactivate");
|
|
return MOBILEACTIVATION_E_SUCCESS;
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* afc_* */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
struct afc_client_private {
|
|
uint32_t magic;
|
|
uint64_t next_handle;
|
|
};
|
|
|
|
#define AFC_MAGIC 0x41464343u /* "AFCC" */
|
|
|
|
afc_error_t afc_client_new(idevice_t device,
|
|
lockdownd_service_descriptor_t service,
|
|
afc_client_t *client)
|
|
{
|
|
struct afc_client_private *c;
|
|
(void)device; (void)service;
|
|
mock_log_append("afc_client_new");
|
|
if (!client) return AFC_E_INVALID_ARG;
|
|
c = calloc(1, sizeof(*c));
|
|
if (!c) return AFC_E_NO_MEM;
|
|
c->magic = AFC_MAGIC;
|
|
c->next_handle = 0x1000;
|
|
*client = c;
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
afc_error_t afc_client_start_service(idevice_t device, afc_client_t *client,
|
|
const char *label)
|
|
{
|
|
(void)label;
|
|
return afc_client_new(device, NULL, client);
|
|
}
|
|
|
|
afc_error_t afc_client_free(afc_client_t client)
|
|
{
|
|
mock_log_append("afc_client_free");
|
|
if (!client) return AFC_E_SUCCESS;
|
|
client->magic = 0;
|
|
free(client);
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
afc_error_t afc_file_open(afc_client_t client, const char *filename,
|
|
afc_file_mode_t mode, uint64_t *handle)
|
|
{
|
|
(void)mode;
|
|
mock_log_append("afc_file_open(%s)", filename ? filename : "");
|
|
if (!client || !handle) return AFC_E_INVALID_ARG;
|
|
*handle = ++client->next_handle;
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
afc_error_t afc_file_close(afc_client_t client, uint64_t handle)
|
|
{
|
|
(void)client; (void)handle;
|
|
mock_log_append("afc_file_close");
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
afc_error_t afc_file_read(afc_client_t client, uint64_t handle,
|
|
char *data, uint32_t length, uint32_t *bytes_read)
|
|
{
|
|
(void)client; (void)handle; (void)data; (void)length;
|
|
if (bytes_read) *bytes_read = 0;
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
afc_error_t afc_file_write(afc_client_t client, uint64_t handle,
|
|
const char *data, uint32_t length,
|
|
uint32_t *bytes_written)
|
|
{
|
|
(void)client; (void)handle; (void)data;
|
|
mock_log_append("afc_file_write(%u)", length);
|
|
if (bytes_written) *bytes_written = length;
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
afc_error_t afc_remove_path(afc_client_t client, const char *path)
|
|
{
|
|
(void)client;
|
|
mock_log_append("afc_remove_path(%s)", path ? path : "");
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
afc_error_t afc_make_directory(afc_client_t client, const char *path)
|
|
{
|
|
(void)client;
|
|
mock_log_append("afc_make_directory(%s)", path ? path : "");
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
afc_error_t afc_read_directory(afc_client_t client, const char *path,
|
|
char ***directory_information)
|
|
{
|
|
(void)client; (void)path;
|
|
if (directory_information) {
|
|
char **arr = calloc(1, sizeof(char *));
|
|
if (arr) *directory_information = arr;
|
|
else return AFC_E_NO_MEM;
|
|
}
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
afc_error_t afc_get_file_info(afc_client_t client, const char *path,
|
|
char ***file_information)
|
|
{
|
|
(void)client; (void)path;
|
|
if (file_information) {
|
|
char **arr = calloc(1, sizeof(char *));
|
|
if (arr) *file_information = arr;
|
|
else return AFC_E_NO_MEM;
|
|
}
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
afc_error_t afc_rename_path(afc_client_t client, const char *from,
|
|
const char *to)
|
|
{
|
|
(void)client;
|
|
mock_log_append("afc_rename_path(%s -> %s)",
|
|
from ? from : "", to ? to : "");
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
afc_error_t afc_dictionary_free(char **dictionary)
|
|
{
|
|
int i;
|
|
if (!dictionary) return AFC_E_SUCCESS;
|
|
for (i = 0; dictionary[i]; i++)
|
|
free(dictionary[i]);
|
|
free(dictionary);
|
|
return AFC_E_SUCCESS;
|
|
}
|
|
|
|
const char *afc_strerror(afc_error_t err)
|
|
{
|
|
switch ((int)err) {
|
|
case 0: return "Success";
|
|
default: return "Mock AFC error";
|
|
}
|
|
}
|