summaryrefslogtreecommitdiffstats
path: root/src
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 /src
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>
Diffstat (limited to 'src')
-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
AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(libgnutls_LIBS)
bin_PROGRAMS = iphoneclient ifuse
-iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c
-ifuse_SOURCES = ifuse.c usbmux.c iphone.c plist.c lockdown.c AFC.c
+iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c userpref.c
+ifuse_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 @@
#include "plist.h"
#include "lockdown.h"
#include "AFC.h"
+#include "userpref.h"
AFClient *afc = NULL;
@@ -109,6 +110,7 @@ static int ifuse_read(const char *path, char *buf, size_t size, off_t offset,
void *ifuse_init(struct fuse_conn_info *conn) {
char *response = (char*)malloc(sizeof(char) * 2048);
int bytes = 0, port = 0, i = 0;
+ char* host_id = NULL;
file_handles = g_hash_table_new(g_int_hash, g_int_equal);
@@ -123,11 +125,14 @@ void *ifuse_init(struct fuse_conn_info *conn) {
fprintf(stderr, "Something went wrong in the lockdownd client.\n");
return NULL;
}
-
- //if (!lockdownd_start_SSL_session(control, "29942970-207913891623273984")) {
+
+ host_id = get_host_id();
+ if (host_id && !lockdownd_start_SSL_session(control, host_id)) {
fprintf(stderr, "Something went wrong in GnuTLS.\n");
return NULL;
}
+ free(host_id);
+ host_id = NULL;
port = lockdownd_start_service(control, "com.apple.afc");
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 @@
#include "usbmux.h"
#include "iphone.h"
#include "lockdown.h"
+#include "userpref.h"
#include <errno.h>
#include <string.h>
@@ -318,12 +319,17 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
int lockdownd_start_service(lockdownd_client *control, const char *service) {
if (!control) return 0;
- if (!control->in_SSL && !lockdownd_start_SSL_session(control, "29942970-207913891623273984")) return 0;
-
+
+ char* host_id = get_host_id();
+ if (host_id && !control->in_SSL && !lockdownd_start_SSL_session(control, host_id)) return 0;
+
char *XML_query, **dictionary;
uint32 length, i = 0, port = 0;
uint8 result = 0;
-
+
+ free(host_id);
+ host_id = NULL;
+
xmlDocPtr plist = new_plist();
xmlNode *dict = add_child_to_plist(plist, "dict", "\n", NULL, 0);
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 @@
#include "plist.h"
#include "lockdown.h"
#include "AFC.h"
+#include "userpref.h"
int debug = 1;
int main(int argc, char *argv[]) {
+ char* host_id = NULL;
iPhone *phone = get_iPhone();
if (argc > 1 && !strcasecmp(argv[1], "--debug")) debug = 1;
else debug = 0;
@@ -51,9 +53,12 @@ int main(int argc, char *argv[]) {
}
printf("Now starting SSL.\n");
-// if (!lockdownd_start_SSL_session(control, "29942970-207913891623273984")) {
+ host_id = get_host_id();
+ if (host_id && !lockdownd_start_SSL_session(control, host_id)) {
printf("Error happened in GnuTLS...\n");
} else {
+ free(host_id);
+ host_id = NULL;
printf("... we're in SSL with the phone... !?\n");
port = lockdownd_start_service(control, "com.apple.afc");
}
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 @@
+/*
+ * userpref.c
+ * contains methods to access user specific certificates IDs and more.
+ *
+ * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include "userpref.h"
+
+#define LIBIPHONE_CONF_DIR "libiphone"
+#define LIBIPHONE_CONF_FILE "libiphonerc"
+
+extern int debug;
+
+char* get_host_id()
+{
+ char* host_id = NULL;
+ gchar* config_file = NULL;
+
+ /* first get config file */
+ config_file = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, LIBIPHONE_CONF_FILE, NULL);
+ if (g_file_test(config_file, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) {
+
+ /*now parse file to get the HostID*/
+ GKeyFile* key_file = g_key_file_new ();
+ if( g_key_file_load_from_file (key_file, config_file, G_KEY_FILE_KEEP_COMMENTS, NULL) ) {
+
+ gchar* loc_host_id = g_key_file_get_value(key_file, "Global", "HostID", NULL);
+ if (loc_host_id)
+ host_id = strdup(loc_host_id);
+ g_free(loc_host_id);
+ }
+ g_key_file_free(key_file);
+ }
+ if (debug) printf("Using %s as HostID\n",host_id);
+ return host_id;
+}
+
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 @@
+/*
+ * userpref.h
+ * contains methods to access user specific certificates IDs and more.
+ *
+ * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef USERPREF_H
+#define USERPREF_H
+
+/**
+* \fn char* get_host_id()
+* method to get user's HostID. Caller must free returned buffer.
+* \return the HostID if exist in config file. Returns NULL otherwise.
+*/
+char* get_host_id();
+
+#endif