summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2008-07-31 21:54:16 -0700
committerGravatar Matt Colyer2008-07-31 21:54:16 -0700
commitd05ae226356cc674a055c784a4b9b75825162ba6 (patch)
tree9cfff8c5e5f90c4d5b0d7e36a2b1ac5b78a4baf9
parentbbd289b44c94aeb327675352d187209639e64baa (diff)
downloadlibimobiledevice-d05ae226356cc674a055c784a4b9b75825162ba6.tar.gz
libimobiledevice-d05ae226356cc674a055c784a4b9b75825162ba6.tar.bz2
Added a way to load HostID from a user specific config file.
Signed-off-by: Matt Colyer <matt@colyer.name>
-rw-r--r--src/Makefile.am4
-rw-r--r--src/ifuse.c9
-rw-r--r--src/lockdown.c12
-rw-r--r--src/main.c7
-rw-r--r--src/userpref.c52
-rw-r--r--src/userpref.h31
6 files changed, 107 insertions, 8 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 65701d9..fdcbb3d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,5 +2,5 @@ AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libfuse_CFLA
2AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(libgnutls_LIBS) 2AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(libgnutls_LIBS)
3 3
4bin_PROGRAMS = iphoneclient ifuse 4bin_PROGRAMS = iphoneclient ifuse
5iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c 5iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c userpref.c
6ifuse_SOURCES = ifuse.c usbmux.c iphone.c plist.c lockdown.c AFC.c 6ifuse_SOURCES = ifuse.c usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c
diff --git a/src/ifuse.c b/src/ifuse.c
index 8243109..6ee8eb5 100644
--- a/src/ifuse.c
+++ b/src/ifuse.c
@@ -35,6 +35,7 @@
35#include "plist.h" 35#include "plist.h"
36#include "lockdown.h" 36#include "lockdown.h"
37#include "AFC.h" 37#include "AFC.h"
38#include "userpref.h"
38 39
39 40
40AFClient *afc = NULL; 41AFClient *afc = NULL;
@@ -109,6 +110,7 @@ static int ifuse_read(const char *path, char *buf, size_t size, off_t offset,
109void *ifuse_init(struct fuse_conn_info *conn) { 110void *ifuse_init(struct fuse_conn_info *conn) {
110 char *response = (char*)malloc(sizeof(char) * 2048); 111 char *response = (char*)malloc(sizeof(char) * 2048);
111 int bytes = 0, port = 0, i = 0; 112 int bytes = 0, port = 0, i = 0;
113 char* host_id = NULL;
112 114
113 file_handles = g_hash_table_new(g_int_hash, g_int_equal); 115 file_handles = g_hash_table_new(g_int_hash, g_int_equal);
114 116
@@ -123,11 +125,14 @@ void *ifuse_init(struct fuse_conn_info *conn) {
123 fprintf(stderr, "Something went wrong in the lockdownd client.\n"); 125 fprintf(stderr, "Something went wrong in the lockdownd client.\n");
124 return NULL; 126 return NULL;
125 } 127 }
126 128
127 //if (!lockdownd_start_SSL_session(control, "29942970-207913891623273984")) { 129 host_id = get_host_id();
130 if (host_id && !lockdownd_start_SSL_session(control, host_id)) {
128 fprintf(stderr, "Something went wrong in GnuTLS.\n"); 131 fprintf(stderr, "Something went wrong in GnuTLS.\n");
129 return NULL; 132 return NULL;
130 } 133 }
134 free(host_id);
135 host_id = NULL;
131 136
132 port = lockdownd_start_service(control, "com.apple.afc"); 137 port = lockdownd_start_service(control, "com.apple.afc");
133 if (!port) { 138 if (!port) {
diff --git a/src/lockdown.c b/src/lockdown.c
index 452f036..c1b846d 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -21,6 +21,7 @@
21#include "usbmux.h" 21#include "usbmux.h"
22#include "iphone.h" 22#include "iphone.h"
23#include "lockdown.h" 23#include "lockdown.h"
24#include "userpref.h"
24#include <errno.h> 25#include <errno.h>
25#include <string.h> 26#include <string.h>
26 27
@@ -318,12 +319,17 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
318 319
319int lockdownd_start_service(lockdownd_client *control, const char *service) { 320int lockdownd_start_service(lockdownd_client *control, const char *service) {
320 if (!control) return 0; 321 if (!control) return 0;
321 if (!control->in_SSL && !lockdownd_start_SSL_session(control, "29942970-207913891623273984")) return 0; 322
322 323 char* host_id = get_host_id();
324 if (host_id && !control->in_SSL && !lockdownd_start_SSL_session(control, host_id)) return 0;
325
323 char *XML_query, **dictionary; 326 char *XML_query, **dictionary;
324 uint32 length, i = 0, port = 0; 327 uint32 length, i = 0, port = 0;
325 uint8 result = 0; 328 uint8 result = 0;
326 329
330 free(host_id);
331 host_id = NULL;
332
327 xmlDocPtr plist = new_plist(); 333 xmlDocPtr plist = new_plist();
328 xmlNode *dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); 334 xmlNode *dict = add_child_to_plist(plist, "dict", "\n", NULL, 0);
329 xmlNode *key; 335 xmlNode *key;
diff --git a/src/main.c b/src/main.c
index 34126d7..e42440f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -31,10 +31,12 @@
31#include "plist.h" 31#include "plist.h"
32#include "lockdown.h" 32#include "lockdown.h"
33#include "AFC.h" 33#include "AFC.h"
34#include "userpref.h"
34 35
35int debug = 1; 36int debug = 1;
36 37
37int main(int argc, char *argv[]) { 38int main(int argc, char *argv[]) {
39 char* host_id = NULL;
38 iPhone *phone = get_iPhone(); 40 iPhone *phone = get_iPhone();
39 if (argc > 1 && !strcasecmp(argv[1], "--debug")) debug = 1; 41 if (argc > 1 && !strcasecmp(argv[1], "--debug")) debug = 1;
40 else debug = 0; 42 else debug = 0;
@@ -51,9 +53,12 @@ int main(int argc, char *argv[]) {
51 } 53 }
52 54
53 printf("Now starting SSL.\n"); 55 printf("Now starting SSL.\n");
54// if (!lockdownd_start_SSL_session(control, "29942970-207913891623273984")) { 56 host_id = get_host_id();
57 if (host_id && !lockdownd_start_SSL_session(control, host_id)) {
55 printf("Error happened in GnuTLS...\n"); 58 printf("Error happened in GnuTLS...\n");
56 } else { 59 } else {
60 free(host_id);
61 host_id = NULL;
57 printf("... we're in SSL with the phone... !?\n"); 62 printf("... we're in SSL with the phone... !?\n");
58 port = lockdownd_start_service(control, "com.apple.afc"); 63 port = lockdownd_start_service(control, "com.apple.afc");
59 } 64 }
diff --git a/src/userpref.c b/src/userpref.c
new file mode 100644
index 0000000..b877700
--- /dev/null
+++ b/src/userpref.c
@@ -0,0 +1,52 @@
1/*
2 * userpref.c
3 * contains methods to access user specific certificates IDs and more.
4 *
5 * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program 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
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <glib.h>
22#include "userpref.h"
23
24#define LIBIPHONE_CONF_DIR "libiphone"
25#define LIBIPHONE_CONF_FILE "libiphonerc"
26
27extern int debug;
28
29char* get_host_id()
30{
31 char* host_id = NULL;
32 gchar* config_file = NULL;
33
34 /* first get config file */
35 config_file = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, LIBIPHONE_CONF_FILE, NULL);
36 if (g_file_test(config_file, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) {
37
38 /*now parse file to get the HostID*/
39 GKeyFile* key_file = g_key_file_new ();
40 if( g_key_file_load_from_file (key_file, config_file, G_KEY_FILE_KEEP_COMMENTS, NULL) ) {
41
42 gchar* loc_host_id = g_key_file_get_value(key_file, "Global", "HostID", NULL);
43 if (loc_host_id)
44 host_id = strdup(loc_host_id);
45 g_free(loc_host_id);
46 }
47 g_key_file_free(key_file);
48 }
49 if (debug) printf("Using %s as HostID\n",host_id);
50 return host_id;
51}
52
diff --git a/src/userpref.h b/src/userpref.h
new file mode 100644
index 0000000..8567a53
--- /dev/null
+++ b/src/userpref.h
@@ -0,0 +1,31 @@
1/*
2 * userpref.h
3 * contains methods to access user specific certificates IDs and more.
4 *
5 * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program 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
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef USERPREF_H
22#define USERPREF_H
23
24/**
25* \fn char* get_host_id()
26* method to get user's HostID. Caller must free returned buffer.
27* \return the HostID if exist in config file. Returns NULL otherwise.
28*/
29char* get_host_id();
30
31#endif