diff options
Diffstat (limited to 'src/lockdown.c')
| -rw-r--r-- | src/lockdown.c | 105 |
1 files changed, 48 insertions, 57 deletions
diff --git a/src/lockdown.c b/src/lockdown.c index 0957fa2..4c96a7d 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -177,11 +177,8 @@ iphone_error_t lockdownd_hello(iphone_lckd_client_t control) | |||
| 177 | int bytes = 0, i = 0; | 177 | int bytes = 0, i = 0; |
| 178 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 178 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 179 | 179 | ||
| 180 | plist_t plist = NULL; | 180 | plist_t dict = NULL; |
| 181 | plist_new_plist(&plist); | 181 | plist_new_dict(&dict); |
| 182 | |||
| 183 | dict_t dict = NULL; | ||
| 184 | plist_new_dict_in_plist(plist, &dict); | ||
| 185 | 182 | ||
| 186 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "QueryType"); | 183 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "QueryType"); |
| 187 | 184 | ||
| @@ -189,23 +186,23 @@ iphone_error_t lockdownd_hello(iphone_lckd_client_t control) | |||
| 189 | char *XML_content = NULL; | 186 | char *XML_content = NULL; |
| 190 | uint32_t length = 0; | 187 | uint32_t length = 0; |
| 191 | 188 | ||
| 192 | plist_to_xml(plist, &XML_content, &length); | 189 | plist_to_xml(dict, &XML_content, &length); |
| 193 | log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); | 190 | log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); |
| 194 | ret = iphone_lckd_send(control, XML_content, length, &bytes); | 191 | ret = iphone_lckd_send(control, XML_content, length, &bytes); |
| 195 | 192 | ||
| 196 | xmlFree(XML_content); | 193 | xmlFree(XML_content); |
| 197 | XML_content = NULL; | 194 | XML_content = NULL; |
| 198 | plist_free(plist); | 195 | plist_free(dict); |
| 199 | plist = NULL; | 196 | dict = NULL; |
| 200 | 197 | ||
| 201 | ret = iphone_lckd_recv(control, &XML_content, &bytes); | 198 | ret = iphone_lckd_recv(control, &XML_content, &bytes); |
| 202 | log_debug_msg("Receive msg :\nsize : %i\nxml : %s", bytes, XML_content); | 199 | log_debug_msg("Receive msg :\nsize : %i\nxml : %s", bytes, XML_content); |
| 203 | xml_to_plist(XML_content, bytes, &plist); | 200 | xml_to_plist(XML_content, bytes, &dict); |
| 204 | 201 | ||
| 205 | if (!plist) | 202 | if (!dict) |
| 206 | return IPHONE_E_PLIST_ERROR; | 203 | return IPHONE_E_PLIST_ERROR; |
| 207 | 204 | ||
| 208 | plist_t query_node = find_query_node(plist, "Request", "QueryType"); | 205 | plist_t query_node = find_query_node(dict, "Request", "QueryType"); |
| 209 | plist_t result_node = g_node_next_sibling(query_node); | 206 | plist_t result_node = g_node_next_sibling(query_node); |
| 210 | plist_t value_node = g_node_next_sibling(result_node); | 207 | plist_t value_node = g_node_next_sibling(result_node); |
| 211 | 208 | ||
| @@ -239,19 +236,18 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r | |||
| 239 | { | 236 | { |
| 240 | if (!control || !req_key || !value || (value && *value)) | 237 | if (!control || !req_key || !value || (value && *value)) |
| 241 | return IPHONE_E_INVALID_ARG; | 238 | return IPHONE_E_INVALID_ARG; |
| 242 | plist_t plist = NULL; | 239 | |
| 243 | dict_t dict = NULL; | 240 | plist_t dict = NULL; |
| 244 | int bytes = 0, i = 0; | 241 | int bytes = 0, i = 0; |
| 245 | char *XML_content = NULL; | 242 | char *XML_content = NULL; |
| 246 | uint32_t length = 0; | 243 | uint32_t length = 0; |
| 247 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 244 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 248 | 245 | ||
| 249 | /* Setup DevicePublicKey request plist */ | 246 | /* Setup DevicePublicKey request plist */ |
| 250 | plist_new_plist(&plist); | 247 | plist_new_dict(&dict); |
| 251 | plist_new_dict_in_plist(plist, &dict); | ||
| 252 | plist_add_dict_element(dict, req_key, PLIST_STRING, (void *) req_string); | 248 | plist_add_dict_element(dict, req_key, PLIST_STRING, (void *) req_string); |
| 253 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "GetValue"); | 249 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "GetValue"); |
| 254 | plist_to_xml(plist, &XML_content, &length); | 250 | plist_to_xml(dict, &XML_content, &length); |
| 255 | 251 | ||
| 256 | /* send to iPhone */ | 252 | /* send to iPhone */ |
| 257 | log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); | 253 | log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); |
| @@ -259,8 +255,8 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r | |||
| 259 | 255 | ||
| 260 | xmlFree(XML_content); | 256 | xmlFree(XML_content); |
| 261 | XML_content = NULL; | 257 | XML_content = NULL; |
| 262 | plist_free(plist); | 258 | plist_free(dict); |
| 263 | plist = NULL; | 259 | dict = NULL; |
| 264 | 260 | ||
| 265 | if (ret != IPHONE_E_SUCCESS) | 261 | if (ret != IPHONE_E_SUCCESS) |
| 266 | return ret; | 262 | return ret; |
| @@ -272,11 +268,11 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r | |||
| 272 | if (ret != IPHONE_E_SUCCESS) | 268 | if (ret != IPHONE_E_SUCCESS) |
| 273 | return ret; | 269 | return ret; |
| 274 | 270 | ||
| 275 | xml_to_plist(XML_content, bytes, &plist); | 271 | xml_to_plist(XML_content, bytes, &dict); |
| 276 | if (!plist) | 272 | if (!dict) |
| 277 | return IPHONE_E_PLIST_ERROR; | 273 | return IPHONE_E_PLIST_ERROR; |
| 278 | 274 | ||
| 279 | plist_t query_node = find_query_node(plist, "Request", "GetValue"); | 275 | plist_t query_node = find_query_node(dict, "Request", "GetValue"); |
| 280 | plist_t result_key_node = g_node_next_sibling(query_node); | 276 | plist_t result_key_node = g_node_next_sibling(query_node); |
| 281 | plist_t result_value_node = g_node_next_sibling(result_key_node); | 277 | plist_t result_value_node = g_node_next_sibling(result_key_node); |
| 282 | 278 | ||
| @@ -314,7 +310,7 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r | |||
| 314 | ret = IPHONE_E_SUCCESS; | 310 | ret = IPHONE_E_SUCCESS; |
| 315 | } | 311 | } |
| 316 | 312 | ||
| 317 | plist_free(plist); | 313 | plist_free(dict); |
| 318 | free(XML_content); | 314 | free(XML_content); |
| 319 | return ret; | 315 | return ret; |
| 320 | } | 316 | } |
| @@ -408,9 +404,8 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client | |||
| 408 | iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, char *host_id) | 404 | iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, char *host_id) |
| 409 | { | 405 | { |
| 410 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 406 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 411 | plist_t plist = NULL; | 407 | plist_t dict = NULL; |
| 412 | dict_t dict = NULL; | 408 | plist_t dict_record = NULL; |
| 413 | dict_t dict_record = NULL; | ||
| 414 | int bytes = 0, i = 0; | 409 | int bytes = 0, i = 0; |
| 415 | char *XML_content = NULL; | 410 | char *XML_content = NULL; |
| 416 | uint32_t length = 0; | 411 | uint32_t length = 0; |
| @@ -433,8 +428,7 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch | |||
| 433 | } | 428 | } |
| 434 | 429 | ||
| 435 | /* Setup Pair request plist */ | 430 | /* Setup Pair request plist */ |
| 436 | plist_new_plist(&plist); | 431 | plist_new_dict(&dict); |
| 437 | plist_new_dict_in_plist(plist, &dict); | ||
| 438 | plist_add_dict_element(dict, "PairRecord", PLIST_DICT, NULL); | 432 | plist_add_dict_element(dict, "PairRecord", PLIST_DICT, NULL); |
| 439 | dict_record = g_node_last_child(dict); | 433 | dict_record = g_node_last_child(dict); |
| 440 | plist_add_dict_element(dict_record, "DeviceCertificate", PLIST_DATA, (void *) device_cert_b64); | 434 | plist_add_dict_element(dict_record, "DeviceCertificate", PLIST_DATA, (void *) device_cert_b64); |
| @@ -442,15 +436,15 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch | |||
| 442 | plist_add_dict_element(dict_record, "HostID", PLIST_STRING, (void *) host_id); | 436 | plist_add_dict_element(dict_record, "HostID", PLIST_STRING, (void *) host_id); |
| 443 | plist_add_dict_element(dict_record, "RootCertificate", PLIST_DATA, (void *) root_cert_b64); | 437 | plist_add_dict_element(dict_record, "RootCertificate", PLIST_DATA, (void *) root_cert_b64); |
| 444 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "Pair"); | 438 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "Pair"); |
| 445 | plist_to_xml(plist, &XML_content, &length); | 439 | plist_to_xml(dict, &XML_content, &length); |
| 446 | log_debug_msg("XML Pairing request :\nsize : %i\nxml :\n %s", length, XML_content); | 440 | log_debug_msg("XML Pairing request :\nsize : %i\nxml :\n %s", length, XML_content); |
| 447 | 441 | ||
| 448 | /* send to iPhone */ | 442 | /* send to iPhone */ |
| 449 | ret = iphone_lckd_send(control, XML_content, length, &bytes); | 443 | ret = iphone_lckd_send(control, XML_content, length, &bytes); |
| 450 | 444 | ||
| 451 | xmlFree(XML_content); | 445 | xmlFree(XML_content); |
| 452 | plist_free(plist); | 446 | plist_free(dict); |
| 453 | plist = NULL; | 447 | dict = NULL; |
| 454 | 448 | ||
| 455 | if (ret != IPHONE_E_SUCCESS) | 449 | if (ret != IPHONE_E_SUCCESS) |
| 456 | return ret; | 450 | return ret; |
| @@ -465,11 +459,11 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch | |||
| 465 | log_debug_msg(XML_content); | 459 | log_debug_msg(XML_content); |
| 466 | log_debug_msg("\n\n"); | 460 | log_debug_msg("\n\n"); |
| 467 | 461 | ||
| 468 | xml_to_plist(XML_content, bytes, &plist); | 462 | xml_to_plist(XML_content, bytes, &dict); |
| 469 | if (!plist) | 463 | if (!dict) |
| 470 | return IPHONE_E_PLIST_ERROR; | 464 | return IPHONE_E_PLIST_ERROR; |
| 471 | 465 | ||
| 472 | plist_t query_node = find_query_node(plist, "Request", "Pair"); | 466 | plist_t query_node = find_query_node(dict, "Request", "Pair"); |
| 473 | plist_t result_key_node = g_node_next_sibling(query_node); | 467 | plist_t result_key_node = g_node_next_sibling(query_node); |
| 474 | plist_t result_value_node = g_node_next_sibling(result_key_node); | 468 | plist_t result_value_node = g_node_next_sibling(result_key_node); |
| 475 | 469 | ||
| @@ -635,27 +629,25 @@ iphone_error_t lockdownd_gen_pair_cert(char *public_key_b64, char **device_cert_ | |||
| 635 | */ | 629 | */ |
| 636 | iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID) | 630 | iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID) |
| 637 | { | 631 | { |
| 638 | plist_t plist = NULL; | 632 | plist_t dict = NULL; |
| 639 | dict_t dict = NULL; | ||
| 640 | char *XML_content = NULL; | 633 | char *XML_content = NULL; |
| 641 | uint32_t length = 0, bytes = 0, return_me = 0; | 634 | uint32_t length = 0, bytes = 0, return_me = 0; |
| 642 | 635 | ||
| 643 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 636 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 644 | 637 | ||
| 645 | /* Setup DevicePublicKey request plist */ | 638 | /* Setup DevicePublicKey request plist */ |
| 646 | plist_new_plist(&plist); | 639 | plist_new_dict(&dict); |
| 647 | plist_new_dict_in_plist(plist, &dict); | ||
| 648 | plist_add_dict_element(dict, "HostID", PLIST_STRING, (void *) HostID); | 640 | plist_add_dict_element(dict, "HostID", PLIST_STRING, (void *) HostID); |
| 649 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "StartSession"); | 641 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "StartSession"); |
| 650 | plist_to_xml(plist, &XML_content, &length); | 642 | plist_to_xml(dict, &XML_content, &length); |
| 651 | log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); | 643 | log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); |
| 652 | 644 | ||
| 653 | ret = iphone_lckd_send(control, XML_content, length, &bytes); | 645 | ret = iphone_lckd_send(control, XML_content, length, &bytes); |
| 654 | 646 | ||
| 655 | xmlFree(XML_content); | 647 | xmlFree(XML_content); |
| 656 | XML_content = NULL; | 648 | XML_content = NULL; |
| 657 | plist_free(plist); | 649 | plist_free(dict); |
| 658 | plist = NULL; | 650 | dict = NULL; |
| 659 | 651 | ||
| 660 | if (ret != IPHONE_E_SUCCESS) | 652 | if (ret != IPHONE_E_SUCCESS) |
| 661 | return ret; | 653 | return ret; |
| @@ -663,11 +655,11 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c | |||
| 663 | if (bytes > 0) { | 655 | if (bytes > 0) { |
| 664 | ret = iphone_lckd_recv(control, &XML_content, &bytes); | 656 | ret = iphone_lckd_recv(control, &XML_content, &bytes); |
| 665 | log_debug_msg("Receive msg :\nsize : %i\nxml : %s", bytes, XML_content); | 657 | log_debug_msg("Receive msg :\nsize : %i\nxml : %s", bytes, XML_content); |
| 666 | xml_to_plist(XML_content, bytes, &plist); | 658 | xml_to_plist(XML_content, bytes, &dict); |
| 667 | if (!plist) | 659 | if (!dict) |
| 668 | return IPHONE_E_PLIST_ERROR; | 660 | return IPHONE_E_PLIST_ERROR; |
| 669 | 661 | ||
| 670 | plist_t query_node = find_query_node(plist, "Request", "StartSession"); | 662 | plist_t query_node = find_query_node(dict, "Request", "StartSession"); |
| 671 | plist_t result_key_node = g_node_next_sibling(query_node); | 663 | plist_t result_key_node = g_node_next_sibling(query_node); |
| 672 | plist_t result_value_node = g_node_next_sibling(result_key_node); | 664 | plist_t result_value_node = g_node_next_sibling(result_key_node); |
| 673 | 665 | ||
| @@ -681,8 +673,8 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c | |||
| 681 | 673 | ||
| 682 | xmlFree(XML_content); | 674 | xmlFree(XML_content); |
| 683 | XML_content = NULL; | 675 | XML_content = NULL; |
| 684 | plist_free(plist); | 676 | plist_free(dict); |
| 685 | plist = NULL; | 677 | dict = NULL; |
| 686 | 678 | ||
| 687 | if (result_key_type == PLIST_KEY && | 679 | if (result_key_type == PLIST_KEY && |
| 688 | result_value_type == PLIST_STRING && !strcmp(result_key, "Result") && !strcmp(result_value, "Success")) { | 680 | result_value_type == PLIST_STRING && !strcmp(result_key, "Result") && !strcmp(result_value, "Success")) { |
| @@ -871,8 +863,7 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char | |||
| 871 | return IPHONE_E_SSL_ERROR; | 863 | return IPHONE_E_SSL_ERROR; |
| 872 | 864 | ||
| 873 | 865 | ||
| 874 | plist_t plist = NULL; | 866 | plist_t dict = NULL; |
| 875 | dict_t dict = NULL; | ||
| 876 | char *XML_content = NULL; | 867 | char *XML_content = NULL; |
| 877 | uint32_t length, i = 0, port_loc = 0, bytes = 0; | 868 | uint32_t length, i = 0, port_loc = 0, bytes = 0; |
| 878 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 869 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| @@ -880,11 +871,10 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char | |||
| 880 | free(host_id); | 871 | free(host_id); |
| 881 | host_id = NULL; | 872 | host_id = NULL; |
| 882 | 873 | ||
| 883 | plist_new_plist(&plist); | 874 | plist_new_dict(&dict); |
| 884 | plist_new_dict_in_plist(plist, &dict); | ||
| 885 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "StartService"); | 875 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "StartService"); |
| 886 | plist_add_dict_element(dict, "Service", PLIST_STRING, (void *) service); | 876 | plist_add_dict_element(dict, "Service", PLIST_STRING, (void *) service); |
| 887 | plist_to_xml(plist, &XML_content, &length); | 877 | plist_to_xml(dict, &XML_content, &length); |
| 888 | 878 | ||
| 889 | /* send to iPhone */ | 879 | /* send to iPhone */ |
| 890 | log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); | 880 | log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); |
| @@ -892,8 +882,8 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char | |||
| 892 | 882 | ||
| 893 | xmlFree(XML_content); | 883 | xmlFree(XML_content); |
| 894 | XML_content = NULL; | 884 | XML_content = NULL; |
| 895 | plist_free(plist); | 885 | plist_free(dict); |
| 896 | plist = NULL; | 886 | dict = NULL; |
| 897 | 887 | ||
| 898 | if (IPHONE_E_SUCCESS != ret) | 888 | if (IPHONE_E_SUCCESS != ret) |
| 899 | return ret; | 889 | return ret; |
| @@ -903,8 +893,8 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char | |||
| 903 | if (IPHONE_E_SUCCESS != ret) | 893 | if (IPHONE_E_SUCCESS != ret) |
| 904 | return ret; | 894 | return ret; |
| 905 | 895 | ||
| 906 | xml_to_plist(XML_content, bytes, &plist); | 896 | xml_to_plist(XML_content, bytes, &dict); |
| 907 | if (!plist) | 897 | if (!dict) |
| 908 | return IPHONE_E_PLIST_ERROR; | 898 | return IPHONE_E_PLIST_ERROR; |
| 909 | 899 | ||
| 910 | 900 | ||
| @@ -912,11 +902,11 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char | |||
| 912 | return IPHONE_E_NOT_ENOUGH_DATA; | 902 | return IPHONE_E_NOT_ENOUGH_DATA; |
| 913 | else { | 903 | else { |
| 914 | 904 | ||
| 915 | plist_t query_node = find_query_node(plist, "Request", "StartService"); | 905 | plist_t query_node = find_query_node(dict, "Request", "StartService"); |
| 916 | plist_t result_key_node = g_node_next_sibling(query_node); | 906 | plist_t result_key_node = g_node_next_sibling(query_node); |
| 917 | plist_t result_value_node = g_node_next_sibling(result_key_node); | 907 | plist_t result_value_node = g_node_next_sibling(result_key_node); |
| 918 | 908 | ||
| 919 | plist_t port_key_node = find_node(plist, PLIST_KEY, "Port"); | 909 | plist_t port_key_node = find_node(dict, PLIST_KEY, "Port"); |
| 920 | plist_t port_value_node = g_node_next_sibling(port_key_node); | 910 | plist_t port_value_node = g_node_next_sibling(port_key_node); |
| 921 | 911 | ||
| 922 | plist_type result_key_type; | 912 | plist_type result_key_type; |
| @@ -947,7 +937,8 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char | |||
| 947 | log_debug_msg("end data received by lockdownd_start_service()\n"); | 937 | log_debug_msg("end data received by lockdownd_start_service()\n"); |
| 948 | 938 | ||
| 949 | free(XML_content); | 939 | free(XML_content); |
| 950 | plist_free(plist); | 940 | plist_free(dict); |
| 941 | dict = NULL; | ||
| 951 | if (port && ret == IPHONE_E_SUCCESS) { | 942 | if (port && ret == IPHONE_E_SUCCESS) { |
| 952 | *port = port_loc; | 943 | *port = port_loc; |
| 953 | return IPHONE_E_SUCCESS; | 944 | return IPHONE_E_SUCCESS; |
