Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a16 support #10

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ swig/*
xcuserdata
!tsschecker/*.h
!tsschecker/*.c
*.zst
91 changes: 83 additions & 8 deletions tsschecker/tss.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ char* ecid_to_string(uint64_t ecid)
return ecid_string;
}

plist_t tss_request_new(plist_t overrides) {
plist_t tss_request_new(plist_t overrides)
{
plist_t request = plist_new_dict();

plist_dict_set_item(request, "@Locality", plist_new_string("en_US"));
plist_dict_set_item(request, "@HostPlatformInfo",
#ifdef WIN32
plist_new_string("windows")
Expand Down Expand Up @@ -210,6 +210,7 @@ int tss_parameters_add_from_manifest(plist_t parameters, plist_t build_identity,

_plist_dict_copy_uint(parameters, build_identity, "eUICC,ChipID", NULL);

_plist_dict_copy_uint(parameters, build_identity, "NeRDEpoch", NULL);
_plist_dict_copy_data(parameters, build_identity, "PearlCertificationRootPub", NULL);

_plist_dict_copy_uint(parameters, build_identity, "Timer,BoardID,1", NULL);
Expand Down Expand Up @@ -238,6 +239,11 @@ int tss_parameters_add_from_manifest(plist_t parameters, plist_t build_identity,
_plist_dict_copy_item(parameters, build_identity, "Cryptex1,MobileAssetBrainVolume", NULL);
_plist_dict_copy_item(parameters, build_identity, "Cryptex1,MobileAssetBrainTrustCache", NULL);

node = plist_dict_get_item(build_identity, "Info");
if (node) {
_plist_dict_copy_bool(parameters, node, "RequiresUIDMode", NULL);
}

if (include_manifest) {
/* add build identity manifest dictionary */
node = plist_dict_get_item(build_identity, "Manifest");
Expand All @@ -257,6 +263,7 @@ int tss_request_add_ap_img4_tags(plist_t request, plist_t parameters)
tsserror("ERROR: Missing required AP parameters\n");
return -1;
}

_plist_dict_copy_string(request, parameters, "Ap,OSLongVersion", NULL);

if (_plist_dict_copy_data(request, parameters, "ApNonce", NULL) < 0) {
Expand All @@ -282,8 +289,16 @@ int tss_request_add_ap_img4_tags(plist_t request, plist_t parameters)
}

_plist_dict_copy_data(request, parameters, "SepNonce", "ApSepNonce");
_plist_dict_copy_uint(request, parameters, "NeRDEpoch", NULL);
_plist_dict_copy_data(request, parameters, "PearlCertificationRootPub", NULL);

if (plist_dict_get_item(parameters, "UID_MODE")) {
_plist_dict_copy_item(request, parameters, "UID_MODE", NULL);
} else if (_plist_dict_get_bool(parameters, "RequiresUIDMode")) {
// The logic here is missing why this value is expected to be 'false'
plist_dict_set_item(request, "UID_MODE", plist_new_bool(0));
}

return 0;
}

Expand Down Expand Up @@ -615,7 +630,7 @@ int tss_request_add_ap_tags(plist_t request, plist_t parameters, plist_t overrid
return -1;
}

/* do not populate BasebandFirmware, only in baseband request */
/* do not populate BaseBandFirmware, only in basebaseband request */
if ((strcmp(key, "BasebandFirmware") == 0)) {
continue;
}
Expand Down Expand Up @@ -659,6 +674,12 @@ int tss_request_add_ap_tags(plist_t request, plist_t parameters, plist_t overrid
}
}

/* skip components with IsFTAB:true */
if (_plist_dict_get_bool(info_dict, "IsFTAB")) {
debug("DEBUG: %s: Skipping FTAB component '%s'\n", __func__, key);
continue;
}

/* copy this entry */
plist_t tss_entry = plist_copy(manifest_entry);

Expand Down Expand Up @@ -1065,10 +1086,29 @@ int tss_request_add_vinyl_tags(plist_t request, plist_t parameters, plist_t over
plist_dict_set_item(request, "@BBTicket", plist_new_bool(1));
plist_dict_set_item(request, "@eUICC,Ticket", plist_new_bool(1));

_plist_dict_copy_bool(request, parameters, "eUICC,ApProductionMode", "ApProductionMode");
_plist_dict_copy_uint(request, parameters, "eUICC,ChipID", NULL);
_plist_dict_copy_data(request, parameters, "eUICC,EID", NULL);
_plist_dict_copy_data(request, parameters, "eUICC,RootKeyIdentifier", NULL);

if (!plist_dict_get_item(request, "eUICC,Gold")) {
plist_t n = plist_access_path(parameters, 2, "Manifest", "eUICC,Gold");
if (n) {
plist_t p = plist_new_dict();
_plist_dict_copy_data(p, n, "Digest", NULL);
plist_dict_set_item(request, "eUICC,Gold", p);
}
}

if (!plist_dict_get_item(request, "eUICC,Main")) {
plist_t n = plist_access_path(parameters, 2, "Manifest", "eUICC,Main");
if (n) {
plist_t p = plist_new_dict();
_plist_dict_copy_data(p, n, "Digest", NULL);
plist_dict_set_item(request, "eUICC,Main", p);
}
}

/* set Nonce for eUICC,Gold component */
node = plist_dict_get_item(parameters, "EUICCGoldNonce");
if (node) {
Expand Down Expand Up @@ -1372,6 +1412,44 @@ int tss_request_add_timer_tags(plist_t request, plist_t parameters, plist_t over
return 0;
}

int tss_request_add_cryptex_tags(plist_t request, plist_t parameters, plist_t overrides)
{
tss_request_add_common_tags(request, parameters, NULL);

if (plist_dict_get_item(parameters, "Ap,LocalPolicy")) {
/* Cryptex1LocalPolicy */
tss_request_add_local_policy_tags(request, parameters);
_plist_dict_copy_data(request, parameters, "Ap,NextStageCryptex1IM4MHash", NULL);
} else {
/* Cryptex1 */
plist_dict_set_item(request, "@Cryptex1,Ticket", plist_new_bool(1));

_plist_dict_copy_bool(request, parameters, "ApSecurityMode", NULL);
_plist_dict_copy_bool(request, parameters, "ApProductionMode", NULL);

plist_dict_iter iter = NULL;
plist_dict_new_iter(parameters, &iter);
plist_t value = NULL;
while (1) {
char *key = NULL;
plist_dict_next_item(parameters, iter, &key, &value);
if (key == NULL)
break;
if (strncmp(key, "Cryptex1", 8) == 0) {
plist_dict_set_item(request, key, plist_copy(value));
}
free(key);
}
}

/* apply overrides */
if (overrides) {
plist_dict_merge(&request, overrides);
}

return 0;
}

static size_t tss_write_callback(char* data, size_t size, size_t nmemb, tss_response* response)
{
size_t total = size * nmemb;
Expand All @@ -1385,7 +1463,8 @@ static size_t tss_write_callback(char* data, size_t size, size_t nmemb, tss_resp
return total;
}

plist_t tss_request_send(plist_t tss_request, const char* server_url_string) {
plist_t tss_request_send(plist_t tss_request, const char* server_url_string)
{
if (idevicerestore_debug) {
debug_plist(tss_request);
}
Expand Down Expand Up @@ -1493,10 +1572,6 @@ plist_t tss_request_send(plist_t tss_request, const char* server_url_string) {
} else if (status_code == 126) {
// An internal error occured, most likely the request was malformed
break;
/* FIXME: fully fix 128 error; now it's ignored */
} else if (status_code == 128) {
// Error that occurs when TSS request on certain devices
break;
} else {
tsserror("ERROR: tss_send_request: Unhandled status code %d\n", status_code);
}
Expand Down
6 changes: 5 additions & 1 deletion tsschecker/tss.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ extern int print_tss_request;
int tss_parameters_add_from_manifest(plist_t parameters, plist_t build_identity, bool include_manifest);

/* request */
plist_t tss_request_new_ota(plist_t overrides);
plist_t tss_request_new(plist_t overrides);

int tss_request_add_local_policy_tags(plist_t request, plist_t parameters);
int tss_request_add_common_tags(plist_t request, plist_t parameters, plist_t overrides);
int tss_request_add_ap_tags(plist_t request, plist_t parameters, plist_t overrides);
int tss_request_add_ap_recovery_tags(plist_t request, plist_t parameters, plist_t overrides);
int tss_request_add_baseband_tags(plist_t request, plist_t parameters, plist_t overrides);
int tss_request_add_se_tags(plist_t request, plist_t parameters, plist_t overrides);
int tss_request_add_savage_tags(plist_t request, plist_t parameters, plist_t overrides, char **component_name);
int tss_request_add_yonkers_tags(plist_t request, plist_t parameters, plist_t overrides, char **component_name);
int tss_request_add_vinyl_tags(plist_t request, plist_t parameters, plist_t overrides);
int tss_request_add_rose_tags(plist_t request, plist_t parameters, plist_t overrides);
int tss_request_add_veridian_tags(plist_t request, plist_t parameters, plist_t overrides);
int tss_request_add_tcon_tags(plist_t request, plist_t parameters, plist_t overrides);
int tss_request_add_timer_tags(plist_t request, plist_t parameters, plist_t overrides);
int tss_request_add_cryptex_tags(plist_t request, plist_t parameters, plist_t overrides);

int tss_request_add_ap_img4_tags(plist_t request, plist_t parameters);
int tss_request_add_ap_img3_tags(plist_t request, plist_t parameters);
Expand Down