diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 3 | ||||
| -rw-r--r-- | src/initconf.c | 79 |
2 files changed, 64 insertions, 18 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 09d232f..dc32c04 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
| @@ -4,4 +4,7 @@ AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(l | |||
| 4 | bin_PROGRAMS = iphoneclient ifuse libiphone-initconf | 4 | bin_PROGRAMS = iphoneclient ifuse libiphone-initconf |
| 5 | iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c userpref.c | 5 | iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c userpref.c |
| 6 | ifuse_SOURCES = ifuse.c usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c | 6 | ifuse_SOURCES = ifuse.c usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c |
| 7 | |||
| 7 | libiphone_initconf_SOURCES = initconf.c userpref.c | 8 | libiphone_initconf_SOURCES = initconf.c userpref.c |
| 9 | libiphone_initconf_CFLAGS = $(libgthread2_CFLAGS) | ||
| 10 | libiphone_initconf_LDFLAGS = $(libgthread2_LIBS) | ||
diff --git a/src/initconf.c b/src/initconf.c index b4952e7..a8d56e4 100644 --- a/src/initconf.c +++ b/src/initconf.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | #include <stdio.h> | 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
| 24 | #include <string.h> | ||
| 24 | #include <gnutls/gnutls.h> | 25 | #include <gnutls/gnutls.h> |
| 25 | #include <gnutls/x509.h> | 26 | #include <gnutls/x509.h> |
| 26 | #include <glib.h> | 27 | #include <glib.h> |
| @@ -51,21 +52,46 @@ char *lockdownd_generate_hostid() { | |||
| 51 | return hostid; | 52 | return hostid; |
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | int main(int argc, char *argv[]) { | 55 | void generate_key(gpointer key){ |
| 55 | 56 | gnutls_x509_privkey_generate(*((gnutls_x509_privkey_t*)key), GNUTLS_PK_RSA, 2048, 0); | |
| 56 | printf("This program generates keys required to connect with the iPhone\n"); | 57 | g_thread_exit(0); |
| 57 | printf("It only needs to be run ONCE.\n\n"); | 58 | } |
| 58 | printf("Additionally it may take several minutes to run, please be patient.\n\n"); | ||
| 59 | 59 | ||
| 60 | gnutls_global_init(); | 60 | void progress_bar(gpointer mutex){ |
| 61 | const char *spinner = "|/-\\|/-\\"; | ||
| 62 | int i = 0; | ||
| 63 | |||
| 64 | while (!g_static_mutex_trylock((GStaticMutex*)mutex)){ | ||
| 65 | usleep(500000); | ||
| 66 | printf("Generating root key... %c\r", spinner[i++]); | ||
| 67 | fflush(stdout); | ||
| 68 | if (i > 8) i = 0; | ||
| 69 | } | ||
| 70 | printf("Generating key... done\n"); | ||
| 71 | g_thread_exit(0); | ||
| 72 | } | ||
| 61 | 73 | ||
| 74 | int main(int argc, char *argv[]) { | ||
| 75 | GThread *progress_thread, *key_thread; | ||
| 76 | GError *err; | ||
| 77 | static GStaticMutex mutex = G_STATIC_MUTEX_INIT; | ||
| 62 | char* host_id = NULL; | 78 | char* host_id = NULL; |
| 63 | gnutls_x509_privkey_t root_privkey; | 79 | gnutls_x509_privkey_t root_privkey; |
| 64 | gnutls_x509_privkey_t host_privkey; | 80 | gnutls_x509_privkey_t host_privkey; |
| 65 | |||
| 66 | gnutls_x509_crt_t root_cert; | 81 | gnutls_x509_crt_t root_cert; |
| 67 | gnutls_x509_crt_t host_cert; | 82 | gnutls_x509_crt_t host_cert; |
| 68 | 83 | ||
| 84 | // Create the thread | ||
| 85 | if (!g_thread_supported()){ | ||
| 86 | g_thread_init(NULL); | ||
| 87 | } | ||
| 88 | gnutls_global_init(); | ||
| 89 | |||
| 90 | printf("This program generates keys required to connect with the iPhone\n"); | ||
| 91 | printf("It only needs to be run ONCE.\n\n"); | ||
| 92 | printf("Additionally it may take several minutes to run, please be patient.\n\n"); | ||
| 93 | |||
| 94 | |||
| 69 | gnutls_x509_privkey_init(&root_privkey); | 95 | gnutls_x509_privkey_init(&root_privkey); |
| 70 | gnutls_x509_privkey_init(&host_privkey); | 96 | gnutls_x509_privkey_init(&host_privkey); |
| 71 | 97 | ||
| @@ -73,19 +99,36 @@ int main(int argc, char *argv[]) { | |||
| 73 | gnutls_x509_crt_init(&host_cert); | 99 | gnutls_x509_crt_init(&host_cert); |
| 74 | 100 | ||
| 75 | /* generate HostID */ | 101 | /* generate HostID */ |
| 76 | //TODO | ||
| 77 | host_id = lockdownd_generate_hostid(); | 102 | host_id = lockdownd_generate_hostid(); |
| 78 | 103 | ||
| 79 | /* generate keys */ | 104 | /* generate root key */ |
| 80 | printf("Generating root key..."); | 105 | g_static_mutex_lock(&mutex); |
| 81 | fflush(stdout); | 106 | if((key_thread = g_thread_create((GThreadFunc)generate_key, &root_privkey, TRUE, &err)) == NULL) { |
| 82 | gnutls_x509_privkey_generate(root_privkey, GNUTLS_PK_RSA, 2048, 0); | 107 | printf("Thread create failed: %s!!\n", err->message ); |
| 83 | printf("done\n"); | 108 | g_error_free(err) ; |
| 109 | } | ||
| 110 | if((progress_thread = g_thread_create((GThreadFunc)progress_bar, &mutex, TRUE, &err)) == NULL) { | ||
| 111 | printf("Thread create failed: %s!!\n", err->message ); | ||
| 112 | g_error_free(err) ; | ||
| 113 | } | ||
| 114 | g_thread_join(key_thread); | ||
| 115 | g_static_mutex_unlock(&mutex); | ||
| 116 | g_thread_join(progress_thread); | ||
| 84 | 117 | ||
| 85 | printf("Generating private key..."); | 118 | /* generate host key */ |
| 86 | fflush(stdout); | 119 | g_static_mutex_init(&mutex); |
| 87 | gnutls_x509_privkey_generate(host_privkey, GNUTLS_PK_RSA, 2048, 0); | 120 | g_static_mutex_lock(&mutex); |
| 88 | printf("done\n"); | 121 | if((key_thread = g_thread_create((GThreadFunc)generate_key, &host_privkey, TRUE, &err)) == NULL) { |
| 122 | printf("Thread create failed: %s!!\n", err->message ); | ||
| 123 | g_error_free(err) ; | ||
| 124 | } | ||
| 125 | if((progress_thread = g_thread_create((GThreadFunc)progress_bar, &mutex, TRUE, &err)) == NULL) { | ||
| 126 | printf("Thread create failed: %s!!\n", err->message ); | ||
| 127 | g_error_free(err) ; | ||
| 128 | } | ||
| 129 | g_thread_join(key_thread); | ||
| 130 | g_static_mutex_unlock(&mutex); | ||
| 131 | g_thread_join(progress_thread); | ||
| 89 | 132 | ||
| 90 | /* generate certificates */ | 133 | /* generate certificates */ |
| 91 | gnutls_x509_crt_set_key(root_cert, root_privkey); | 134 | gnutls_x509_crt_set_key(root_cert, root_privkey); |
| @@ -133,7 +176,7 @@ int main(int argc, char *argv[]) { | |||
| 133 | gnutls_x509_crt_export (root_cert, GNUTLS_X509_FMT_PEM, root_cert_pem.data, &root_cert_pem.size); | 176 | gnutls_x509_crt_export (root_cert, GNUTLS_X509_FMT_PEM, root_cert_pem.data, &root_cert_pem.size); |
| 134 | printf("done\n"); | 177 | printf("done\n"); |
| 135 | 178 | ||
| 136 | printf("Generating root certificate..."); | 179 | printf("Generating host certificate..."); |
| 137 | gnutls_x509_crt_export (host_cert, GNUTLS_X509_FMT_PEM, host_cert_pem.data, &host_cert_pem.size); | 180 | gnutls_x509_crt_export (host_cert, GNUTLS_X509_FMT_PEM, host_cert_pem.data, &host_cert_pem.size); |
| 138 | printf("done\n"); | 181 | printf("done\n"); |
| 139 | 182 | ||
