Commit d05ae226 authored by Jonathan Beck's avatar Jonathan Beck Committed by Matt Colyer

Added a way to load HostID from a user specific config file.

Signed-off-by: 's avatarMatt Colyer <matt@colyer.name>
parent bbd289b4
......@@ -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
......@@ -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);
......@@ -124,10 +126,13 @@ void *ifuse_init(struct fuse_conn_info *conn) {
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) {
......
......@@ -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;
......
......@@ -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");
}
......
/*
* 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;
}
/*
* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment