summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2008-09-02 22:54:32 +0200
committerGravatar Matt Colyer2008-09-11 22:05:45 -0700
commit3287ba4cb6f6e1a268dba039853c633938c6e200 (patch)
tree13fd1f95d6a8cc1b3bfc60c6f0f7ce07d1339546 /src
parentb61d63f43f28d2ec94f750753b1d6d4748fd944b (diff)
downloadlibimobiledevice-3287ba4cb6f6e1a268dba039853c633938c6e200.tar.gz
libimobiledevice-3287ba4cb6f6e1a268dba039853c633938c6e200.tar.bz2
Setup a very basic lockdownd command line client
Signed-off-by: Matt Colyer <matt@colyer.name>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am7
-rw-r--r--src/lckdclient.c105
-rw-r--r--src/lockdown.c8
-rw-r--r--src/lockdown.h1
4 files changed, 116 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index f26deb1..9a5df62 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir)/include
3AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libfuse_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) -g 3AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libfuse_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) -g
4AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) 4AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS)
5 5
6bin_PROGRAMS = iphoneclient ifuse libiphone-initconf 6bin_PROGRAMS = iphoneclient ifuse libiphone-initconf lckd-client
7iphoneclient_SOURCES = main.c 7iphoneclient_SOURCES = main.c
8iphoneclient_LDADD = libiphone.la 8iphoneclient_LDADD = libiphone.la
9 9
@@ -14,6 +14,11 @@ libiphone_initconf_LDFLAGS = $(libgthread2_LIBS) $(AM_LDFLAGS)
14ifuse_SOURCES = ifuse.c 14ifuse_SOURCES = ifuse.c
15ifuse_LDADD = libiphone.la 15ifuse_LDADD = libiphone.la
16 16
17lckd_client_SOURCES = lckdclient.c
18lckd_client_CFLAGS = $(AM_CFLAGS)
19lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS)
20lckd_client_LDADD = libiphone.la
21
17lib_LTLIBRARIES = libiphone.la 22lib_LTLIBRARIES = libiphone.la
18libiphone_la_SOURCES = usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c 23libiphone_la_SOURCES = usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c
19 24
diff --git a/src/lckdclient.c b/src/lckdclient.c
new file mode 100644
index 0000000..179ecae
--- /dev/null
+++ b/src/lckdclient.c
@@ -0,0 +1,105 @@
1/*
2 * lckdclient.c
3 * Rudimentary command line interface to the Lockdown protocol
4 *
5 * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdio.h>
23#include <string.h>
24#include <glib.h>
25#include <readline/readline.h>
26#include <readline/history.h>
27
28
29#include "usbmux.h"
30#include "iphone.h"
31#include <libiphone/libiphone.h>
32
33int debug = 1;
34
35int main(int argc, char *argv[])
36{
37 int bytes = 0, port = 0, i = 0;
38 iphone_lckd_client_t control = NULL;
39 iphone_device_t phone = NULL;
40
41
42 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {
43 printf("No iPhone found, is it plugged in?\n");
44 return -1;
45 }
46
47 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
48 iphone_free_device(phone);
49 return -1;
50 }
51
52 char *uid = NULL;
53 if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) {
54 printf("DeviceUniqueID : %s\n", uid);
55 free(uid);
56 }
57
58 using_history();
59 int loop = TRUE;
60 while(loop)
61 {
62 char *cmd = readline("> ");
63 if (cmd)
64 {
65
66 gchar** args = g_strsplit(cmd, " ", 0);
67
68 int len = 0;
69 if (args) {
70 while ( *(args+len) ) {
71 g_strstrip(*(args+len));
72 len++;
73 }
74 }
75
76 if (len > 0) {
77 add_history(cmd);
78 if (!strcmp(*args, "quit"))
79 loop = FALSE;
80
81 if (!strcmp(*args, "get") && len == 3) {
82 char *value = NULL;
83 if (IPHONE_E_SUCCESS == lockdownd_generic_get_value(control, *(args+1), *(args+2), &value))
84 printf("Success : value = %s\n", value);
85 else
86 printf("Error\n");
87 }
88
89 if (!strcmp(*args, "start") && len == 2) {
90 int port = 0;
91 iphone_lckd_start_service(control, *(args+1), &port);
92 printf("%i\n", port);
93 }
94 }
95 g_strfreev(args);
96 }
97 free(cmd);
98 cmd = NULL;
99 }
100 clear_history();
101 iphone_lckd_free_client(control);
102 iphone_free_device(phone);
103
104 return 0;
105}
diff --git a/src/lockdown.c b/src/lockdown.c
index 80974d2..ffabd88 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -265,7 +265,7 @@ iphone_error_t lockdownd_hello(iphone_lckd_client_t control)
265 * 265 *
266 * @return IPHONE_E_SUCCESS on success. 266 * @return IPHONE_E_SUCCESS on success.
267 */ 267 */
268iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *req_key, char **value) 268iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *req_key, char *req_string, char **value)
269{ 269{
270 if (!control || !req_key || !value || (value && *value)) 270 if (!control || !req_key || !value || (value && *value))
271 return IPHONE_E_INVALID_ARG; 271 return IPHONE_E_INVALID_ARG;
@@ -280,7 +280,7 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r
280 280
281 /* Setup DevicePublicKey request plist */ 281 /* Setup DevicePublicKey request plist */
282 dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); 282 dict = add_child_to_plist(plist, "dict", "\n", NULL, 0);
283 key = add_key_str_dict_element(plist, dict, "Key", req_key, 1); 283 key = add_key_str_dict_element(plist, dict, req_key, req_string, 1);
284 key = add_key_str_dict_element(plist, dict, "Request", "GetValue", 1); 284 key = add_key_str_dict_element(plist, dict, "Request", "GetValue", 1);
285 xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); 285 xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length);
286 286
@@ -343,7 +343,7 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r
343 */ 343 */
344iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid) 344iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid)
345{ 345{
346 return lockdownd_generic_get_value(control, "UniqueDeviceID", uid); 346 return lockdownd_generic_get_value(control, "Key", "UniqueDeviceID", uid);
347} 347}
348 348
349/** Askes for the device's public key. Part of the lockdownd handshake. 349/** Askes for the device's public key. Part of the lockdownd handshake.
@@ -354,7 +354,7 @@ iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid
354 */ 354 */
355iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key) 355iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key)
356{ 356{
357 return lockdownd_generic_get_value(control, "DevicePublicKey", public_key); 357 return lockdownd_generic_get_value(control, "Key", "DevicePublicKey", public_key);
358} 358}
359 359
360/** Completes the entire lockdownd handshake. 360/** Completes the entire lockdownd handshake.
diff --git a/src/lockdown.h b/src/lockdown.h
index 41402c4..9176524 100644
--- a/src/lockdown.h
+++ b/src/lockdown.h
@@ -44,6 +44,7 @@ char *lockdownd_generate_hostid();
44 44
45iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone); 45iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone);
46iphone_error_t lockdownd_hello(iphone_lckd_client_t control); 46iphone_error_t lockdownd_hello(iphone_lckd_client_t control);
47iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *req_key, char *req_string, char **value);
47iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid); 48iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid);
48iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key); 49iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key);
49 50