From 78a239bf2c64c9e37c21b2ddabbc0d76ec599afb Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Mon, 18 Nov 2013 22:51:28 +0100 Subject: Split nonce retrieval into ApNonce and SepNonce for DFU and Recovery modes --- src/dfu.c | 25 +++++++++++++++++++++---- src/dfu.h | 3 ++- src/idevicerestore.c | 4 ++-- src/recovery.c | 21 +++++++++++++++++++-- src/recovery.h | 3 ++- 5 files changed, 46 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/dfu.c b/src/dfu.c index 9393fe8..5cea9ad 100644 --- a/src/dfu.c +++ b/src/dfu.c @@ -239,7 +239,7 @@ int dfu_get_cpid(struct idevicerestore_client_t* client, unsigned int* cpid) { return 0; } -int dfu_get_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { +int dfu_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { irecv_error_t dfu_error = IRECV_E_SUCCESS; if(client->dfu == NULL) { @@ -248,7 +248,24 @@ int dfu_get_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, } } - dfu_error = irecv_get_nonce(client->dfu->client, nonce, nonce_size); + dfu_error = irecv_get_nonce_with_tag(client->dfu->client, "NONC", nonce, nonce_size); + if (dfu_error != IRECV_E_SUCCESS) { + return -1; + } + + return 0; +} + +int dfu_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { + irecv_error_t dfu_error = IRECV_E_SUCCESS; + + if(client->dfu == NULL) { + if (dfu_client_new(client) < 0) { + return -1; + } + } + + dfu_error = irecv_get_nonce_with_tag(client->dfu->client, "SNON", nonce, nonce_size); if (dfu_error != IRECV_E_SUCCESS) { return -1; } @@ -300,8 +317,8 @@ int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_ide unsigned char* nonce = NULL; int nonce_size = 0; int nonce_changed = 0; - if (dfu_get_nonce(client, &nonce, &nonce_size) < 0) { - error("ERROR: Unable to get nonce from device!\n"); + if (dfu_get_ap_nonce(client, &nonce, &nonce_size) < 0) { + error("ERROR: Unable to get ApNonce from device!\n"); return -1; } diff --git a/src/dfu.h b/src/dfu.h index 8b57022..36badb2 100644 --- a/src/dfu.h +++ b/src/dfu.h @@ -44,7 +44,8 @@ const char* dfu_check_product_type(struct idevicerestore_client_t* client); int dfu_send_buffer(struct idevicerestore_client_t* client, unsigned char* buffer, unsigned int size); int dfu_send_component(struct idevicerestore_client_t* client, plist_t build_identity, const char* component); int dfu_get_cpid(struct idevicerestore_client_t* client, unsigned int* cpid); -int dfu_get_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); +int dfu_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); +int dfu_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_identity); diff --git a/src/idevicerestore.c b/src/idevicerestore.c index d1f3c00..9bf37e0 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -1273,14 +1273,14 @@ int get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, break; case MODE_DFU: info("in dfu mode... "); - if (dfu_get_nonce(client, nonce, nonce_size) < 0) { + if (dfu_get_ap_nonce(client, nonce, nonce_size) < 0) { info("failed\n"); return -1; } break; case MODE_RECOVERY: info("in recovery mode... "); - if (recovery_get_nonce(client, nonce, nonce_size) < 0) { + if (recovery_get_ap_nonce(client, nonce, nonce_size) < 0) { info("failed\n"); return -1; } diff --git a/src/recovery.c b/src/recovery.c index e4575fc..42bb234 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -461,7 +461,7 @@ int recovery_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { return 0; } -int recovery_get_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { +int recovery_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { irecv_error_t recovery_error = IRECV_E_SUCCESS; if(client->recovery == NULL) { @@ -470,7 +470,24 @@ int recovery_get_nonce(struct idevicerestore_client_t* client, unsigned char** n } } - recovery_error = irecv_get_nonce(client->recovery->client, nonce, nonce_size); + recovery_error = irecv_get_nonce_with_tag(client->recovery->client, "NONC", nonce, nonce_size); + if (recovery_error != IRECV_E_SUCCESS) { + return -1; + } + + return 0; +} + +int recovery_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { + irecv_error_t recovery_error = IRECV_E_SUCCESS; + + if(client->recovery == NULL) { + if (recovery_client_new(client) < 0) { + return -1; + } + } + + recovery_error = irecv_get_nonce_with_tag(client->recovery->client, "SNON", nonce, nonce_size); if (recovery_error != IRECV_E_SUCCESS) { return -1; } diff --git a/src/recovery.h b/src/recovery.h index d9b4597..d1fd71e 100644 --- a/src/recovery.h +++ b/src/recovery.h @@ -54,7 +54,8 @@ int recovery_send_reset(struct idevicerestore_client_t* client); int recovery_send_ticket(struct idevicerestore_client_t* client); int recovery_set_autoboot(struct idevicerestore_client_t* client, int enable); int recovery_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid); -int recovery_get_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); +int recovery_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); +int recovery_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); int recovery_get_cpid(struct idevicerestore_client_t* client, uint32_t* cpid); int recovery_get_bdid(struct idevicerestore_client_t* client, uint32_t* bdid); -- cgit v1.1-32-gdbae