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>
This commit is contained in:
parent
5b758931ac
commit
30807c8ef6
58 changed files with 7967 additions and 1210 deletions
67
include/activation/cert_extract.h
Normal file
67
include/activation/cert_extract.h
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* cert_extract.h -- Device certificate extraction via lockdownd.
|
||||
*
|
||||
* Pulls the three certificate blobs that the activation record needs
|
||||
* directly from a connected device's lockdownd service:
|
||||
*
|
||||
* - DeviceCertificate
|
||||
* - AccountTokenCertificate
|
||||
* - UniqueDeviceCertificate
|
||||
*
|
||||
* Each is returned as a raw byte blob (DER-encoded X.509 in practice).
|
||||
* The caller owns the buffer and must release it with cert_blob_free().
|
||||
*/
|
||||
|
||||
#ifndef CERT_EXTRACT_H
|
||||
#define CERT_EXTRACT_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <libimobiledevice/lockdown.h>
|
||||
|
||||
typedef struct {
|
||||
unsigned char *data;
|
||||
size_t len;
|
||||
} cert_blob_t;
|
||||
|
||||
/*
|
||||
* cert_blob_free -- Release a cert_blob_t's backing buffer.
|
||||
*
|
||||
* Safe to call on a NULL pointer or a zeroed blob. After the call,
|
||||
* blob->data is NULL and blob->len is zero.
|
||||
*/
|
||||
void cert_blob_free(cert_blob_t *blob);
|
||||
|
||||
/*
|
||||
* cert_extract_device_certificate -- Read the DeviceCertificate.
|
||||
*
|
||||
* Queries the key "DeviceCertificate" in domain
|
||||
* "com.apple.mobile.lockdown". On success returns 0 and populates *out;
|
||||
* on any failure returns -1 and leaves *out zeroed.
|
||||
*/
|
||||
int cert_extract_device_certificate(lockdownd_client_t client,
|
||||
cert_blob_t *out);
|
||||
|
||||
/*
|
||||
* cert_extract_account_token_certificate -- Read the AccountTokenCertificate.
|
||||
*
|
||||
* Tries, in order:
|
||||
* 1. key "AccountTokenCertificate" (NULL domain)
|
||||
* 2. key "ActivationStateDeadline" (NULL domain)
|
||||
* 3. first element of "CertificateChain" array (NULL domain)
|
||||
*
|
||||
* Returns 0 on success and populates *out; -1 on failure.
|
||||
*/
|
||||
int cert_extract_account_token_certificate(lockdownd_client_t client,
|
||||
cert_blob_t *out);
|
||||
|
||||
/*
|
||||
* cert_extract_unique_device_certificate -- Read the UniqueDeviceCertificate.
|
||||
*
|
||||
* Queries the key "UniqueDeviceCertificate" in domain
|
||||
* "com.apple.mobile.activation". Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int cert_extract_unique_device_certificate(lockdownd_client_t client,
|
||||
cert_blob_t *out);
|
||||
|
||||
#endif /* CERT_EXTRACT_H */
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <plist/plist.h>
|
||||
#include <libimobiledevice/lockdown.h>
|
||||
#include "device/device.h"
|
||||
|
||||
/*
|
||||
|
|
@ -19,6 +20,9 @@
|
|||
* Returns a new plist dict containing all required activation fields.
|
||||
* Caller must free with record_free() or plist_free().
|
||||
* Returns NULL on error.
|
||||
*
|
||||
* Equivalent to record_build_with_client(dev, NULL): cert fields are
|
||||
* left as empty-blob placeholders.
|
||||
*/
|
||||
plist_t record_build(const device_info_t *dev);
|
||||
|
||||
|
|
@ -27,9 +31,27 @@ plist_t record_build(const device_info_t *dev);
|
|||
* Uses the FActivation/drmHandshake variant with additional fields
|
||||
* required for A12 and newer chipsets (SEP-aware activation).
|
||||
* Returns a new plist dict, or NULL on error. Caller must free.
|
||||
*
|
||||
* Equivalent to record_build_a12_with_client(dev, NULL).
|
||||
*/
|
||||
plist_t record_build_a12(const device_info_t *dev);
|
||||
|
||||
/*
|
||||
* record_build_with_client -- As record_build, but when `client` is
|
||||
* non-NULL, pull DeviceCertificate / AccountTokenCertificate /
|
||||
* UniqueDeviceCertificate from lockdownd and embed them in the record.
|
||||
* Falls back to empty-blob placeholders if extraction fails.
|
||||
*/
|
||||
plist_t record_build_with_client(const device_info_t *dev,
|
||||
lockdownd_client_t client);
|
||||
|
||||
/*
|
||||
* record_build_a12_with_client -- As record_build_a12, but with live
|
||||
* cert extraction when `client` is non-NULL (see above).
|
||||
*/
|
||||
plist_t record_build_a12_with_client(const device_info_t *dev,
|
||||
lockdownd_client_t client);
|
||||
|
||||
/*
|
||||
* record_to_xml -- Serialize an activation record to XML string.
|
||||
* On success, *len is set to the byte length (excluding NUL).
|
||||
|
|
|
|||
49
include/activation/signer.h
Normal file
49
include/activation/signer.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* signer.h -- ECDSA P-256 signing and verification helpers.
|
||||
*
|
||||
* Thin wrapper over OpenSSL 3.x EVP API. All signatures are ECDSA over
|
||||
* SHA-256, DER-encoded (not raw r||s). Keys are read from and written
|
||||
* to PEM files on disk.
|
||||
*/
|
||||
|
||||
#ifndef SIGNER_H
|
||||
#define SIGNER_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
* signer_ecdsa_sign -- Sign a byte buffer with an EC private key on disk.
|
||||
*
|
||||
* Reads a P-256 private key from `pem_path`, signs `data[len]` (SHA-256
|
||||
* first), and returns the DER-encoded signature via *sig / *sig_len.
|
||||
*
|
||||
* The output buffer is malloc'd and the caller must free() it.
|
||||
* Returns 0 on success, -1 on any failure.
|
||||
*/
|
||||
int signer_ecdsa_sign(const char *pem_path,
|
||||
const unsigned char *data, size_t len,
|
||||
unsigned char **sig, size_t *sig_len);
|
||||
|
||||
/*
|
||||
* signer_ecdsa_verify -- Verify a DER-encoded ECDSA signature.
|
||||
*
|
||||
* Returns 1 if `sig[sig_len]` is a valid signature over SHA-256 of
|
||||
* `data[len]` under the public key in `pem_path`. Returns 0 if the
|
||||
* signature is well-formed but invalid, and -1 on any system error
|
||||
* (bad file, malformed PEM, OOM, etc.).
|
||||
*/
|
||||
int signer_ecdsa_verify(const char *pem_path,
|
||||
const unsigned char *data, size_t len,
|
||||
const unsigned char *sig, size_t sig_len);
|
||||
|
||||
/*
|
||||
* signer_generate_test_keypair -- Write a fresh P-256 keypair to disk.
|
||||
*
|
||||
* Intended for tests. Produces two files: an unencrypted PKCS#8 private
|
||||
* PEM and a SubjectPublicKeyInfo PEM. Overwrites existing files.
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int signer_generate_test_keypair(const char *priv_pem_path,
|
||||
const char *pub_pem_path);
|
||||
|
||||
#endif /* SIGNER_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue