summaryrefslogtreecommitdiffstats
path: root/src/property_list_service.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2010-01-13 00:11:43 +0100
committerGravatar Martin Szulecki2010-01-13 01:03:03 +0100
commitb578398a2883e1e81dbf5bdbd8b8ae917bf9e29d (patch)
tree03e25d7cca039f6c97fcaec4891327c6b58e23fe /src/property_list_service.c
parent65346c9ddd92e6ea3650040d791a411b9ac308af (diff)
downloadlibimobiledevice-b578398a2883e1e81dbf5bdbd8b8ae917bf9e29d.tar.gz
libimobiledevice-b578398a2883e1e81dbf5bdbd8b8ae917bf9e29d.tar.bz2
lockdown/property_list_service: use new SSL code
Diffstat (limited to 'src/property_list_service.c')
-rw-r--r--src/property_list_service.c132
1 files changed, 38 insertions, 94 deletions
diff --git a/src/property_list_service.c b/src/property_list_service.c
index e39c7bb..b4c2f44 100644
--- a/src/property_list_service.c
+++ b/src/property_list_service.c
@@ -43,6 +43,8 @@ static property_list_service_error_t iphone_to_property_list_service_error(iphon
43 return PROPERTY_LIST_SERVICE_E_SUCCESS; 43 return PROPERTY_LIST_SERVICE_E_SUCCESS;
44 case IPHONE_E_INVALID_ARG: 44 case IPHONE_E_INVALID_ARG:
45 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 45 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
46 case IPHONE_E_SSL_ERROR:
47 return PROPERTY_LIST_SERVICE_E_SSL_ERROR;
46 default: 48 default:
47 break; 49 break;
48 } 50 }
@@ -106,12 +108,8 @@ property_list_service_error_t property_list_service_client_free(property_list_se
106 * Internally used generic plist send function. 108 * Internally used generic plist send function.
107 * 109 *
108 * @param client The property list service client to use for sending. 110 * @param client The property list service client to use for sending.
109 * Can be NULL if ssl_session is non-NULL.
110 * @param plist plist to send 111 * @param plist plist to send
111 * @param binary 1 = send binary plist, 0 = send xml plist 112 * @param binary 1 = send binary plist, 0 = send xml plist
112 * @param ssl_session If set to NULL, the communication will be unencrypted.
113 * For encrypted communication, pass a valid and properly initialized
114 * gnutls_session_t. client is ignored when ssl_session is non-NULL.
115 * 113 *
116 * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success, 114 * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success,
117 * PROPERTY_LIST_SERVICE_E_INVALID_ARG when one or more parameters are 115 * PROPERTY_LIST_SERVICE_E_INVALID_ARG when one or more parameters are
@@ -119,7 +117,7 @@ property_list_service_error_t property_list_service_client_free(property_list_se
119 * plist, or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR when an unspecified 117 * plist, or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR when an unspecified
120 * error occurs. 118 * error occurs.
121 */ 119 */
122static property_list_service_error_t internal_plist_send(property_list_service_client_t client, plist_t plist, int binary, gnutls_session_t ssl_session) 120static property_list_service_error_t internal_plist_send(property_list_service_client_t client, plist_t plist, int binary)
123{ 121{
124 property_list_service_error_t res = PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR; 122 property_list_service_error_t res = PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR;
125 char *content = NULL; 123 char *content = NULL;
@@ -127,7 +125,7 @@ static property_list_service_error_t internal_plist_send(property_list_service_c
127 uint32_t nlen = 0; 125 uint32_t nlen = 0;
128 int bytes = 0; 126 int bytes = 0;
129 127
130 if ((!client && !ssl_session) || (client && !client->connection) || !plist) { 128 if (!client || (client && !client->connection) || !plist) {
131 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 129 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
132 } 130 }
133 131
@@ -143,17 +141,9 @@ static property_list_service_error_t internal_plist_send(property_list_service_c
143 141
144 nlen = htonl(length); 142 nlen = htonl(length);
145 debug_info("sending %d bytes", length); 143 debug_info("sending %d bytes", length);
146 if (ssl_session) { 144 iphone_device_send(client->connection, (const char*)&nlen, sizeof(nlen), (uint32_t*)&bytes);
147 bytes = gnutls_record_send(ssl_session, (const char*)&nlen, sizeof(nlen));
148 } else {
149 iphone_device_send(client->connection, (const char*)&nlen, sizeof(nlen), (uint32_t*)&bytes);
150 }
151 if (bytes == sizeof(nlen)) { 145 if (bytes == sizeof(nlen)) {
152 if (ssl_session) { 146 iphone_device_send(client->connection, content, length, (uint32_t*)&bytes);
153 bytes = gnutls_record_send(ssl_session, content, length);
154 } else {
155 iphone_device_send(client->connection, content, length, (uint32_t*)&bytes);
156 }
157 if (bytes > 0) { 147 if (bytes > 0) {
158 debug_info("sent %d bytes", bytes); 148 debug_info("sent %d bytes", bytes);
159 debug_buffer(content, bytes); 149 debug_buffer(content, bytes);
@@ -186,7 +176,7 @@ static property_list_service_error_t internal_plist_send(property_list_service_c
186 */ 176 */
187property_list_service_error_t property_list_service_send_xml_plist(property_list_service_client_t client, plist_t plist) 177property_list_service_error_t property_list_service_send_xml_plist(property_list_service_client_t client, plist_t plist)
188{ 178{
189 return internal_plist_send(client, plist, 0, NULL); 179 return internal_plist_send(client, plist, 0);
190} 180}
191 181
192/** 182/**
@@ -202,39 +192,7 @@ property_list_service_error_t property_list_service_send_xml_plist(property_list
202 */ 192 */
203property_list_service_error_t property_list_service_send_binary_plist(property_list_service_client_t client, plist_t plist) 193property_list_service_error_t property_list_service_send_binary_plist(property_list_service_client_t client, plist_t plist)
204{ 194{
205 return internal_plist_send(client, plist, 1, NULL); 195 return internal_plist_send(client, plist, 1);
206}
207
208/**
209 * Sends an encrypted XML plist.
210 *
211 * @param ssl_session Valid and properly initialized gnutls_session_t.
212 * @param plist plist to send
213 *
214 * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success,
215 * PROPERTY_LIST_SERVICE_E_INVALID_ARG when ssl_session or plist is NULL
216 * PROPERTY_LIST_SERVICE_E_PLIST_ERROR when dict is not a valid plist,
217 * or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR when an unspecified error occurs.
218 */
219property_list_service_error_t property_list_service_send_encrypted_xml_plist(gnutls_session_t ssl_session, plist_t plist)
220{
221 return internal_plist_send(NULL, plist, 0, ssl_session);
222}
223
224/**
225 * Sends an encrypted binary plist.
226 *
227 * @param ssl_session Valid and properly initialized gnutls_session_t.
228 * @param plist plist to send
229 *
230 * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success,
231 * PROPERTY_LIST_SERVICE_E_INVALID_ARG when ssl_session or plist is NULL,
232 * PROPERTY_LIST_SERVICE_E_PLIST_ERROR when dict is not a valid plist,
233 * or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR when an unspecified error occurs.
234 */
235property_list_service_error_t property_list_service_send_encrypted_binary_plist(gnutls_session_t ssl_session, plist_t plist)
236{
237 return internal_plist_send(NULL, plist, 1, ssl_session);
238} 196}
239 197
240/** 198/**
@@ -244,36 +202,26 @@ property_list_service_error_t property_list_service_send_encrypted_binary_plist(
244 * @param client The property list service client to use for receiving 202 * @param client The property list service client to use for receiving
245 * @param plist pointer to a plist_t that will point to the received plist 203 * @param plist pointer to a plist_t that will point to the received plist
246 * upon successful return 204 * upon successful return
247 * @param timeout Maximum time in milliseconds to wait for data. This parameter 205 * @param timeout Maximum time in milliseconds to wait for data.
248 * is ignored when ssl_session is not NULL (i.e. encrypted communication is
249 * used). A timeout has to be implemented inside the functions passed to
250 * gnutls_transport_set_push_function / gnutls_transport_set_pull_function.
251 * @param ssl_session If set to NULL, the communication will be unencrypted.
252 * For encrypted communication, pass a valid and properly initialized
253 * gnutls_session_t.
254 * 206 *
255 * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success, 207 * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success,
256 * PROPERTY_LIST_SERVICE_E_INVALID_ARG when client or *plist is NULL, 208 * PROPERTY_LIST_SERVICE_E_INVALID_ARG when client or *plist is NULL,
257 * PROPERTY_LIST_SERVICE_E_PLIST_ERROR when the received data cannot be 209 * PROPERTY_LIST_SERVICE_E_PLIST_ERROR when the received data cannot be
258 * converted to a plist, PROPERTY_LIST_SERVICE_E_MUX_ERROR when a 210 * converted to a plist, PROPERTY_LIST_SERVICE_E_MUX_ERROR when a
259 * communication error occurs, or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR when 211 * communication error occurs, or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR
260 * an unspecified error occurs. 212 * when an unspecified error occurs.
261 */ 213 */
262static property_list_service_error_t internal_plist_recv_timeout(property_list_service_client_t client, plist_t *plist, unsigned int timeout, gnutls_session_t ssl_session) 214static property_list_service_error_t internal_plist_recv_timeout(property_list_service_client_t client, plist_t *plist, unsigned int timeout)
263{ 215{
264 property_list_service_error_t res = PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR; 216 property_list_service_error_t res = PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR;
265 uint32_t pktlen = 0; 217 uint32_t pktlen = 0;
266 uint32_t bytes = 0; 218 uint32_t bytes = 0;
267 219
268 if ((!client && !ssl_session) || (client && !client->connection) || !plist) { 220 if (!client || (client && !client->connection) || !plist) {
269 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 221 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
270 } 222 }
271 223
272 if (ssl_session) { 224 iphone_device_recv_timeout(client->connection, (char*)&pktlen, sizeof(pktlen), &bytes, timeout);
273 bytes = gnutls_record_recv(ssl_session, (char*)&pktlen, sizeof(pktlen));
274 } else {
275 iphone_device_recv_timeout(client->connection, (char*)&pktlen, sizeof(pktlen), &bytes, timeout);
276 }
277 debug_info("initial read=%i", bytes); 225 debug_info("initial read=%i", bytes);
278 if (bytes < 4) { 226 if (bytes < 4) {
279 debug_info("initial read failed!"); 227 debug_info("initial read failed!");
@@ -287,11 +235,7 @@ static property_list_service_error_t internal_plist_recv_timeout(property_list_s
287 content = (char*)malloc(pktlen); 235 content = (char*)malloc(pktlen);
288 236
289 while (curlen < pktlen) { 237 while (curlen < pktlen) {
290 if (ssl_session) { 238 iphone_device_recv(client->connection, content+curlen, pktlen-curlen, &bytes);
291 bytes = gnutls_record_recv(ssl_session, content+curlen, pktlen-curlen);
292 } else {
293 iphone_device_recv(client->connection, content+curlen, pktlen-curlen, &bytes);
294 }
295 if (bytes <= 0) { 239 if (bytes <= 0) {
296 res = PROPERTY_LIST_SERVICE_E_MUX_ERROR; 240 res = PROPERTY_LIST_SERVICE_E_MUX_ERROR;
297 break; 241 break;
@@ -338,7 +282,7 @@ static property_list_service_error_t internal_plist_recv_timeout(property_list_s
338 */ 282 */
339property_list_service_error_t property_list_service_receive_plist_with_timeout(property_list_service_client_t client, plist_t *plist, unsigned int timeout) 283property_list_service_error_t property_list_service_receive_plist_with_timeout(property_list_service_client_t client, plist_t *plist, unsigned int timeout)
340{ 284{
341 return internal_plist_recv_timeout(client, plist, timeout, NULL); 285 return internal_plist_recv_timeout(client, plist, timeout);
342} 286}
343 287
344/** 288/**
@@ -362,41 +306,41 @@ property_list_service_error_t property_list_service_receive_plist_with_timeout(p
362 */ 306 */
363property_list_service_error_t property_list_service_receive_plist(property_list_service_client_t client, plist_t *plist) 307property_list_service_error_t property_list_service_receive_plist(property_list_service_client_t client, plist_t *plist)
364{ 308{
365 return internal_plist_recv_timeout(client, plist, 10000, NULL); 309 return internal_plist_recv_timeout(client, plist, 10000);
366} 310}
367 311
368/** 312/**
369 * Receives an encrypted plist. 313 * Enable SSL for the given property list service client.
370 * Binary or XML plists are automatically handled.
371 * This function is like property_list_service_receive_encrypted_plist_with_timeout
372 * with a timeout value of 10 seconds.
373 * 314 *
374 * @param ssl_session Valid and properly initialized gnutls_session_t. 315 * @param client The connected property list service client for which SSL
375 * @param plist pointer to a plist_t that will point to the received plist 316 * should be enabled.
376 * upon successful return
377 * 317 *
378 * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success, 318 * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success,
379 * PROPERTY_LIST_SERVICE_E_INVALID_ARG when ssl_session or *plist is NULL, 319 * PROPERTY_LIST_SERVICE_E_INVALID_ARG if client or client->connection is
380 * PROPERTY_LIST_SERVICE_E_PLIST_ERROR when the received data cannot be 320 * NULL, PROPERTY_LIST_SERVICE_E_SSL_ERROR when SSL could not be enabled,
381 * converted to a plist, PROPERTY_LIST_SERVICE_E_MUX_ERROR when a 321 * or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR otherwise.
382 * communication error occurs, or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR when
383 * an unspecified error occurs.
384 */ 322 */
385property_list_service_error_t property_list_service_receive_encrypted_plist(gnutls_session_t ssl_session, plist_t *plist) 323property_list_service_error_t property_list_service_enable_ssl(property_list_service_client_t client)
386{ 324{
387 return internal_plist_recv_timeout(NULL, plist, 10000, ssl_session); 325 if (!client || !client->connection)
326 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
327 return iphone_to_property_list_service_error(iphone_connection_enable_ssl(client->connection));
388} 328}
389 329
390/** 330/**
391 * Getter for the iphone_connection_t used by this client. 331 * Disable SSL for the given property list service client.
392 * 332 *
393 * @param client The property list service client to get the connection for. 333 * @param client The connected property list service client for which SSL
334 * should be disabled.
394 * 335 *
395 * @return The connection used by client. 336 * @return PROPERTY_LIST_SERVICE_E_SUCCESS on success,
337 * PROPERTY_LIST_SERVICE_E_INVALID_ARG if client or client->connection is
338 * NULL, or PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR otherwise.
396 */ 339 */
397iphone_connection_t property_list_service_get_connection(property_list_service_client_t client) 340property_list_service_error_t property_list_service_disable_ssl(property_list_service_client_t client)
398{ 341{
399 if (!client) 342 if (!client || !client->connection)
400 return NULL; 343 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
401 return client->connection; 344 return iphone_to_property_list_service_error(iphone_connection_disable_ssl(client->connection));
402} 345}
346