diff options
| author | 2017-07-03 03:09:35 +0200 | |
|---|---|---|
| committer | 2017-07-03 03:09:35 +0200 | |
| commit | 0dbe76b4e75eef5d0e033aac99409fb6df36c512 (patch) | |
| tree | 8e1be338944418ac92470610088a5d7f3bacd523 | |
| parent | 5250024b53b799a427a486ae133ecb927f5c555e (diff) | |
| download | libimobiledevice-0dbe76b4e75eef5d0e033aac99409fb6df36c512.tar.gz libimobiledevice-0dbe76b4e75eef5d0e033aac99409fb6df36c512.tar.bz2 | |
mobileactivation: Add new functions required for drmHandshake / session mode device activation
| -rw-r--r-- | include/libimobiledevice/mobileactivation.h | 47 | ||||
| -rw-r--r-- | src/mobileactivation.c | 75 |
2 files changed, 119 insertions, 3 deletions
diff --git a/include/libimobiledevice/mobileactivation.h b/include/libimobiledevice/mobileactivation.h index bb977fe..bb1f3f4 100644 --- a/include/libimobiledevice/mobileactivation.h +++ b/include/libimobiledevice/mobileactivation.h | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | * @brief Handle device activation and deactivation. | 3 | * @brief Handle device activation and deactivation. |
| 4 | * \internal | 4 | * \internal |
| 5 | * | 5 | * |
| 6 | * Copyright (c) 2016 Nikias Bassen, All Rights Reserved. | 6 | * Copyright (c) 2016-2017 Nikias Bassen, All Rights Reserved. |
| 7 | * | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or | 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public | 9 | * modify it under the terms of the GNU Lesser General Public |
| @@ -104,6 +104,20 @@ mobileactivation_error_t mobileactivation_client_free(mobileactivation_client_t | |||
| 104 | mobileactivation_error_t mobileactivation_get_activation_state(mobileactivation_client_t client, plist_t *state); | 104 | mobileactivation_error_t mobileactivation_get_activation_state(mobileactivation_client_t client, plist_t *state); |
| 105 | 105 | ||
| 106 | /** | 106 | /** |
| 107 | * Retrieves a session blob required for 'drmHandshake' via albert.apple.com. | ||
| 108 | * | ||
| 109 | * @param client The mobileactivation client | ||
| 110 | * @param blob Pointer to a plist_t variable that will be set to the | ||
| 111 | * session blob created by the mobielactivation service. The | ||
| 112 | * consumer is responsible for freeing the returned object using | ||
| 113 | * plist_free(). | ||
| 114 | * | ||
| 115 | * @return MOBILEACTIVATION_E_SUCCESS on success, or an MOBILEACTIVATION_E_* | ||
| 116 | * error code otherwise. | ||
| 117 | */ | ||
| 118 | mobileactivation_error_t mobileactivation_create_activation_session_info(mobileactivation_client_t client, plist_t *blob); | ||
| 119 | |||
| 120 | /** | ||
| 107 | * Retrieves the activation info required for device activation. | 121 | * Retrieves the activation info required for device activation. |
| 108 | * | 122 | * |
| 109 | * @param client The mobileactivation client | 123 | * @param client The mobileactivation client |
| @@ -118,6 +132,24 @@ mobileactivation_error_t mobileactivation_get_activation_state(mobileactivation_ | |||
| 118 | mobileactivation_error_t mobileactivation_create_activation_info(mobileactivation_client_t client, plist_t *info); | 132 | mobileactivation_error_t mobileactivation_create_activation_info(mobileactivation_client_t client, plist_t *info); |
| 119 | 133 | ||
| 120 | /** | 134 | /** |
| 135 | * Retrieves the activation info required for device activation in 'session' | ||
| 136 | * mode. This function expects a handshake result retrieved from | ||
| 137 | * https://albert.apple.com/deviceservies/drmHandshake with a blob | ||
| 138 | * provided by mobileactivation_create_activation_session_info(). | ||
| 139 | * | ||
| 140 | * @param client The mobileactivation client | ||
| 141 | * @aram handshake_result The handshake result returned from drmHandshake | ||
| 142 | * @param info Pointer to a plist_t variable that will be set to the | ||
| 143 | * activation info created by the mobileactivation service. The | ||
| 144 | * consumer is responsible for freeing the returned object using | ||
| 145 | * plist_free(). | ||
| 146 | * | ||
| 147 | * @return MOBILEACTIVATION_E_SUCCESS on success, or an MOBILEACTIVATION_E_* | ||
| 148 | * error code otherwise. | ||
| 149 | */ | ||
| 150 | mobileactivation_error_t mobileactivation_create_activation_info_with_session(mobileactivation_client_t client, plist_t handshake_result, plist_t *info); | ||
| 151 | |||
| 152 | /** | ||
| 121 | * Activates the device with the given activation record. | 153 | * Activates the device with the given activation record. |
| 122 | * The activation record plist dictionary must be obtained using the | 154 | * The activation record plist dictionary must be obtained using the |
| 123 | * activation protocol requesting from Apple's https webservice. | 155 | * activation protocol requesting from Apple's https webservice. |
| @@ -131,6 +163,19 @@ mobileactivation_error_t mobileactivation_create_activation_info(mobileactivatio | |||
| 131 | mobileactivation_error_t mobileactivation_activate(mobileactivation_client_t client, plist_t activation_record); | 163 | mobileactivation_error_t mobileactivation_activate(mobileactivation_client_t client, plist_t activation_record); |
| 132 | 164 | ||
| 133 | /** | 165 | /** |
| 166 | * Activates the device with the given activation record in 'session' mode. | ||
| 167 | * The activation record plist dictionary must be obtained using the | ||
| 168 | * activation protocol requesting from Apple's https webservice. | ||
| 169 | * | ||
| 170 | * @param client The mobileactivation client | ||
| 171 | * @param activation_record The activation record plist dictionary | ||
| 172 | * | ||
| 173 | * @return MOBILEACTIVATION_E_SUCCESS on success, or an MOBILEACTIVATION_E_* | ||
| 174 | * error code otherwise. | ||
| 175 | */ | ||
| 176 | mobileactivation_error_t mobileactivation_activate_with_session(mobileactivation_client_t client, plist_t activation_record); | ||
| 177 | |||
| 178 | /** | ||
| 134 | * Deactivates the device. | 179 | * Deactivates the device. |
| 135 | * | 180 | * |
| 136 | * @param client The mobileactivation client | 181 | * @param client The mobileactivation client |
diff --git a/src/mobileactivation.c b/src/mobileactivation.c index f14eb73..7ae35bb 100644 --- a/src/mobileactivation.c +++ b/src/mobileactivation.c | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | * mobileactivation.c | 2 | * mobileactivation.c |
| 3 | * com.apple.mobileactivationd service implementation. | 3 | * com.apple.mobileactivationd service implementation. |
| 4 | * | 4 | * |
| 5 | * Copyright (c) 2016 Nikias Bassen, All Rights Reserved. | 5 | * Copyright (c) 2016-2017 Nikias Bassen, All Rights Reserved. |
| 6 | * | 6 | * |
| 7 | * This library is free software; you can redistribute it and/or | 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public | 8 | * modify it under the terms of the GNU Lesser General Public |
| @@ -89,6 +89,17 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_client_free(mobil | |||
| 89 | return MOBILEACTIVATION_E_SUCCESS; | 89 | return MOBILEACTIVATION_E_SUCCESS; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | static plist_t plist_data_from_plist(plist_t plist) | ||
| 93 | { | ||
| 94 | plist_t result = NULL; | ||
| 95 | char *xml = NULL; | ||
| 96 | uint32_t xml_len = 0; | ||
| 97 | plist_to_xml(plist, &xml, &xml_len); | ||
| 98 | result = plist_new_data(xml, xml_len); | ||
| 99 | free(xml); | ||
| 100 | return result; | ||
| 101 | } | ||
| 102 | |||
| 92 | static mobileactivation_error_t mobileactivation_check_result(plist_t dict, const char *command) | 103 | static mobileactivation_error_t mobileactivation_check_result(plist_t dict, const char *command) |
| 93 | { | 104 | { |
| 94 | mobileactivation_error_t ret = MOBILEACTIVATION_E_UNKNOWN_ERROR; | 105 | mobileactivation_error_t ret = MOBILEACTIVATION_E_UNKNOWN_ERROR; |
| @@ -104,8 +115,8 @@ static mobileactivation_error_t mobileactivation_check_result(plist_t dict, cons | |||
| 104 | char *errmsg = NULL; | 115 | char *errmsg = NULL; |
| 105 | plist_get_string_val(err_node, &errmsg); | 116 | plist_get_string_val(err_node, &errmsg); |
| 106 | debug_info("ERROR: %s: %s", command, errmsg); | 117 | debug_info("ERROR: %s: %s", command, errmsg); |
| 107 | free(errmsg); | ||
| 108 | ret = MOBILEACTIVATION_E_REQUEST_FAILED; | 118 | ret = MOBILEACTIVATION_E_REQUEST_FAILED; |
| 119 | free(errmsg); | ||
| 109 | } | 120 | } |
| 110 | return ret; | 121 | return ret; |
| 111 | } | 122 | } |
| @@ -160,6 +171,26 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_get_activation_st | |||
| 160 | return ret; | 171 | return ret; |
| 161 | } | 172 | } |
| 162 | 173 | ||
| 174 | LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_create_activation_session_info(mobileactivation_client_t client, plist_t *blob) | ||
| 175 | { | ||
| 176 | if (!client || !blob) | ||
| 177 | return MOBILEACTIVATION_E_INVALID_ARG; | ||
| 178 | |||
| 179 | plist_t result = NULL; | ||
| 180 | mobileactivation_error_t ret = mobileactivation_send_command(client, "CreateTunnel1SessionInfoRequest", NULL, &result); | ||
| 181 | if (ret == MOBILEACTIVATION_E_SUCCESS) { | ||
| 182 | plist_t node = plist_dict_get_item(result, "Value"); | ||
| 183 | if (!node) { | ||
| 184 | debug_info("ERROR: CreateTunnel1SessionInfoRequest command returned success but has no value in reply"); | ||
| 185 | ret = MOBILEACTIVATION_E_UNKNOWN_ERROR; | ||
| 186 | } else { | ||
| 187 | *blob = plist_copy(node); | ||
| 188 | } | ||
| 189 | } | ||
| 190 | |||
| 191 | return ret; | ||
| 192 | } | ||
| 193 | |||
| 163 | LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_create_activation_info(mobileactivation_client_t client, plist_t *info) | 194 | LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_create_activation_info(mobileactivation_client_t client, plist_t *info) |
| 164 | { | 195 | { |
| 165 | if (!client || !info) | 196 | if (!client || !info) |
| @@ -179,6 +210,30 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_create_activation | |||
| 179 | plist_free(result); | 210 | plist_free(result); |
| 180 | result = NULL; | 211 | result = NULL; |
| 181 | 212 | ||
| 213 | return ret; | ||
| 214 | } | ||
| 215 | |||
| 216 | LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_create_activation_info_with_session(mobileactivation_client_t client, plist_t handshake_response, plist_t *info) | ||
| 217 | { | ||
| 218 | if (!client || !info) | ||
| 219 | return MOBILEACTIVATION_E_INVALID_ARG; | ||
| 220 | |||
| 221 | plist_t result = NULL; | ||
| 222 | plist_t data = plist_data_from_plist(handshake_response); | ||
| 223 | mobileactivation_error_t ret = mobileactivation_send_command(client, "CreateTunnel1ActivationInfoRequest", data, &result); | ||
| 224 | plist_free(data); | ||
| 225 | if (ret == MOBILEACTIVATION_E_SUCCESS) { | ||
| 226 | plist_t node = plist_dict_get_item(result, "Value"); | ||
| 227 | if (!node) { | ||
| 228 | debug_info("ERROR: CreateTunnel1ActivationInfoRequest command returned success but has no value in reply"); | ||
| 229 | ret = MOBILEACTIVATION_E_UNKNOWN_ERROR; | ||
| 230 | } else { | ||
| 231 | *info = plist_copy(node); | ||
| 232 | } | ||
| 233 | } | ||
| 234 | plist_free(result); | ||
| 235 | result = NULL; | ||
| 236 | |||
| 182 | return ret; | 237 | return ret; |
| 183 | } | 238 | } |
| 184 | 239 | ||
| @@ -195,6 +250,22 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_activate(mobileac | |||
| 195 | return ret; | 250 | return ret; |
| 196 | } | 251 | } |
| 197 | 252 | ||
| 253 | LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_activate_with_session(mobileactivation_client_t client, plist_t activation_record) | ||
| 254 | { | ||
| 255 | if (!client || !activation_record) | ||
| 256 | return MOBILEACTIVATION_E_INVALID_ARG; | ||
| 257 | |||
| 258 | plist_t result = NULL; | ||
| 259 | plist_t data = plist_data_from_plist(activation_record); | ||
| 260 | mobileactivation_error_t ret = mobileactivation_send_command(client, "HandleActivationInfoWithSessionRequest", data, &result); | ||
| 261 | plist_free(data); | ||
| 262 | plist_free(result); | ||
| 263 | result = NULL; | ||
| 264 | |||
| 265 | return ret; | ||
| 266 | } | ||
| 267 | |||
| 268 | |||
| 198 | LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_deactivate(mobileactivation_client_t client) | 269 | LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_deactivate(mobileactivation_client_t client) |
| 199 | { | 270 | { |
| 200 | if (!client) | 271 | if (!client) |
