Commit 8e82524e authored by Matt Colyer's avatar Matt Colyer

Enhance the usability of initconf, by giving more feedback to the user.

parent 495dd184
...@@ -14,6 +14,7 @@ AC_PROG_CC ...@@ -14,6 +14,7 @@ AC_PROG_CC
PKG_CHECK_MODULES(libxml2, libxml-2.0 >= 2.6.30) PKG_CHECK_MODULES(libxml2, libxml-2.0 >= 2.6.30)
PKG_CHECK_MODULES(libusb, libusb >= 0.1.12) PKG_CHECK_MODULES(libusb, libusb >= 0.1.12)
PKG_CHECK_MODULES(libglib2, glib-2.0 >= 2.14.1) PKG_CHECK_MODULES(libglib2, glib-2.0 >= 2.14.1)
PKG_CHECK_MODULES(libgthread2, gthread-2.0 >= 2.14.1)
PKG_CHECK_MODULES(libgnutls, gnutls >= 1.6.3) PKG_CHECK_MODULES(libgnutls, gnutls >= 1.6.3)
PKG_CHECK_MODULES(libfuse, fuse >= 2.7.0) PKG_CHECK_MODULES(libfuse, fuse >= 2.7.0)
......
...@@ -4,4 +4,7 @@ AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(l ...@@ -4,4 +4,7 @@ AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(l
bin_PROGRAMS = iphoneclient ifuse libiphone-initconf bin_PROGRAMS = iphoneclient ifuse libiphone-initconf
iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c userpref.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 ifuse_SOURCES = ifuse.c usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c
libiphone_initconf_SOURCES = initconf.c userpref.c libiphone_initconf_SOURCES = initconf.c userpref.c
libiphone_initconf_CFLAGS = $(libgthread2_CFLAGS)
libiphone_initconf_LDFLAGS = $(libgthread2_LIBS)
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <gnutls/gnutls.h> #include <gnutls/gnutls.h>
#include <gnutls/x509.h> #include <gnutls/x509.h>
#include <glib.h> #include <glib.h>
...@@ -51,21 +52,46 @@ char *lockdownd_generate_hostid() { ...@@ -51,21 +52,46 @@ char *lockdownd_generate_hostid() {
return hostid; return hostid;
} }
int main(int argc, char *argv[]) { void generate_key(gpointer key){
gnutls_x509_privkey_generate(*((gnutls_x509_privkey_t*)key), GNUTLS_PK_RSA, 2048, 0);
g_thread_exit(0);
}
printf("This program generates keys required to connect with the iPhone\n"); void progress_bar(gpointer mutex){
printf("It only needs to be run ONCE.\n\n"); const char *spinner = "|/-\\|/-\\";
printf("Additionally it may take several minutes to run, please be patient.\n\n"); int i = 0;
gnutls_global_init(); while (!g_static_mutex_trylock((GStaticMutex*)mutex)){
usleep(500000);
printf("Generating root key... %c\r", spinner[i++]);
fflush(stdout);
if (i > 8) i = 0;
}
printf("Generating key... done\n");
g_thread_exit(0);
}
int main(int argc, char *argv[]) {
GThread *progress_thread, *key_thread;
GError *err;
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
char* host_id = NULL; char* host_id = NULL;
gnutls_x509_privkey_t root_privkey; gnutls_x509_privkey_t root_privkey;
gnutls_x509_privkey_t host_privkey; gnutls_x509_privkey_t host_privkey;
gnutls_x509_crt_t root_cert; gnutls_x509_crt_t root_cert;
gnutls_x509_crt_t host_cert; gnutls_x509_crt_t host_cert;
// Create the thread
if (!g_thread_supported()){
g_thread_init(NULL);
}
gnutls_global_init();
printf("This program generates keys required to connect with the iPhone\n");
printf("It only needs to be run ONCE.\n\n");
printf("Additionally it may take several minutes to run, please be patient.\n\n");
gnutls_x509_privkey_init(&root_privkey); gnutls_x509_privkey_init(&root_privkey);
gnutls_x509_privkey_init(&host_privkey); gnutls_x509_privkey_init(&host_privkey);
...@@ -73,19 +99,36 @@ int main(int argc, char *argv[]) { ...@@ -73,19 +99,36 @@ int main(int argc, char *argv[]) {
gnutls_x509_crt_init(&host_cert); gnutls_x509_crt_init(&host_cert);
/* generate HostID */ /* generate HostID */
//TODO
host_id = lockdownd_generate_hostid(); host_id = lockdownd_generate_hostid();
/* generate keys */ /* generate root key */
printf("Generating root key..."); g_static_mutex_lock(&mutex);
fflush(stdout); if((key_thread = g_thread_create((GThreadFunc)generate_key, &root_privkey, TRUE, &err)) == NULL) {
gnutls_x509_privkey_generate(root_privkey, GNUTLS_PK_RSA, 2048, 0); printf("Thread create failed: %s!!\n", err->message );
printf("done\n"); g_error_free(err) ;
}
printf("Generating private key..."); if((progress_thread = g_thread_create((GThreadFunc)progress_bar, &mutex, TRUE, &err)) == NULL) {
fflush(stdout); printf("Thread create failed: %s!!\n", err->message );
gnutls_x509_privkey_generate(host_privkey, GNUTLS_PK_RSA, 2048, 0); g_error_free(err) ;
printf("done\n"); }
g_thread_join(key_thread);
g_static_mutex_unlock(&mutex);
g_thread_join(progress_thread);
/* generate host key */
g_static_mutex_init(&mutex);
g_static_mutex_lock(&mutex);
if((key_thread = g_thread_create((GThreadFunc)generate_key, &host_privkey, TRUE, &err)) == NULL) {
printf("Thread create failed: %s!!\n", err->message );
g_error_free(err) ;
}
if((progress_thread = g_thread_create((GThreadFunc)progress_bar, &mutex, TRUE, &err)) == NULL) {
printf("Thread create failed: %s!!\n", err->message );
g_error_free(err) ;
}
g_thread_join(key_thread);
g_static_mutex_unlock(&mutex);
g_thread_join(progress_thread);
/* generate certificates */ /* generate certificates */
gnutls_x509_crt_set_key(root_cert, root_privkey); gnutls_x509_crt_set_key(root_cert, root_privkey);
...@@ -133,7 +176,7 @@ int main(int argc, char *argv[]) { ...@@ -133,7 +176,7 @@ int main(int argc, char *argv[]) {
gnutls_x509_crt_export (root_cert, GNUTLS_X509_FMT_PEM, root_cert_pem.data, &root_cert_pem.size); gnutls_x509_crt_export (root_cert, GNUTLS_X509_FMT_PEM, root_cert_pem.data, &root_cert_pem.size);
printf("done\n"); printf("done\n");
printf("Generating root certificate..."); printf("Generating host certificate...");
gnutls_x509_crt_export (host_cert, GNUTLS_X509_FMT_PEM, host_cert_pem.data, &host_cert_pem.size); gnutls_x509_crt_export (host_cert, GNUTLS_X509_FMT_PEM, host_cert_pem.data, &host_cert_pem.size);
printf("done\n"); printf("done\n");
......
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