diff options
| author | 2009-12-07 18:58:55 +0100 | |
|---|---|---|
| committer | 2009-12-07 19:46:43 -0800 | |
| commit | b9ecd70c30ac1fd7024cadfcda9c7be1d1f7f44f (patch) | |
| tree | 0d4b425c9d4293f86224612c5d1fb29b99199082 /src | |
| parent | 62c23c1ccafedab1bf8bed2fb0e511462b8ab4cc (diff) | |
| download | libimobiledevice-b9ecd70c30ac1fd7024cadfcda9c7be1d1f7f44f.tar.gz libimobiledevice-b9ecd70c30ac1fd7024cadfcda9c7be1d1f7f44f.tar.bz2 | |
cache device uuid in client struct
When accessing/storing key info with userprefs, a device uuid is
required that makes it possible to distinguish between different
devices. On execution of lockdownd_client_new, the uuid is queried
via lockdown and now stored in the client struct for later reuse.
This patch also removes the uuid parameter from lockdownd_pair().
Diffstat (limited to 'src')
| -rw-r--r-- | src/lockdown.c | 51 | ||||
| -rw-r--r-- | src/lockdown.h | 1 |
2 files changed, 26 insertions, 26 deletions
diff --git a/src/lockdown.c b/src/lockdown.c index 02b0024..b6289ed 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -220,6 +220,9 @@ lockdownd_error_t lockdownd_client_free(lockdownd_client_t client) | |||
| 220 | if (client->session_id) { | 220 | if (client->session_id) { |
| 221 | free(client->session_id); | 221 | free(client->session_id); |
| 222 | } | 222 | } |
| 223 | if (client->uuid) { | ||
| 224 | free(client->uuid); | ||
| 225 | } | ||
| 223 | 226 | ||
| 224 | free(client); | 227 | free(client); |
| 225 | return ret; | 228 | return ret; |
| @@ -655,31 +658,26 @@ lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_ | |||
| 655 | client_loc->ssl_certificate = NULL; | 658 | client_loc->ssl_certificate = NULL; |
| 656 | client_loc->in_SSL = 0; | 659 | client_loc->in_SSL = 0; |
| 657 | client_loc->session_id = NULL; | 660 | client_loc->session_id = NULL; |
| 661 | client_loc->uuid = NULL; | ||
| 658 | 662 | ||
| 659 | if (LOCKDOWN_E_SUCCESS != lockdownd_query_type(client_loc)) { | 663 | if (LOCKDOWN_E_SUCCESS != lockdownd_query_type(client_loc)) { |
| 660 | log_debug_msg("%s: QueryType failed in the lockdownd client.\n", __func__); | 664 | log_debug_msg("%s: QueryType failed in the lockdownd client.\n", __func__); |
| 661 | ret = LOCKDOWN_E_NOT_ENOUGH_DATA; | 665 | ret = LOCKDOWN_E_NOT_ENOUGH_DATA; |
| 662 | } | 666 | } |
| 663 | 667 | ||
| 664 | char *uuid = NULL; | 668 | ret = iphone_device_get_uuid(device, &client_loc->uuid); |
| 665 | ret = iphone_device_get_uuid(device, &uuid); | ||
| 666 | if (LOCKDOWN_E_SUCCESS != ret) { | 669 | if (LOCKDOWN_E_SUCCESS != ret) { |
| 667 | log_debug_msg("%s: failed to get device uuid.\n", __func__); | 670 | log_debug_msg("%s: failed to get device uuid.\n", __func__); |
| 668 | } | 671 | } |
| 669 | log_debug_msg("%s: device uuid: %s\n", __func__, uuid); | 672 | log_debug_msg("%s: device uuid: %s\n", __func__, client_loc->uuid); |
| 670 | 673 | ||
| 671 | userpref_get_host_id(&host_id); | 674 | userpref_get_host_id(&host_id); |
| 672 | if (LOCKDOWN_E_SUCCESS == ret && !host_id) { | 675 | if (LOCKDOWN_E_SUCCESS == ret && !host_id) { |
| 673 | ret = LOCKDOWN_E_INVALID_CONF; | 676 | ret = LOCKDOWN_E_INVALID_CONF; |
| 674 | } | 677 | } |
| 675 | 678 | ||
| 676 | if (LOCKDOWN_E_SUCCESS == ret && !userpref_has_device_public_key(uuid)) | 679 | if (LOCKDOWN_E_SUCCESS == ret && !userpref_has_device_public_key(client_loc->uuid)) |
| 677 | ret = lockdownd_pair(client_loc, uuid, host_id); | 680 | ret = lockdownd_pair(client_loc, host_id); |
| 678 | |||
| 679 | if (uuid) { | ||
| 680 | free(uuid); | ||
| 681 | uuid = NULL; | ||
| 682 | } | ||
| 683 | 681 | ||
| 684 | if (LOCKDOWN_E_SUCCESS == ret) { | 682 | if (LOCKDOWN_E_SUCCESS == ret) { |
| 685 | ret = lockdownd_start_ssl_session(client_loc, host_id); | 683 | ret = lockdownd_start_ssl_session(client_loc, host_id); |
| @@ -703,9 +701,14 @@ lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_ | |||
| 703 | /** Generates the appropriate keys and pairs the device. It's part of the | 701 | /** Generates the appropriate keys and pairs the device. It's part of the |
| 704 | * lockdownd handshake. | 702 | * lockdownd handshake. |
| 705 | * | 703 | * |
| 704 | * @param client The lockdown client to pair with. | ||
| 705 | * @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 | ||
| 707 | * generated automatically when pairing is done for the first time. | ||
| 708 | * | ||
| 706 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 709 | * @return an error code (LOCKDOWN_E_SUCCESS on success) |
| 707 | */ | 710 | */ |
| 708 | lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *uuid, char *host_id) | 711 | lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *host_id) |
| 709 | { | 712 | { |
| 710 | lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; | 713 | lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; |
| 711 | plist_t dict = NULL; | 714 | plist_t dict = NULL; |
| @@ -764,7 +767,7 @@ lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *uuid, char *ho | |||
| 764 | /* store public key in config if pairing succeeded */ | 767 | /* store public key in config if pairing succeeded */ |
| 765 | if (ret == LOCKDOWN_E_SUCCESS) { | 768 | if (ret == LOCKDOWN_E_SUCCESS) { |
| 766 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__); | 769 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__); |
| 767 | userpref_set_device_public_key(uuid, public_key); | 770 | userpref_set_device_public_key(client->uuid, public_key); |
| 768 | } else { | 771 | } else { |
| 769 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__); | 772 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__); |
| 770 | } | 773 | } |
| @@ -1027,26 +1030,22 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c | |||
| 1027 | 1030 | ||
| 1028 | if (!strcmp(error, "InvalidHostID")) { | 1031 | if (!strcmp(error, "InvalidHostID")) { |
| 1029 | /* hostid is unknown. Pair and try again */ | 1032 | /* hostid is unknown. Pair and try again */ |
| 1030 | char *uuid = NULL; | ||
| 1031 | char *host_id = NULL; | 1033 | char *host_id = NULL; |
| 1032 | userpref_get_host_id(&host_id); | 1034 | userpref_get_host_id(&host_id); |
| 1033 | 1035 | ||
| 1034 | if (LOCKDOWN_E_SUCCESS == lockdownd_get_device_uuid(client, &uuid) ) { | 1036 | if (LOCKDOWN_E_SUCCESS == lockdownd_pair(client, host_id) ) { |
| 1035 | if (LOCKDOWN_E_SUCCESS == lockdownd_pair(client, uuid, host_id) ) { | 1037 | /* start session again */ |
| 1036 | /* start session again */ | 1038 | plist_free(dict); |
| 1037 | plist_free(dict); | 1039 | dict = plist_new_dict(); |
| 1038 | dict = plist_new_dict(); | 1040 | plist_dict_insert_item(dict,"HostID", plist_new_string(HostID)); |
| 1039 | plist_dict_insert_item(dict,"HostID", plist_new_string(HostID)); | 1041 | plist_dict_insert_item(dict,"Request", plist_new_string("StartSession")); |
| 1040 | plist_dict_insert_item(dict,"Request", plist_new_string("StartSession")); | ||
| 1041 | 1042 | ||
| 1042 | ret = lockdownd_send(client, dict); | 1043 | ret = lockdownd_send(client, dict); |
| 1043 | plist_free(dict); | 1044 | plist_free(dict); |
| 1044 | dict = NULL; | 1045 | dict = NULL; |
| 1045 | 1046 | ||
| 1046 | ret = lockdownd_recv(client, &dict); | 1047 | ret = lockdownd_recv(client, &dict); |
| 1047 | } | ||
| 1048 | } | 1048 | } |
| 1049 | free(uuid); | ||
| 1050 | free(host_id); | 1049 | free(host_id); |
| 1051 | } | 1050 | } |
| 1052 | free(error); | 1051 | free(error); |
diff --git a/src/lockdown.h b/src/lockdown.h index 49b467f..931623a 100644 --- a/src/lockdown.h +++ b/src/lockdown.h | |||
| @@ -33,6 +33,7 @@ struct lockdownd_client_int { | |||
| 33 | gnutls_certificate_credentials_t ssl_certificate; | 33 | gnutls_certificate_credentials_t ssl_certificate; |
| 34 | int in_SSL; | 34 | int in_SSL; |
| 35 | char *session_id; | 35 | char *session_id; |
| 36 | char *uuid; | ||
| 36 | }; | 37 | }; |
| 37 | 38 | ||
| 38 | lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key); | 39 | lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key); |
