diff options
Diffstat (limited to 'include/libimobiledevice/lockdown.h')
-rw-r--r-- | include/libimobiledevice/lockdown.h | 170 |
1 files changed, 133 insertions, 37 deletions
diff --git a/include/libimobiledevice/lockdown.h b/include/libimobiledevice/lockdown.h index c35e5e9..21669ef 100644 --- a/include/libimobiledevice/lockdown.h +++ b/include/libimobiledevice/lockdown.h @@ -31,7 +31,6 @@ extern "C" { #endif #include <libimobiledevice/libimobiledevice.h> -#include <libimobiledevice/lockdown.h> /** Error Codes */ typedef enum { @@ -80,7 +79,7 @@ typedef enum { LOCKDOWN_E_UNKNOWN_ERROR = -256 } lockdownd_error_t; -typedef struct lockdownd_client_private lockdownd_client_private; +typedef struct lockdownd_client_private lockdownd_client_private; /**< \private */ typedef lockdownd_client_private *lockdownd_client_t; /**< The client handle. */ struct lockdownd_pair_record { @@ -88,18 +87,32 @@ struct lockdownd_pair_record { char *host_certificate; /**< The host certificate */ char *root_certificate; /**< The root certificate */ char *host_id; /**< A unique HostID for the host computer */ - char *system_buid; /**< A unique system id */ + char *system_buid; /**< A unique system id */ }; -/** A pair record holding device, host and root certificates along the host_id */ -typedef struct lockdownd_pair_record *lockdownd_pair_record_t; +/** pair record holding device, host and root certificates along the host_id */ +typedef struct lockdownd_pair_record *lockdownd_pair_record_t; /**< pair record */ +/** service descriptor */ struct lockdownd_service_descriptor { - uint16_t port; - uint8_t ssl_enabled; - char* identifier; + uint16_t port; /**< port number the service was started on */ + uint8_t ssl_enabled; /**< an indicator if the service requires SSL */ + char* identifier; /**< identifier of the service */ }; typedef struct lockdownd_service_descriptor *lockdownd_service_descriptor_t; +/** Callback types used in #lockdownd_cu_pairing_cb_t */ +typedef enum { + LOCKDOWN_CU_PAIRING_PIN_REQUESTED, /**< PIN requested: data_ptr is a char* buffer, and data_size points to the size of this buffer that must not be exceeded and has to be updated to the actual number of characters filled into the buffer. */ + LOCKDOWN_CU_PAIRING_DEVICE_INFO, /**< device information available: data_ptr is a plist_t, and data_size is ignored. The plist_t has to be copied if required, since it is freed when the callback function returns. */ + LOCKDOWN_CU_PAIRING_ERROR /**< pairing error message available: data_ptr is a NULL-terminated char* buffer containing the error message, and data_size is ignored. Buffer needs to be copied if it shall persist outside the callback. */ +} lockdownd_cu_pairing_cb_type_t; + +/* CU pairing callback function prototype */ +/** Callback used to supply the pairing PIN during a CU pairing session, + * and to report device information and pairing error messages. */ +typedef void (*lockdownd_cu_pairing_cb_t) (lockdownd_cu_pairing_cb_type_t cb_type, void *user_data, void* data_ptr, unsigned int* data_size); + + /* Interface */ /** @@ -117,7 +130,7 @@ typedef struct lockdownd_service_descriptor *lockdownd_service_descriptor_t; * * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL */ -lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label); /** * Creates a new lockdownd client for the device and starts initial handshake. @@ -136,7 +149,7 @@ lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *cli * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL, * LOCKDOWN_E_INVALID_CONF if configuration data is wrong */ -lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label); /** * Closes the lockdownd client session if one is running and frees up the @@ -146,7 +159,7 @@ lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdown * * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL */ -lockdownd_error_t lockdownd_client_free(lockdownd_client_t client); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_free(lockdownd_client_t client); /** @@ -158,7 +171,7 @@ lockdownd_error_t lockdownd_client_free(lockdownd_client_t client); * * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL */ -lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type); /** * Retrieves a preferences plist using an optional domain and/or key name. @@ -170,7 +183,7 @@ lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type); * * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL */ -lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value); /** * Sets a preferences value using a plist and optional by domain and/or key name. @@ -183,7 +196,7 @@ lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *dom * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client or * value is NULL */ -lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value); /** * Removes a preference node by domain and/or key name. @@ -196,7 +209,7 @@ lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *dom * * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL */ -lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key); /** * Requests to start a service and retrieve it's port on success. @@ -210,7 +223,7 @@ lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char * * by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not be * started by the device */ -lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service); /** * Requests to start a service and retrieve it's port on success. @@ -226,7 +239,7 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char * started by the device, LOCKDOWN_E_INVALID_CONF if the host id or escrow bag are * missing from the device record. */ -lockdownd_error_t lockdownd_start_service_with_escrow_bag(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_start_service_with_escrow_bag(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service); /** * Opens a session with lockdownd and switches to SSL mode if device wants it. @@ -241,7 +254,7 @@ lockdownd_error_t lockdownd_start_service_with_escrow_bag(lockdownd_client_t cli * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the supplied HostID, * LOCKDOWN_E_SSL_ERROR if enabling SSL communication failed */ -lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled); /** * Closes the lockdownd session by sending the StopSession request. @@ -253,7 +266,7 @@ lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char * * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL */ -lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id); /** * Sends a plist to lockdownd. @@ -267,7 +280,7 @@ lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char * * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client or * plist is NULL */ -lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist); /** * Receives a plist from lockdownd. @@ -278,7 +291,7 @@ lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist); * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client or * plist is NULL */ -lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist); /** * Pairs the device using the supplied pair record. @@ -294,7 +307,7 @@ lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist); * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected, * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id */ -lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); /** * Pairs the device using the supplied pair record and passing the given options. @@ -313,7 +326,7 @@ lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_recor * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected, * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id */ -lockdownd_error_t lockdownd_pair_with_options(lockdownd_client_t client, lockdownd_pair_record_t pair_record, plist_t options, plist_t *response); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair_with_options(lockdownd_client_t client, lockdownd_pair_record_t pair_record, plist_t options, plist_t *response); /** * Validates if the device is paired with the given HostID. If successful the @@ -332,7 +345,7 @@ lockdownd_error_t lockdownd_pair_with_options(lockdownd_client_t client, lockdow * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected, * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id */ -lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); /** * Unpairs the device with the given HostID and removes the pairing records @@ -348,7 +361,7 @@ lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_p * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected, * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id */ -lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); /** * Activates the device. Only works within an open session. @@ -365,7 +378,7 @@ lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_rec * LOCKDOWN_E_INVALID_ACTIVATION_RECORD if the device reports that the * activation_record is invalid */ -lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record); /** * Deactivates the device, returning it to the locked “Activate with iTunes” @@ -377,7 +390,7 @@ lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activati * LOCKDOWN_E_NO_RUNNING_SESSION if no session is open, * LOCKDOWN_E_PLIST_ERROR if the received plist is broken */ -lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client); /** * Tells the device to immediately enter recovery mode. @@ -386,7 +399,7 @@ lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client); * * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL */ -lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client); /** * Sends the Goodbye request to lockdownd signaling the end of communication. @@ -397,7 +410,90 @@ lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client); * is NULL, LOCKDOWN_E_PLIST_ERROR if the device did not acknowledge the * request */ -lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client); + +/** + * Creates a CU pairing session for the current lockdown client. + * This is required to allow lockdownd_cu_send_request_and_get_reply(), + * lockdownd_get_value_cu() and lockdonwd_pair_cu() requests, and eventually + * allows to perform an actual wireless pairing. + * + * Through the callback function, the PIN displayed on the device has to be + * supplied during the process. Currently, only AppleTV devices have this + * capability. + * + * @param client The lockdown client to perform the CU pairing for + * @param pairing_callback Callback function that is used to supply the PIN + * for the pairing process, but also to receive device information or + * pairing error messages. + * @param cb_user_data User data that will be passed as additional argument + * to the callback function. + * @param host_info (Optional) A dictionary containing host information to + * send to the device when finalizing the CU pairing. The supplied + * values will override the default values gathered for the current host. + * @param acl (Optional) A dictionary containing ACL information. Currently + * only com.apple.ScreenCapture:true and com.apple.developer:true are known + * valid ACL values, which are used as default when NULL is passed. + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG if one of the + * parameters is invalid, LOCKDOWN_E_PAIRING_FAILED if the pairing failed, + * or a LOCKDOWN_E_* error code otherwise. + */ +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_pairing_create(lockdownd_client_t client, lockdownd_cu_pairing_cb_t pairing_callback, void* cb_user_data, plist_t host_info, plist_t acl); + +/** + * Sends a request via lockdown client with established CU pairing session + * and attempts to retrieve a reply. This function is used internally + * by lockdownd_get_value_cu() and lockdownd_pair_cu(), but exposed here to + * allow custom requests being sent and their replies being received. + * + * @param client A lockdown client with an established CU pairing. + * @param request The request to perform. + * @param request_payload The payload for the request. + * @param reply (Optional) If not NULL, the plist_t will be set to the reply + * dictionary that has been received. Consumer is responsible to free it + * using plist_free() when no longer required. + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG if one of the + * parameters is invalid, LOCKDOWN_E_NO_RUNNING_SESSION if the current + * lockdown client does not have an established CU pairing session, + * or a LOCKDOWN_E_* error code otherwise. + */ +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_send_request_and_get_reply(lockdownd_client_t client, const char* request, plist_t request_payload, plist_t* reply); + +/** + * Retrieves a value using an optional domain and/or key name from a lockdown + * client with established CU pairing session. + * + * This is used to retrieve values that are only accessible after a CU pairing + * has been established, and would otherwise only be accessible with a valid + * device pairing. + * + * @param client A lockdown client with an established CU pairing. + * @param domain The domain to query on or NULL for global domain + * @param key The key name to request or NULL to query for all keys + * @param value A plist node representing the result value node + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG if one of the + * parameters is invalid, LOCKDOWN_E_NO_RUNNING_SESSION if the current + * lockdown client does not have an established CU pairing session, + * or a LOCKDOWN_E_* error code otherwise. + */ +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value_cu(lockdownd_client_t client, const char* domain, const char* key, plist_t* value); + +/** + * Perform a device pairing with a lockdown client that has an established + * CU pairing session. + * + * @param client A lockdown client with an established CU pairing. + * + * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client + * is NULL, LOCKDOWN_E_NO_RUNNING_SESSION if the current lockdown client + * does not have an established CU pairing session, or a LOCKDOWN_E_* error + * code otherwise. + */ +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair_cu(lockdownd_client_t client); + /* Helper */ @@ -408,7 +504,7 @@ lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client); * @param label The label to set or NULL to disable sending a label * */ -void lockdownd_client_set_label(lockdownd_client_t client, const char *label); +LIBIMOBILEDEVICE_API void lockdownd_client_set_label(lockdownd_client_t client, const char *label); /** * Returns the unique id of the device from lockdownd. @@ -419,7 +515,7 @@ void lockdownd_client_set_label(lockdownd_client_t client, const char *label); * * @return LOCKDOWN_E_SUCCESS on success */ -lockdownd_error_t lockdownd_get_device_udid(lockdownd_client_t client, char **udid); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_device_udid(lockdownd_client_t client, char **udid); /** * Retrieves the name of the device from lockdownd set by the user. @@ -430,7 +526,7 @@ lockdownd_error_t lockdownd_get_device_udid(lockdownd_client_t client, char **ud * * @return LOCKDOWN_E_SUCCESS on success */ -lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name); /** * Calculates and returns the data classes the device supports from lockdownd. @@ -445,7 +541,7 @@ lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **de * LOCKDOWN_E_NO_RUNNING_SESSION if no session is open, * LOCKDOWN_E_PLIST_ERROR if the received plist is broken */ -lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count); /** * Frees memory of an allocated array of data classes as returned by lockdownd_get_sync_data_classes() @@ -454,7 +550,7 @@ lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, cha * * @return LOCKDOWN_E_SUCCESS on success */ -lockdownd_error_t lockdownd_data_classes_free(char **classes); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_data_classes_free(char **classes); /** * Frees memory of a service descriptor as returned by lockdownd_start_service() @@ -463,16 +559,16 @@ lockdownd_error_t lockdownd_data_classes_free(char **classes); * * @return LOCKDOWN_E_SUCCESS on success */ -lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service); +LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service); /** * Gets a readable error string for a given lockdown error code. * - * @params err A lockdownd error code + * @param err A lockdownd error code * * @returns A readable error string */ -const char* lockdownd_strerror(lockdownd_error_t err); +LIBIMOBILEDEVICE_API const char* lockdownd_strerror(lockdownd_error_t err); #ifdef __cplusplus } |