summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
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)
* the StopSession Request to the device.
*
* @param control The lockdown client
+ *
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_stop_session(lockdownd_client_t client)
+lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client)
{
if (!client)
- return IPHONE_E_INVALID_ARG;
+ return LOCKDOWN_E_INVALID_ARG;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
plist_t dict = plist_new_dict();
plist_add_sub_key_el(dict, "Request");
@@ -151,13 +153,13 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client)
if (!dict) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: LOCKDOWN_E_PLIST_ERROR\n", __func__);
- return IPHONE_E_PLIST_ERROR;
+ return LOCKDOWN_E_PLIST_ERROR;
}
- ret = IPHONE_E_UNKNOWN_ERROR;
+ ret = LOCKDOWN_E_UNKNOWN_ERROR;
if (lockdown_check_result(dict, "StopSession") == RESULT_SUCCESS) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
plist_free(dict);
dict = NULL;
@@ -171,14 +173,16 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client)
* performing a close notify, which is done by "gnutls_bye".
*
* @param client The lockdown client
+ *
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-static iphone_error_t lockdownd_stop_ssl_session(lockdownd_client_t client)
+static lockdownd_error_t lockdownd_stop_ssl_session(lockdownd_client_t client)
{
if (!client) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: invalid argument!\n", __func__);
- return IPHONE_E_INVALID_ARG;
+ return LOCKDOWN_E_INVALID_ARG;
}
- iphone_error_t ret = IPHONE_E_SUCCESS;
+ lockdownd_error_t ret = LOCKDOWN_E_SUCCESS;
if (client->in_SSL) {
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)
/** Closes the lockdownd client and does the necessary housekeeping.
*
* @param client The lockdown client
+ *
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_free_client(lockdownd_client_t client)
+lockdownd_error_t lockdownd_client_free(lockdownd_client_t client)
{
if (!client)
- return IPHONE_E_INVALID_ARG;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ return LOCKDOWN_E_INVALID_ARG;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
lockdownd_stop_ssl_session(client);
@@ -224,13 +230,13 @@ iphone_error_t lockdownd_free_client(lockdownd_client_t client)
* @param control The lockdownd client
* @param plist The plist to store the received data
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
+lockdownd_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
{
if (!client || !plist || (plist && *plist))
- return IPHONE_E_INVALID_ARG;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ return LOCKDOWN_E_INVALID_ARG;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
char *receive = NULL;
uint32_t datalen = 0, bytes = 0, received_bytes = 0;
@@ -240,10 +246,10 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
ssize_t res = gnutls_record_recv(*client->ssl_session, &datalen, sizeof(datalen));
if (res < 0) {
log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_recv: Error occured: %s\n", gnutls_strerror(res));
- return IPHONE_E_SSL_ERROR;
+ return LOCKDOWN_E_SSL_ERROR;
} else {
bytes = res;
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
}
datalen = ntohl(datalen);
@@ -253,32 +259,32 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
/* fill buffer and request more packets if needed */
if (!client->in_SSL) {
- while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) {
+ while ((received_bytes < datalen) && (ret == LOCKDOWN_E_SUCCESS)) {
ret = usbmuxd_recv(client->sfd, receive + received_bytes, datalen - received_bytes, &bytes);
received_bytes += bytes;
}
} else {
ssize_t res = 0;
- while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) {
+ while ((received_bytes < datalen) && (ret == LOCKDOWN_E_SUCCESS)) {
res = gnutls_record_recv(*client->ssl_session, receive + received_bytes, datalen - received_bytes);
if (res < 0) {
log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_recv: Error occured: %s\n", gnutls_strerror(res));
- ret = IPHONE_E_SSL_ERROR;
+ ret = LOCKDOWN_E_SSL_ERROR;
} else {
received_bytes += res;
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
}
}
- if (ret != IPHONE_E_SUCCESS) {
+ if (ret != LOCKDOWN_E_SUCCESS) {
free(receive);
return ret;
}
if ((ssize_t)received_bytes <= 0) {
free(receive);
- return IPHONE_E_NOT_ENOUGH_DATA;
+ return LOCKDOWN_E_NOT_ENOUGH_DATA;
}
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)
free(receive);
if (!*plist)
- ret = IPHONE_E_PLIST_ERROR;
+ ret = LOCKDOWN_E_PLIST_ERROR;
return ret;
}
@@ -299,17 +305,17 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
* @param client The lockdownd client
* @param plist The plist to send
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist)
+lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist)
{
if (!client || !plist)
- return IPHONE_E_INVALID_ARG;
+ return LOCKDOWN_E_INVALID_ARG;
char *real_query;
int bytes;
char *XMLContent = NULL;
uint32_t length = 0;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
plist_to_xml(plist, &XMLContent, &length);
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)
ssize_t res = gnutls_record_send(*client->ssl_session, real_query, ntohl(length) + sizeof(length));
if (res < 0) {
log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_send: Error occured: %s\n", gnutls_strerror(res));
- ret = IPHONE_E_SSL_ERROR;
+ ret = LOCKDOWN_E_SSL_ERROR;
} else {
bytes = res;
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
}
- if (ret == IPHONE_E_SUCCESS) {
+ if (ret == LOCKDOWN_E_SUCCESS) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sent it!\n", __func__);
} else {
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)
*
* @param client The lockdownd client
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_query_type(lockdownd_client_t client)
+lockdownd_error_t lockdownd_query_type(lockdownd_client_t client)
{
if (!client)
- return IPHONE_E_INVALID_ARG;
+ return LOCKDOWN_E_INVALID_ARG;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
plist_t dict = plist_new_dict();
plist_add_sub_key_el(dict, "Request");
@@ -368,13 +374,13 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client)
ret = lockdownd_recv(client, &dict);
- if (IPHONE_E_SUCCESS != ret)
+ if (LOCKDOWN_E_SUCCESS != ret)
return ret;
- ret = IPHONE_E_UNKNOWN_ERROR;
+ ret = LOCKDOWN_E_UNKNOWN_ERROR;
if (lockdown_check_result(dict, "QueryType") == RESULT_SUCCESS) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
plist_free(dict);
dict = NULL;
@@ -389,15 +395,15 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client)
* @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 an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value)
+lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value)
{
if (!client)
- return IPHONE_E_INVALID_ARG;
+ return LOCKDOWN_E_INVALID_ARG;
plist_t dict = NULL;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
/* setup request plist */
dict = plist_new_dict();
@@ -418,19 +424,19 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain
plist_free(dict);
dict = NULL;
- if (ret != IPHONE_E_SUCCESS)
+ if (ret != LOCKDOWN_E_SUCCESS)
return ret;
/* Now get device's answer */
ret = lockdownd_recv(client, &dict);
- if (ret != IPHONE_E_SUCCESS)
+ if (ret != LOCKDOWN_E_SUCCESS)
return ret;
if (lockdown_check_result(dict, "GetValue") == RESULT_SUCCESS) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
- if (ret != IPHONE_E_SUCCESS) {
+ if (ret != LOCKDOWN_E_SUCCESS) {
plist_free(dict);
return ret;
}
@@ -462,15 +468,15 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain
* @param key the key name to set the value or NULL to set a value dict plist
* @param value a plist node of any node type representing the value to set
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value)
+lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value)
{
if (!client || !value)
- return IPHONE_E_INVALID_ARG;
+ return LOCKDOWN_E_INVALID_ARG;
plist_t dict = NULL;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
/* setup request plist */
dict = plist_new_dict();
@@ -494,20 +500,20 @@ iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain
plist_free(dict);
dict = NULL;
- if (ret != IPHONE_E_SUCCESS)
+ if (ret != LOCKDOWN_E_SUCCESS)
return ret;
/* Now get device's answer */
ret = lockdownd_recv(client, &dict);
- if (ret != IPHONE_E_SUCCESS)
+ if (ret != LOCKDOWN_E_SUCCESS)
return ret;
if (lockdown_check_result(dict, "SetValue") == RESULT_SUCCESS) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
- if (ret != IPHONE_E_SUCCESS) {
+ if (ret != LOCKDOWN_E_SUCCESS) {
plist_free(dict);
return ret;
}
@@ -524,15 +530,15 @@ iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain
* @param domain the domain to query on or NULL for global domain
* @param key the key name to remove or NULL remove all keys for the current domain
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key)
+lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key)
{
if (!client)
- return IPHONE_E_INVALID_ARG;
+ return LOCKDOWN_E_INVALID_ARG;
plist_t dict = NULL;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
/* setup request plist */
dict = plist_new_dict();
@@ -553,20 +559,20 @@ iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *dom
plist_free(dict);
dict = NULL;
- if (ret != IPHONE_E_SUCCESS)
+ if (ret != LOCKDOWN_E_SUCCESS)
return ret;
/* Now get device's answer */
ret = lockdownd_recv(client, &dict);
- if (ret != IPHONE_E_SUCCESS)
+ if (ret != LOCKDOWN_E_SUCCESS)
return ret;
if (lockdown_check_result(dict, "RemoveValue") == RESULT_SUCCESS) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
- if (ret != IPHONE_E_SUCCESS) {
+ if (ret != LOCKDOWN_E_SUCCESS) {
plist_free(dict);
return ret;
}
@@ -577,18 +583,18 @@ iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *dom
/** Asks for the device's unique id. Part of the lockdownd handshake.
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_get_device_uid(lockdownd_client_t client, char **uid)
+lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t client, char **uuid)
{
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
plist_t value = NULL;
ret = lockdownd_get_value(client, NULL, "UniqueDeviceID", &value);
- if (ret != IPHONE_E_SUCCESS) {
+ if (ret != LOCKDOWN_E_SUCCESS) {
return ret;
}
- plist_get_string_val(value, uid);
+ plist_get_string_val(value, uuid);
plist_free(value);
value = NULL;
@@ -597,17 +603,17 @@ iphone_error_t lockdownd_get_device_uid(lockdownd_client_t client, char **uid)
/** Askes for the device's public key. Part of the lockdownd handshake.
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key)
+lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key)
{
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
plist_t value = NULL;
char *value_value = NULL;
uint64_t size = 0;
ret = lockdownd_get_value(client, NULL, "DevicePublicKey", &value);
- if (ret != IPHONE_E_SUCCESS) {
+ if (ret != LOCKDOWN_E_SUCCESS) {
return ret;
}
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
* @param client The pointer to the location of the new lockdownd_client
*
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name)
+lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name)
{
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
plist_t value = NULL;
ret = lockdownd_get_value(client, NULL, "DeviceName", &value);
- if (ret != IPHONE_E_SUCCESS) {
+ if (ret != LOCKDOWN_E_SUCCESS) {
return ret;
}
plist_get_string_val(value, device_name);
@@ -649,19 +655,19 @@ iphone_error_t lockdownd_get_device_name(lockdownd_client_t client, char **devic
* @param phone The iPhone to create a lockdownd client for
* @param client The pointer to the location of the new lockdownd_client
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *client)
+lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_t *client)
{
if (!device || !client || (client && *client))
- return IPHONE_E_INVALID_ARG;
- iphone_error_t ret = IPHONE_E_SUCCESS;
+ return LOCKDOWN_E_INVALID_ARG;
+ lockdownd_error_t ret = LOCKDOWN_E_SUCCESS;
char *host_id = NULL;
int sfd = usbmuxd_connect(device->handle, 0xf27e);
if (sfd < 0) {
log_debug_msg("%s: could not connect to lockdownd (device handle %d)\n", __func__, device->handle);
- return IPHONE_E_UNKNOWN_ERROR;
+ return LOCKDOWN_E_MUX_ERROR;
}
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 *
client_loc->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t));
client_loc->in_SSL = 0;
+ if (LOCKDOWN_E_SUCCESS != lockdownd_query_type(client_loc)) {
log_debug_msg("%s: QueryType failed in the lockdownd client.\n", __func__);
- ret = IPHONE_E_NOT_ENOUGH_DATA;
+ ret = LOCKDOWN_E_NOT_ENOUGH_DATA;
}
char *uuid = NULL;
ret = iphone_device_get_uuid(device, &uuid);
- if (IPHONE_E_SUCCESS != ret) {
+ if (LOCKDOWN_E_SUCCESS != ret) {
log_debug_msg("%s: failed to get device uuid.\n", __func__);
}
log_debug_msg("%s: device uuid: %s\n", __func__, uuid);
userpref_get_host_id(&host_id);
- if (IPHONE_E_SUCCESS == ret && !host_id) {
- ret = IPHONE_E_INVALID_CONF;
+ if (LOCKDOWN_E_SUCCESS == ret && !host_id) {
+ ret = LOCKDOWN_E_INVALID_CONF;
}
- if (IPHONE_E_SUCCESS == ret && !userpref_has_device_public_key(uuid))
+ if (LOCKDOWN_E_SUCCESS == ret && !userpref_has_device_public_key(uuid))
ret = lockdownd_pair(client_loc, uuid, host_id);
if (uuid) {
@@ -693,10 +700,10 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *
uuid = NULL;
}
- if (IPHONE_E_SUCCESS == ret) {
+ if (LOCKDOWN_E_SUCCESS == ret) {
ret = lockdownd_start_ssl_session(client_loc, host_id);
- if (IPHONE_E_SUCCESS != ret) {
- ret = IPHONE_E_SSL_ERROR;
+ if (LOCKDOWN_E_SUCCESS != ret) {
+ ret = LOCKDOWN_E_SSL_ERROR;
log_debug_msg("%s: SSL Session opening failed.\n", __func__);
}
@@ -705,7 +712,7 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *
host_id = NULL;
}
- if (IPHONE_E_SUCCESS == ret)
+ if (LOCKDOWN_E_SUCCESS == ret)
*client = client_loc;
}
@@ -715,11 +722,11 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *
/** Generates the appropriate keys and pairs the device. It's part of the
* lockdownd handshake.
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_id)
+lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *uuid, char *host_id)
{
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
plist_t dict = NULL;
plist_t dict_record = NULL;
@@ -729,14 +736,14 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i
gnutls_datum_t public_key = { NULL, 0 };
ret = lockdownd_get_device_public_key(client, &public_key);
- if (ret != IPHONE_E_SUCCESS) {
+ if (ret != LOCKDOWN_E_SUCCESS) {
log_debug_msg("%s: device refused to send public key.\n", __func__);
return ret;
}
log_debug_msg("%s: device public key follows:\n%s\n", __func__, public_key.data);
ret = lockdownd_gen_pair_cert(public_key, &device_cert, &host_cert, &root_cert);
- if (ret != IPHONE_E_SUCCESS) {
+ if (ret != LOCKDOWN_E_SUCCESS) {
free(public_key.data);
return ret;
}
@@ -762,28 +769,28 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i
plist_free(dict);
dict = NULL;
- if (ret != IPHONE_E_SUCCESS)
+ if (ret != LOCKDOWN_E_SUCCESS)
return ret;
/* Now get iPhone's answer */
ret = lockdownd_recv(client, &dict);
- if (ret != IPHONE_E_SUCCESS)
+ if (ret != LOCKDOWN_E_SUCCESS)
return ret;
if (lockdown_check_result(dict, "Pair") == RESULT_SUCCESS) {
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
plist_free(dict);
dict = NULL;
/* store public key in config if pairing succeeded */
- if (ret == IPHONE_E_SUCCESS) {
+ if (ret == LOCKDOWN_E_SUCCESS) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__);
userpref_set_device_public_key(uuid, public_key);
} else {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__);
- ret = IPHONE_E_PAIRING_FAILED;
+ ret = LOCKDOWN_E_PAIRING_FAILED;
}
free(public_key.data);
return ret;
@@ -794,14 +801,14 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i
*
* @param client The lockdown client
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client)
+lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client)
{
if (!client)
- return IPHONE_E_INVALID_ARG;
+ return LOCKDOWN_E_INVALID_ARG;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
plist_t dict = plist_new_dict();
plist_add_sub_key_el(dict, "Request");
@@ -817,7 +824,7 @@ iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client)
if (lockdown_check_result(dict, "EnterRecovery") == RESULT_SUCCESS) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
plist_free(dict);
dict = NULL;
@@ -830,14 +837,14 @@ iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client)
*
* @param client The lockdown client
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_goodbye(lockdownd_client_t client)
+lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client)
{
if (!client)
- return IPHONE_E_INVALID_ARG;
+ return LOCKDOWN_E_INVALID_ARG;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
plist_t dict = plist_new_dict();
plist_add_sub_key_el(dict, "Request");
@@ -852,12 +859,12 @@ iphone_error_t lockdownd_goodbye(lockdownd_client_t client)
ret = lockdownd_recv(client, &dict);
if (!dict) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: did not get goodbye response back\n", __func__);
- return IPHONE_E_PLIST_ERROR;
+ return LOCKDOWN_E_PLIST_ERROR;
}
if (lockdown_check_result(dict, "Goodbye") == RESULT_SUCCESS) {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
plist_free(dict);
dict = NULL;
@@ -867,14 +874,14 @@ iphone_error_t lockdownd_goodbye(lockdownd_client_t client)
/** Generates the device certificate from the public key as well as the host
* and root certificates.
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert,
+lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert,
gnutls_datum_t * ohost_cert, gnutls_datum_t * oroot_cert)
{
if (!public_key.data || !odevice_cert || !ohost_cert || !oroot_cert)
- return IPHONE_E_INVALID_ARG;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ return LOCKDOWN_E_INVALID_ARG;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
userpref_error_t uret = USERPREF_E_UNKNOWN_ERROR;
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
ret1 = asn1_read_value(asn1_pub_key, "modulus", modulus.data, (int*)&modulus.size);
ret2 = asn1_read_value(asn1_pub_key, "publicExponent", exponent.data, (int*)&exponent.size);
if (ASN1_SUCCESS == ret1 && ASN1_SUCCESS == ret2)
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
if (asn1_pub_key)
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
}
/* now generate certifcates */
- if (IPHONE_E_SUCCESS == ret && 0 != modulus.size && 0 != exponent.size) {
+ if (LOCKDOWN_E_SUCCESS == ret && 0 != modulus.size && 0 != exponent.size) {
gnutls_global_init();
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
gnutls_x509_crt_set_expiration_time(dev_cert, time(NULL) + (60 * 60 * 24 * 365 * 10));
gnutls_x509_crt_sign(dev_cert, root_cert, root_privkey);
- if (IPHONE_E_SUCCESS == ret) {
+ if (LOCKDOWN_E_SUCCESS == ret) {
/* if everything went well, export in PEM format */
gnutls_datum_t dev_pem = { NULL, 0 };
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
switch(uret) {
case USERPREF_E_INVALID_ARG:
- ret = IPHONE_E_INVALID_ARG;
+ ret = LOCKDOWN_E_INVALID_ARG;
break;
case USERPREF_E_INVALID_CONF:
- ret = IPHONE_E_INVALID_CONF;
+ ret = LOCKDOWN_E_INVALID_CONF;
break;
case USERPREF_E_SSL_ERROR:
- ret = IPHONE_E_SSL_ERROR;
+ ret = LOCKDOWN_E_SSL_ERROR;
default:
break;
}
@@ -1005,14 +1012,14 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t
* @param client The lockdownd client
* @param HostID The HostID used with this phone
*
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID)
+lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID)
{
plist_t dict = NULL;
uint32_t return_me = 0;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
client->session_id[0] = '\0';
/* Setup DevicePublicKey request plist */
@@ -1026,13 +1033,13 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
plist_free(dict);
dict = NULL;
- if (ret != IPHONE_E_SUCCESS)
+ if (ret != LOCKDOWN_E_SUCCESS)
return ret;
ret = lockdownd_recv(client, &dict);
if (!dict)
- return IPHONE_E_PLIST_ERROR;
+ return LOCKDOWN_E_PLIST_ERROR;
if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) {
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
char *host_id = NULL;
userpref_get_host_id(&host_id);
- if (IPHONE_E_SUCCESS == lockdownd_get_device_uuid(client, &uuid) ) {
- if (IPHONE_E_SUCCESS == lockdownd_pair(client, uuid, host_id) ) {
+ if (LOCKDOWN_E_SUCCESS == lockdownd_get_device_uuid(client, &uuid) ) {
+ if (LOCKDOWN_E_SUCCESS == lockdownd_pair(client, uuid, host_id) ) {
/* start session again */
plist_free(dict);
dict = plist_new_dict();
@@ -1070,7 +1077,7 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
}
}
- ret = IPHONE_E_SSL_ERROR;
+ ret = LOCKDOWN_E_SSL_ERROR;
if (lockdown_check_result(dict, "StartSession") == RESULT_SUCCESS) {
// Set up GnuTLS...
//gnutls_anon_client_credentials_t anoncred;
@@ -1114,13 +1121,13 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS reported something wrong.\n", __func__);
gnutls_perror(return_me);
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: oh.. errno says %s\n", __func__, strerror(errno));
- return IPHONE_E_SSL_ERROR;
+ return LOCKDOWN_E_SSL_ERROR;
} else {
client->in_SSL = 1;
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
}
- //store session id
+ /* store session id */
plist_t session_node = plist_find_node_by_key(dict, "SessionID");
if (session_node) {
@@ -1133,7 +1140,7 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
plist_get_string_val(session_node_val, &session_id);
if (session_node_val_type == PLIST_STRING && session_id) {
- // we need to store the session ID for StopSession
+ /* we need to store the session ID for StopSession */
strcpy(client->session_id, session_id);
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id);
}
@@ -1145,11 +1152,11 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
plist_free(dict);
dict = NULL;
- if (ret == IPHONE_E_SUCCESS)
+ if (ret == LOCKDOWN_E_SUCCESS)
return ret;
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Apparently failed negotiating with lockdownd.\n", __func__);
- return IPHONE_E_SSL_ERROR;
+ return LOCKDOWN_E_SSL_ERROR;
}
/** gnutls callback for writing data to the iPhone.
@@ -1196,7 +1203,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
// repeat until we have the full data or an error occurs.
do {
- if ((res = usbmuxd_recv(client->sfd, recv_buffer, this_len, (uint32_t*)&bytes)) != IPHONE_E_SUCCESS) {
+ if ((res = usbmuxd_recv(client->sfd, recv_buffer, this_len, (uint32_t*)&bytes)) != LOCKDOWN_E_SUCCESS) {
log_debug_msg("%s: ERROR: usbmux_recv returned %d\n", __func__, res);
return res;
}
@@ -1230,23 +1237,23 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
* @param service The name of the service to start
* @param port The port number the service was started on
- * @return an error code (IPHONE_E_SUCCESS on success)
+ * @return an error code (LOCKDOWN_E_SUCCESS on success)
*/
-iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, int *port)
+lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, int *port)
{
if (!client || !service || !port)
- return IPHONE_E_INVALID_ARG;
+ return LOCKDOWN_E_INVALID_ARG;
char *host_id = NULL;
userpref_get_host_id(&host_id);
if (!host_id)
- return IPHONE_E_INVALID_CONF;
+ return LOCKDOWN_E_INVALID_CONF;
if (!client->in_SSL && !lockdownd_start_ssl_session(client, host_id))
- return IPHONE_E_SSL_ERROR;
+ return LOCKDOWN_E_SSL_ERROR;
plist_t dict = NULL;
uint32_t port_loc = 0;
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
free(host_id);
host_id = NULL;
@@ -1262,18 +1269,18 @@ iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *se
plist_free(dict);
dict = NULL;
- if (IPHONE_E_SUCCESS != ret)
+ if (LOCKDOWN_E_SUCCESS != ret)
return ret;
ret = lockdownd_recv(client, &dict);
- if (IPHONE_E_SUCCESS != ret)
+ if (LOCKDOWN_E_SUCCESS != ret)
return ret;
if (!dict)
- return IPHONE_E_PLIST_ERROR;
+ return LOCKDOWN_E_PLIST_ERROR;
- ret = IPHONE_E_UNKNOWN_ERROR;
+ ret = LOCKDOWN_E_UNKNOWN_ERROR;
if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) {
plist_t port_key_node = plist_find_node_by_key(dict, "Port");
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
plist_get_uint_val(port_value_node, &port_value);
if (port_key && !strcmp(port_key, "Port")) {
port_loc = port_value;
- ret = IPHONE_E_SUCCESS;
+ ret = LOCKDOWN_E_SUCCESS;
}
if (port_key)
free(port_key);
- if (port && ret == IPHONE_E_SUCCESS)
+ if (port && ret == LOCKDOWN_E_SUCCESS)
*port = port_loc;
}
}
else
- ret = IPHONE_E_START_SERVICE_FAILED;
+ ret = LOCKDOWN_E_START_SERVICE_FAILED;
plist_free(dict);
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 @@
#include <gnutls/gnutls.h>
#include <string.h>
+
#include "libiphone/lockdown.h"
struct lockdownd_client_int {
@@ -33,13 +34,14 @@ struct lockdownd_client_int {
char session_id[40];
};
-iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key);
-iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * device_cert,
+lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key);
+lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * device_cert,
gnutls_datum_t * host_cert, gnutls_datum_t * root_cert);
-// SSL functions
-iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID);
+/* SSL functions */
+lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID);
ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_t length);
ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size_t length);
+
#endif