diff options
Diffstat (limited to 'src/userpref.c')
| -rw-r--r-- | src/userpref.c | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/src/userpref.c b/src/userpref.c index 6eff534..3a8a9d6 100644 --- a/src/userpref.c +++ b/src/userpref.c | |||
| @@ -33,20 +33,20 @@ | |||
| 33 | #include "userpref.h" | 33 | #include "userpref.h" |
| 34 | #include "debug.h" | 34 | #include "debug.h" |
| 35 | 35 | ||
| 36 | #define LIBIPHONE_CONF_DIR "libiphone" | 36 | #define LIBIMOBILEDEVICE_CONF_DIR "libimobiledevice" |
| 37 | #define LIBIPHONE_CONF_FILE "libiphonerc" | 37 | #define LIBIMOBILEDEVICE_CONF_FILE "libimobiledevicerc" |
| 38 | 38 | ||
| 39 | #define LIBIPHONE_ROOT_PRIVKEY "RootPrivateKey.pem" | 39 | #define LIBIMOBILEDEVICE_ROOT_PRIVKEY "RootPrivateKey.pem" |
| 40 | #define LIBIPHONE_HOST_PRIVKEY "HostPrivateKey.pem" | 40 | #define LIBIMOBILEDEVICE_HOST_PRIVKEY "HostPrivateKey.pem" |
| 41 | #define LIBIPHONE_ROOT_CERTIF "RootCertificate.pem" | 41 | #define LIBIMOBILEDEVICE_ROOT_CERTIF "RootCertificate.pem" |
| 42 | #define LIBIPHONE_HOST_CERTIF "HostCertificate.pem" | 42 | #define LIBIMOBILEDEVICE_HOST_CERTIF "HostCertificate.pem" |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | /** Creates a freedesktop compatible configuration directory for libiphone. | 45 | /** Creates a freedesktop compatible configuration directory. |
| 46 | */ | 46 | */ |
| 47 | static void userpref_create_config_dir(void) | 47 | static void userpref_create_config_dir(void) |
| 48 | { | 48 | { |
| 49 | gchar *config_dir = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, NULL); | 49 | gchar *config_dir = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, NULL); |
| 50 | 50 | ||
| 51 | if (!g_file_test(config_dir, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) | 51 | if (!g_file_test(config_dir, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) |
| 52 | g_mkdir_with_parents(config_dir, 0755); | 52 | g_mkdir_with_parents(config_dir, 0755); |
| @@ -112,7 +112,7 @@ static int userpref_set_host_id(const char *host_id) | |||
| 112 | /* Write config file on disk */ | 112 | /* Write config file on disk */ |
| 113 | buf = g_key_file_to_data(key_file, &length, NULL); | 113 | buf = g_key_file_to_data(key_file, &length, NULL); |
| 114 | config_file = | 114 | config_file = |
| 115 | g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, LIBIPHONE_CONF_FILE, NULL); | 115 | g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_CONF_FILE, NULL); |
| 116 | file = g_io_channel_new_file(config_file, "w", NULL); | 116 | file = g_io_channel_new_file(config_file, "w", NULL); |
| 117 | g_free(config_file); | 117 | g_free(config_file); |
| 118 | g_io_channel_write_chars(file, buf, length, NULL, NULL); | 118 | g_io_channel_write_chars(file, buf, length, NULL, NULL); |
| @@ -136,7 +136,7 @@ void userpref_get_host_id(char **host_id) | |||
| 136 | gchar *loc_host_id; | 136 | gchar *loc_host_id; |
| 137 | 137 | ||
| 138 | config_file = | 138 | config_file = |
| 139 | g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, LIBIPHONE_CONF_FILE, NULL); | 139 | g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_CONF_FILE, NULL); |
| 140 | 140 | ||
| 141 | /* now parse file to get the HostID */ | 141 | /* now parse file to get the HostID */ |
| 142 | key_file = g_key_file_new(); | 142 | key_file = g_key_file_new(); |
| @@ -158,11 +158,11 @@ void userpref_get_host_id(char **host_id) | |||
| 158 | debug_info("Using %s as HostID", *host_id); | 158 | debug_info("Using %s as HostID", *host_id); |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | /** Determines whether this iPhone has been connected to this system before. | 161 | /** Determines whether this device has been connected to this system before. |
| 162 | * | 162 | * |
| 163 | * @param uid The device uid as given by the iPhone. | 163 | * @param uid The device uid as given by the device. |
| 164 | * | 164 | * |
| 165 | * @return 1 if the iPhone has been connected previously to this configuration | 165 | * @return 1 if the device has been connected previously to this configuration |
| 166 | * or 0 otherwise. | 166 | * or 0 otherwise. |
| 167 | */ | 167 | */ |
| 168 | int userpref_has_device_public_key(const char *uuid) | 168 | int userpref_has_device_public_key(const char *uuid) |
| @@ -172,7 +172,7 @@ int userpref_has_device_public_key(const char *uuid) | |||
| 172 | 172 | ||
| 173 | /* first get config file */ | 173 | /* first get config file */ |
| 174 | gchar *device_file = g_strconcat(uuid, ".pem", NULL); | 174 | gchar *device_file = g_strconcat(uuid, ".pem", NULL); |
| 175 | config_file = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, device_file, NULL); | 175 | config_file = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, device_file, NULL); |
| 176 | if (g_file_test(config_file, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) | 176 | if (g_file_test(config_file, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) |
| 177 | ret = 1; | 177 | ret = 1; |
| 178 | g_free(config_file); | 178 | g_free(config_file); |
| @@ -180,10 +180,10 @@ int userpref_has_device_public_key(const char *uuid) | |||
| 180 | return ret; | 180 | return ret; |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | /** Mark the iPhone (as represented by the key) as having connected to this | 183 | /** Mark the device (as represented by the key) as having connected to this |
| 184 | * configuration. | 184 | * configuration. |
| 185 | * | 185 | * |
| 186 | * @param public_key The public key given by the iPhone | 186 | * @param public_key The public key given by the device |
| 187 | * | 187 | * |
| 188 | * @return 1 on success and 0 if no public key is given or if it has already | 188 | * @return 1 on success and 0 if no public key is given or if it has already |
| 189 | * been marked as connected previously. | 189 | * been marked as connected previously. |
| @@ -201,7 +201,7 @@ userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t | |||
| 201 | 201 | ||
| 202 | /* build file path */ | 202 | /* build file path */ |
| 203 | gchar *device_file = g_strconcat(uuid, ".pem", NULL); | 203 | gchar *device_file = g_strconcat(uuid, ".pem", NULL); |
| 204 | gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, device_file, NULL); | 204 | gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, device_file, NULL); |
| 205 | 205 | ||
| 206 | /* store file */ | 206 | /* store file */ |
| 207 | FILE *pFile = fopen(pem, "wb"); | 207 | FILE *pFile = fopen(pem, "wb"); |
| @@ -226,7 +226,7 @@ userpref_error_t userpref_remove_device_public_key(const char *uuid) | |||
| 226 | 226 | ||
| 227 | /* build file path */ | 227 | /* build file path */ |
| 228 | gchar *device_file = g_strconcat(uuid, ".pem", NULL); | 228 | gchar *device_file = g_strconcat(uuid, ".pem", NULL); |
| 229 | gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, device_file, NULL); | 229 | gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, device_file, NULL); |
| 230 | 230 | ||
| 231 | /* remove file */ | 231 | /* remove file */ |
| 232 | g_remove(pem); | 232 | g_remove(pem); |
| @@ -255,7 +255,7 @@ static int userpref_get_file_contents(const char *file, gnutls_datum_t * data) | |||
| 255 | return 0; | 255 | return 0; |
| 256 | 256 | ||
| 257 | /* Read file */ | 257 | /* Read file */ |
| 258 | filepath = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, file, NULL); | 258 | filepath = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, file, NULL); |
| 259 | success = g_file_get_contents(filepath, &content, &size, NULL); | 259 | success = g_file_get_contents(filepath, &content, &size, NULL); |
| 260 | g_free(filepath); | 260 | g_free(filepath); |
| 261 | 261 | ||
| @@ -392,7 +392,7 @@ static userpref_error_t userpref_import_key(const char* key_name, gnutls_x509_pr | |||
| 392 | * @param crt_name The filename of the certificate to import. | 392 | * @param crt_name The filename of the certificate to import. |
| 393 | * @param cert the gnutls certificate structure. | 393 | * @param cert the gnutls certificate structure. |
| 394 | * | 394 | * |
| 395 | * @return IPHONE_E_SUCCESS if the certificate was successfully imported. | 395 | * @return IDEVICE_E_SUCCESS if the certificate was successfully imported. |
| 396 | */ | 396 | */ |
| 397 | static userpref_error_t userpref_import_crt(const char* crt_name, gnutls_x509_crt_t cert) | 397 | static userpref_error_t userpref_import_crt(const char* crt_name, gnutls_x509_crt_t cert) |
| 398 | { | 398 | { |
| @@ -426,16 +426,16 @@ userpref_error_t userpref_get_keys_and_certs(gnutls_x509_privkey_t root_privkey, | |||
| 426 | userpref_error_t ret = USERPREF_E_SUCCESS; | 426 | userpref_error_t ret = USERPREF_E_SUCCESS; |
| 427 | 427 | ||
| 428 | if (ret == USERPREF_E_SUCCESS) | 428 | if (ret == USERPREF_E_SUCCESS) |
| 429 | ret = userpref_import_key(LIBIPHONE_ROOT_PRIVKEY, root_privkey); | 429 | ret = userpref_import_key(LIBIMOBILEDEVICE_ROOT_PRIVKEY, root_privkey); |
| 430 | 430 | ||
| 431 | if (ret == USERPREF_E_SUCCESS) | 431 | if (ret == USERPREF_E_SUCCESS) |
| 432 | ret = userpref_import_key(LIBIPHONE_HOST_PRIVKEY, host_privkey); | 432 | ret = userpref_import_key(LIBIMOBILEDEVICE_HOST_PRIVKEY, host_privkey); |
| 433 | 433 | ||
| 434 | if (ret == USERPREF_E_SUCCESS) | 434 | if (ret == USERPREF_E_SUCCESS) |
| 435 | ret = userpref_import_crt(LIBIPHONE_ROOT_CERTIF, root_crt); | 435 | ret = userpref_import_crt(LIBIMOBILEDEVICE_ROOT_CERTIF, root_crt); |
| 436 | 436 | ||
| 437 | if (ret == USERPREF_E_SUCCESS) | 437 | if (ret == USERPREF_E_SUCCESS) |
| 438 | ret = userpref_import_crt(LIBIPHONE_HOST_CERTIF, host_crt); | 438 | ret = userpref_import_crt(LIBIMOBILEDEVICE_HOST_CERTIF, host_crt); |
| 439 | 439 | ||
| 440 | 440 | ||
| 441 | if (USERPREF_E_SUCCESS != ret) { | 441 | if (USERPREF_E_SUCCESS != ret) { |
| @@ -444,16 +444,16 @@ userpref_error_t userpref_get_keys_and_certs(gnutls_x509_privkey_t root_privkey, | |||
| 444 | ret = userpref_gen_keys_and_cert(); | 444 | ret = userpref_gen_keys_and_cert(); |
| 445 | 445 | ||
| 446 | if (ret == USERPREF_E_SUCCESS) | 446 | if (ret == USERPREF_E_SUCCESS) |
| 447 | ret = userpref_import_key(LIBIPHONE_ROOT_PRIVKEY, root_privkey); | 447 | ret = userpref_import_key(LIBIMOBILEDEVICE_ROOT_PRIVKEY, root_privkey); |
| 448 | 448 | ||
| 449 | if (ret == USERPREF_E_SUCCESS) | 449 | if (ret == USERPREF_E_SUCCESS) |
| 450 | ret = userpref_import_key(LIBIPHONE_HOST_PRIVKEY, host_privkey); | 450 | ret = userpref_import_key(LIBIMOBILEDEVICE_HOST_PRIVKEY, host_privkey); |
| 451 | 451 | ||
| 452 | if (ret == USERPREF_E_SUCCESS) | 452 | if (ret == USERPREF_E_SUCCESS) |
| 453 | ret = userpref_import_crt(LIBIPHONE_ROOT_CERTIF, root_crt); | 453 | ret = userpref_import_crt(LIBIMOBILEDEVICE_ROOT_CERTIF, root_crt); |
| 454 | 454 | ||
| 455 | if (ret == USERPREF_E_SUCCESS) | 455 | if (ret == USERPREF_E_SUCCESS) |
| 456 | ret = userpref_import_crt(LIBIPHONE_HOST_CERTIF, host_crt); | 456 | ret = userpref_import_crt(LIBIMOBILEDEVICE_HOST_CERTIF, host_crt); |
| 457 | } | 457 | } |
| 458 | 458 | ||
| 459 | return ret; | 459 | return ret; |
| @@ -471,7 +471,7 @@ userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls | |||
| 471 | if (!pem_root_cert || !pem_host_cert) | 471 | if (!pem_root_cert || !pem_host_cert) |
| 472 | return USERPREF_E_INVALID_ARG; | 472 | return USERPREF_E_INVALID_ARG; |
| 473 | 473 | ||
| 474 | if (userpref_get_file_contents(LIBIPHONE_ROOT_CERTIF, pem_root_cert) && userpref_get_file_contents(LIBIPHONE_HOST_CERTIF, pem_host_cert)) | 474 | if (userpref_get_file_contents(LIBIMOBILEDEVICE_ROOT_CERTIF, pem_root_cert) && userpref_get_file_contents(LIBIMOBILEDEVICE_HOST_CERTIF, pem_host_cert)) |
| 475 | return USERPREF_E_SUCCESS; | 475 | return USERPREF_E_SUCCESS; |
| 476 | else { | 476 | else { |
| 477 | g_free(pem_root_cert->data); | 477 | g_free(pem_root_cert->data); |
| @@ -503,25 +503,25 @@ userpref_error_t userpref_set_keys_and_certs(gnutls_datum_t * root_key, gnutls_d | |||
| 503 | userpref_create_config_dir(); | 503 | userpref_create_config_dir(); |
| 504 | 504 | ||
| 505 | /* Now write keys and certificates to disk */ | 505 | /* Now write keys and certificates to disk */ |
| 506 | pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, LIBIPHONE_ROOT_PRIVKEY, NULL); | 506 | pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_ROOT_PRIVKEY, NULL); |
| 507 | pFile = fopen(pem, "wb"); | 507 | pFile = fopen(pem, "wb"); |
| 508 | fwrite(root_key->data, 1, root_key->size, pFile); | 508 | fwrite(root_key->data, 1, root_key->size, pFile); |
| 509 | fclose(pFile); | 509 | fclose(pFile); |
| 510 | g_free(pem); | 510 | g_free(pem); |
| 511 | 511 | ||
| 512 | pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, LIBIPHONE_HOST_PRIVKEY, NULL); | 512 | pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_HOST_PRIVKEY, NULL); |
| 513 | pFile = fopen(pem, "wb"); | 513 | pFile = fopen(pem, "wb"); |
| 514 | fwrite(host_key->data, 1, host_key->size, pFile); | 514 | fwrite(host_key->data, 1, host_key->size, pFile); |
| 515 | fclose(pFile); | 515 | fclose(pFile); |
| 516 | g_free(pem); | 516 | g_free(pem); |
| 517 | 517 | ||
| 518 | pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, LIBIPHONE_ROOT_CERTIF, NULL); | 518 | pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_ROOT_CERTIF, NULL); |
| 519 | pFile = fopen(pem, "wb"); | 519 | pFile = fopen(pem, "wb"); |
| 520 | fwrite(root_cert->data, 1, root_cert->size, pFile); | 520 | fwrite(root_cert->data, 1, root_cert->size, pFile); |
| 521 | fclose(pFile); | 521 | fclose(pFile); |
| 522 | g_free(pem); | 522 | g_free(pem); |
| 523 | 523 | ||
| 524 | pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, LIBIPHONE_HOST_CERTIF, NULL); | 524 | pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_HOST_CERTIF, NULL); |
| 525 | pFile = fopen(pem, "wb"); | 525 | pFile = fopen(pem, "wb"); |
| 526 | fwrite(host_cert->data, 1, host_cert->size, pFile); | 526 | fwrite(host_cert->data, 1, host_cert->size, pFile); |
| 527 | fclose(pFile); | 527 | fclose(pFile); |
