summaryrefslogtreecommitdiffstats
path: root/src/lockdown.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-12-07 19:27:54 +0100
committerGravatar Matt Colyer2009-12-07 19:48:21 -0800
commit318cc4f7b336109819c7b4c6a1a9f2e8d37d9bed (patch)
tree04472b547ed5363dc1d6d4b9c4766823683ebc9d /src/lockdown.c
parent6ae6880ce5cf00977dfdb204855a7308d7bf42c9 (diff)
downloadlibimobiledevice-318cc4f7b336109819c7b4c6a1a9f2e8d37d9bed.tar.gz
libimobiledevice-318cc4f7b336109819c7b4c6a1a9f2e8d37d9bed.tar.bz2
New function lockdownd_validate_pair()
This function allows the current host (or the host specified by the given HostID to become the trusted host of the device. [#89 state:resolved] Signed-off-by: Matt Colyer <matt@colyer.name>
Diffstat (limited to 'src/lockdown.c')
-rw-r--r--src/lockdown.c47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/lockdown.c b/src/lockdown.c
index d717c01..fb5f8f5 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -698,17 +698,17 @@ lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_
698 return ret; 698 return ret;
699} 699}
700 700
701/** Generates the appropriate keys and pairs the device. It's part of the 701/** Function used internally by lockdownd_pair() and lockdownd_validate_pair()
702 * lockdownd handshake.
703 * 702 *
704 * @param client The lockdown client to pair with. 703 * @param client The lockdown client to pair with.
705 * @param host_id The HostID to use for pairing. If NULL is passed, then 704 * @param host_id The HostID to use for pairing. If NULL is passed, then
706 * the HostID of the current machine is used. A new HostID will be 705 * the HostID of the current machine is used. A new HostID will be
707 * generated automatically when pairing is done for the first time. 706 * generated automatically when pairing is done for the first time.
707 * @param verb This is either "Pair" or "ValidatePair".
708 * 708 *
709 * @return an error code (LOCKDOWN_E_SUCCESS on success) 709 * @return an error code (LOCKDOWN_E_SUCCESS on success)
710 */ 710 */
711lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *host_id) 711static lockdownd_error_t lockdownd_do_pair(lockdownd_client_t client, char *host_id, const char *verb)
712{ 712{
713 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; 713 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
714 plist_t dict = NULL; 714 plist_t dict = NULL;
@@ -748,7 +748,7 @@ lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *host_id)
748 plist_dict_insert_item(dict_record, "HostID", plist_new_string(host_id_loc)); 748 plist_dict_insert_item(dict_record, "HostID", plist_new_string(host_id_loc));
749 plist_dict_insert_item(dict_record, "RootCertificate", plist_new_data((const char*)root_cert.data, root_cert.size)); 749 plist_dict_insert_item(dict_record, "RootCertificate", plist_new_data((const char*)root_cert.data, root_cert.size));
750 750
751 plist_dict_insert_item(dict, "Request", plist_new_string("Pair")); 751 plist_dict_insert_item(dict, "Request", plist_new_string(verb));
752 752
753 /* send to iPhone */ 753 /* send to iPhone */
754 ret = lockdownd_send(client, dict); 754 ret = lockdownd_send(client, dict);
@@ -768,7 +768,7 @@ lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *host_id)
768 if (ret != LOCKDOWN_E_SUCCESS) 768 if (ret != LOCKDOWN_E_SUCCESS)
769 return ret; 769 return ret;
770 770
771 if (lockdown_check_result(dict, "Pair") != RESULT_SUCCESS) { 771 if (lockdown_check_result(dict, verb) != RESULT_SUCCESS) {
772 ret = LOCKDOWN_E_PAIRING_FAILED; 772 ret = LOCKDOWN_E_PAIRING_FAILED;
773 } 773 }
774 plist_free(dict); 774 plist_free(dict);
@@ -776,15 +776,48 @@ lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *host_id)
776 776
777 /* store public key in config if pairing succeeded */ 777 /* store public key in config if pairing succeeded */
778 if (ret == LOCKDOWN_E_SUCCESS) { 778 if (ret == LOCKDOWN_E_SUCCESS) {
779 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__); 779 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: %s success\n", __func__, verb);
780 userpref_set_device_public_key(client->uuid, public_key); 780 userpref_set_device_public_key(client->uuid, public_key);
781 } else { 781 } else {
782 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__); 782 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: %s failure\n", __func__, verb);
783 } 783 }
784 free(public_key.data); 784 free(public_key.data);
785 return ret; 785 return ret;
786} 786}
787 787
788/**
789 * Pairs the device with the given HostID.
790 * It's part of the lockdownd handshake.
791 *
792 * @param client The lockdown client to pair with.
793 * @param host_id The HostID to use for pairing. If NULL is passed, then
794 * the HostID of the current machine is used. A new HostID will be
795 * generated automatically when pairing is done for the first time.
796 *
797 * @return an error code (LOCKDOWN_E_SUCCESS on success)
798 */
799lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *host_id)
800{
801 return lockdownd_do_pair(client, host_id, "Pair");
802}
803
804/**
805 * Pairs the device with the given HostID. The difference to lockdownd_pair()
806 * is that the specified host will become trusted host of the device.
807 * It's part of the lockdownd handshake.
808 *
809 * @param client The lockdown client to pair with.
810 * @param host_id The HostID to use for pairing. If NULL is passed, then
811 * the HostID of the current machine is used. A new HostID will be
812 * generated automatically when pairing is done for the first time.
813 *
814 * @return an error code (LOCKDOWN_E_SUCCESS on success)
815 */
816lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, char *host_id)
817{
818 return lockdownd_do_pair(client, host_id, "ValidatePair");
819}
820
788/** 821/**
789 * Tells the device to immediately enter recovery mode. 822 * Tells the device to immediately enter recovery mode.
790 * 823 *