summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-07-25 02:40:25 +0200
committerGravatar Martin Szulecki2009-07-25 02:40:25 +0200
commitf5e9d76ebd74999512ab73f44fabba86879b1c1f (patch)
tree9e01e1b8bda52c04c31c5334805a530403713e08 /src
parentd11abfb48218a37d9c66831ebec8b0a736d5385f (diff)
downloadlibimobiledevice-f5e9d76ebd74999512ab73f44fabba86879b1c1f.tar.gz
libimobiledevice-f5e9d76ebd74999512ab73f44fabba86879b1c1f.tar.bz2
Update lockdown API and introduce new error codes
Diffstat (limited to 'src')
-rw-r--r--src/lockdown.c305
-rw-r--r--src/lockdown.h10
2 files changed, 162 insertions, 153 deletions
diff --git a/src/lockdown.c b/src/lockdown.c
index 757a94a..29e5046 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -126,13 +126,15 @@ static int lockdown_check_result(plist_t dict, const char *query_match)
126 * the StopSession Request to the device. 126 * the StopSession Request to the device.
127 * 127 *
128 * @param control The lockdown client 128 * @param control The lockdown client
129 *
130 * @return an error code (LOCKDOWN_E_SUCCESS on success)
129 */ 131 */
130iphone_error_t lockdownd_stop_session(lockdownd_client_t client) 132lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client)
131{ 133{
132 if (!client) 134 if (!client)
133 return IPHONE_E_INVALID_ARG; 135 return LOCKDOWN_E_INVALID_ARG;
134 136
135 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 137 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
136 138
137 plist_t dict = plist_new_dict(); 139 plist_t dict = plist_new_dict();
138 plist_add_sub_key_el(dict, "Request"); 140 plist_add_sub_key_el(dict, "Request");
@@ -151,13 +153,13 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client)
151 153
152 if (!dict) { 154 if (!dict) {
153 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: LOCKDOWN_E_PLIST_ERROR\n", __func__); 155 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: LOCKDOWN_E_PLIST_ERROR\n", __func__);
154 return IPHONE_E_PLIST_ERROR; 156 return LOCKDOWN_E_PLIST_ERROR;
155 } 157 }
156 158
157 ret = IPHONE_E_UNKNOWN_ERROR; 159 ret = LOCKDOWN_E_UNKNOWN_ERROR;
158 if (lockdown_check_result(dict, "StopSession") == RESULT_SUCCESS) { 160 if (lockdown_check_result(dict, "StopSession") == RESULT_SUCCESS) {
159 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); 161 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
160 ret = IPHONE_E_SUCCESS; 162 ret = LOCKDOWN_E_SUCCESS;
161 } 163 }
162 plist_free(dict); 164 plist_free(dict);
163 dict = NULL; 165 dict = NULL;
@@ -171,14 +173,16 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client)
171 * performing a close notify, which is done by "gnutls_bye". 173 * performing a close notify, which is done by "gnutls_bye".
172 * 174 *
173 * @param client The lockdown client 175 * @param client The lockdown client
176 *
177 * @return an error code (LOCKDOWN_E_SUCCESS on success)
174 */ 178 */
175static iphone_error_t lockdownd_stop_ssl_session(lockdownd_client_t client) 179static lockdownd_error_t lockdownd_stop_ssl_session(lockdownd_client_t client)
176{ 180{
177 if (!client) { 181 if (!client) {
178 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: invalid argument!\n", __func__); 182 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: invalid argument!\n", __func__);
179 return IPHONE_E_INVALID_ARG; 183 return LOCKDOWN_E_INVALID_ARG;
180 } 184 }
181 iphone_error_t ret = IPHONE_E_SUCCESS; 185 lockdownd_error_t ret = LOCKDOWN_E_SUCCESS;
182 186
183 if (client->in_SSL) { 187 if (client->in_SSL) {
184 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: stopping SSL session\n", __func__); 188 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: stopping SSL session\n", __func__);
@@ -198,12 +202,14 @@ static iphone_error_t lockdownd_stop_ssl_session(lockdownd_client_t client)
198/** Closes the lockdownd client and does the necessary housekeeping. 202/** Closes the lockdownd client and does the necessary housekeeping.
199 * 203 *
200 * @param client The lockdown client 204 * @param client The lockdown client
205 *
206 * @return an error code (LOCKDOWN_E_SUCCESS on success)
201 */ 207 */
202iphone_error_t lockdownd_free_client(lockdownd_client_t client) 208lockdownd_error_t lockdownd_client_free(lockdownd_client_t client)
203{ 209{
204 if (!client) 210 if (!client)
205 return IPHONE_E_INVALID_ARG; 211 return LOCKDOWN_E_INVALID_ARG;
206 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 212 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
207 213
208 lockdownd_stop_ssl_session(client); 214 lockdownd_stop_ssl_session(client);
209 215
@@ -224,13 +230,13 @@ iphone_error_t lockdownd_free_client(lockdownd_client_t client)
224 * @param control The lockdownd client 230 * @param control The lockdownd client
225 * @param plist The plist to store the received data 231 * @param plist The plist to store the received data
226 * 232 *
227 * @return an error code (IPHONE_E_SUCCESS on success) 233 * @return an error code (LOCKDOWN_E_SUCCESS on success)
228 */ 234 */
229iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist) 235lockdownd_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
230{ 236{
231 if (!client || !plist || (plist && *plist)) 237 if (!client || !plist || (plist && *plist))
232 return IPHONE_E_INVALID_ARG; 238 return LOCKDOWN_E_INVALID_ARG;
233 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 239 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
234 char *receive = NULL; 240 char *receive = NULL;
235 uint32_t datalen = 0, bytes = 0, received_bytes = 0; 241 uint32_t datalen = 0, bytes = 0, received_bytes = 0;
236 242
@@ -240,10 +246,10 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
240 ssize_t res = gnutls_record_recv(*client->ssl_session, &datalen, sizeof(datalen)); 246 ssize_t res = gnutls_record_recv(*client->ssl_session, &datalen, sizeof(datalen));
241 if (res < 0) { 247 if (res < 0) {
242 log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_recv: Error occured: %s\n", gnutls_strerror(res)); 248 log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_recv: Error occured: %s\n", gnutls_strerror(res));
243 return IPHONE_E_SSL_ERROR; 249 return LOCKDOWN_E_SSL_ERROR;
244 } else { 250 } else {
245 bytes = res; 251 bytes = res;
246 ret = IPHONE_E_SUCCESS; 252 ret = LOCKDOWN_E_SUCCESS;
247 } 253 }
248 } 254 }
249 datalen = ntohl(datalen); 255 datalen = ntohl(datalen);
@@ -253,32 +259,32 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
253 259
254 /* fill buffer and request more packets if needed */ 260 /* fill buffer and request more packets if needed */
255 if (!client->in_SSL) { 261 if (!client->in_SSL) {
256 while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) { 262 while ((received_bytes < datalen) && (ret == LOCKDOWN_E_SUCCESS)) {
257 ret = usbmuxd_recv(client->sfd, receive + received_bytes, datalen - received_bytes, &bytes); 263 ret = usbmuxd_recv(client->sfd, receive + received_bytes, datalen - received_bytes, &bytes);
258 received_bytes += bytes; 264 received_bytes += bytes;
259 } 265 }
260 } else { 266 } else {
261 ssize_t res = 0; 267 ssize_t res = 0;
262 while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) { 268 while ((received_bytes < datalen) && (ret == LOCKDOWN_E_SUCCESS)) {
263 res = gnutls_record_recv(*client->ssl_session, receive + received_bytes, datalen - received_bytes); 269 res = gnutls_record_recv(*client->ssl_session, receive + received_bytes, datalen - received_bytes);
264 if (res < 0) { 270 if (res < 0) {
265 log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_recv: Error occured: %s\n", gnutls_strerror(res)); 271 log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_recv: Error occured: %s\n", gnutls_strerror(res));
266 ret = IPHONE_E_SSL_ERROR; 272 ret = LOCKDOWN_E_SSL_ERROR;
267 } else { 273 } else {
268 received_bytes += res; 274 received_bytes += res;
269 ret = IPHONE_E_SUCCESS; 275 ret = LOCKDOWN_E_SUCCESS;
270 } 276 }
271 } 277 }
272 } 278 }
273 279
274 if (ret != IPHONE_E_SUCCESS) { 280 if (ret != LOCKDOWN_E_SUCCESS) {
275 free(receive); 281 free(receive);
276 return ret; 282 return ret;
277 } 283 }
278 284
279 if ((ssize_t)received_bytes <= 0) { 285 if ((ssize_t)received_bytes <= 0) {
280 free(receive); 286 free(receive);
281 return IPHONE_E_NOT_ENOUGH_DATA; 287 return LOCKDOWN_E_NOT_ENOUGH_DATA;
282 } 288 }
283 289
284 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: received msg size: %i, buffer follows:\n%s", __func__, received_bytes, receive); 290 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: received msg size: %i, buffer follows:\n%s", __func__, received_bytes, receive);
@@ -286,7 +292,7 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
286 free(receive); 292 free(receive);
287 293
288 if (!*plist) 294 if (!*plist)
289 ret = IPHONE_E_PLIST_ERROR; 295 ret = LOCKDOWN_E_PLIST_ERROR;
290 296
291 return ret; 297 return ret;
292} 298}
@@ -299,17 +305,17 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
299 * @param client The lockdownd client 305 * @param client The lockdownd client
300 * @param plist The plist to send 306 * @param plist The plist to send
301 * 307 *
302 * @return an error code (IPHONE_E_SUCCESS on success) 308 * @return an error code (LOCKDOWN_E_SUCCESS on success)
303 */ 309 */
304iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) 310lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist)
305{ 311{
306 if (!client || !plist) 312 if (!client || !plist)
307 return IPHONE_E_INVALID_ARG; 313 return LOCKDOWN_E_INVALID_ARG;
308 char *real_query; 314 char *real_query;
309 int bytes; 315 int bytes;
310 char *XMLContent = NULL; 316 char *XMLContent = NULL;
311 uint32_t length = 0; 317 uint32_t length = 0;
312 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 318 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
313 319
314 plist_to_xml(plist, &XMLContent, &length); 320 plist_to_xml(plist, &XMLContent, &length);
315 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending msg size %i, buffer follows:\n%s", __func__, length, XMLContent); 321 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending msg size %i, buffer follows:\n%s", __func__, length, XMLContent);
@@ -327,13 +333,13 @@ iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist)
327 ssize_t res = gnutls_record_send(*client->ssl_session, real_query, ntohl(length) + sizeof(length)); 333 ssize_t res = gnutls_record_send(*client->ssl_session, real_query, ntohl(length) + sizeof(length));
328 if (res < 0) { 334 if (res < 0) {
329 log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_send: Error occured: %s\n", gnutls_strerror(res)); 335 log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_send: Error occured: %s\n", gnutls_strerror(res));
330 ret = IPHONE_E_SSL_ERROR; 336 ret = LOCKDOWN_E_SSL_ERROR;
331 } else { 337 } else {
332 bytes = res; 338 bytes = res;
333 ret = IPHONE_E_SUCCESS; 339 ret = LOCKDOWN_E_SUCCESS;
334 } 340 }
335 } 341 }
336 if (ret == IPHONE_E_SUCCESS) { 342 if (ret == LOCKDOWN_E_SUCCESS) {
337 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sent it!\n", __func__); 343 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sent it!\n", __func__);
338 } else { 344 } else {
339 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending failed!\n", __func__); 345 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending failed!\n", __func__);
@@ -347,14 +353,14 @@ iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist)
347 * 353 *
348 * @param client The lockdownd client 354 * @param client The lockdownd client
349 * 355 *
350 * @return an error code (IPHONE_E_SUCCESS on success) 356 * @return an error code (LOCKDOWN_E_SUCCESS on success)
351 */ 357 */
352iphone_error_t lockdownd_query_type(lockdownd_client_t client) 358lockdownd_error_t lockdownd_query_type(lockdownd_client_t client)
353{ 359{
354 if (!client) 360 if (!client)
355 return IPHONE_E_INVALID_ARG; 361 return LOCKDOWN_E_INVALID_ARG;
356 362
357 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 363 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
358 364
359 plist_t dict = plist_new_dict(); 365 plist_t dict = plist_new_dict();
360 plist_add_sub_key_el(dict, "Request"); 366 plist_add_sub_key_el(dict, "Request");
@@ -368,13 +374,13 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client)
368 374
369 ret = lockdownd_recv(client, &dict); 375 ret = lockdownd_recv(client, &dict);
370 376
371 if (IPHONE_E_SUCCESS != ret) 377 if (LOCKDOWN_E_SUCCESS != ret)
372 return ret; 378 return ret;
373 379
374 ret = IPHONE_E_UNKNOWN_ERROR; 380 ret = LOCKDOWN_E_UNKNOWN_ERROR;
375 if (lockdown_check_result(dict, "QueryType") == RESULT_SUCCESS) { 381 if (lockdown_check_result(dict, "QueryType") == RESULT_SUCCESS) {
376 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); 382 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
377 ret = IPHONE_E_SUCCESS; 383 ret = LOCKDOWN_E_SUCCESS;
378 } 384 }
379 plist_free(dict); 385 plist_free(dict);
380 dict = NULL; 386 dict = NULL;
@@ -389,15 +395,15 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client)
389 * @param key the key name to request or NULL to query for all keys 395 * @param key the key name to request or NULL to query for all keys
390 * @param value a plist node representing the result value node 396 * @param value a plist node representing the result value node
391 * 397 *
392 * @return an error code (IPHONE_E_SUCCESS on success) 398 * @return an error code (LOCKDOWN_E_SUCCESS on success)
393 */ 399 */
394iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value) 400lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value)
395{ 401{
396 if (!client) 402 if (!client)
397 return IPHONE_E_INVALID_ARG; 403 return LOCKDOWN_E_INVALID_ARG;
398 404
399 plist_t dict = NULL; 405 plist_t dict = NULL;
400 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 406 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
401 407
402 /* setup request plist */ 408 /* setup request plist */
403 dict = plist_new_dict(); 409 dict = plist_new_dict();
@@ -418,19 +424,19 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain
418 plist_free(dict); 424 plist_free(dict);
419 dict = NULL; 425 dict = NULL;
420 426
421 if (ret != IPHONE_E_SUCCESS) 427 if (ret != LOCKDOWN_E_SUCCESS)
422 return ret; 428 return ret;
423 429
424 /* Now get device's answer */ 430 /* Now get device's answer */
425 ret = lockdownd_recv(client, &dict); 431 ret = lockdownd_recv(client, &dict);
426 if (ret != IPHONE_E_SUCCESS) 432 if (ret != LOCKDOWN_E_SUCCESS)
427 return ret; 433 return ret;
428 434
429 if (lockdown_check_result(dict, "GetValue") == RESULT_SUCCESS) { 435 if (lockdown_check_result(dict, "GetValue") == RESULT_SUCCESS) {
430 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); 436 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
431 ret = IPHONE_E_SUCCESS; 437 ret = LOCKDOWN_E_SUCCESS;
432 } 438 }
433 if (ret != IPHONE_E_SUCCESS) { 439 if (ret != LOCKDOWN_E_SUCCESS) {
434 plist_free(dict); 440 plist_free(dict);
435 return ret; 441 return ret;
436 } 442 }
@@ -462,15 +468,15 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain
462 * @param key the key name to set the value or NULL to set a value dict plist 468 * @param key the key name to set the value or NULL to set a value dict plist
463 * @param value a plist node of any node type representing the value to set 469 * @param value a plist node of any node type representing the value to set
464 * 470 *
465 * @return an error code (IPHONE_E_SUCCESS on success) 471 * @return an error code (LOCKDOWN_E_SUCCESS on success)
466 */ 472 */
467iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value) 473lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value)
468{ 474{
469 if (!client || !value) 475 if (!client || !value)
470 return IPHONE_E_INVALID_ARG; 476 return LOCKDOWN_E_INVALID_ARG;
471 477
472 plist_t dict = NULL; 478 plist_t dict = NULL;
473 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 479 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
474 480
475 /* setup request plist */ 481 /* setup request plist */
476 dict = plist_new_dict(); 482 dict = plist_new_dict();
@@ -494,20 +500,20 @@ iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain
494 plist_free(dict); 500 plist_free(dict);
495 dict = NULL; 501 dict = NULL;
496 502
497 if (ret != IPHONE_E_SUCCESS) 503 if (ret != LOCKDOWN_E_SUCCESS)
498 return ret; 504 return ret;
499 505
500 /* Now get device's answer */ 506 /* Now get device's answer */
501 ret = lockdownd_recv(client, &dict); 507 ret = lockdownd_recv(client, &dict);
502 if (ret != IPHONE_E_SUCCESS) 508 if (ret != LOCKDOWN_E_SUCCESS)
503 return ret; 509 return ret;
504 510
505 if (lockdown_check_result(dict, "SetValue") == RESULT_SUCCESS) { 511 if (lockdown_check_result(dict, "SetValue") == RESULT_SUCCESS) {
506 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); 512 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
507 ret = IPHONE_E_SUCCESS; 513 ret = LOCKDOWN_E_SUCCESS;
508 } 514 }
509 515
510 if (ret != IPHONE_E_SUCCESS) { 516 if (ret != LOCKDOWN_E_SUCCESS) {
511 plist_free(dict); 517 plist_free(dict);
512 return ret; 518 return ret;
513 } 519 }
@@ -524,15 +530,15 @@ iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain
524 * @param domain the domain to query on or NULL for global domain 530 * @param domain the domain to query on or NULL for global domain
525 * @param key the key name to remove or NULL remove all keys for the current domain 531 * @param key the key name to remove or NULL remove all keys for the current domain
526 * 532 *
527 * @return an error code (IPHONE_E_SUCCESS on success) 533 * @return an error code (LOCKDOWN_E_SUCCESS on success)
528 */ 534 */
529iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key) 535lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key)
530{ 536{
531 if (!client) 537 if (!client)
532 return IPHONE_E_INVALID_ARG; 538 return LOCKDOWN_E_INVALID_ARG;
533 539
534 plist_t dict = NULL; 540 plist_t dict = NULL;
535 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 541 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
536 542
537 /* setup request plist */ 543 /* setup request plist */
538 dict = plist_new_dict(); 544 dict = plist_new_dict();
@@ -553,20 +559,20 @@ iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *dom
553 plist_free(dict); 559 plist_free(dict);
554 dict = NULL; 560 dict = NULL;
555 561
556 if (ret != IPHONE_E_SUCCESS) 562 if (ret != LOCKDOWN_E_SUCCESS)
557 return ret; 563 return ret;
558 564
559 /* Now get device's answer */ 565 /* Now get device's answer */
560 ret = lockdownd_recv(client, &dict); 566 ret = lockdownd_recv(client, &dict);
561 if (ret != IPHONE_E_SUCCESS) 567 if (ret != LOCKDOWN_E_SUCCESS)
562 return ret; 568 return ret;
563 569
564 if (lockdown_check_result(dict, "RemoveValue") == RESULT_SUCCESS) { 570 if (lockdown_check_result(dict, "RemoveValue") == RESULT_SUCCESS) {
565 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); 571 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
566 ret = IPHONE_E_SUCCESS; 572 ret = LOCKDOWN_E_SUCCESS;
567 } 573 }
568 574
569 if (ret != IPHONE_E_SUCCESS) { 575 if (ret != LOCKDOWN_E_SUCCESS) {
570 plist_free(dict); 576 plist_free(dict);
571 return ret; 577 return ret;
572 } 578 }
@@ -577,18 +583,18 @@ iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *dom
577 583
578/** Asks for the device's unique id. Part of the lockdownd handshake. 584/** Asks for the device's unique id. Part of the lockdownd handshake.
579 * 585 *
580 * @return an error code (IPHONE_E_SUCCESS on success) 586 * @return an error code (LOCKDOWN_E_SUCCESS on success)
581 */ 587 */
582iphone_error_t lockdownd_get_device_uid(lockdownd_client_t client, char **uid) 588lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t client, char **uuid)
583{ 589{
584 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 590 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
585 plist_t value = NULL; 591 plist_t value = NULL;
586 592
587 ret = lockdownd_get_value(client, NULL, "UniqueDeviceID", &value); 593 ret = lockdownd_get_value(client, NULL, "UniqueDeviceID", &value);
588 if (ret != IPHONE_E_SUCCESS) { 594 if (ret != LOCKDOWN_E_SUCCESS) {
589 return ret; 595 return ret;
590 } 596 }
591 plist_get_string_val(value, uid); 597 plist_get_string_val(value, uuid);
592 598
593 plist_free(value); 599 plist_free(value);
594 value = NULL; 600 value = NULL;
@@ -597,17 +603,17 @@ iphone_error_t lockdownd_get_device_uid(lockdownd_client_t client, char **uid)
597 603
598/** Askes for the device's public key. Part of the lockdownd handshake. 604/** Askes for the device's public key. Part of the lockdownd handshake.
599 * 605 *
600 * @return an error code (IPHONE_E_SUCCESS on success) 606 * @return an error code (LOCKDOWN_E_SUCCESS on success)
601 */ 607 */
602iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key) 608lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key)
603{ 609{
604 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 610 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
605 plist_t value = NULL; 611 plist_t value = NULL;
606 char *value_value = NULL; 612 char *value_value = NULL;
607 uint64_t size = 0; 613 uint64_t size = 0;
608 614
609 ret = lockdownd_get_value(client, NULL, "DevicePublicKey", &value); 615 ret = lockdownd_get_value(client, NULL, "DevicePublicKey", &value);
610 if (ret != IPHONE_E_SUCCESS) { 616 if (ret != LOCKDOWN_E_SUCCESS) {
611 return ret; 617 return ret;
612 } 618 }
613 plist_get_data_val(value, &value_value, &size); 619 plist_get_data_val(value, &value_value, &size);
@@ -625,15 +631,15 @@ iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls
625 * @param client The pointer to the location of the new lockdownd_client 631 * @param client The pointer to the location of the new lockdownd_client
626 * 632 *
627 * 633 *
628 * @return an error code (IPHONE_E_SUCCESS on success) 634 * @return an error code (LOCKDOWN_E_SUCCESS on success)
629 */ 635 */
630iphone_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name) 636lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name)
631{ 637{
632 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 638 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
633 plist_t value = NULL; 639 plist_t value = NULL;
634 640
635 ret = lockdownd_get_value(client, NULL, "DeviceName", &value); 641 ret = lockdownd_get_value(client, NULL, "DeviceName", &value);
636 if (ret != IPHONE_E_SUCCESS) { 642 if (ret != LOCKDOWN_E_SUCCESS) {
637 return ret; 643 return ret;
638 } 644 }
639 plist_get_string_val(value, device_name); 645 plist_get_string_val(value, device_name);
@@ -649,19 +655,19 @@ iphone_error_t lockdownd_get_device_name(lockdownd_client_t client, char **devic
649 * @param phone The iPhone to create a lockdownd client for 655 * @param phone The iPhone to create a lockdownd client for
650 * @param client The pointer to the location of the new lockdownd_client 656 * @param client The pointer to the location of the new lockdownd_client
651 * 657 *
652 * @return an error code (IPHONE_E_SUCCESS on success) 658 * @return an error code (LOCKDOWN_E_SUCCESS on success)
653 */ 659 */
654iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *client) 660lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_t *client)
655{ 661{
656 if (!device || !client || (client && *client)) 662 if (!device || !client || (client && *client))
657 return IPHONE_E_INVALID_ARG; 663 return LOCKDOWN_E_INVALID_ARG;
658 iphone_error_t ret = IPHONE_E_SUCCESS; 664 lockdownd_error_t ret = LOCKDOWN_E_SUCCESS;
659 char *host_id = NULL; 665 char *host_id = NULL;
660 666
661 int sfd = usbmuxd_connect(device->handle, 0xf27e); 667 int sfd = usbmuxd_connect(device->handle, 0xf27e);
662 if (sfd < 0) { 668 if (sfd < 0) {
663 log_debug_msg("%s: could not connect to lockdownd (device handle %d)\n", __func__, device->handle); 669 log_debug_msg("%s: could not connect to lockdownd (device handle %d)\n", __func__, device->handle);
664 return IPHONE_E_UNKNOWN_ERROR; 670 return LOCKDOWN_E_MUX_ERROR;
665 } 671 }
666 672
667 lockdownd_client_t client_loc = (lockdownd_client_t) malloc(sizeof(struct lockdownd_client_int)); 673 lockdownd_client_t client_loc = (lockdownd_client_t) malloc(sizeof(struct lockdownd_client_int));
@@ -669,23 +675,24 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *
669 client_loc->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t)); 675 client_loc->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t));
670 client_loc->in_SSL = 0; 676 client_loc->in_SSL = 0;
671 677
678 if (LOCKDOWN_E_SUCCESS != lockdownd_query_type(client_loc)) {
672 log_debug_msg("%s: QueryType failed in the lockdownd client.\n", __func__); 679 log_debug_msg("%s: QueryType failed in the lockdownd client.\n", __func__);
673 ret = IPHONE_E_NOT_ENOUGH_DATA; 680 ret = LOCKDOWN_E_NOT_ENOUGH_DATA;
674 } 681 }
675 682
676 char *uuid = NULL; 683 char *uuid = NULL;
677 ret = iphone_device_get_uuid(device, &uuid); 684 ret = iphone_device_get_uuid(device, &uuid);
678 if (IPHONE_E_SUCCESS != ret) { 685 if (LOCKDOWN_E_SUCCESS != ret) {
679 log_debug_msg("%s: failed to get device uuid.\n", __func__); 686 log_debug_msg("%s: failed to get device uuid.\n", __func__);
680 } 687 }
681 log_debug_msg("%s: device uuid: %s\n", __func__, uuid); 688 log_debug_msg("%s: device uuid: %s\n", __func__, uuid);
682 689
683 userpref_get_host_id(&host_id); 690 userpref_get_host_id(&host_id);
684 if (IPHONE_E_SUCCESS == ret && !host_id) { 691 if (LOCKDOWN_E_SUCCESS == ret && !host_id) {
685 ret = IPHONE_E_INVALID_CONF; 692 ret = LOCKDOWN_E_INVALID_CONF;
686 } 693 }
687 694
688 if (IPHONE_E_SUCCESS == ret && !userpref_has_device_public_key(uuid)) 695 if (LOCKDOWN_E_SUCCESS == ret && !userpref_has_device_public_key(uuid))
689 ret = lockdownd_pair(client_loc, uuid, host_id); 696 ret = lockdownd_pair(client_loc, uuid, host_id);
690 697
691 if (uuid) { 698 if (uuid) {
@@ -693,10 +700,10 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *
693 uuid = NULL; 700 uuid = NULL;
694 } 701 }
695 702
696 if (IPHONE_E_SUCCESS == ret) { 703 if (LOCKDOWN_E_SUCCESS == ret) {
697 ret = lockdownd_start_ssl_session(client_loc, host_id); 704 ret = lockdownd_start_ssl_session(client_loc, host_id);
698 if (IPHONE_E_SUCCESS != ret) { 705 if (LOCKDOWN_E_SUCCESS != ret) {
699 ret = IPHONE_E_SSL_ERROR; 706 ret = LOCKDOWN_E_SSL_ERROR;
700 log_debug_msg("%s: SSL Session opening failed.\n", __func__); 707 log_debug_msg("%s: SSL Session opening failed.\n", __func__);
701 } 708 }
702 709
@@ -705,7 +712,7 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *
705 host_id = NULL; 712 host_id = NULL;
706 } 713 }
707 714
708 if (IPHONE_E_SUCCESS == ret) 715 if (LOCKDOWN_E_SUCCESS == ret)
709 *client = client_loc; 716 *client = client_loc;
710 } 717 }
711 718
@@ -715,11 +722,11 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *
715/** Generates the appropriate keys and pairs the device. It's part of the 722/** Generates the appropriate keys and pairs the device. It's part of the
716 * lockdownd handshake. 723 * lockdownd handshake.
717 * 724 *
718 * @return an error code (IPHONE_E_SUCCESS on success) 725 * @return an error code (LOCKDOWN_E_SUCCESS on success)
719 */ 726 */
720iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_id) 727lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *uuid, char *host_id)
721{ 728{
722 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 729 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
723 plist_t dict = NULL; 730 plist_t dict = NULL;
724 plist_t dict_record = NULL; 731 plist_t dict_record = NULL;
725 732
@@ -729,14 +736,14 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i
729 gnutls_datum_t public_key = { NULL, 0 }; 736 gnutls_datum_t public_key = { NULL, 0 };
730 737
731 ret = lockdownd_get_device_public_key(client, &public_key); 738 ret = lockdownd_get_device_public_key(client, &public_key);
732 if (ret != IPHONE_E_SUCCESS) { 739 if (ret != LOCKDOWN_E_SUCCESS) {
733 log_debug_msg("%s: device refused to send public key.\n", __func__); 740 log_debug_msg("%s: device refused to send public key.\n", __func__);
734 return ret; 741 return ret;
735 } 742 }
736 log_debug_msg("%s: device public key follows:\n%s\n", __func__, public_key.data); 743 log_debug_msg("%s: device public key follows:\n%s\n", __func__, public_key.data);
737 744
738 ret = lockdownd_gen_pair_cert(public_key, &device_cert, &host_cert, &root_cert); 745 ret = lockdownd_gen_pair_cert(public_key, &device_cert, &host_cert, &root_cert);
739 if (ret != IPHONE_E_SUCCESS) { 746 if (ret != LOCKDOWN_E_SUCCESS) {
740 free(public_key.data); 747 free(public_key.data);
741 return ret; 748 return ret;
742 } 749 }
@@ -762,28 +769,28 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i
762 plist_free(dict); 769 plist_free(dict);
763 dict = NULL; 770 dict = NULL;
764 771
765 if (ret != IPHONE_E_SUCCESS) 772 if (ret != LOCKDOWN_E_SUCCESS)
766 return ret; 773 return ret;
767 774
768 /* Now get iPhone's answer */ 775 /* Now get iPhone's answer */
769 ret = lockdownd_recv(client, &dict); 776 ret = lockdownd_recv(client, &dict);
770 777
771 if (ret != IPHONE_E_SUCCESS) 778 if (ret != LOCKDOWN_E_SUCCESS)
772 return ret; 779 return ret;
773 780
774 if (lockdown_check_result(dict, "Pair") == RESULT_SUCCESS) { 781 if (lockdown_check_result(dict, "Pair") == RESULT_SUCCESS) {
775 ret = IPHONE_E_SUCCESS; 782 ret = LOCKDOWN_E_SUCCESS;
776 } 783 }
777 plist_free(dict); 784 plist_free(dict);
778 dict = NULL; 785 dict = NULL;
779 786
780 /* store public key in config if pairing succeeded */ 787 /* store public key in config if pairing succeeded */
781 if (ret == IPHONE_E_SUCCESS) { 788 if (ret == LOCKDOWN_E_SUCCESS) {
782 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__); 789 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__);
783 userpref_set_device_public_key(uuid, public_key); 790 userpref_set_device_public_key(uuid, public_key);
784 } else { 791 } else {
785 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__); 792 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__);
786 ret = IPHONE_E_PAIRING_FAILED; 793 ret = LOCKDOWN_E_PAIRING_FAILED;
787 } 794 }
788 free(public_key.data); 795 free(public_key.data);
789 return ret; 796 return ret;
@@ -794,14 +801,14 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i
794 * 801 *
795 * @param client The lockdown client 802 * @param client The lockdown client
796 * 803 *
797 * @return an error code (IPHONE_E_SUCCESS on success) 804 * @return an error code (LOCKDOWN_E_SUCCESS on success)
798 */ 805 */
799iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client) 806lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client)
800{ 807{
801 if (!client) 808 if (!client)
802 return IPHONE_E_INVALID_ARG; 809 return LOCKDOWN_E_INVALID_ARG;
803 810
804 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 811 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
805 812
806 plist_t dict = plist_new_dict(); 813 plist_t dict = plist_new_dict();
807 plist_add_sub_key_el(dict, "Request"); 814 plist_add_sub_key_el(dict, "Request");
@@ -817,7 +824,7 @@ iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client)
817 824
818 if (lockdown_check_result(dict, "EnterRecovery") == RESULT_SUCCESS) { 825 if (lockdown_check_result(dict, "EnterRecovery") == RESULT_SUCCESS) {
819 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); 826 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
820 ret = IPHONE_E_SUCCESS; 827 ret = LOCKDOWN_E_SUCCESS;
821 } 828 }
822 plist_free(dict); 829 plist_free(dict);
823 dict = NULL; 830 dict = NULL;
@@ -830,14 +837,14 @@ iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client)
830 * 837 *
831 * @param client The lockdown client 838 * @param client The lockdown client
832 * 839 *
833 * @return an error code (IPHONE_E_SUCCESS on success) 840 * @return an error code (LOCKDOWN_E_SUCCESS on success)
834 */ 841 */
835iphone_error_t lockdownd_goodbye(lockdownd_client_t client) 842lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client)
836{ 843{
837 if (!client) 844 if (!client)
838 return IPHONE_E_INVALID_ARG; 845 return LOCKDOWN_E_INVALID_ARG;
839 846
840 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 847 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
841 848
842 plist_t dict = plist_new_dict(); 849 plist_t dict = plist_new_dict();
843 plist_add_sub_key_el(dict, "Request"); 850 plist_add_sub_key_el(dict, "Request");
@@ -852,12 +859,12 @@ iphone_error_t lockdownd_goodbye(lockdownd_client_t client)
852 ret = lockdownd_recv(client, &dict); 859 ret = lockdownd_recv(client, &dict);
853 if (!dict) { 860 if (!dict) {
854 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: did not get goodbye response back\n", __func__); 861 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: did not get goodbye response back\n", __func__);
855 return IPHONE_E_PLIST_ERROR; 862 return LOCKDOWN_E_PLIST_ERROR;
856 } 863 }
857 864
858 if (lockdown_check_result(dict, "Goodbye") == RESULT_SUCCESS) { 865 if (lockdown_check_result(dict, "Goodbye") == RESULT_SUCCESS) {
859 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); 866 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
860 ret = IPHONE_E_SUCCESS; 867 ret = LOCKDOWN_E_SUCCESS;
861 } 868 }
862 plist_free(dict); 869 plist_free(dict);
863 dict = NULL; 870 dict = NULL;
@@ -867,14 +874,14 @@ iphone_error_t lockdownd_goodbye(lockdownd_client_t client)
867/** Generates the device certificate from the public key as well as the host 874/** Generates the device certificate from the public key as well as the host
868 * and root certificates. 875 * and root certificates.
869 * 876 *
870 * @return an error code (IPHONE_E_SUCCESS on success) 877 * @return an error code (LOCKDOWN_E_SUCCESS on success)
871 */ 878 */
872iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert, 879lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert,
873 gnutls_datum_t * ohost_cert, gnutls_datum_t * oroot_cert) 880 gnutls_datum_t * ohost_cert, gnutls_datum_t * oroot_cert)
874{ 881{
875 if (!public_key.data || !odevice_cert || !ohost_cert || !oroot_cert) 882 if (!public_key.data || !odevice_cert || !ohost_cert || !oroot_cert)
876 return IPHONE_E_INVALID_ARG; 883 return LOCKDOWN_E_INVALID_ARG;
877 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 884 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
878 userpref_error_t uret = USERPREF_E_UNKNOWN_ERROR; 885 userpref_error_t uret = USERPREF_E_UNKNOWN_ERROR;
879 886
880 gnutls_datum_t modulus = { NULL, 0 }; 887 gnutls_datum_t modulus = { NULL, 0 };
@@ -903,7 +910,7 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t
903 ret1 = asn1_read_value(asn1_pub_key, "modulus", modulus.data, (int*)&modulus.size); 910 ret1 = asn1_read_value(asn1_pub_key, "modulus", modulus.data, (int*)&modulus.size);
904 ret2 = asn1_read_value(asn1_pub_key, "publicExponent", exponent.data, (int*)&exponent.size); 911 ret2 = asn1_read_value(asn1_pub_key, "publicExponent", exponent.data, (int*)&exponent.size);
905 if (ASN1_SUCCESS == ret1 && ASN1_SUCCESS == ret2) 912 if (ASN1_SUCCESS == ret1 && ASN1_SUCCESS == ret2)
906 ret = IPHONE_E_SUCCESS; 913 ret = LOCKDOWN_E_SUCCESS;
907 } 914 }
908 if (asn1_pub_key) 915 if (asn1_pub_key)
909 asn1_delete_structure(&asn1_pub_key); 916 asn1_delete_structure(&asn1_pub_key);
@@ -913,7 +920,7 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t
913 } 920 }
914 921
915 /* now generate certifcates */ 922 /* now generate certifcates */
916 if (IPHONE_E_SUCCESS == ret && 0 != modulus.size && 0 != exponent.size) { 923 if (LOCKDOWN_E_SUCCESS == ret && 0 != modulus.size && 0 != exponent.size) {
917 924
918 gnutls_global_init(); 925 gnutls_global_init();
919 gnutls_datum_t essentially_null = { (unsigned char*)strdup("abababababababab"), strlen("abababababababab") }; 926 gnutls_datum_t essentially_null = { (unsigned char*)strdup("abababababababab"), strlen("abababababababab") };
@@ -945,7 +952,7 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t
945 gnutls_x509_crt_set_expiration_time(dev_cert, time(NULL) + (60 * 60 * 24 * 365 * 10)); 952 gnutls_x509_crt_set_expiration_time(dev_cert, time(NULL) + (60 * 60 * 24 * 365 * 10));
946 gnutls_x509_crt_sign(dev_cert, root_cert, root_privkey); 953 gnutls_x509_crt_sign(dev_cert, root_cert, root_privkey);
947 954
948 if (IPHONE_E_SUCCESS == ret) { 955 if (LOCKDOWN_E_SUCCESS == ret) {
949 /* if everything went well, export in PEM format */ 956 /* if everything went well, export in PEM format */
950 gnutls_datum_t dev_pem = { NULL, 0 }; 957 gnutls_datum_t dev_pem = { NULL, 0 };
951 gnutls_x509_crt_export(dev_cert, GNUTLS_X509_FMT_PEM, NULL, &dev_pem.size); 958 gnutls_x509_crt_export(dev_cert, GNUTLS_X509_FMT_PEM, NULL, &dev_pem.size);
@@ -979,13 +986,13 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t
979 986
980 switch(uret) { 987 switch(uret) {
981 case USERPREF_E_INVALID_ARG: 988 case USERPREF_E_INVALID_ARG:
982 ret = IPHONE_E_INVALID_ARG; 989 ret = LOCKDOWN_E_INVALID_ARG;
983 break; 990 break;
984 case USERPREF_E_INVALID_CONF: 991 case USERPREF_E_INVALID_CONF:
985 ret = IPHONE_E_INVALID_CONF; 992 ret = LOCKDOWN_E_INVALID_CONF;
986 break; 993 break;
987 case USERPREF_E_SSL_ERROR: 994 case USERPREF_E_SSL_ERROR:
988 ret = IPHONE_E_SSL_ERROR; 995 ret = LOCKDOWN_E_SSL_ERROR;
989 default: 996 default:
990 break; 997 break;
991 } 998 }
@@ -1005,14 +1012,14 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t
1005 * @param client The lockdownd client 1012 * @param client The lockdownd client
1006 * @param HostID The HostID used with this phone 1013 * @param HostID The HostID used with this phone
1007 * 1014 *
1008 * @return an error code (IPHONE_E_SUCCESS on success) 1015 * @return an error code (LOCKDOWN_E_SUCCESS on success)
1009 */ 1016 */
1010iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID) 1017lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID)
1011{ 1018{
1012 plist_t dict = NULL; 1019 plist_t dict = NULL;
1013 uint32_t return_me = 0; 1020 uint32_t return_me = 0;
1014 1021
1015 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 1022 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
1016 client->session_id[0] = '\0'; 1023 client->session_id[0] = '\0';
1017 1024
1018 /* Setup DevicePublicKey request plist */ 1025 /* Setup DevicePublicKey request plist */
@@ -1026,13 +1033,13 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
1026 plist_free(dict); 1033 plist_free(dict);
1027 dict = NULL; 1034 dict = NULL;
1028 1035
1029 if (ret != IPHONE_E_SUCCESS) 1036 if (ret != LOCKDOWN_E_SUCCESS)
1030 return ret; 1037 return ret;
1031 1038
1032 ret = lockdownd_recv(client, &dict); 1039 ret = lockdownd_recv(client, &dict);
1033 1040
1034 if (!dict) 1041 if (!dict)
1035 return IPHONE_E_PLIST_ERROR; 1042 return LOCKDOWN_E_PLIST_ERROR;
1036 1043
1037 if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) { 1044 if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) {
1038 plist_t error_node = plist_get_dict_el_from_key(dict, "Error"); 1045 plist_t error_node = plist_get_dict_el_from_key(dict, "Error");
@@ -1046,8 +1053,8 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
1046 char *host_id = NULL; 1053 char *host_id = NULL;
1047 userpref_get_host_id(&host_id); 1054 userpref_get_host_id(&host_id);
1048 1055
1049 if (IPHONE_E_SUCCESS == lockdownd_get_device_uuid(client, &uuid) ) { 1056 if (LOCKDOWN_E_SUCCESS == lockdownd_get_device_uuid(client, &uuid) ) {
1050 if (IPHONE_E_SUCCESS == lockdownd_pair(client, uuid, host_id) ) { 1057 if (LOCKDOWN_E_SUCCESS == lockdownd_pair(client, uuid, host_id) ) {
1051 /* start session again */ 1058 /* start session again */
1052 plist_free(dict); 1059 plist_free(dict);
1053 dict = plist_new_dict(); 1060 dict = plist_new_dict();
@@ -1070,7 +1077,7 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
1070 } 1077 }
1071 } 1078 }
1072 1079
1073 ret = IPHONE_E_SSL_ERROR; 1080 ret = LOCKDOWN_E_SSL_ERROR;
1074 if (lockdown_check_result(dict, "StartSession") == RESULT_SUCCESS) { 1081 if (lockdown_check_result(dict, "StartSession") == RESULT_SUCCESS) {
1075 // Set up GnuTLS... 1082 // Set up GnuTLS...
1076 //gnutls_anon_client_credentials_t anoncred; 1083 //gnutls_anon_client_credentials_t anoncred;
@@ -1114,13 +1121,13 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
1114 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS reported something wrong.\n", __func__); 1121 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS reported something wrong.\n", __func__);
1115 gnutls_perror(return_me); 1122 gnutls_perror(return_me);
1116 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: oh.. errno says %s\n", __func__, strerror(errno)); 1123 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: oh.. errno says %s\n", __func__, strerror(errno));
1117 return IPHONE_E_SSL_ERROR; 1124 return LOCKDOWN_E_SSL_ERROR;
1118 } else { 1125 } else {
1119 client->in_SSL = 1; 1126 client->in_SSL = 1;
1120 ret = IPHONE_E_SUCCESS; 1127 ret = LOCKDOWN_E_SUCCESS;
1121 } 1128 }
1122 } 1129 }
1123 //store session id 1130 /* store session id */
1124 plist_t session_node = plist_find_node_by_key(dict, "SessionID"); 1131 plist_t session_node = plist_find_node_by_key(dict, "SessionID");
1125 if (session_node) { 1132 if (session_node) {
1126 1133
@@ -1133,7 +1140,7 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
1133 plist_get_string_val(session_node_val, &session_id); 1140 plist_get_string_val(session_node_val, &session_id);
1134 1141
1135 if (session_node_val_type == PLIST_STRING && session_id) { 1142 if (session_node_val_type == PLIST_STRING && session_id) {
1136 // we need to store the session ID for StopSession 1143 /* we need to store the session ID for StopSession */
1137 strcpy(client->session_id, session_id); 1144 strcpy(client->session_id, session_id);
1138 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id); 1145 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id);
1139 } 1146 }
@@ -1145,11 +1152,11 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
1145 plist_free(dict); 1152 plist_free(dict);
1146 dict = NULL; 1153 dict = NULL;
1147 1154
1148 if (ret == IPHONE_E_SUCCESS) 1155 if (ret == LOCKDOWN_E_SUCCESS)
1149 return ret; 1156 return ret;
1150 1157
1151 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Apparently failed negotiating with lockdownd.\n", __func__); 1158 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Apparently failed negotiating with lockdownd.\n", __func__);
1152 return IPHONE_E_SSL_ERROR; 1159 return LOCKDOWN_E_SSL_ERROR;
1153} 1160}
1154 1161
1155/** gnutls callback for writing data to the iPhone. 1162/** gnutls callback for writing data to the iPhone.
@@ -1196,7 +1203,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
1196 1203
1197 // repeat until we have the full data or an error occurs. 1204 // repeat until we have the full data or an error occurs.
1198 do { 1205 do {
1199 if ((res = usbmuxd_recv(client->sfd, recv_buffer, this_len, (uint32_t*)&bytes)) != IPHONE_E_SUCCESS) { 1206 if ((res = usbmuxd_recv(client->sfd, recv_buffer, this_len, (uint32_t*)&bytes)) != LOCKDOWN_E_SUCCESS) {
1200 log_debug_msg("%s: ERROR: usbmux_recv returned %d\n", __func__, res); 1207 log_debug_msg("%s: ERROR: usbmux_recv returned %d\n", __func__, res);
1201 return res; 1208 return res;
1202 } 1209 }
@@ -1230,23 +1237,23 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
1230 * @param service The name of the service to start 1237 * @param service The name of the service to start
1231 * @param port The port number the service was started on 1238 * @param port The port number the service was started on
1232 1239
1233 * @return an error code (IPHONE_E_SUCCESS on success) 1240 * @return an error code (LOCKDOWN_E_SUCCESS on success)
1234 */ 1241 */
1235iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, int *port) 1242lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, int *port)
1236{ 1243{
1237 if (!client || !service || !port) 1244 if (!client || !service || !port)
1238 return IPHONE_E_INVALID_ARG; 1245 return LOCKDOWN_E_INVALID_ARG;
1239 1246
1240 char *host_id = NULL; 1247 char *host_id = NULL;
1241 userpref_get_host_id(&host_id); 1248 userpref_get_host_id(&host_id);
1242 if (!host_id) 1249 if (!host_id)
1243 return IPHONE_E_INVALID_CONF; 1250 return LOCKDOWN_E_INVALID_CONF;
1244 if (!client->in_SSL && !lockdownd_start_ssl_session(client, host_id)) 1251 if (!client->in_SSL && !lockdownd_start_ssl_session(client, host_id))
1245 return IPHONE_E_SSL_ERROR; 1252 return LOCKDOWN_E_SSL_ERROR;
1246 1253
1247 plist_t dict = NULL; 1254 plist_t dict = NULL;
1248 uint32_t port_loc = 0; 1255 uint32_t port_loc = 0;
1249 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 1256 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
1250 1257
1251 free(host_id); 1258 free(host_id);
1252 host_id = NULL; 1259 host_id = NULL;
@@ -1262,18 +1269,18 @@ iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *se
1262 plist_free(dict); 1269 plist_free(dict);
1263 dict = NULL; 1270 dict = NULL;
1264 1271
1265 if (IPHONE_E_SUCCESS != ret) 1272 if (LOCKDOWN_E_SUCCESS != ret)
1266 return ret; 1273 return ret;
1267 1274
1268 ret = lockdownd_recv(client, &dict); 1275 ret = lockdownd_recv(client, &dict);
1269 1276
1270 if (IPHONE_E_SUCCESS != ret) 1277 if (LOCKDOWN_E_SUCCESS != ret)
1271 return ret; 1278 return ret;
1272 1279
1273 if (!dict) 1280 if (!dict)
1274 return IPHONE_E_PLIST_ERROR; 1281 return LOCKDOWN_E_PLIST_ERROR;
1275 1282
1276 ret = IPHONE_E_UNKNOWN_ERROR; 1283 ret = LOCKDOWN_E_UNKNOWN_ERROR;
1277 if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { 1284 if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) {
1278 plist_t port_key_node = plist_find_node_by_key(dict, "Port"); 1285 plist_t port_key_node = plist_find_node_by_key(dict, "Port");
1279 plist_t port_value_node = plist_get_next_sibling(port_key_node); 1286 plist_t port_value_node = plist_get_next_sibling(port_key_node);
@@ -1287,17 +1294,17 @@ iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *se
1287 plist_get_uint_val(port_value_node, &port_value); 1294 plist_get_uint_val(port_value_node, &port_value);
1288 if (port_key && !strcmp(port_key, "Port")) { 1295 if (port_key && !strcmp(port_key, "Port")) {
1289 port_loc = port_value; 1296 port_loc = port_value;
1290 ret = IPHONE_E_SUCCESS; 1297 ret = LOCKDOWN_E_SUCCESS;
1291 } 1298 }
1292 if (port_key) 1299 if (port_key)
1293 free(port_key); 1300 free(port_key);
1294 1301
1295 if (port && ret == IPHONE_E_SUCCESS) 1302 if (port && ret == LOCKDOWN_E_SUCCESS)
1296 *port = port_loc; 1303 *port = port_loc;
1297 } 1304 }
1298 } 1305 }
1299 else 1306 else
1300 ret = IPHONE_E_START_SERVICE_FAILED; 1307 ret = LOCKDOWN_E_START_SERVICE_FAILED;
1301 1308
1302 plist_free(dict); 1309 plist_free(dict);
1303 dict = NULL; 1310 dict = NULL;
diff --git a/src/lockdown.h b/src/lockdown.h
index 185d27a..1e193f6 100644
--- a/src/lockdown.h
+++ b/src/lockdown.h
@@ -24,6 +24,7 @@
24 24
25#include <gnutls/gnutls.h> 25#include <gnutls/gnutls.h>
26#include <string.h> 26#include <string.h>
27
27#include "libiphone/lockdown.h" 28#include "libiphone/lockdown.h"
28 29
29struct lockdownd_client_int { 30struct lockdownd_client_int {
@@ -33,13 +34,14 @@ struct lockdownd_client_int {
33 char session_id[40]; 34 char session_id[40];
34}; 35};
35 36
36iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key); 37lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key);
37iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * device_cert, 38lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * device_cert,
38 gnutls_datum_t * host_cert, gnutls_datum_t * root_cert); 39 gnutls_datum_t * host_cert, gnutls_datum_t * root_cert);
39 40
40// SSL functions 41/* SSL functions */
41iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID); 42lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID);
42ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_t length); 43ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_t length);
43ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size_t length); 44ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size_t length);
44 45
46
45#endif 47#endif