diff options
| author | 2009-07-25 01:39:35 +0200 | |
|---|---|---|
| committer | 2009-07-25 01:39:35 +0200 | |
| commit | 66695e6b7db9457d5ecfe6f4f6624dc195e5274d (patch) | |
| tree | ab5c432974cc2c54b5554b050879a2e3975ae6b8 /src/lockdown.c | |
| parent | 028646335acca403cc8a601d77c2272e077445e0 (diff) | |
| download | libimobiledevice-66695e6b7db9457d5ecfe6f4f6624dc195e5274d.tar.gz libimobiledevice-66695e6b7db9457d5ecfe6f4f6624dc195e5274d.tar.bz2 | |
Improve API of userpref system
Diffstat (limited to 'src/lockdown.c')
| -rw-r--r-- | src/lockdown.c | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/src/lockdown.c b/src/lockdown.c index 3d2b04c..757a94a 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -19,10 +19,6 @@ | |||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include "utils.h" | ||
| 23 | #include "iphone.h" | ||
| 24 | #include "lockdown.h" | ||
| 25 | #include "userpref.h" | ||
| 26 | #include <arpa/inet.h> | 22 | #include <arpa/inet.h> |
| 27 | #include <errno.h> | 23 | #include <errno.h> |
| 28 | #include <string.h> | 24 | #include <string.h> |
| @@ -30,9 +26,13 @@ | |||
| 30 | #include <glib.h> | 26 | #include <glib.h> |
| 31 | #include <libtasn1.h> | 27 | #include <libtasn1.h> |
| 32 | #include <gnutls/x509.h> | 28 | #include <gnutls/x509.h> |
| 33 | |||
| 34 | #include <plist/plist.h> | 29 | #include <plist/plist.h> |
| 35 | 30 | ||
| 31 | #include "lockdown.h" | ||
| 32 | #include "iphone.h" | ||
| 33 | #include "utils.h" | ||
| 34 | #include "userpref.h" | ||
| 35 | |||
| 36 | #define RESULT_SUCCESS 0 | 36 | #define RESULT_SUCCESS 0 |
| 37 | #define RESULT_FAILURE 1 | 37 | #define RESULT_FAILURE 1 |
| 38 | 38 | ||
| @@ -680,12 +680,12 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t * | |||
| 680 | } | 680 | } |
| 681 | log_debug_msg("%s: device uuid: %s\n", __func__, uuid); | 681 | log_debug_msg("%s: device uuid: %s\n", __func__, uuid); |
| 682 | 682 | ||
| 683 | host_id = get_host_id(); | 683 | userpref_get_host_id(&host_id); |
| 684 | if (IPHONE_E_SUCCESS == ret && !host_id) { | 684 | if (IPHONE_E_SUCCESS == ret && !host_id) { |
| 685 | ret = IPHONE_E_INVALID_CONF; | 685 | ret = IPHONE_E_INVALID_CONF; |
| 686 | } | 686 | } |
| 687 | 687 | ||
| 688 | if (IPHONE_E_SUCCESS == ret && !is_device_known(uuid)) | 688 | if (IPHONE_E_SUCCESS == ret && !userpref_has_device_public_key(uuid)) |
| 689 | ret = lockdownd_pair(client_loc, uuid, host_id); | 689 | ret = lockdownd_pair(client_loc, uuid, host_id); |
| 690 | 690 | ||
| 691 | if (uuid) { | 691 | if (uuid) { |
| @@ -780,7 +780,7 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i | |||
| 780 | /* store public key in config if pairing succeeded */ | 780 | /* store public key in config if pairing succeeded */ |
| 781 | if (ret == IPHONE_E_SUCCESS) { | 781 | if (ret == IPHONE_E_SUCCESS) { |
| 782 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__); | 782 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__); |
| 783 | store_device_public_key(uuid, public_key); | 783 | userpref_set_device_public_key(uuid, public_key); |
| 784 | } else { | 784 | } else { |
| 785 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__); | 785 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__); |
| 786 | ret = IPHONE_E_PAIRING_FAILED; | 786 | ret = IPHONE_E_PAIRING_FAILED; |
| @@ -875,6 +875,7 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t | |||
| 875 | if (!public_key.data || !odevice_cert || !ohost_cert || !oroot_cert) | 875 | if (!public_key.data || !odevice_cert || !ohost_cert || !oroot_cert) |
| 876 | return IPHONE_E_INVALID_ARG; | 876 | return IPHONE_E_INVALID_ARG; |
| 877 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 877 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 878 | userpref_error_t uret = USERPREF_E_UNKNOWN_ERROR; | ||
| 878 | 879 | ||
| 879 | gnutls_datum_t modulus = { NULL, 0 }; | 880 | gnutls_datum_t modulus = { NULL, 0 }; |
| 880 | gnutls_datum_t exponent = { NULL, 0 }; | 881 | gnutls_datum_t exponent = { NULL, 0 }; |
| @@ -932,10 +933,9 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t | |||
| 932 | gnutls_x509_privkey_init(&root_privkey); | 933 | gnutls_x509_privkey_init(&root_privkey); |
| 933 | gnutls_x509_privkey_init(&host_privkey); | 934 | gnutls_x509_privkey_init(&host_privkey); |
| 934 | 935 | ||
| 935 | ret = get_keys_and_certs(root_privkey, root_cert, host_privkey, host_cert); | 936 | uret = userpref_get_keys_and_certs(root_privkey, root_cert, host_privkey, host_cert); |
| 936 | |||
| 937 | if (IPHONE_E_SUCCESS == ret) { | ||
| 938 | 937 | ||
| 938 | if (USERPREF_E_SUCCESS == uret) { | ||
| 939 | /* generate device certificate */ | 939 | /* generate device certificate */ |
| 940 | gnutls_x509_crt_set_key(dev_cert, fake_privkey); | 940 | gnutls_x509_crt_set_key(dev_cert, fake_privkey); |
| 941 | gnutls_x509_crt_set_serial(dev_cert, "\x00", 1); | 941 | gnutls_x509_crt_set_serial(dev_cert, "\x00", 1); |
| @@ -955,7 +955,9 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t | |||
| 955 | gnutls_datum_t pem_root_cert = { NULL, 0 }; | 955 | gnutls_datum_t pem_root_cert = { NULL, 0 }; |
| 956 | gnutls_datum_t pem_host_cert = { NULL, 0 }; | 956 | gnutls_datum_t pem_host_cert = { NULL, 0 }; |
| 957 | 957 | ||
| 958 | if ( IPHONE_E_SUCCESS == get_certs_as_pem(&pem_root_cert, &pem_host_cert) ) { | 958 | uret = userpref_get_certs_as_pem(&pem_root_cert, &pem_host_cert); |
| 959 | |||
| 960 | if (USERPREF_E_SUCCESS == uret) { | ||
| 959 | /* copy buffer for output */ | 961 | /* copy buffer for output */ |
| 960 | odevice_cert->data = malloc(dev_pem.size); | 962 | odevice_cert->data = malloc(dev_pem.size); |
| 961 | memcpy(odevice_cert->data, dev_pem.data, dev_pem.size); | 963 | memcpy(odevice_cert->data, dev_pem.data, dev_pem.size); |
| @@ -974,6 +976,19 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t | |||
| 974 | } | 976 | } |
| 975 | } | 977 | } |
| 976 | } | 978 | } |
| 979 | |||
| 980 | switch(uret) { | ||
| 981 | case USERPREF_E_INVALID_ARG: | ||
| 982 | ret = IPHONE_E_INVALID_ARG; | ||
| 983 | break; | ||
| 984 | case USERPREF_E_INVALID_CONF: | ||
| 985 | ret = IPHONE_E_INVALID_CONF; | ||
| 986 | break; | ||
| 987 | case USERPREF_E_SSL_ERROR: | ||
| 988 | ret = IPHONE_E_SSL_ERROR; | ||
| 989 | default: | ||
| 990 | break; | ||
| 991 | } | ||
| 977 | } | 992 | } |
| 978 | } | 993 | } |
| 979 | 994 | ||
| @@ -1026,12 +1041,14 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char | |||
| 1026 | plist_get_string_val(error_node, &error); | 1041 | plist_get_string_val(error_node, &error); |
| 1027 | 1042 | ||
| 1028 | if (!strcmp(error, "InvalidHostID")) { | 1043 | if (!strcmp(error, "InvalidHostID")) { |
| 1029 | //hostid is unknown. Pair and try again | 1044 | /* hostid is unknown. Pair and try again */ |
| 1030 | char *uid = NULL; | 1045 | char *uuid = NULL; |
| 1031 | char* host_id = get_host_id(); | 1046 | char *host_id = NULL; |
| 1032 | if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(client, &uid) ) { | 1047 | userpref_get_host_id(&host_id); |
| 1033 | if (IPHONE_E_SUCCESS == lockdownd_pair(client, uid, host_id) ) { | 1048 | |
| 1034 | //start session again | 1049 | if (IPHONE_E_SUCCESS == lockdownd_get_device_uuid(client, &uuid) ) { |
| 1050 | if (IPHONE_E_SUCCESS == lockdownd_pair(client, uuid, host_id) ) { | ||
| 1051 | /* start session again */ | ||
| 1035 | plist_free(dict); | 1052 | plist_free(dict); |
| 1036 | dict = plist_new_dict(); | 1053 | dict = plist_new_dict(); |
| 1037 | plist_add_sub_key_el(dict, "HostID"); | 1054 | plist_add_sub_key_el(dict, "HostID"); |
| @@ -1046,7 +1063,7 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char | |||
| 1046 | ret = lockdownd_recv(client, &dict); | 1063 | ret = lockdownd_recv(client, &dict); |
| 1047 | } | 1064 | } |
| 1048 | } | 1065 | } |
| 1049 | free(uid); | 1066 | free(uuid); |
| 1050 | free(host_id); | 1067 | free(host_id); |
| 1051 | } | 1068 | } |
| 1052 | free(error); | 1069 | free(error); |
| @@ -1220,7 +1237,8 @@ iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *se | |||
| 1220 | if (!client || !service || !port) | 1237 | if (!client || !service || !port) |
| 1221 | return IPHONE_E_INVALID_ARG; | 1238 | return IPHONE_E_INVALID_ARG; |
| 1222 | 1239 | ||
| 1223 | char *host_id = get_host_id(); | 1240 | char *host_id = NULL; |
| 1241 | userpref_get_host_id(&host_id); | ||
| 1224 | if (!host_id) | 1242 | if (!host_id) |
| 1225 | return IPHONE_E_INVALID_CONF; | 1243 | return IPHONE_E_INVALID_CONF; |
| 1226 | if (!client->in_SSL && !lockdownd_start_ssl_session(client, host_id)) | 1244 | if (!client->in_SSL && !lockdownd_start_ssl_session(client, host_id)) |
