Commit 36eff97c authored by Jonathan Beck's avatar Jonathan Beck

finish new plist API migration.

parent 505c9758
...@@ -662,51 +662,57 @@ iphone_error_t lockdownd_gen_pair_cert(char *public_key_b64, char **device_cert_ ...@@ -662,51 +662,57 @@ iphone_error_t lockdownd_gen_pair_cert(char *public_key_b64, char **device_cert_
*/ */
iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID) iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID)
{ {
xmlDocPtr plist = new_plist(); plist_t plist = NULL;
xmlNode *dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); dict_t dict = NULL;
xmlNode *key; char *XML_content = NULL;
char *what2send = NULL, **dictionary = NULL; uint32_t length = 0, bytes = 0, return_me = 0;
uint32_t len = 0, bytes = 0, return_me = 0, i = 0;
iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
// end variables
key = add_key_str_dict_element(plist, dict, "HostID", HostID, 1); /* Setup DevicePublicKey request plist */
if (!key) { plist_new_plist(&plist);
log_debug_msg("Couldn't add a key.\n"); plist_new_dict_in_plist(plist, &dict);
xmlFreeDoc(plist); plist_add_dict_element(dict, "HostID", PLIST_STRING, (void *) HostID);
return IPHONE_E_DICT_ERROR; plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "StartSession");
} plist_to_xml(plist, &XML_content, &length);
key = add_key_str_dict_element(plist, dict, "Request", "StartSession", 1); log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content);
if (!key) {
log_debug_msg("Couldn't add a key.\n");
xmlFreeDoc(plist);
return IPHONE_E_DICT_ERROR;
}
xmlDocDumpMemory(plist, (xmlChar **) & what2send, &len); ret = iphone_lckd_send(control, XML_content, length, &bytes);
ret = iphone_lckd_send(control, what2send, len, &bytes);
xmlFree(what2send); xmlFree(XML_content);
xmlFreeDoc(plist); XML_content = NULL;
plist_free(plist);
plist = NULL;
if (ret != IPHONE_E_SUCCESS) if (ret != IPHONE_E_SUCCESS)
return ret; return ret;
if (bytes > 0) { if (bytes > 0) {
ret = iphone_lckd_recv(control, &what2send, &len); ret = iphone_lckd_recv(control, &XML_content, &bytes);
plist = xmlReadMemory(what2send, len, NULL, NULL, 0); log_debug_msg("Receive msg :\nsize : %i\nxml : %s", bytes, XML_content);
dict = xmlDocGetRootElement(plist); xml_to_plist(XML_content, bytes, &plist);
if (!dict) if (!plist)
return IPHONE_E_DICT_ERROR; return IPHONE_E_PLIST_ERROR;
for (dict = dict->children; dict; dict = dict->next) {
if (!xmlStrcmp(dict->name, "dict")) plist_t query_node = find_query_node(plist, "Request", "StartSession");
break; plist_t result_key_node = g_node_next_sibling(query_node);
} plist_t result_value_node = g_node_next_sibling(result_key_node);
dictionary = read_dict_element_strings(dict);
xmlFreeDoc(plist); plist_type result_key_type;
free(what2send); plist_type result_value_type;
for (i = 0; dictionary[i]; i += 2) { char *result_key = NULL;
if (!strcmp(dictionary[i], "Result") && !strcmp(dictionary[i + 1], "Success")) { char *result_value = NULL;
get_type_and_value(result_key_node, &result_key_type, (void *) (&result_key));
get_type_and_value(result_value_node, &result_value_type, (void *) (&result_value));
xmlFree(XML_content);
XML_content = NULL;
plist_free(plist);
plist = NULL;
if (result_key_type == PLIST_KEY &&
result_value_type == PLIST_STRING && !strcmp(result_key, "Result") && !strcmp(result_value, "Success")) {
// Set up GnuTLS... // Set up GnuTLS...
//gnutls_anon_client_credentials_t anoncred; //gnutls_anon_client_credentials_t anoncred;
gnutls_certificate_credentials_t xcred; gnutls_certificate_credentials_t xcred;
...@@ -747,8 +753,6 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c ...@@ -747,8 +753,6 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c
return_me = gnutls_handshake(*control->ssl_session); return_me = gnutls_handshake(*control->ssl_session);
log_debug_msg("GnuTLS handshake done...\n"); log_debug_msg("GnuTLS handshake done...\n");
free_dictionary(dictionary);
if (return_me != GNUTLS_E_SUCCESS) { if (return_me != GNUTLS_E_SUCCESS) {
log_debug_msg("GnuTLS reported something wrong.\n"); log_debug_msg("GnuTLS reported something wrong.\n");
gnutls_perror(return_me); gnutls_perror(return_me);
...@@ -759,16 +763,9 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c ...@@ -759,16 +763,9 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c
return IPHONE_E_SUCCESS; return IPHONE_E_SUCCESS;
} }
} }
}
log_debug_msg("Apparently failed negotiating with lockdownd.\n"); log_debug_msg("Apparently failed negotiating with lockdownd.\n");
log_debug_msg("Responding dictionary: \n"); log_debug_msg("Responding dictionary: \n");
for (i = 0; dictionary[i]; i += 2) {
log_debug_msg("\t%s: %s\n", dictionary[i], dictionary[i + 1]);
}
free_dictionary(dictionary);
return IPHONE_E_SSL_ERROR; return IPHONE_E_SSL_ERROR;
} else { } else {
log_debug_msg("Didn't get enough bytes.\n"); log_debug_msg("Didn't get enough bytes.\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment