Commit 3d8ba053 authored by Jonathan Beck's avatar Jonathan Beck

Change from Base64 encoded buffers to real buffers. Base64 decoding/encoding...

Change from Base64 encoded buffers to real buffers. Base64 decoding/encoding only happens in xml plists.
parent 9ca88730
This diff is collapsed.
...@@ -42,13 +42,14 @@ struct iphone_lckd_client_int { ...@@ -42,13 +42,14 @@ struct iphone_lckd_client_int {
iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone); iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone);
iphone_error_t lockdownd_hello(iphone_lckd_client_t control); iphone_error_t lockdownd_hello(iphone_lckd_client_t control);
iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *req_key, char *req_string, char **value); iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *req_key, char *req_string,
gnutls_datum_t * value);
iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid); iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid);
iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key); iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, gnutls_datum_t * public_key);
iphone_error_t lockdownd_gen_pair_cert(char *public_key_b64, char **device_cert_b64, char **host_cert_b64, iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * device_cert,
char **root_cert_b64); gnutls_datum_t * host_cert, gnutls_datum_t * root_cert);
iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *public_key, char *host_id); iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, char *host_id);
void lockdownd_close(iphone_lckd_client_t control); void lockdownd_close(iphone_lckd_client_t control);
// SSL functions // SSL functions
......
...@@ -67,7 +67,7 @@ void plist_new_dict_in_plist(plist_t plist, plist_t * dict) ...@@ -67,7 +67,7 @@ void plist_new_dict_in_plist(plist_t plist, plist_t * dict)
* @param value a pointer to the actual buffer containing the value. WARNING : the buffer is supposed to match the type of the value * @param value a pointer to the actual buffer containing the value. WARNING : the buffer is supposed to match the type of the value
* *
*/ */
void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *value) void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *value, uint64_t length)
{ {
if (!dict || !key || !value) if (!dict || !key || !value)
return; return;
...@@ -81,6 +81,7 @@ void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *valu ...@@ -81,6 +81,7 @@ void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *valu
//now handle value //now handle value
struct plist_data *val = (struct plist_data *) calloc(sizeof(struct plist_data), 1); struct plist_data *val = (struct plist_data *) calloc(sizeof(struct plist_data), 1);
val->type = type; val->type = type;
val->length = length;
switch (type) { switch (type) {
case PLIST_BOOLEAN: case PLIST_BOOLEAN:
...@@ -99,7 +100,7 @@ void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *valu ...@@ -99,7 +100,7 @@ void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *valu
val->unicodeval = wcsdup((wchar_t *) value); val->unicodeval = wcsdup((wchar_t *) value);
break; break;
case PLIST_DATA: case PLIST_DATA:
val->buff = strdup((char *) value); memcpy(val->buff, value, length);
break; break;
case PLIST_ARRAY: case PLIST_ARRAY:
case PLIST_DICT: case PLIST_DICT:
...@@ -195,7 +196,7 @@ plist_t find_node(plist_t plist, plist_type type, void *value) ...@@ -195,7 +196,7 @@ plist_t find_node(plist_t plist, plist_type type, void *value)
return NULL; return NULL;
} }
void get_type_and_value(GNode * node, plist_type * type, void *value) void get_type_and_value(GNode * node, plist_type * type, void *value, uint64_t * length)
{ {
if (!node) if (!node)
return; return;
...@@ -203,6 +204,7 @@ void get_type_and_value(GNode * node, plist_type * type, void *value) ...@@ -203,6 +204,7 @@ void get_type_and_value(GNode * node, plist_type * type, void *value)
struct plist_data *data = (struct plist_data *) node->data; struct plist_data *data = (struct plist_data *) node->data;
*type = data->type; *type = data->type;
*length = data->length;
switch (*type) { switch (*type) {
case PLIST_BOOLEAN: case PLIST_BOOLEAN:
......
...@@ -67,7 +67,7 @@ typedef GNode *plist_t; ...@@ -67,7 +67,7 @@ typedef GNode *plist_t;
void plist_new_dict(plist_t * plist); void plist_new_dict(plist_t * plist);
void plist_new_array(plist_t * plist); void plist_new_array(plist_t * plist);
void plist_new_dict_in_plist(plist_t plist, plist_t * dict); void plist_new_dict_in_plist(plist_t plist, plist_t * dict);
void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *value); void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *value, uint64_t length);
void plist_free(plist_t plist); void plist_free(plist_t plist);
void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length); void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length);
...@@ -78,6 +78,6 @@ void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist); ...@@ -78,6 +78,6 @@ void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist);
plist_t find_query_node(plist_t plist, char *key, char *request); plist_t find_query_node(plist_t plist, char *key, char *request);
plist_t find_node(plist_t plist, plist_type type, void *value); plist_t find_node(plist_t plist, plist_type type, void *value);
void get_type_and_value(plist_t node, plist_type * type, void *value); void get_type_and_value(plist_t node, plist_type * type, void *value, uint64_t * length);
#endif #endif
...@@ -114,10 +114,10 @@ int is_device_known(char *uid) ...@@ -114,10 +114,10 @@ int is_device_known(char *uid)
* @return 1 on success and 0 if no public key is given or if it has already * @return 1 on success and 0 if no public key is given or if it has already
* been marked as connected previously. * been marked as connected previously.
*/ */
int store_device_public_key(char *uid, char *public_key) int store_device_public_key(char *uid, gnutls_datum_t public_key)
{ {
if (NULL == public_key || is_device_known(uid)) if (NULL == public_key.data || is_device_known(uid))
return 0; return 0;
/* ensure config directory exists */ /* ensure config directory exists */
...@@ -127,15 +127,11 @@ int store_device_public_key(char *uid, char *public_key) ...@@ -127,15 +127,11 @@ int store_device_public_key(char *uid, char *public_key)
gchar *device_file = g_strconcat(uid, ".pem", NULL); gchar *device_file = g_strconcat(uid, ".pem", NULL);
gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, device_file, NULL); gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, device_file, NULL);
/* decode public key for storing */
gsize decoded_size;
gchar *data = g_base64_decode(public_key, &decoded_size);
/* store file */ /* store file */
FILE *pFile = fopen(pem, "wb"); FILE *pFile = fopen(pem, "wb");
fwrite(data, 1, decoded_size, pFile); fwrite(public_key.data, 1, public_key.size, pFile);
fclose(pFile); fclose(pFile);
g_free(pem); g_free(pem);
g_free(data);
g_free(device_file); g_free(device_file);
return 1; return 1;
} }
......
...@@ -40,7 +40,7 @@ int is_device_known(char *uid); ...@@ -40,7 +40,7 @@ int is_device_known(char *uid);
/** /**
* @return 1 if everything went well. Returns 0 otherwise. * @return 1 if everything went well. Returns 0 otherwise.
*/ */
int store_device_public_key(char *uid, char *public_key); int store_device_public_key(char *uid, gnutls_datum_t public_key);
/** /**
* @return 1 if everything went well. Returns 0 otherwise. * @return 1 if everything went well. Returns 0 otherwise.
......
...@@ -165,7 +165,9 @@ void node_to_xml(GNode * node, gpointer xml_struct) ...@@ -165,7 +165,9 @@ void node_to_xml(GNode * node, gpointer xml_struct)
case PLIST_DATA: case PLIST_DATA:
tag = "data"; tag = "data";
val = format_string(node_data->buff, 60, xstruct->depth); gchar *valtmp = g_base64_encode(node_data->buff, node_data->length);
val = format_string(valtmp, 60, xstruct->depth);
g_free(valtmp);
break; break;
case PLIST_ARRAY: case PLIST_ARRAY:
tag = "array"; tag = "array";
...@@ -267,7 +269,9 @@ void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) ...@@ -267,7 +269,9 @@ void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
} }
if (!xmlStrcmp(node->name, "data")) { if (!xmlStrcmp(node->name, "data")) {
data->buff = strdup(xmlNodeGetContent(node)); gsize size = 0;
data->buff = g_base64_decode(xmlNodeGetContent(node), &size);
data->length = size;
data->type = PLIST_DATA; data->type = PLIST_DATA;
continue; continue;
} }
......
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