From 55f6d26b7424d660c99bc89f3677b20294e87a27 Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Tue, 4 Feb 2020 18:42:04 +0100 Subject: Refactoring reclaim attestations --- src/reclaim/gnunet-reclaim.c | 72 ++-- src/reclaim/gnunet-service-reclaim.c | 602 ++------------------------- src/reclaim/gnunet-service-reclaim_tickets.c | 271 +++++------- src/reclaim/gnunet-service-reclaim_tickets.h | 4 +- src/reclaim/json_reclaim.c | 149 ++----- src/reclaim/json_reclaim.h | 14 +- src/reclaim/oidc_helper.c | 153 +++---- src/reclaim/oidc_helper.h | 9 +- src/reclaim/plugin_gnsrecord_reclaim.c | 30 +- src/reclaim/plugin_rest_openid_connect.c | 295 ++++++------- src/reclaim/plugin_rest_reclaim.c | 524 ++++------------------- src/reclaim/reclaim.h | 46 ++ src/reclaim/reclaim_api.c | 433 ++++++++----------- 13 files changed, 737 insertions(+), 1865 deletions(-) (limited to 'src/reclaim') diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index c3d305eb5..b72336907 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.c @@ -135,7 +135,7 @@ static struct GNUNET_RECLAIM_Ticket ticket; /** * Attribute list */ -static struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list; +static struct GNUNET_RECLAIM_AttributeList *attr_list; /** * Attribute expiration interval @@ -155,7 +155,7 @@ static struct GNUNET_SCHEDULER_Task *cleanup_task; /** * Claim to store */ -struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; +struct GNUNET_RECLAIM_Attribute *claim; /** * Claim to delete @@ -165,7 +165,7 @@ static char *attr_delete; /** * Claim object to delete */ -static struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr_to_delete; +static struct GNUNET_RECLAIM_Attribute *attr_to_delete; static void do_cleanup (void *cls) @@ -226,9 +226,8 @@ store_attr_cont (void *cls, int32_t success, const char *emsg) static void process_attrs (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) + const struct GNUNET_RECLAIM_Attribute *attr, + const struct GNUNET_RECLAIM_Attestation *attest) { char *value_str; char *id; @@ -245,18 +244,19 @@ process_attrs (void *cls, ret = 1; return; } - value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, + value_str = GNUNET_RECLAIM_attribute_value_to_string (attr->type, attr->data, attr->data_size); - attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); + attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type); id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id)); fprintf (stdout, - "Name: %s; Value: %s (%s); Flag %u; ID: %s\n", + "Name: %s; Value: %s (%s); Flag %u; ID: %s %s\n", attr->name, value_str, attr_type, attr->flag, - id); + id, + (NULL == attest) ? "" : "ATTESTED"); GNUNET_free (id); } @@ -412,10 +412,10 @@ iter_finished (void *cls) if (NULL == type_str) type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; else - type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); + type = GNUNET_RECLAIM_attribute_typename_to_number (type_str); GNUNET_assert (GNUNET_SYSERR != - GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, + GNUNET_RECLAIM_attribute_string_to_value (type, attr_value, (void **) &data, &data_size)); @@ -428,7 +428,7 @@ iter_finished (void *cls) else { claim = - GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size); + GNUNET_RECLAIM_attribute_new (attr_name, NULL, type, data, data_size); } reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle, pkey, @@ -447,11 +447,10 @@ iter_finished (void *cls) static void iter_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) + const struct GNUNET_RECLAIM_Attribute *attr, + const struct GNUNET_RECLAIM_Attestation *attest) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_RECLAIM_AttributeListEntry *le; char *attrs_tmp; char *attr_str; char *label; @@ -462,10 +461,11 @@ iter_cb (void *cls, { if (0 == strcasecmp (attr_name, attr->name)) { - claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, - attr->type, - attr->data, - attr->data_size); + claim = GNUNET_RECLAIM_attribute_new (attr->name, + &attr->attestation, + attr->type, + attr->data, + attr->data_size); } } else if (issue_attrs) @@ -479,13 +479,14 @@ iter_cb (void *cls, attr_str = strtok (NULL, ","); continue; } - le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, - attr->type, - attr->data, - attr->data_size); - le->claim->flag = attr->flag; - le->claim->id = attr->id; + le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); + le->attribute = GNUNET_RECLAIM_attribute_new (attr->name, + &attr->attestation, + attr->type, + attr->data, + attr->data_size); + le->attribute->flag = attr->flag; + le->attribute->id = attr->id; GNUNET_CONTAINER_DLL_insert (attr_list->list_head, attr_list->list_tail, le); @@ -498,20 +499,21 @@ iter_cb (void *cls, label = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id)); if (0 == strcasecmp (attr_delete, label)) { - attr_to_delete = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, - attr->type, - attr->data, - attr->data_size); + attr_to_delete = GNUNET_RECLAIM_attribute_new (attr->name, + &attr->attestation, + attr->type, + attr->data, + attr->data_size); attr_to_delete->id = attr->id; } GNUNET_free (label); } else if (list) { - attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, + attr_str = GNUNET_RECLAIM_attribute_value_to_string (attr->type, attr->data, attr->data_size); - attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); + attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type); id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id)); fprintf (stdout, "Name: %s; Value: %s (%s); Flag %u; ID: %s\n", @@ -568,7 +570,7 @@ start_process () &ticket, sizeof(struct GNUNET_RECLAIM_Ticket)); - attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); + attr_list = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); claim = NULL; attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle, pkey, diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index a00bc5730..15f9a8385 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c @@ -263,17 +263,13 @@ struct AttributeDeleteHandle /** * The attribute to delete */ - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; + struct GNUNET_RECLAIM_Attribute *claim; /** * The attestation to delete */ - struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; + struct GNUNET_RECLAIM_Attestation *attest; - /** - * The reference to delete - */ - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference; /** * Tickets to update */ @@ -334,17 +330,12 @@ struct AttributeStoreHandle /** * The attribute to store */ - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; + struct GNUNET_RECLAIM_Attribute *claim; /** * The attestation to store */ - struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; - - /** - * The reference to store - */ - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference; + struct GNUNET_RECLAIM_Attestation *attest; /** * The attribute expiration interval @@ -480,8 +471,6 @@ cleanup_adh (struct AttributeDeleteHandle *adh) GNUNET_free (adh->claim); if (NULL != adh->attest) GNUNET_free (adh->attest); - if (NULL != adh->reference) - GNUNET_free (adh->reference); while (NULL != (le = adh->tickets_to_update_head)) { GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, @@ -511,8 +500,6 @@ cleanup_as_handle (struct AttributeStoreHandle *ash) GNUNET_free (ash->claim); if (NULL != ash->attest) GNUNET_free (ash->attest); - if (NULL != ash->reference) - GNUNET_free (ash->reference); GNUNET_free (ash); } @@ -718,13 +705,13 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im) { struct TicketIssueOperation *tio; struct IdpClient *idp = cls; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; + struct GNUNET_RECLAIM_AttributeList *attrs; size_t attrs_len; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n"); tio = GNUNET_new (struct TicketIssueOperation); attrs_len = ntohs (im->attr_len); - attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *) &im[1], + attrs = GNUNET_RECLAIM_attribute_list_deserialize ((char *) &im[1], attrs_len); tio->r_id = ntohl (im->id); tio->client = idp; @@ -735,7 +722,7 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im) &issue_ticket_result_cb, tio); GNUNET_SERVICE_client_continue (idp->client); - GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); + GNUNET_RECLAIM_attribute_list_destroy (attrs); } @@ -828,7 +815,7 @@ handle_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *rm) static void consume_result_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, + const struct GNUNET_RECLAIM_AttributeList *attrs, int32_t success, const char *emsg) { @@ -842,7 +829,7 @@ consume_result_cb (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error consuming ticket: %s\n", emsg); } - attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); + attrs_len = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending CONSUME_TICKET_RESULT message\n"); env = GNUNET_MQ_msg_extra (crm, @@ -853,7 +840,7 @@ consume_result_cb (void *cls, crm->identity = *identity; crm->result = htonl (success); data_tmp = (char *) &crm[1]; - GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, data_tmp); + GNUNET_RECLAIM_attribute_list_serialize (attrs, data_tmp); GNUNET_MQ_send (cop->client->mq, env); GNUNET_CONTAINER_DLL_remove (cop->client->consume_op_head, cop->client->consume_op_tail, @@ -965,20 +952,20 @@ attr_store_task (void *cls) size_t buf_size; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing attribute\n"); - buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (ash->claim); + buf_size = GNUNET_RECLAIM_attribute_serialize_get_size (ash->claim); buf = GNUNET_malloc (buf_size); // Give the ash a new id if unset if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&ash->claim->id)) GNUNET_RECLAIM_id_generate (&ash->claim->id); - GNUNET_RECLAIM_ATTRIBUTE_serialize (ash->claim, buf); + GNUNET_RECLAIM_attribute_serialize (ash->claim, buf); label = GNUNET_STRINGS_data_to_string_alloc (&ash->claim->id, - sizeof (ash->reference->id)); + sizeof (ash->claim->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); rd[0].data_size = buf_size; rd[0].data = buf; - rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR; + rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE; rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; rd[0].expiration_time = ash->exp.rel_value_us; ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, @@ -1034,7 +1021,7 @@ handle_attribute_store_message (void *cls, data_len = ntohs (sam->attr_len); ash = GNUNET_new (struct AttributeStoreHandle); - ash->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *) &sam[1], + ash->claim = GNUNET_RECLAIM_attribute_deserialize ((char *) &sam[1], data_len); ash->r_id = ntohl (sam->id); @@ -1087,32 +1074,6 @@ attest_store_cont (void *cls, int32_t success, const char *emsg) } -/** - * Send a reference error response - * - * @param ash our attribute store handle - * @param success the success status - */ -static void -send_ref_error (struct AttributeStoreHandle *ash) -{ - struct GNUNET_MQ_Envelope *env; - struct SuccessResultMessage *acr_msg; - - ash->ns_qe = NULL; - GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head, - ash->client->store_op_tail, - ash); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n"); - env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE); - acr_msg->id = htonl (ash->r_id); - acr_msg->op_result = htonl (GNUNET_SYSERR); - GNUNET_MQ_send (ash->client->mq, env); - cleanup_as_handle (ash); -} - - /** * Error looking up potential attestation. Abort. * @@ -1131,7 +1092,7 @@ attest_error (void *cls) /** -* Check for existing record before storing reference +* Check for existing record before storing attestation * * @param cls our attribute store handle * @param zone zone we are iterating @@ -1149,56 +1110,27 @@ attest_add_cb (void *cls, struct AttributeStoreHandle *ash = cls; char *buf; size_t buf_size; - buf_size = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (ash->attest); + buf_size = GNUNET_RECLAIM_attestation_serialize_get_size (ash->attest); buf = GNUNET_malloc (buf_size); - GNUNET_RECLAIM_ATTESTATION_serialize (ash->attest, buf); - if (0 == rd_count) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Storing new Attestation\n"); - struct GNUNET_GNSRECORD_Data rd_new[1]; - rd_new[0].data_size = buf_size; - rd_new[0].data = buf; - rd_new[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR; - rd_new[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; - rd_new[0].expiration_time = ash->exp.rel_value_us; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); - ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, - &ash->identity, - label, - 1, - rd_new, - &attest_store_cont, - ash); - GNUNET_free (buf); - return; - } - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Existing Attestation location is not an Attestation\n"); - send_ref_error (ash); - return; - } - struct GNUNET_GNSRECORD_Data rd_new[rd_count]; - for (int i = 0; iattest, buf); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Storing new Attestation\n"); + struct GNUNET_GNSRECORD_Data rd_new[1]; rd_new[0].data_size = buf_size; rd_new[0].data = buf; - rd_new[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR; + rd_new[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION; rd_new[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; rd_new[0].expiration_time = ash->exp.rel_value_us; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, &ash->identity, label, - rd_count, + 1, rd_new, &attest_store_cont, ash); GNUNET_free (buf); + return; } @@ -1273,7 +1205,7 @@ handle_attestation_store_message (void *cls, data_len = ntohs (sam->attr_len); ash = GNUNET_new (struct AttributeStoreHandle); - ash->attest = GNUNET_RECLAIM_ATTESTATION_deserialize ((char *) &sam[1], + ash->attest = GNUNET_RECLAIM_attestation_deserialize ((char *) &sam[1], data_len); ash->r_id = ntohl (sam->id); @@ -1288,250 +1220,6 @@ handle_attestation_store_message (void *cls, } -/** - * Error looking up potential reference value. Abort. - * - * @param cls our attribute store handle - */ -static void -ref_error (void *cls) -{ - struct AttributeStoreHandle *ash = cls; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to find Attestation entry for Attestation reference\n"); - cleanup_as_handle (ash); - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - return; -} - - -/** - * Error looking up potential reference value. Abort. - * - * @param cls our attribute delete handle - */ -static void -ref_del_error (void *cls) -{ - struct AttributeDeleteHandle *adh = cls; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to find Attestation entry for Attestation reference\n"); - cleanup_adh (adh); - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - return; -} - - -/** -* Reference store result handler -* -* @param cls our attribute store handle -* @param success GNUNET_OK if successful -* @param emsg error message (NULL if success=GNUNET_OK) -*/ -static void -reference_store_cont (void *cls, int32_t success, const char *emsg) -{ - struct AttributeStoreHandle *ash = cls; - struct GNUNET_MQ_Envelope *env; - struct SuccessResultMessage *acr_msg; - - ash->ns_qe = NULL; - GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head, - ash->client->store_op_tail, - ash); - - if (GNUNET_SYSERR == success) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to store reference %s\n", - emsg); - cleanup_as_handle (ash); - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n"); - env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE); - acr_msg->id = htonl (ash->r_id); - acr_msg->op_result = htonl (GNUNET_OK); - GNUNET_MQ_send (ash->client->mq, env); - cleanup_as_handle (ash); -} - - -/** -* Check for existing record before storing reference -* -* @param cls our attribute store handle -* @param zone zone we are iterating -* @param label label of the records -* @param rd_count record count -* @param rd records -*/ -static void -ref_add_cb (void *cls, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - struct AttributeStoreHandle *ash = cls; - char *buf; - size_t buf_size; - buf_size = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (ash->reference); - buf = GNUNET_malloc (buf_size); - GNUNET_RECLAIM_ATTESTATION_REF_serialize (ash->reference, buf); - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *ref; - char *data_tmp; - if (0 == rd_count) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to find Attestation entry for Attestation reference\n"); - send_ref_error (ash); - return; - } - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Intended Reference storage location is not an attestation\n"); - send_ref_error (ash); - return; - } - struct GNUNET_GNSRECORD_Data rd_new[rd_count + 1]; - int i; - for (i = 0; ireference->name,ref->name) == 0) && - (strcmp (ash->reference->reference_value,ref->reference_value)==0) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Reference already stored\n"); - reference_store_cont (ash,GNUNET_OK, NULL); - return; - } - } - rd_new[rd_count].data_size = buf_size; - rd_new[rd_count].data = buf; - rd_new[rd_count].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE; - rd_new[rd_count].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; - rd_new[rd_count].expiration_time = ash->exp.rel_value_us; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); - ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, - &ash->identity, - label, - rd_count + 1, - rd_new, - &reference_store_cont, - ash); - GNUNET_free (buf); -} - - -/** - * Add a new reference - * - * @param cls the AttributeStoreHandle - */ -static void -reference_store_task (void *cls) -{ - struct AttributeStoreHandle *ash = cls; - char *label; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing reference\n"); - - // Give the ash a new id if unset - if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&ash->reference->id)) - { - if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&ash->reference->id_attest)) - { - GNUNET_RECLAIM_id_generate (&ash->reference->id); - } - else - { - ash->reference->id = ash->reference->id_attest; - } - } - - label = GNUNET_STRINGS_data_to_string_alloc (&ash->reference->id, - sizeof (ash->reference->id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Looking up existing data under label %s\n", label); -// Test for the content of the existing ID - - ash->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, - &ash->identity, - label, - &ref_error, - ash, - &ref_add_cb, - ash); - GNUNET_free (label); -} - - -/** - * Check an attestation reference store message - * - * @param cls unused - * @param sam the message to check - */ -static int -check_reference_store_message (void *cls, - const struct - AttributeStoreMessage *sam) -{ - uint16_t size; - - size = ntohs (sam->header.size); - if (size <= sizeof(struct AttributeStoreMessage)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - return GNUNET_OK; -} - - -/** - * Handle an attestation reference store message - * - * @param cls our client - * @param sam the message to handle - */ -static void -handle_reference_store_message (void *cls, - const struct AttributeStoreMessage *sam) -{ - struct AttributeStoreHandle *ash; - struct IdpClient *idp = cls; - size_t data_len; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REFERENCE_STORE message\n"); - - data_len = ntohs (sam->attr_len); - ash = GNUNET_new (struct AttributeStoreHandle); - ash->reference = GNUNET_RECLAIM_ATTESTATION_REF_deserialize ((char *) &sam[1], - data_len); - ash->r_id = ntohl (sam->id); - ash->identity = sam->identity; - ash->exp.rel_value_us = GNUNET_ntohll (sam->exp); - GNUNET_CRYPTO_ecdsa_key_get_public (&sam->identity, &ash->identity_pkey); - - - GNUNET_SERVICE_client_continue (idp->client); - ash->client = idp; - GNUNET_CONTAINER_DLL_insert (idp->store_op_head, idp->store_op_tail, ash); - GNUNET_SCHEDULER_add_now (&reference_store_task, ash); -} - - /** * Send a deletion success response * @@ -1578,7 +1266,7 @@ ticket_iter (void *cls, int has_changed = GNUNET_NO; for (int i = 0; i < rd_count; i++) { - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) continue; if (adh->claim != NULL) if (GNUNET_YES != GNUNET_RECLAIM_id_is_equal (rd[i].data, @@ -1588,12 +1276,8 @@ ticket_iter (void *cls, if (GNUNET_YES != GNUNET_RECLAIM_id_is_equal (rd[i].data, &adh->attest->id)) continue; - if (adh->reference != NULL) - if (GNUNET_YES != GNUNET_RECLAIM_id_is_equal (rd[i].data, - &adh->reference->id)) - continue; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Attribute or Attestation/Reference to delete found (%s)\n", + "Attribute or Attestation to delete found (%s)\n", adh->label); has_changed = GNUNET_YES; break; @@ -1684,20 +1368,15 @@ update_tickets (void *cls) for (int i = 0; i < le->rd_count; i++) { if (adh->claim != NULL) - if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) + if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF == rd[i].record_type) && (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, &adh->claim->id))) continue; if (adh->attest != NULL) - if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) + if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF == rd[i].record_type) && (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, &adh->attest->id))) continue; - if (adh->reference != NULL) - if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) - && (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, - &adh->reference->id))) - continue; rd_new[j] = rd[i]; j++; } @@ -1837,9 +1516,8 @@ handle_attribute_delete_message (void *cls, data_len = ntohs (dam->attr_len); adh = GNUNET_new (struct AttributeDeleteHandle); - adh->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *) &dam[1], + adh->claim = GNUNET_RECLAIM_attribute_deserialize ((char *) &dam[1], data_len); - adh->reference = NULL; adh->attest = NULL; adh->r_id = ntohl (dam->id); @@ -1928,9 +1606,8 @@ handle_attestation_delete_message (void *cls, data_len = ntohs (dam->attr_len); adh = GNUNET_new (struct AttributeDeleteHandle); - adh->attest = GNUNET_RECLAIM_ATTESTATION_deserialize ((char *) &dam[1], + adh->attest = GNUNET_RECLAIM_attestation_deserialize ((char *) &dam[1], data_len); - adh->reference = NULL; adh->claim = NULL; adh->r_id = ntohl (dam->id); @@ -1951,169 +1628,6 @@ handle_attestation_delete_message (void *cls, } -/** -* Reference deleted callback -* -* @param cls our handle -* @param success success status -* @param emsg error message (NULL if success=GNUNET_OK) -*/ -static void -reference_delete_cont (void *cls, int32_t success, const char *emsg) -{ - struct AttributeDeleteHandle *adh = cls; - - adh->ns_qe = NULL; - if (GNUNET_SYSERR == success) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Error deleting reference %s\n", - adh->label); - send_delete_response (adh, GNUNET_SYSERR); - cleanup_adh (adh); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating tickets...\n"); - // GNUNET_SCHEDULER_add_now (&start_ticket_update, adh); - send_delete_response (adh, GNUNET_OK); - cleanup_adh (adh); - return; -} - - -static void -ref_del_cb (void *cls, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - - struct AttributeDeleteHandle *adh = cls; - char *data_tmp; - struct GNUNET_GNSRECORD_Data rd_new[rd_count - 1]; - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *ref; - size_t attr_len; - - if (0 == rd_count) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to find Attestation entry for Attestation reference\n"); - cleanup_adh (adh); - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - return; - } - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Intended Reference location is not an attestation\n"); - cleanup_adh (adh); - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - return; - } - rd_new[0] = rd[0]; - int i; - int j = 1; - for (i = 1; ireference->name,ref->name) == 0) && - (strcmp (adh->reference->reference_value,ref->reference_value)==0) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found reference to delete.\n"); - } - else - { - rd_new[j] = rd[i]; - j += 1; - } - GNUNET_free (data_tmp); - } - adh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, - &adh->identity, - label, - j, - rd_new, - &reference_delete_cont, - adh); -} - - -/** - * Check an attestation reference delete message - * - * @param cls unused - * @param sam the message to check - */ -static int -check_reference_delete_message (void *cls, - const struct AttributeDeleteMessage *dam) -{ - uint16_t size; - - size = ntohs (dam->header.size); - if (size <= sizeof(struct AttributeDeleteMessage)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - return GNUNET_OK; -} - - -/** - * Handle reference deletion - * - * @param cls our client - * @param dam deletion message - */ -static void -handle_reference_delete_message (void *cls, - const struct AttributeDeleteMessage *dam) -{ - struct AttributeDeleteHandle *adh; - struct IdpClient *idp = cls; - size_t data_len; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REFERENCE_DELETE message\n"); - data_len = ntohs (dam->attr_len); - adh = GNUNET_new (struct AttributeDeleteHandle); - adh->reference = GNUNET_RECLAIM_ATTESTATION_REF_deserialize ((char *) &dam[1], - data_len); - adh->attest = NULL; - adh->claim = NULL; - - adh->r_id = ntohl (dam->id); - adh->identity = dam->identity; - adh->label - = GNUNET_STRINGS_data_to_string_alloc (&adh->reference->id, - sizeof(adh->reference->id)); - GNUNET_SERVICE_client_continue (idp->client); - adh->client = idp; - GNUNET_CONTAINER_DLL_insert (idp->delete_op_head, idp->delete_op_tail, adh); - adh->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, - &adh->identity, - adh->label, - &ref_del_error, - adh, - &ref_del_cb, - adh); -} - - /************************************************* * Attrubute iteration *************************************************/ @@ -2159,7 +1673,7 @@ attr_iter_error (void *cls) /** - * Got record. Return if it is an attribute or attestation/reference. + * Got record. Return if it is an attribute or attestation. * * @param cls our attribute iterator * @param zone zone we are iterating @@ -2185,14 +1699,14 @@ attr_iter_cb (void *cls, } if (rd_count > 1) { - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[0].record_type) + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF == rd[0].record_type) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found Ticket. Ignoring.\n"); GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); return; } - else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) + else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION != rd[0].record_type) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Non-Attestation record with multiple entries found: %u\n", @@ -2204,15 +1718,14 @@ attr_iter_cb (void *cls, for (int i = 0; ins_it, 1); return; } - - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR == rd[i].record_type) + // FIXME Send attribute TOGETHER with respective attestation if applicable + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE == rd[i].record_type) { struct AttributeResultMessage *arm; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", @@ -2231,7 +1744,7 @@ attr_iter_cb (void *cls, } else { - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd[i].record_type) + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION == rd[i].record_type) { struct AttributeResultMessage *arm; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attestation under: %s\n", @@ -2248,26 +1761,6 @@ attr_iter_cb (void *cls, GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size); GNUNET_MQ_send (ai->client->mq, env); } - else - { - struct ReferenceResultMessage *rrm; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found reference under: %s\n", - label); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending REFERENCE_RESULT message\n"); - env = GNUNET_MQ_msg_extra (rrm, - rd[i].data_size + rd[0].data_size, - GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT); - rrm->id = htonl (ai->request_id); - rrm->attest_len = htons (rd[0].data_size); - rrm->ref_len = htons (rd[i].data_size); - GNUNET_CRYPTO_ecdsa_key_get_public (zone, &rrm->identity); - data_tmp = (char *) &rrm[1]; - GNUNET_memcpy (data_tmp, rd[0].data, rd[0].data_size); - data_tmp += rd[0].data_size; - GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size); - GNUNET_MQ_send (ai->client->mq, env); - } } } } @@ -2610,19 +2103,10 @@ GNUNET_SERVICE_MAIN ( GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_DELETE, struct AttributeDeleteMessage, NULL), - GNUNET_MQ_hd_var_size (reference_store_message, - GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_STORE, - struct AttributeStoreMessage, - NULL), - GNUNET_MQ_hd_var_size (reference_delete_message, - GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_DELETE, - struct AttributeDeleteMessage, - NULL), - GNUNET_MQ_hd_fixed_size ( - iteration_start, - GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, - struct AttributeIterationStartMessage, - NULL), + GNUNET_MQ_hd_fixed_size (iteration_start, + GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, + struct AttributeIterationStartMessage, + NULL), GNUNET_MQ_hd_fixed_size (iteration_next, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT, struct AttributeIterationNextMessage, diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c index bdb9e6dd9..019ce51b0 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.c +++ b/src/reclaim/gnunet-service-reclaim_tickets.c @@ -59,7 +59,7 @@ struct TicketReference /** * Attributes */ - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; + struct GNUNET_RECLAIM_AttributeList *attrs; /** * Tickets @@ -111,7 +111,12 @@ struct RECLAIM_TICKETS_ConsumeHandle /** * Attributes */ - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; + struct GNUNET_RECLAIM_AttributeList *attrs; + + /** + * Attestations + */ + struct GNUNET_RECLAIM_AttestationList *attests; /** * Lookup time @@ -165,7 +170,7 @@ struct TicketIssueHandle /** * Attributes to issue */ - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; + struct GNUNET_RECLAIM_AttributeList *attrs; /** * Issuer Key @@ -431,7 +436,7 @@ process_tickets (void *cls) } for (int i = 0; i < le->rd_count; i++) { - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) continue; for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) { @@ -493,7 +498,7 @@ rvk_ticket_update (void *cls, /** Let everything point to the old record **/ for (int i = 0; i < rd_count; i++) { - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) continue; for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) { @@ -685,80 +690,55 @@ rvk_move_attr_cb (void *cls, // new_rd = *rd; for (int i = 0; i < rd_count; i++) { - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR == rd[i].record_type) + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE == rd[i].record_type) { /** find a new place for this attribute **/ - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; - claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd[i].data, + struct GNUNET_RECLAIM_Attribute *claim; + claim = GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute to update: Name=%s\n", claim->name); claim->id = rvk->move_attr->new_id; - new_rd[i].data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (claim); + new_rd[i].data_size = GNUNET_RECLAIM_attribute_serialize_get_size (claim); attr_data = GNUNET_malloc (rd[i].data_size); - new_rd[i].data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize (claim, + new_rd[i].data_size = GNUNET_RECLAIM_attribute_serialize (claim, attr_data); new_rd[i].data = attr_data; new_rd[i].record_type = rd[i].record_type; new_rd[i].flags = rd[i].flags; new_rd[i].expiration_time = rd[i].expiration_time; - new_label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, - sizeof (rvk->move_attr-> - new_id)); + new_label = + GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, + sizeof (rvk->move_attr->new_id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label); GNUNET_free (claim); } - else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd[i].record_type) + else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION == rd[i].record_type) { - struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; - attest = GNUNET_RECLAIM_ATTESTATION_deserialize (rd[i].data, + struct GNUNET_RECLAIM_Attestation *attest; + attest = GNUNET_RECLAIM_attestation_deserialize (rd[i].data, rd[i].data_size); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attestation to update: Name=%s\n", attest->name); attest->id = rvk->move_attr->new_id; - new_rd[i].data_size = GNUNET_RECLAIM_ATTESTATION_serialize_get_size ( - attest); + new_rd[i].data_size = + GNUNET_RECLAIM_attestation_serialize_get_size (attest); attr_data = GNUNET_malloc (rd[i].data_size); - new_rd[i].data_size = GNUNET_RECLAIM_ATTESTATION_serialize (attest, + new_rd[i].data_size = GNUNET_RECLAIM_attestation_serialize (attest, attr_data); new_rd[i].data = attr_data; new_rd[i].record_type = rd[i].record_type; new_rd[i].flags = rd[i].flags; new_rd[i].expiration_time = rd[i].expiration_time; - new_label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, - sizeof (rvk->move_attr-> - new_id)); + new_label = + GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, + sizeof (rvk->move_attr->new_id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attestation %s\n", new_label); GNUNET_free (attest); } - else if (GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE == rd[i].record_type) - { - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference; - reference = GNUNET_RECLAIM_ATTESTATION_REF_deserialize (rd[i].data, - rd[i].data_size); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Reference to update: Name=%s\n", - reference->name); - reference->id = rvk->move_attr->new_id; - reference->id_attest = rvk->move_attr->new_id; - new_rd[i].data_size = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size ( - reference); - attr_data = GNUNET_malloc (rd[i].data_size); - new_rd[i].data_size = GNUNET_RECLAIM_ATTESTATION_REF_serialize (reference, - attr_data); - new_rd[i].data = attr_data; - new_label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, - sizeof (rvk->move_attr-> - new_id)); - new_rd[i].record_type = rd[i].record_type; - new_rd[i].flags = rd[i].flags; - new_rd[i].expiration_time = rd[i].expiration_time; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding reference %s\n", new_label); - GNUNET_free (reference); - } } rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, &rvk->identity, @@ -880,7 +860,7 @@ revoke_attrs_cb (void *cls, */ for (int i = 0; i < rd_count; i++) { - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) continue; le = GNUNET_new (struct RevokedAttributeEntry); le->old_id = *((struct GNUNET_RECLAIM_Identifier *) rd[i].data); @@ -999,7 +979,9 @@ cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth) } if (NULL != cth->attrs) - GNUNET_RECLAIM_ATTRIBUTE_list_destroy (cth->attrs); + GNUNET_RECLAIM_attribute_list_destroy (cth->attrs); + if (NULL != cth->attests) + GNUNET_RECLAIM_attestation_list_destroy (cth->attests); GNUNET_free (cth); } @@ -1018,7 +1000,7 @@ process_parallel_lookup_result (void *cls, { struct ParallelLookup *parallel_lookup = cls; struct RECLAIM_TICKETS_ConsumeHandle *cth = parallel_lookup->handle; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le; + struct GNUNET_RECLAIM_AttributeListEntry *attr_le; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parallel lookup finished (count=%u)\n", @@ -1044,62 +1026,34 @@ process_parallel_lookup_result (void *cls, // REMARK: It is possible now to find rd_count > 1 for (int i = 0; i < rd_count; i++) { - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR == rd[i].record_type) + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE == rd[i].record_type) { - attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - attr_le->claim = - GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd[i].data, rd[i].data_size); + attr_le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); + attr_le->attribute = + GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size); GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head, cth->attrs->list_tail, attr_le); - attr_le->reference = NULL; - attr_le->attest = NULL; } - else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd[i].record_type) + else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION == rd[i].record_type) { - /**Ignore all plain attestations - *attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - *attr_le->attest = - * GNUNET_RECLAIM_ATTESTATION_deserialize (rd[i].data, rd[i].data_size); - *GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head, - * cth->attrs->list_tail, - * attr_le); - */ - continue; + struct GNUNET_RECLAIM_AttestationListEntry *ale; + ale = GNUNET_new (struct GNUNET_RECLAIM_AttestationListEntry); + ale->attestation = + GNUNET_RECLAIM_attestation_deserialize (rd[i].data, + rd[i].data_size); + GNUNET_CONTAINER_DLL_insert (cth->attests->list_head, + cth->attests->list_tail, + ale); } - else if (GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE == rd[i].record_type) + else { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le2; - attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - attr_le2 = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd[0].record_type) - { - attr_le->attest = GNUNET_RECLAIM_ATTESTATION_deserialize (rd[0].data, - rd[0]. - data_size); - attr_le2->reference = - GNUNET_RECLAIM_ATTESTATION_REF_deserialize (rd[i].data, - rd[i].data_size); - attr_le->claim = NULL; - attr_le->reference = NULL; - attr_le2->claim = NULL; - attr_le2->attest = NULL; - GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head, - cth->attrs->list_tail, - attr_le); - GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head, - cth->attrs->list_tail, - attr_le2); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Parallel Lookup of Reference without Attestation"); - continue; - } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Parallel Lookup of Reference without Attestation"); + continue; + } - } } if (NULL != cth->parallel_lookups_head) return; // Wait for more @@ -1170,7 +1124,7 @@ lookup_authz_cb (void *cls, for (int i = 0; i < rd_count; i++) { - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) continue; lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute ref found %s\n", lbl); @@ -1234,7 +1188,7 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, cth->identity = *id; GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub); - cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); + cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); cth->ticket = *ticket; cth->cb = cb; cth->cb_cls = cb_cls; @@ -1249,7 +1203,7 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, GNUNET_GNS_lookup (gns, label, &cth->ticket.identity, - GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF, + GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF, GNUNET_GNS_LO_DEFAULT, &lookup_authz_cb, cth); @@ -1325,73 +1279,39 @@ store_ticket_issue_cont (void *cls, int32_t success, const char *emsg) static void issue_ticket (struct TicketIssueHandle *ih) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_RECLAIM_AttributeListEntry *le; struct GNUNET_GNSRECORD_Data *attrs_record; char *label; size_t list_len = 1; int i; - char *attest_string; for (le = ih->attrs->list_head; NULL != le; le = le->next) + { list_len++; + if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) + list_len++; + } attrs_record = GNUNET_malloc (list_len * sizeof(struct GNUNET_GNSRECORD_Data)); i = 0; for (le = ih->attrs->list_head; NULL != le; le = le->next) { - if (NULL != le->claim) - { - attrs_record[i].data = &le->claim->id; - attrs_record[i].data_size = sizeof(le->claim->id); - } - else if (NULL != le->attest) - { - // REMARK: Since we only store IDs, the references are irrelevant - int j = 0; - GNUNET_asprintf (&attest_string,"%d",le->attest->id); - while (jattest->id; - attrs_record[i].data_size = sizeof(le->attest->id); - } - else if (NULL != le->reference) - { - list_len--; - continue; - /* - int j = 0; - GNUNET_asprintf (&attest_string,"%d",le->attest->id); - while (jreference->id; - attrs_record[i].data_size = sizeof(le->reference->id); - */ - } - /** - * FIXME: Should this be the attribute expiration time or ticket - * refresh interval? Probably min(attrs.expiration) - */ + attrs_record[i].data = &le->attribute->id; + attrs_record[i].data_size = sizeof(le->attribute->id); attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; - attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF; + attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF; attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; + if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) + { + i++; + attrs_record[i].data = &le->attribute->attestation; + attrs_record[i].data_size = sizeof(le->attribute->attestation); + attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; + attrs_record[i].record_type = + GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF; + attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; + } i++; } attrs_record[i].data = &ih->ticket; @@ -1464,14 +1384,20 @@ filter_tickets_cb (void *cls, struct GNUNET_RECLAIM_Ticket *ticket = NULL; // figure out the number of requested attributes - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_RECLAIM_AttributeListEntry *le; unsigned int attr_cnt = 0; + unsigned int attest_cnt = 0; for (le = tih->attrs->list_head; NULL != le; le = le->next) + { attr_cnt++; + if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) + attest_cnt++; + } // ticket search unsigned int found_attrs_cnt = 0; + unsigned int found_attests_cnt = 0; for (int i = 0; i < rd_count; i++) { @@ -1491,31 +1417,20 @@ filter_tickets_cb (void *cls, } // cmp requested attributes with ticket attributes - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) + if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) && + (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF != rd[i].record_type)) continue; for (le = tih->attrs->list_head; NULL != le; le = le->next) { - // cmp attr_ref id with requested attr id - if (NULL !=le->claim) - { - if (0 == memcmp (rd[i].data, &le->claim->id, sizeof(le->claim->id))) - found_attrs_cnt++; - } - else if (NULL !=le->attest) - { - if (0 == memcmp (rd[i].data, - &le->attest->id, - sizeof(le->attest->id))) - found_attrs_cnt++; - } - else if (NULL != le->reference) - { - if (0 == memcmp (rd[i].data, - &le->reference->id, - sizeof(le->reference->id))) - found_attrs_cnt++; - } - + if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, + &le->attribute->id)) + found_attrs_cnt++; + } + for (le = tih->attrs->list_head; NULL != le; le = le->next) + { + if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, + &le->attribute->attestation)) + found_attests_cnt++; } } @@ -1523,7 +1438,9 @@ filter_tickets_cb (void *cls, * If we found a matching ticket, return that to the caller and * we are done. */ - if ((attr_cnt == found_attrs_cnt) && (NULL != ticket)) + if ((attr_cnt == found_attrs_cnt) && + (attest_cnt == found_attests_cnt) && + (NULL != ticket)) { GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it); tih->cb (tih->cb_cls, &tih->ticket, GNUNET_OK, NULL); @@ -1567,7 +1484,7 @@ filter_tickets_finished_cb (void *cls) */ void RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, + const struct GNUNET_RECLAIM_AttributeList *attrs, const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, RECLAIM_TICKETS_TicketResult cb, void *cb_cls) @@ -1577,7 +1494,7 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, tih = GNUNET_new (struct TicketIssueHandle); tih->cb = cb; tih->cb_cls = cb_cls; - tih->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (attrs); + tih->attrs = GNUNET_RECLAIM_attribute_list_dup (attrs); tih->identity = *identity; tih->ticket.audience = *audience; diff --git a/src/reclaim/gnunet-service-reclaim_tickets.h b/src/reclaim/gnunet-service-reclaim_tickets.h index c75cefc03..e8299718c 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.h +++ b/src/reclaim/gnunet-service-reclaim_tickets.h @@ -136,7 +136,7 @@ typedef void (*RECLAIM_TICKETS_TicketResult) ( typedef void (*RECLAIM_TICKETS_ConsumeCallback) ( void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *l, + const struct GNUNET_RECLAIM_AttributeList *l, int32_t success, const char *emsg); @@ -217,7 +217,7 @@ RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth); */ void RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, + const struct GNUNET_RECLAIM_AttributeList *attrs, const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, RECLAIM_TICKETS_TicketResult cb, void *cb_cls); diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index 6ac60a704..4c08430e7 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c @@ -43,11 +43,12 @@ static int parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) { - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; + struct GNUNET_RECLAIM_Attribute *attr; const char *name_str = NULL; const char *val_str = NULL; const char *type_str = NULL; const char *id_str = NULL; + const char *attest_str = NULL; const char *flag_str = NULL; char *data; int unpack_state; @@ -64,11 +65,13 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) } // interpret single attribute unpack_state = json_unpack (root, - "{s:s, s?s, s:s, s:s, s?s!}", + "{s:s, s?s, s?s, s:s, s:s, s?s!}", "name", &name_str, "id", &id_str, + "attestation", + &attest_str, "type", &type_str, "value", @@ -82,9 +85,9 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) "Error json object has a wrong format!\n"); return GNUNET_SYSERR; } - type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); + type = GNUNET_RECLAIM_attribute_typename_to_number (type_str); if (GNUNET_SYSERR == - (GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, + (GNUNET_RECLAIM_attribute_string_to_value (type, val_str, (void **) &data, &data_size))) @@ -92,7 +95,15 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); return GNUNET_SYSERR; } - attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str, type, data, data_size); + attr = GNUNET_RECLAIM_attribute_new (name_str, NULL, + type, data, data_size); + if ((NULL != attest_str) && (0 != strlen (attest_str))) + { + GNUNET_STRINGS_string_to_data (attest_str, + strlen (attest_str), + &attr->attestation, + sizeof(attr->attestation)); + } if ((NULL == id_str) || (0 == strlen (id_str))) memset (&attr->id, 0, sizeof (attr->id)); else @@ -101,7 +112,7 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) &attr->id, sizeof(attr->id)); - *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr = attr; + *(struct GNUNET_RECLAIM_Attribute **) spec->ptr = attr; return GNUNET_OK; } @@ -115,9 +126,9 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) static void clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) { - struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; + struct GNUNET_RECLAIM_Attribute **attr; - attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr; + attr = (struct GNUNET_RECLAIM_Attribute **) spec->ptr; if (NULL != *attr) { GNUNET_free (*attr); @@ -129,11 +140,11 @@ clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) /** * JSON Specification for Reclaim claims. * - * @param ticket struct of GNUNET_RECLAIM_ATTRIBUTE_Claim to fill + * @param ticket struct of GNUNET_RECLAIM_Attribute to fill * @return JSON Specification */ struct GNUNET_JSON_Specification -GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) +GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_Attribute **attr) { struct GNUNET_JSON_Specification ret = { .parser = &parse_attr, .cleaner = &clean_attr, @@ -279,7 +290,7 @@ GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket) static int parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) { - struct GNUNET_RECLAIM_ATTESTATION_Claim *attr; + struct GNUNET_RECLAIM_Attestation *attr; const char *name_str = NULL; const char *val_str = NULL; const char *type_str = NULL; @@ -315,9 +326,9 @@ parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) "Error json object has a wrong format!\n"); return GNUNET_SYSERR; } - type = GNUNET_RECLAIM_ATTESTATION_typename_to_number (type_str); + type = GNUNET_RECLAIM_attestation_typename_to_number (type_str); if (GNUNET_SYSERR == - (GNUNET_RECLAIM_ATTESTATION_string_to_value (type, + (GNUNET_RECLAIM_attestation_string_to_value (type, val_str, (void **) &data, &data_size))) @@ -325,7 +336,7 @@ parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attestation value invalid!\n"); return GNUNET_SYSERR; } - attr = GNUNET_RECLAIM_ATTESTATION_claim_new (name_str, type, data, data_size); + attr = GNUNET_RECLAIM_attestation_new (name_str, type, data, data_size); if ((NULL == id_str) || (0 == strlen (id_str))) memset (&attr->id, 0, sizeof (attr->id)); else @@ -334,7 +345,7 @@ parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) &attr->id, sizeof(attr->id)); - *(struct GNUNET_RECLAIM_ATTESTATION_Claim **) spec->ptr = attr; + *(struct GNUNET_RECLAIM_Attestation **) spec->ptr = attr; return GNUNET_OK; } @@ -347,9 +358,9 @@ parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) static void clean_attest (void *cls, struct GNUNET_JSON_Specification *spec) { - struct GNUNET_RECLAIM_ATTESTATION_Claim **attr; + struct GNUNET_RECLAIM_Attestation **attr; - attr = (struct GNUNET_RECLAIM_ATTESTATION_Claim **) spec->ptr; + attr = (struct GNUNET_RECLAIM_Attestation **) spec->ptr; if (NULL != *attr) { GNUNET_free (*attr); @@ -364,7 +375,7 @@ clean_attest (void *cls, struct GNUNET_JSON_Specification *spec) */ struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_claim_attest (struct - GNUNET_RECLAIM_ATTESTATION_Claim **attr) + GNUNET_RECLAIM_Attestation **attr) { struct GNUNET_JSON_Specification ret = { .parser = &parse_attest, .cleaner = &clean_attest, @@ -378,105 +389,3 @@ GNUNET_RECLAIM_JSON_spec_claim_attest (struct return ret; } -/** - * Parse given JSON object to an attestation claim - * - * @param cls closure, NULL - * @param root the json object representing data - * @param spec where to write the data - * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error - */ -static int -parse_attest_ref (void *cls, json_t *root, struct - GNUNET_JSON_Specification *spec) -{ - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr; - const char *name_str = NULL; - const char *ref_val_str = NULL; - const char *ref_id_str = NULL; - const char *id_str = NULL; - int unpack_state; - - GNUNET_assert (NULL != root); - - if (! json_is_object (root)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Error json is not array nor object!\n"); - return GNUNET_SYSERR; - } - // interpret single reference - unpack_state = json_unpack (root, - "{s:s, s?s, s:s, s:s!}", - "name", - &name_str, - "id", - &id_str, - "ref_id", - &ref_id_str, - "ref_value", - &ref_val_str); - if ((0 != unpack_state) || (NULL == name_str) || (NULL == ref_val_str) || - (NULL == ref_id_str)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Error json object has a wrong format!\n"); - return GNUNET_SYSERR; - } - - attr = GNUNET_RECLAIM_ATTESTATION_reference_new (name_str, ref_val_str); - memset (&attr->id, 0, sizeof (attr->id)); - - if ((NULL == ref_id_str) || (0 == strlen (ref_id_str))) - memset (&attr->id_attest, 0, sizeof (attr->id_attest)); - else - GNUNET_STRINGS_string_to_data (ref_id_str, - strlen (ref_id_str), - &attr->id_attest, - sizeof(attr->id_attest)); - - *(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **) spec->ptr = attr; - return GNUNET_OK; -} - -/** - * Cleanup data left from parsing RSA public key. - * - * @param cls closure, NULL - * @param[out] spec where to free the data - */ -static void -clean_attest_ref (void *cls, struct GNUNET_JSON_Specification *spec) -{ - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **attr; - - attr = (struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **) spec->ptr; - if (NULL != *attr) - { - GNUNET_free (*attr); - *attr = NULL; - } -} - -/** - * JSON Specification for Reclaim attestation references. - * - * @param ticket struct of GNUNET_RECLAIM_ATTESTATION_REFERENCE to fill - * @return JSON Specification - */ -struct GNUNET_JSON_Specification -GNUNET_RECLAIM_JSON_spec_claim_attest_ref (struct - GNUNET_RECLAIM_ATTESTATION_REFERENCE - **attr) -{ - struct GNUNET_JSON_Specification ret = { .parser = &parse_attest_ref, - .cleaner = &clean_attest_ref, - .cls = NULL, - .field = NULL, - .ptr = attr, - .ptr_size = 0, - .size_ptr = NULL }; - - *attr = NULL; - return ret; -} diff --git a/src/reclaim/json_reclaim.h b/src/reclaim/json_reclaim.h index 9e6479e5e..5aaf81b93 100644 --- a/src/reclaim/json_reclaim.h +++ b/src/reclaim/json_reclaim.h @@ -36,7 +36,7 @@ * @return JSON Specification */ struct GNUNET_JSON_Specification -GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr); +GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_Attribute **attr); /** * JSON Specification for Reclaim tickets. @@ -50,18 +50,10 @@ GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket); /** * JSON Specification for Reclaim attestation claims. * - * @param ticket struct of GNUNET_RECLAIM_ATTESTATION_Claim to fill + * @param ticket struct of GNUNET_RECLAIM_Attestation to fill * @return JSON Specification */ struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_claim_attest (struct - GNUNET_RECLAIM_ATTESTATION_Claim **attr); + GNUNET_RECLAIM_Attestation **attr); - /** - * JSON Specification for Reclaim attestation references. - * - * @param ticket struct of GNUNET_RECLAIM_ATTESTATION_REFERENCE to fill - * @return JSON Specification - */ - struct GNUNET_JSON_Specification - GNUNET_RECLAIM_JSON_spec_claim_attest_ref(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **attr); diff --git a/src/reclaim/oidc_helper.c b/src/reclaim/oidc_helper.c index 1d23003ab..487aa5695 100644 --- a/src/reclaim/oidc_helper.c +++ b/src/reclaim/oidc_helper.c @@ -60,6 +60,11 @@ struct OIDC_Parameters * The length of the attributes list */ uint32_t attr_list_len GNUNET_PACKED; + + /** + * The length of the attestation list + */ + uint32_t attest_list_len GNUNET_PACKED; }; GNUNET_NETWORK_STRUCT_END @@ -118,12 +123,14 @@ fix_base64 (char *str) char * OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, + struct GNUNET_RECLAIM_AttributeList *attrs, + struct GNUNET_RECLAIM_AttestationList *attests, const struct GNUNET_TIME_Relative *expiration_time, const char *nonce, const char *secret_key) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_RECLAIM_AttributeListEntry *le; + struct GNUNET_RECLAIM_AttestationListEntry *ale; struct GNUNET_HashCode signature; struct GNUNET_TIME_Absolute exp_time; struct GNUNET_TIME_Absolute time_now; @@ -146,7 +153,12 @@ OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, json_t *aggr_names; json_t *aggr_sources; json_t *aggr_sources_jwt; - struct GNUNET_RECLAIM_Identifier attest_arr[GNUNET_RECLAIM_ATTRIBUTE_list_count_attest (attrs)]; + int num_attestations = 0; + for (le = attrs->list_head; NULL != le; le = le->next) + { + if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) + num_attestations++; + } // iat REQUIRED time now time_now = GNUNET_TIME_absolute_get (); @@ -191,97 +203,73 @@ OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, // nonce if (NULL != nonce) json_object_set_new (body, "nonce", json_string (nonce)); - int i = 0; attest_val_str = NULL; aggr_names_str = NULL; aggr_sources_str = NULL; aggr_sources_jwt_str = NULL; source_name = NULL; + int i = 0; + for (ale = attests->list_head; NULL != ale; ale = ale->next) + { + // New Attestation + GNUNET_asprintf (&source_name, + "src%d", + i); + aggr_sources_jwt = json_object (); + attest_val_str = + GNUNET_RECLAIM_attestation_value_to_string (ale->attestation->type, + ale->attestation->data, + ale->attestation->data_size); + json_object_set_new (aggr_sources_jwt, "JWT", + json_string (attest_val_str) ); + aggr_sources_jwt_str = json_dumps (aggr_sources_jwt, JSON_INDENT (0) + | JSON_COMPACT); + json_object_set_new (aggr_sources, source_name,json_string ( + aggr_sources_jwt_str)); + i++; + } + for (le = attrs->list_head; NULL != le; le = le->next) { - if (le->claim != NULL) + if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) { attr_val_str = - GNUNET_RECLAIM_ATTRIBUTE_value_to_string (le->claim->type, - le->claim->data, - le->claim->data_size); - json_object_set_new (body, le->claim->name, json_string (attr_val_str)); + GNUNET_RECLAIM_attribute_value_to_string (le->attribute->type, + le->attribute->data, + le->attribute->data_size); + json_object_set_new (body, le->attribute->name, + json_string (attr_val_str)); GNUNET_free (attr_val_str); } - else if (NULL != le->reference) + else { // Check if attest is there int j = 0; - while (jlist_head; NULL != ale; ale = ale->next) { - if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (&attest_arr[j], - &le->reference->id_attest)) + if (GNUNET_YES == + GNUNET_RECLAIM_id_is_equal (&ale->attestation->id, + &le->attribute->attestation)) break; j++; } - if (j==i) - { - // Attest not yet existent. Append to the end of the list - GNUNET_CONTAINER_DLL_remove (attrs->list_head, attrs->list_tail, le); - GNUNET_CONTAINER_DLL_insert_tail (attrs->list_head, attrs->list_tail, - le); - continue; - } - else - { - // Attestation is existing, hence take the respective source str - GNUNET_asprintf (&source_name, - "src%d", - j); - json_object_set_new (aggr_names, le->reference->name, json_string ( - source_name)); - } - - } - else if (NULL != le->attest) - { - // We assume that at max 99 different attestations - int j = 0; - while (jattest->id)) - break; - j++; - } - if (j==i) - { - // New Attestation - attest_arr[i] = le->attest->id; - GNUNET_asprintf (&source_name, - "src%d", - i); - aggr_sources_jwt = json_object (); - attest_val_str = GNUNET_RECLAIM_ATTESTATION_value_to_string ( - le->attest->type, le->attest->data, le->attest->data_size); - json_object_set_new (aggr_sources_jwt, "JWT",json_string ( - attest_val_str) ); - aggr_sources_jwt_str = json_dumps (aggr_sources_jwt, JSON_INDENT (0) - | JSON_COMPACT); - json_object_set_new (aggr_sources, source_name,json_string ( - aggr_sources_jwt_str)); - i++; - } - else - { - // Attestation already existent. Ignore - continue; - } - + GNUNET_assert (NULL != ale); + // Attestation is existing, hence take the respective source str + GNUNET_asprintf (&source_name, + "src%d", + j); + json_object_set_new (aggr_names, le->attribute->data, + json_string (source_name)); } } + if (NULL != attest_val_str) GNUNET_free (attest_val_str); if (NULL != source_name) GNUNET_free (source_name); - if (0!=i) + if (0 != i) { aggr_names_str = json_dumps (aggr_names, JSON_INDENT (0) | JSON_COMPACT); aggr_sources_str = json_dumps (aggr_sources, JSON_INDENT (0) @@ -574,7 +562,8 @@ encrypt_payload (const struct GNUNET_CRYPTO_EcdsaPublicKey *ecdsa_pub, char * OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, const struct GNUNET_RECLAIM_Ticket *ticket, - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, + struct GNUNET_RECLAIM_AttributeList *attrs, + struct GNUNET_RECLAIM_AttestationList *attests, const char *nonce_str, const char *code_challenge) { @@ -587,6 +576,7 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, size_t payload_len; size_t code_payload_len; size_t attr_list_len = 0; + size_t attests_list_len = 0; size_t code_challenge_len = 0; uint32_t nonce; uint32_t nonce_tmp; @@ -625,7 +615,7 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, if (NULL != attrs) { // Get length - attr_list_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); + attr_list_len = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs); params.attr_list_len = htonl (attr_list_len); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Length of serialized attributes: %lu\n", @@ -633,6 +623,19 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, // Get serialized attributes payload_len += attr_list_len; } + if (NULL != attests) + { + // Get length + attests_list_len = + GNUNET_RECLAIM_attestation_list_serialize_get_size (attests); + params.attest_list_len = htonl (attests_list_len); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Length of serialized attestations: %lu\n", + attests_list_len); + // Get serialized attributes + payload_len += attests_list_len; + } + // Get plaintext length payload = GNUNET_malloc (payload_len); memcpy (payload, ¶ms, sizeof(params)); @@ -643,7 +646,10 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, tmp += code_challenge_len; } if (0 < attr_list_len) - GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, tmp); + GNUNET_RECLAIM_attribute_list_serialize (attrs, tmp); + if (0 < attests_list_len) + GNUNET_RECLAIM_attestation_list_serialize (attests, tmp); + /** END **/ /** ENCRYPT **/ @@ -711,7 +717,8 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv, const char *code, const char *code_verifier, struct GNUNET_RECLAIM_Ticket *ticket, - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList **attrs, + struct GNUNET_RECLAIM_AttributeList **attrs, + struct GNUNET_RECLAIM_AttestationList **attests, char **nonce_str) { char *code_payload; @@ -829,7 +836,7 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv, // Attributes attrs_ser = ((char *) ¶ms[1]) + code_challenge_len; attrs_ser_len = ntohl (params->attr_list_len); - *attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attrs_ser, attrs_ser_len); + *attrs = GNUNET_RECLAIM_attribute_list_deserialize (attrs_ser, attrs_ser_len); *nonce_str = NULL; if (nonce != 0) diff --git a/src/reclaim/oidc_helper.h b/src/reclaim/oidc_helper.h index a7072755b..2c533357e 100644 --- a/src/reclaim/oidc_helper.h +++ b/src/reclaim/oidc_helper.h @@ -51,7 +51,8 @@ char* OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, + struct GNUNET_RECLAIM_AttributeList *attrs, + struct GNUNET_RECLAIM_AttestationList *attests, const struct GNUNET_TIME_Relative *expiration_time, const char *nonce, const char *secret_key); @@ -70,7 +71,8 @@ OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, char* OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, const struct GNUNET_RECLAIM_Ticket *ticket, - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, + struct GNUNET_RECLAIM_AttributeList *attrs, + struct GNUNET_RECLAIM_AttestationList *attests, const char *nonce, const char *code_challenge); @@ -92,7 +94,8 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv, const char *code, const char *code_verifier, struct GNUNET_RECLAIM_Ticket *ticket, - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList **attrs, + struct GNUNET_RECLAIM_AttributeList **attrs, + struct GNUNET_RECLAIM_AttestationList **attests, char **nonce); /** diff --git a/src/reclaim/plugin_gnsrecord_reclaim.c b/src/reclaim/plugin_gnsrecord_reclaim.c index f7145a272..b91e123a3 100644 --- a/src/reclaim/plugin_gnsrecord_reclaim.c +++ b/src/reclaim/plugin_gnsrecord_reclaim.c @@ -44,18 +44,15 @@ value_to_string (void *cls, uint32_t type, const void *data, size_t data_size) { switch (type) { - case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: - return GNUNET_STRINGS_data_to_string_alloc (data, data_size); - case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: return GNUNET_strndup (data, data_size); - - case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: + case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE: + case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF: case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: - case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR: - case GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE: + case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION: + case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF: return GNUNET_STRINGS_data_to_string_alloc (data, data_size); default: @@ -83,20 +80,17 @@ string_to_value (void *cls, uint32_t type, const char *s, void **data, return GNUNET_SYSERR; switch (type) { - case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: - return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); - case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: *data = GNUNET_strdup (s); *data_size = strlen (s); return GNUNET_OK; - - case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: + case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE: + case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF: case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: - case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR: - case GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE: + case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION: + case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF: return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); default: @@ -114,14 +108,14 @@ static struct const char *name; uint32_t number; } name_map[] = { - { "RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR }, - { "RECLAIM_ATTR_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF }, - { "RECLAIM_ATTEST", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR }, + { "RECLAIM_ATTRIBUTE", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE }, + { "RECLAIM_ATTRIBUTE_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF }, + { "RECLAIM_ATTESTATION", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION }, + { "RECLAIM_ATTESTATION_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF }, { "RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER }, { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT }, { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT }, { "RECLAIM_TICKET", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET }, - { "RECLAIM_REFERENCE", GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE }, { NULL, UINT32_MAX } }; diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c index 741094f21..610f93dbe 100644 --- a/src/reclaim/plugin_rest_openid_connect.c +++ b/src/reclaim/plugin_rest_openid_connect.c @@ -428,7 +428,13 @@ struct RequestHandle /** * Attribute claim list */ - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list; + struct GNUNET_RECLAIM_AttributeList *attr_list; + + /** + * Attestation list + */ + struct GNUNET_RECLAIM_AttestationList *attests_list; + /** * IDENTITY Operation @@ -523,8 +529,7 @@ struct RequestHandle static void cleanup_handle (struct RequestHandle *handle) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_entry; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp; + struct GNUNET_RECLAIM_AttributeListEntry *claim_entry; struct EgoEntry *ego_entry; struct EgoEntry *ego_tmp; @@ -564,22 +569,9 @@ cleanup_handle (struct RequestHandle *handle) json_decref (handle->oidc->response); GNUNET_free (handle->oidc); } - if (NULL != handle->attr_list) - { - for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;) - { - claim_tmp = claim_entry; - claim_entry = claim_entry->next; - if (NULL != claim_tmp->claim) - GNUNET_free (claim_tmp->claim); - if (NULL != claim_tmp->attest) - GNUNET_free (claim_tmp->attest); - if (NULL != claim_tmp->reference) - GNUNET_free (claim_tmp->reference); - GNUNET_free (claim_tmp); - } - GNUNET_free (handle->attr_list); - } + GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list); + GNUNET_RECLAIM_attestation_list_destroy (handle->attests_list); + for (ego_entry = handle->ego_head; NULL != ego_entry;) { ego_tmp = ego_entry; @@ -934,6 +926,7 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) code_string = OIDC_build_authz_code (&handle->priv_key, &handle->ticket, handle->attr_list, + handle->attests_list, handle->oidc->nonce, handle->oidc->code_challenge); if ((NULL != handle->redirect_prefix) && (NULL != handle->redirect_suffix) && @@ -991,107 +984,61 @@ oidc_collect_finished_cb (void *cls) /** - * Collects all attributes/references for an ego if in scope parameter + * Collects all attributes for an ego if in scope parameter */ static void oidc_attr_collect (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) + const struct GNUNET_RECLAIM_Attribute *attr, + const struct GNUNET_RECLAIM_Attestation *attest) { struct RequestHandle *handle = cls; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_RECLAIM_AttributeListEntry *le; char *scope_variables; char *scope_variable; char delimiter[] = " "; - if ((NULL == attr) && (NULL == reference)) + scope_variables = GNUNET_strdup (handle->oidc->scope); + scope_variable = strtok (scope_variables, delimiter); + while (NULL != scope_variable) { - GNUNET_RECLAIM_get_attributes_next (handle->attr_it); - return; + if (0 == strcmp (attr->name, scope_variable)) + break; + scope_variable = strtok (NULL, delimiter); } - if (NULL != reference) + if (NULL == scope_variable) { - if ((NULL == reference->name) || (NULL == reference->reference_value)) - { - return; - } - scope_variables = GNUNET_strdup (handle->oidc->scope); - scope_variable = strtok (scope_variables, delimiter); - while (NULL != scope_variable) - { - if (0 == strcmp (reference->name, scope_variable)) - break; - scope_variable = strtok (NULL, delimiter); - } - if (NULL == scope_variable) - { - GNUNET_free (scope_variables); - return; - } + GNUNET_RECLAIM_get_attributes_next (handle->attr_it); GNUNET_free (scope_variables); - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le2; - le2 = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - le->claim = NULL; - le->reference = NULL; - le->attest = GNUNET_RECLAIM_ATTESTATION_claim_new (attest->name, + // We can ignore this + return; + } + GNUNET_free (scope_variables); + le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); + le->attribute = GNUNET_RECLAIM_attribute_new (attr->name, + &attr->attestation, + attr->type, + attr->data, + attr->data_size); + le->attribute->id = attr->id; + le->attribute->flag = attr->flag; + le->attribute->attestation = attr->attestation; + GNUNET_CONTAINER_DLL_insert (handle->attr_list->list_head, + handle->attr_list->list_tail, + le); + if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&attr->attestation)) + { + struct GNUNET_RECLAIM_AttestationListEntry *ale; + ale = GNUNET_new (struct GNUNET_RECLAIM_AttestationListEntry); + ale->attestation = GNUNET_RECLAIM_attestation_new (attest->name, attest->type, attest->data, attest->data_size); - le->attest->id = attest->id; - le2->attest = NULL; - le2->claim = NULL; - le2->reference = GNUNET_RECLAIM_ATTESTATION_reference_new (reference->name, - reference-> - reference_value); - le2->reference->id = reference->id; - le2->reference->id_attest = reference->id_attest; - GNUNET_CONTAINER_DLL_insert (handle->attr_list->list_head, - handle->attr_list->list_tail, - le); - GNUNET_CONTAINER_DLL_insert (handle->attr_list->list_head, - handle->attr_list->list_tail, - le2); - } - else if (NULL != attr) - { - if ((NULL == attr->name) || (NULL == attr->data)) - { - GNUNET_RECLAIM_get_attributes_next (handle->attr_it); - return; - } - scope_variables = GNUNET_strdup (handle->oidc->scope); - scope_variable = strtok (scope_variables, delimiter); - while (NULL != scope_variable) - { - if (0 == strcmp (attr->name, scope_variable)) - break; - scope_variable = strtok (NULL, delimiter); - } - if (NULL == scope_variable) - { - GNUNET_RECLAIM_get_attributes_next (handle->attr_it); - GNUNET_free (scope_variables); - return; - } - GNUNET_free (scope_variables); - le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - le->reference = NULL; - le->attest = NULL; - le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, - attr->type, - attr->data, - attr->data_size); - le->claim->id = attr->id; - le->claim->flag = attr->flag; - - GNUNET_CONTAINER_DLL_insert (handle->attr_list->list_head, - handle->attr_list->list_tail, - le); - GNUNET_RECLAIM_get_attributes_next (handle->attr_it); + GNUNET_CONTAINER_DLL_insert (handle->attests_list->list_head, + handle->attests_list->list_tail, + ale); } + GNUNET_RECLAIM_get_attributes_next (handle->attr_it); } @@ -1149,7 +1096,7 @@ code_redirect (void *cls) *GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego); handle->idp = GNUNET_RECLAIM_connect (cfg); handle->attr_list = - GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); + GNUNET_new (struct GNUNET_RECLAIM_AttributeList); handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp, &handle->priv_key, @@ -1784,7 +1731,8 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, struct RequestHandle *handle = cls; const struct EgoEntry *ego_entry; struct GNUNET_TIME_Relative expiration_time; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *cl; + struct GNUNET_RECLAIM_AttributeList *cl; + struct GNUNET_RECLAIM_AttestationList *al; struct GNUNET_RECLAIM_Ticket ticket; struct GNUNET_CRYPTO_EcdsaPublicKey cid; const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; @@ -1872,7 +1820,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, // decode code if (GNUNET_OK != OIDC_parse_authz_code (privkey, code, code_verifier, &ticket, - &cl, &nonce)) + &cl, &al, &nonce)) { handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); handle->edesc = GNUNET_strdup ("invalid code"); @@ -1912,6 +1860,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, id_token = OIDC_id_token_new (&ticket.audience, &ticket.identity, cl, + al, &expiration_time, (NULL != nonce) ? nonce : NULL, jwt_secret); @@ -1927,7 +1876,8 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, MHD_add_response_header (resp, "Pragma", "no-cache"); MHD_add_response_header (resp, "Content-Type", "application/json"); handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); - GNUNET_RECLAIM_ATTRIBUTE_list_destroy (cl); + GNUNET_RECLAIM_attribute_list_destroy (cl); + GNUNET_RECLAIM_attestation_list_destroy (al); GNUNET_free (access_token); GNUNET_free (json_response); GNUNET_free (id_token); @@ -1936,14 +1886,13 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, /** - * Collects claims and stores them in handle - */ + * Collects claims and stores them in handle + */ static void consume_ticket (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) + const struct GNUNET_RECLAIM_Attribute *attr, + const struct GNUNET_RECLAIM_Attestation *attest) { struct RequestHandle *handle = cls; if (NULL == identity) @@ -1951,82 +1900,76 @@ consume_ticket (void *cls, GNUNET_SCHEDULER_add_now (&return_userinfo_response, handle); return; } - if (NULL != attr) + if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attr->attestation)) { char *tmp_value; json_t *value; - tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, + tmp_value = GNUNET_RECLAIM_attribute_value_to_string (attr->type, attr->data, attr->data_size); value = json_string (tmp_value); json_object_set_new (handle->oidc->response, attr->name, value); GNUNET_free (tmp_value); + return; } - else if ((NULL != attest) && (NULL != reference)) - { - json_t *claim_sources; - json_t *claim_sources_jwt; - json_t *claim_names; - char *attest_val_str; - claim_sources=json_object_get(handle->oidc->response,"_claim_sources"); - claim_names=json_object_get(handle->oidc->response,"_claim_names"); - attest_val_str = GNUNET_RECLAIM_ATTESTATION_value_to_string (attest->type, - attest->data, - attest-> - data_size); - if ((NULL == claim_sources) && (NULL == claim_names) ) - { - claim_sources = json_object (); - claim_names = json_object (); - } - char *source_name; - int i = 0; - GNUNET_asprintf (&source_name,"src%d",i); - while (NULL != (claim_sources_jwt = json_object_get (claim_sources, - source_name))) + json_t *claim_sources; + json_t *claim_sources_jwt; + json_t *claim_names; + char *attest_val_str; + claim_sources = json_object_get (handle->oidc->response,"_claim_sources"); + claim_names = json_object_get (handle->oidc->response,"_claim_names"); + attest_val_str = + GNUNET_RECLAIM_attestation_value_to_string (attest->type, + attest->data, + attest->data_size); + if ((NULL == claim_sources) && (NULL == claim_names) ) + { + claim_sources = json_object (); + claim_names = json_object (); + } + char *source_name; + int i = 0; + GNUNET_asprintf (&source_name, "src%d", i); + while (NULL != (claim_sources_jwt = json_object_get (claim_sources, + source_name))) + { + if (0 == strcmp (json_string_value (json_object_get (claim_sources_jwt, + "JWT")), + attest_val_str)) { - if (0 == strcmp (json_string_value (json_object_get (claim_sources_jwt, - "JWT")), - attest_val_str)) - { - // Adapt only the claim names - json_object_set_new (claim_names, reference->name, json_string ( - source_name)); - json_object_set (handle->oidc->response, "_claim_names",claim_names); - handle->oidc->response = json_deep_copy(handle->oidc->response); - break; - } - i++; - GNUNET_asprintf (&source_name,"src%d",i); - } - - // Create new one - if (NULL == claim_sources_jwt) - { - claim_sources_jwt = json_object (); - // Set the JWT for names - json_object_set_new (claim_names, reference->name, json_string ( - source_name)); - // Set the JWT for the inner source - json_object_set_new (claim_sources_jwt, "JWT", json_string ( - attest_val_str)); - // Set the JWT for the source - json_object_set_new (claim_sources, source_name,claim_sources_jwt); - // Set as claims - json_object_set (handle->oidc->response, "_claim_names", claim_names); - json_object_set (handle->oidc->response, "_claim_sources",claim_sources); - handle->oidc->response = json_deep_copy(handle->oidc->response); + // Adapt only the claim names + json_object_set_new (claim_names, attr->data, + json_string (source_name)); + json_object_set (handle->oidc->response, + "_claim_names", claim_names); + break; } - - json_decref (claim_sources); - json_decref (claim_names); - json_decref (claim_sources_jwt); - GNUNET_free (attest_val_str); - } - else - { - // REMARK: We should not find any claim, one of attest/ref is NULL - } + i++; + GNUNET_free (source_name); + GNUNET_asprintf (&source_name, "src%d", i); + } + + // Create new one + if (NULL == claim_sources_jwt) + { + claim_sources_jwt = json_object (); + // Set the JWT for names + json_object_set_new (claim_names, attr->data, + json_string (source_name)); + // Set the JWT for the inner source + json_object_set_new (claim_sources_jwt, "JWT", + json_string (attest_val_str)); + // Set the JWT for the source + json_object_set_new (claim_sources, source_name, claim_sources_jwt); + // Set as claims + json_object_set (handle->oidc->response, "_claim_names", claim_names); + json_object_set (handle->oidc->response, "_claim_sources",claim_sources); + } + + json_decref (claim_sources); + json_decref (claim_names); + json_decref (claim_sources_jwt); + GNUNET_free (attest_val_str); } diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 9a6af6bcf..fcb34e11a 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c @@ -48,9 +48,9 @@ #define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES "/reclaim/attributes" /** - * Attestation namespace - */ -#define GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE "/reclaim/attestation" + * Attestation namespace + */ +#define GNUNET_REST_API_NS_RECLAIM_ATTESTATION "/reclaim/attestation" /** * Ticket namespace @@ -167,7 +167,7 @@ struct RequestHandle /** * Attribute claim list */ - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list; + struct GNUNET_RECLAIM_AttributeList *attr_list; /** * IDENTITY Operation @@ -189,6 +189,12 @@ struct RequestHandle */ struct GNUNET_RECLAIM_AttributeIterator *attr_it; + /** + * Attribute iterator + */ + struct GNUNET_RECLAIM_AttestationIterator *attest_it; + + /** * Ticket iterator */ @@ -247,8 +253,6 @@ struct RequestHandle static void cleanup_handle (struct RequestHandle *handle) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_entry; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp; struct EgoEntry *ego_entry; struct EgoEntry *ego_tmp; @@ -261,6 +265,8 @@ cleanup_handle (struct RequestHandle *handle) GNUNET_IDENTITY_disconnect (handle->identity_handle); if (NULL != handle->attr_it) GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); + if (NULL != handle->attest_it) + GNUNET_RECLAIM_get_attestations_stop (handle->attest_it); if (NULL != handle->ticket_it) GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); if (NULL != handle->idp) @@ -269,19 +275,7 @@ cleanup_handle (struct RequestHandle *handle) GNUNET_free (handle->url); if (NULL != handle->emsg) GNUNET_free (handle->emsg); - if (NULL != handle->attr_list) - { - for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;) - { - claim_tmp = claim_entry; - claim_entry = claim_entry->next; - GNUNET_free (claim_tmp->claim); - GNUNET_free (claim_tmp->attest); - GNUNET_free (claim_tmp->reference); - GNUNET_free (claim_tmp); - } - GNUNET_free (handle->attr_list); - } + GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list); for (ego_entry = handle->ego_head; NULL != ego_entry;) { ego_tmp = ego_entry; @@ -366,6 +360,7 @@ finished_cont (void *cls, int32_t success, const char *emsg) GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); } + static void delete_finished_cb (void *cls, int32_t success, const char *emsg) { @@ -382,6 +377,7 @@ delete_finished_cb (void *cls, int32_t success, const char *emsg) GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); } + /** * Return attributes for identity * @@ -455,85 +451,6 @@ ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) } -static void -add_attestation_ref_cont (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) -{ - struct RequestHandle *handle = cls; - const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; - const char *identity; - struct EgoEntry *ego_entry; - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attribute; - struct GNUNET_TIME_Relative exp; - char term_data[handle->rest_handle->data_size + 1]; - json_t *data_json; - json_error_t err; - struct GNUNET_JSON_Specification attrspec[] = - { GNUNET_RECLAIM_JSON_spec_claim_attest_ref (&attribute), - GNUNET_JSON_spec_end () }; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding an attestation reference for %s.\n", - handle->url); - if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + strlen ( - "reference/") + 1 >= strlen ( - handle->url)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - identity = handle->url + strlen ( - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + strlen ("reference/") - + 1; - for (ego_entry = handle->ego_head; NULL != ego_entry; - ego_entry = ego_entry->next) - if (0 == strcmp (identity, ego_entry->identifier)) - break; - if (NULL == ego_entry) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity); - return; - } - identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); - if (0 >= handle->rest_handle->data_size) - { - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - - term_data[handle->rest_handle->data_size] = '\0'; - GNUNET_memcpy (term_data, - handle->rest_handle->data, - handle->rest_handle->data_size); - data_json = json_loads (term_data, JSON_DECODE_ANY, &err); - GNUNET_assert (GNUNET_OK == - GNUNET_JSON_parse (data_json, attrspec, NULL, NULL)); - json_decref (data_json); - if (NULL == attribute) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unable to parse attestation reference from %s\n", - term_data); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - /** - * New ID for attribute - */ - if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id)) - attribute->id = attribute->id_attest; - handle->idp = GNUNET_RECLAIM_connect (cfg); - exp = GNUNET_TIME_UNIT_HOURS; - handle->idp_op = GNUNET_RECLAIM_attestation_reference_store (handle->idp, - identity_priv, - attribute, - &exp, - &finished_cont, - handle); - GNUNET_JSON_parse_free (attrspec); -} - static void parse_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, @@ -576,16 +493,16 @@ parse_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, } if (0 == strcmp (type_str, "JWT")) { - // The value is a JWT - char *decoded_jwt; - char delim[] = "."; - char *jwt_body = strtok (val_str, delim); - jwt_body = strtok (NULL, delim); - GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body), - (void **) &decoded_jwt); - resp = GNUNET_REST_create_response (decoded_jwt); - handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); - GNUNET_free (decoded_jwt); + // The value is a JWT + char *decoded_jwt; + char delim[] = "."; + char *jwt_body = strtok (val_str, delim); + jwt_body = strtok (NULL, delim); + GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body), + (void **) &decoded_jwt); + resp = GNUNET_REST_create_response (decoded_jwt); + handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); + GNUNET_free (decoded_jwt); } else { @@ -598,42 +515,31 @@ parse_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, json_decref (data_json); } + static void add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) { struct RequestHandle *handle = cls; - /* Check for substring "reference" */ - if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) < strlen ( + /* Check for substring "parse" + * FIXME UGLY! */ + if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION) < strlen ( handle->url)) { - if ( strncmp ("reference/", (handle->url + strlen ( - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) - + 1), strlen ( - "reference/")) == 0) + if (strncmp ("parse", (handle->url + strlen ( + GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + + 1), strlen ( + "parse")) == 0) { - add_attestation_ref_cont (con_handle,url,cls); + parse_attestation_cont (con_handle,url,cls); return; } } - /* Check for substring "parse" */ - if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) < strlen ( - handle->url)) - { - if ( strncmp ("parse", (handle->url + strlen ( - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) - + 1), strlen ( - "parse")) == 0) - { - parse_attestation_cont (con_handle,url,cls); - return; - } - } const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; const char *identity; struct EgoEntry *ego_entry; - struct GNUNET_RECLAIM_ATTESTATION_Claim *attribute; + struct GNUNET_RECLAIM_Attestation *attribute; struct GNUNET_TIME_Relative exp; char term_data[handle->rest_handle->data_size + 1]; json_t *data_json; @@ -645,7 +551,7 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding an attestation for %s.\n", handle->url); - if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) >= strlen ( + if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION) >= strlen ( handle->url)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); @@ -653,7 +559,7 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, return; } identity = handle->url + strlen ( - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + 1; + GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; for (ego_entry = handle->ego_head; NULL != ego_entry; ego_entry = ego_entry->next) @@ -705,104 +611,6 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, GNUNET_JSON_parse_free (attrspec); } -/** - * Collect all references for an ego - * - */ -static void -ref_collect (void *cls, - const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) -{ - struct RequestHandle *handle = cls; - json_t *attr_obj; - char *id_str; - char *id_attest_str; - - if (NULL == reference) - { - GNUNET_RECLAIM_get_attributes_next (handle->attr_it); - return; - } - - if ((NULL == reference->name) || (NULL == reference->reference_value)) - { - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding reference: %s\n", - reference->name); - attr_obj = json_object (); - json_object_set_new (attr_obj, "name", json_string (reference->name)); - json_object_set_new (attr_obj, "ref_value", json_string ( - reference->reference_value)); - id_str = GNUNET_STRINGS_data_to_string_alloc (&reference->id, - sizeof(reference->id)); - id_attest_str = GNUNET_STRINGS_data_to_string_alloc (&reference->id_attest, - sizeof(reference->id_attest)); - json_object_set_new (attr_obj, "id", json_string (id_str)); - json_object_set_new (attr_obj, "ref_id", json_string (id_attest_str)); - json_array_append (handle->resp_object, attr_obj); - json_decref (attr_obj); -} - -/** - * Lists references for identity request - * - * @param con_handle the connection handle - * @param url the url - * @param cls the RequestHandle - */ -static void -list_reference_cont (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) -{ - const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; - struct RequestHandle *handle = cls; - struct EgoEntry *ego_entry; - char *identity; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Getting references for %s.\n", - handle->url); - if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + strlen ( - "reference/") + 1 >= strlen ( - handle->url)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - identity = handle->url + strlen ( - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + strlen ("reference/") - + 1; - for (ego_entry = handle->ego_head; NULL != ego_entry; - ego_entry = ego_entry->next) - if (0 == strcmp (identity, ego_entry->identifier)) - break; - handle->resp_object = json_array (); - - if (NULL == ego_entry) - { - // Done - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); - GNUNET_SCHEDULER_add_now (&return_response, handle); - return; - } - priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); - handle->idp = GNUNET_RECLAIM_connect (cfg); - handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp, - priv_key, - &collect_error_cb, - handle, - &ref_collect, - handle, - &collect_finished_cb, - handle); -} /** * Collect all attestations for an ego @@ -811,9 +619,7 @@ list_reference_cont (struct GNUNET_REST_RequestHandle *con_handle, static void attest_collect (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) + const struct GNUNET_RECLAIM_Attestation *attest) { struct RequestHandle *handle = cls; json_t *attr_obj; @@ -822,12 +628,6 @@ attest_collect (void *cls, char *id_str; - if (NULL != reference) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Attestation Collection with Reference\n"); - return; - } if (NULL == attest) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -847,15 +647,16 @@ attest_collect (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attestation: %s\n", attest->name); - tmp_value = GNUNET_RECLAIM_ATTESTATION_value_to_string (attest->type, + tmp_value = GNUNET_RECLAIM_attestation_value_to_string (attest->type, attest->data, attest->data_size); attr_obj = json_object (); json_object_set_new (attr_obj, "value", json_string (tmp_value)); json_object_set_new (attr_obj, "name", json_string (attest->name)); - type = GNUNET_RECLAIM_ATTESTATION_number_to_typename (attest->type); + type = GNUNET_RECLAIM_attestation_number_to_typename (attest->type); json_object_set_new (attr_obj, "type", json_string (type)); - id_str = GNUNET_STRINGS_data_to_string_alloc (&attest->id, sizeof(attest->id)); + id_str = GNUNET_STRINGS_data_to_string_alloc (&attest->id, + sizeof(attest->id)); json_object_set_new (attr_obj, "id", json_string (id_str)); json_array_append (handle->resp_object, attr_obj); json_decref (attr_obj); @@ -877,19 +678,6 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, void *cls) { struct RequestHandle *handle = cls; - /* Check for substring "reference" */ - if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) < strlen ( - handle->url)) - { - if ( strncmp ("reference/", (handle->url + strlen ( - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) - + 1), strlen ( - "reference/")) == 0) - { - list_reference_cont (con_handle,url,cls); - return; - } - } const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; struct EgoEntry *ego_entry; char *identity; @@ -897,7 +685,7 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting attestations for %s.\n", handle->url); - if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) >= strlen ( + if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION) >= strlen ( handle->url)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); @@ -905,7 +693,7 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, return; } identity = handle->url + strlen ( - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + 1; + GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; for (ego_entry = handle->ego_head; NULL != ego_entry; ego_entry = ego_entry->next) @@ -923,109 +711,14 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, } priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); handle->idp = GNUNET_RECLAIM_connect (cfg); - handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp, - priv_key, - &collect_error_cb, - handle, - &attest_collect, - handle, - &collect_finished_cb, - handle); -} - -/** - * Deletes reference from an identity - * - * @param con_handle the connection handle - * @param url the url - * @param cls the RequestHandle - */ -static void -delete_attestation_ref_cont (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) -{ - struct RequestHandle *handle = cls; - const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr; - struct EgoEntry *ego_entry; - char *identity; - char *identity_id_str; - char *id; - char term_data[handle->rest_handle->data_size + 1]; - json_t *data_json; - json_error_t err; - - struct GNUNET_JSON_Specification attrspec[] = - { GNUNET_RECLAIM_JSON_spec_claim_attest_ref (&attr), - GNUNET_JSON_spec_end () }; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Deleting attestation reference.\n"); - if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + strlen ( - "reference/") + 1 >= strlen ( - handle->url)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - identity_id_str = strdup (handle->url + strlen ( - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) - + strlen ("reference/") - + 1); - identity = strtok (identity_id_str, "/"); - id = strtok (NULL, "/"); - - if ((NULL == identity) || (NULL == id)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n"); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - for (ego_entry = handle->ego_head; NULL != ego_entry; - ego_entry = ego_entry->next) - if (0 == strcmp (identity, ego_entry->identifier)) - break; - handle->resp_object = json_array (); - if (NULL == ego_entry) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); - GNUNET_SCHEDULER_add_now (&return_response, handle); - return; - } - priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); - if (0 >= handle->rest_handle->data_size) - { - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - - term_data[handle->rest_handle->data_size] = '\0'; - GNUNET_memcpy (term_data, - handle->rest_handle->data, - handle->rest_handle->data_size); - data_json = json_loads (term_data, JSON_DECODE_ANY, &err); - GNUNET_assert (GNUNET_OK == - GNUNET_JSON_parse (data_json, attrspec, NULL, NULL)); - json_decref (data_json); - if (NULL == attr) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unable to parse attestation reference from %s\n", - term_data); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - GNUNET_STRINGS_string_to_data (id, strlen (id), &attr->id, sizeof(attr->id)); - - handle->idp = GNUNET_RECLAIM_connect (cfg); - handle->idp_op = GNUNET_RECLAIM_attestation_reference_delete (handle->idp, - priv_key, - attr, - & - delete_finished_cb, - handle); - GNUNET_JSON_parse_free (attrspec); + handle->attest_it = GNUNET_RECLAIM_get_attestations_start (handle->idp, + priv_key, + &collect_error_cb, + handle, + &attest_collect, + handle, + &collect_finished_cb, + handle); } @@ -1042,28 +735,15 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, void *cls) { struct RequestHandle *handle = cls; - /* Check for substring "reference" */ - if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) < strlen ( - handle->url)) - { - if ( strncmp ("reference", (handle->url + strlen ( - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) - + 1), strlen ( - "reference")) == 0) - { - delete_attestation_ref_cont (con_handle,url,cls); - return; - } - } const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; - struct GNUNET_RECLAIM_ATTESTATION_Claim attr; + struct GNUNET_RECLAIM_Attestation attr; struct EgoEntry *ego_entry; char *identity_id_str; char *identity; char *id; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attestation.\n"); - if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) >= strlen ( + if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION) >= strlen ( handle->url)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); @@ -1072,7 +752,7 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, } identity_id_str = strdup (handle->url + strlen ( - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + 1); + GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1); identity = strtok (identity_id_str, "/"); id = strtok (NULL, "/"); if ((NULL == identity) || (NULL == id)) @@ -1098,7 +778,7 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, } priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); handle->idp = GNUNET_RECLAIM_connect (cfg); - memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_ATTESTATION_Claim)); + memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attestation)); GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); attr.name = ""; handle->idp_op = GNUNET_RECLAIM_attestation_delete (handle->idp, @@ -1109,6 +789,7 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, GNUNET_free (identity_id_str); } + /** * List tickets for identity request * @@ -1173,7 +854,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *identity; struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attribute; + struct GNUNET_RECLAIM_Attribute *attribute; struct GNUNET_TIME_Relative exp; char term_data[handle->rest_handle->data_size + 1]; json_t *data_json; @@ -1242,20 +923,21 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, GNUNET_JSON_parse_free (attrspec); } + /** * Parse a JWT and return the respective claim value as Attribute * * @param attest the jwt attestation * @param claim the name of the claim in the JWT * - * @return a GNUNET_RECLAIM_ATTRIBUTE_Claim, containing the new value + * @return a GNUNET_RECLAIM_Attribute, containing the new value */ -struct GNUNET_RECLAIM_ATTRIBUTE_Claim * -parse_jwt (const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, +struct GNUNET_RECLAIM_Attribute * +parse_jwt (const struct GNUNET_RECLAIM_Attestation *attest, const char *claim) { char *jwt_string; - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; + struct GNUNET_RECLAIM_Attribute *attr; char delim[] = "."; const char *type_str = NULL; const char *val_str = NULL; @@ -1267,7 +949,7 @@ parse_jwt (const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, json_t *json_val; json_error_t *json_err = NULL; - jwt_string = GNUNET_RECLAIM_ATTESTATION_value_to_string (attest->type, + jwt_string = GNUNET_RECLAIM_attestation_value_to_string (attest->type, attest->data, attest->data_size); char *jwt_body = strtok (jwt_string, delim); @@ -1284,24 +966,26 @@ parse_jwt (const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, } } type_str = "String"; - type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); - if (GNUNET_SYSERR ==(GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type,val_str, + type = GNUNET_RECLAIM_attribute_typename_to_number (type_str); + if (GNUNET_SYSERR == GNUNET_RECLAIM_attribute_string_to_value (type,val_str, (void **) &data, - &data_size))) + &data_size)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value from JWT Parser invalid!\n"); - GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, + GNUNET_RECLAIM_attribute_string_to_value (type, "Error: Referenced Claim Name not Found", (void **) &data, &data_size); - attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (claim, type, data, data_size); + attr = GNUNET_RECLAIM_attribute_new (claim, &attest->id, + type, data, data_size); attr->id = attest->id; attr->flag = 1; } else { - attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (claim, type, data, data_size); + attr = GNUNET_RECLAIM_attribute_new (claim, &attest->id, + type, data, data_size); attr->id = attest->id; attr->flag = 1; } @@ -1316,53 +1000,34 @@ parse_jwt (const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, static void attr_collect (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) + const struct GNUNET_RECLAIM_Attribute *attr, + const struct GNUNET_RECLAIM_Attestation *attest) { struct RequestHandle *handle = cls; json_t *attr_obj; const char *type; char *id_str; - if ((NULL == attr) && (NULL == reference)) + if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&attr->attestation)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Attribute Collection with empty Attribute/Reference\n"); - GNUNET_RECLAIM_get_attributes_next (handle->attr_it); - return; - } - - if (NULL == attr) - { - - if ((NULL == reference->name) || (NULL == reference->reference_value)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Attribute Collection with empty Reference Name/Value\n"); - return; - } - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr2; - attr2 = parse_jwt (attest, reference->reference_value); + struct GNUNET_RECLAIM_Attribute *attr2; + attr2 = parse_jwt (attest, attr->data); if (NULL == attr2) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute Collection with unparsed Attestation\n"); return; } - attr2->name = reference->name; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding reference as attribute: %s\n", - reference->name); + attr2->name = attr->name; char *tmp_value; - tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr2->type, + tmp_value = GNUNET_RECLAIM_attribute_value_to_string (attr2->type, attr2->data, attr2->data_size); attr_obj = json_object (); - json_object_set_new (attr_obj, "value", json_string (tmp_value)); json_object_set_new (attr_obj, "name", json_string (attr2->name)); json_object_set_new (attr_obj, "flag", json_string ("1")); - type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr2->type); + type = GNUNET_RECLAIM_attribute_number_to_typename (attr2->type); json_object_set_new (attr_obj, "type", json_string (type)); id_str = GNUNET_STRINGS_data_to_string_alloc (&attr2->id, sizeof(attr2->id)); @@ -1373,18 +1038,11 @@ attr_collect (void *cls, } else { - if ((NULL == attr->name) || (NULL == attr->data)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Attribute Collection with empty Attribute Name/Value\n"); - GNUNET_RECLAIM_get_attributes_next (handle->attr_it); - return; - } char *tmp_value; char *flag_str; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name); - tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, + tmp_value = GNUNET_RECLAIM_attribute_value_to_string (attr->type, attr->data, attr->data_size); @@ -1393,7 +1051,7 @@ attr_collect (void *cls, json_object_set_new (attr_obj, "name", json_string (attr->name)); GNUNET_asprintf (&flag_str,"%d",attr->flag); json_object_set_new (attr_obj, "flag", json_string (flag_str)); - type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); + type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type); json_object_set_new (attr_obj, "type", json_string (type)); id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id)); @@ -1405,6 +1063,7 @@ attr_collect (void *cls, } } + /** * List attributes for identity request * @@ -1474,7 +1133,7 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, { const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; struct RequestHandle *handle = cls; - struct GNUNET_RECLAIM_ATTRIBUTE_Claim attr; + struct GNUNET_RECLAIM_Attribute attr; struct EgoEntry *ego_entry; char *identity_id_str; char *identity; @@ -1514,7 +1173,7 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, } priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); handle->idp = GNUNET_RECLAIM_connect (cfg); - memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim)); + memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attribute)); GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); attr.name = ""; handle->idp_op = GNUNET_RECLAIM_attribute_delete (handle->idp, @@ -1603,9 +1262,8 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, static void consume_cont (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) + const struct GNUNET_RECLAIM_Attribute *attr, + const struct GNUNET_RECLAIM_Attestation *attest) { struct RequestHandle *handle = cls; char *val_str; @@ -1618,7 +1276,7 @@ consume_cont (void *cls, } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name); - val_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, + val_str = GNUNET_RECLAIM_attribute_value_to_string (attr->type, attr->data, attr->data_size); if (NULL == val_str) @@ -1749,13 +1407,13 @@ init_cont (struct RequestHandle *handle) GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &delete_attribute_cont }, { MHD_HTTP_METHOD_GET, - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE, + GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &list_attestation_cont }, { MHD_HTTP_METHOD_POST, - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE, + GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &add_attestation_cont }, { MHD_HTTP_METHOD_DELETE, - GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE, + GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &delete_attestation_cont }, { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS, diff --git a/src/reclaim/reclaim.h b/src/reclaim/reclaim.h index ff953a096..3da49fe7a 100644 --- a/src/reclaim/reclaim.h +++ b/src/reclaim/reclaim.h @@ -138,6 +138,11 @@ struct AttributeResultMessage */ uint16_t attr_len GNUNET_PACKED; + /** + * Length of serialized attestation data + */ + uint16_t attestation_len GNUNET_PACKED; + /** * always zero (for alignment) */ @@ -153,6 +158,42 @@ struct AttributeResultMessage */ }; +/** + * Attestation is returned from the idp. + */ +struct AttestationResultMessage +{ + /** + * Message header + */ + struct GNUNET_MessageHeader header; + + /** + * Unique identifier for this request (for key collisions). + */ + uint32_t id GNUNET_PACKED; + + /** + * Length of serialized attribute data + */ + uint16_t attestation_len GNUNET_PACKED; + + /** + * always zero (for alignment) + */ + uint16_t reserved GNUNET_PACKED; + + /** + * The public key of the identity. + */ + struct GNUNET_CRYPTO_EcdsaPublicKey identity; + + /* followed by: + * serialized attestation data + */ +}; + + /** * Reference plus Attestation is returned from the idp. */ @@ -462,6 +503,11 @@ struct ConsumeTicketResultMessage */ uint16_t attrs_len GNUNET_PACKED; + /** + * Length of attestation data + */ + uint16_t attestations_len; + /** * always zero (for alignment) */ diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c index 5a3bee218..0fcf95ee3 100644 --- a/src/reclaim/reclaim_api.c +++ b/src/reclaim/reclaim_api.c @@ -71,6 +71,11 @@ struct GNUNET_RECLAIM_Operation */ GNUNET_RECLAIM_AttributeResult ar_cb; + /** + * Attestation result callback + */ + GNUNET_RECLAIM_AttestationResult at_cb; + /** * Revocation result callback */ @@ -228,6 +233,73 @@ struct GNUNET_RECLAIM_AttributeIterator uint32_t r_id; }; +/** + * Handle for a attestation iterator operation + */ +struct GNUNET_RECLAIM_AttestationIterator +{ + /** + * Kept in a DLL. + */ + struct GNUNET_RECLAIM_AttestationIterator *next; + + /** + * Kept in a DLL. + */ + struct GNUNET_RECLAIM_AttestationIterator *prev; + + /** + * Main handle to access the service. + */ + struct GNUNET_RECLAIM_Handle *h; + + /** + * Function to call on completion. + */ + GNUNET_SCHEDULER_TaskCallback finish_cb; + + /** + * Closure for @e finish_cb. + */ + void *finish_cb_cls; + + /** + * The continuation to call with the results + */ + GNUNET_RECLAIM_AttestationResult proc; + + /** + * Closure for @e proc. + */ + void *proc_cls; + + /** + * Function to call on errors. + */ + GNUNET_SCHEDULER_TaskCallback error_cb; + + /** + * Closure for @e error_cb. + */ + void *error_cb_cls; + + /** + * Envelope of the message to send to the service, if not yet + * sent. + */ + struct GNUNET_MQ_Envelope *env; + + /** + * Private key of the zone. + */ + struct GNUNET_CRYPTO_EcdsaPrivateKey identity; + + /** + * The operation id this zone iteration operation has + */ + uint32_t r_id; +}; + /** * Handle to the service. @@ -269,6 +341,16 @@ struct GNUNET_RECLAIM_Handle */ struct GNUNET_RECLAIM_AttributeIterator *it_tail; + /** + * Head of active iterations + */ + struct GNUNET_RECLAIM_AttestationIterator *ait_head; + + /** + * Tail of active iterations + */ + struct GNUNET_RECLAIM_AttestationIterator *ait_tail; + /** * Head of active iterations */ @@ -371,6 +453,23 @@ free_it (struct GNUNET_RECLAIM_AttributeIterator *it) } +/** + * Free @a it. + * + * @param ait entry to free + */ +static void +free_ait (struct GNUNET_RECLAIM_AttestationIterator *ait) +{ + struct GNUNET_RECLAIM_Handle *h = ait->h; + + GNUNET_CONTAINER_DLL_remove (h->ait_head, h->ait_tail, ait); + if (NULL != ait->env) + GNUNET_MQ_discard (ait->env); + GNUNET_free (ait); +} + + /** * Free @a op * @@ -483,9 +582,12 @@ handle_consume_ticket_result (void *cls, struct GNUNET_RECLAIM_Handle *h = cls; struct GNUNET_RECLAIM_Operation *op; size_t attrs_len; + size_t attests_len; uint32_t r_id = ntohl (msg->id); + char *read_ptr; attrs_len = ntohs (msg->attrs_len); + attests_len = ntohs (msg->attestations_len); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing ticket result.\n"); @@ -496,42 +598,53 @@ handle_consume_ticket_result (void *cls, return; { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le2; + struct GNUNET_RECLAIM_AttributeList *attrs; + struct GNUNET_RECLAIM_AttributeListEntry *le; + struct GNUNET_RECLAIM_AttestationList *attests; + struct GNUNET_RECLAIM_AttestationListEntry *ale; attrs = - GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *) &msg[1], attrs_len); + GNUNET_RECLAIM_attribute_list_deserialize ((char *) &msg[1], attrs_len); + read_ptr = ((char *) &msg[1]) + attrs_len; + attests = + GNUNET_RECLAIM_attestation_list_deserialize (read_ptr, attests_len); if (NULL != op->ar_cb) { if (NULL == attrs) { - op->ar_cb (op->cls, &msg->identity, NULL, NULL, NULL); + op->ar_cb (op->cls, &msg->identity, NULL, NULL); } else { for (le = attrs->list_head; NULL != le; le = le->next) { - if ((le->reference != NULL) && (le->attest == NULL)) + if (GNUNET_NO == + GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) { - for (le2 = attrs->list_head; NULL != le2; le2 = le2->next) + for (ale = attests->list_head; NULL != ale; ale = ale->next) { - if ((le2->attest != NULL) && - (0 == memcmp (&le2->attest->id, - &le->reference->id_attest, - sizeof (le2->attest->id)))) + if (GNUNET_YES == + GNUNET_RECLAIM_id_is_equal (&le->attribute->id, + &ale->attestation->id)) { - op->ar_cb (op->cls, &msg->identity, le->claim, le2->attest, - le->reference); + op->ar_cb (op->cls, &msg->identity, + le->attribute, ale->attestation); break; } } } + else // No attestations + { + op->ar_cb (op->cls, &msg->identity, + le->attribute, NULL); + } } - GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); + GNUNET_RECLAIM_attribute_list_destroy (attrs); + GNUNET_RECLAIM_attestation_list_destroy (attests); attrs = NULL; + attests = NULL; } - op->ar_cb (op->cls, NULL, NULL, NULL, NULL); + op->ar_cb (op->cls, NULL, NULL, NULL); } GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); free_op (op); @@ -582,9 +695,11 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) struct GNUNET_RECLAIM_AttributeIterator *it; struct GNUNET_RECLAIM_Operation *op; size_t attr_len; + size_t attest_len; uint32_t r_id = ntohl (msg->id); attr_len = ntohs (msg->attr_len); + attest_len = ntohs (msg->attestation_len); LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); @@ -615,7 +730,7 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) if (NULL != op) { if (NULL != op->ar_cb) - op->ar_cb (op->cls, NULL, NULL, NULL, NULL); + op->ar_cb (op->cls, NULL, NULL, NULL); GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); free_op (op); } @@ -623,17 +738,21 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) } { - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; - attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *) &msg[1], attr_len); + struct GNUNET_RECLAIM_Attribute *attr; + struct GNUNET_RECLAIM_Attestation *attest; + char *read_ptr; + attr = GNUNET_RECLAIM_attribute_deserialize ((char *) &msg[1], attr_len); + read_ptr = ((char *) &msg[1]) + attr_len; + attest = GNUNET_RECLAIM_attestation_deserialize (read_ptr, attest_len); if (NULL != it) { if (NULL != it->proc) - it->proc (it->proc_cls, &msg->identity, attr, NULL, NULL); + it->proc (it->proc_cls, &msg->identity, attr, attest); } else if (NULL != op) { if (NULL != op->ar_cb) - op->ar_cb (op->cls, &msg->identity, attr, NULL, NULL); + op->ar_cb (op->cls, &msg->identity, attr, attest); } GNUNET_free (attr); return; @@ -644,21 +763,21 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) /** * Handle an incoming message of type - * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT + * #GNUNET_MESSAGE_TYPE_RECLAIM_attestation_RESULT * * @param cls * @param msg the message we received * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -check_attestation_result (void *cls, const struct AttributeResultMessage *msg) +check_attestation_result (void *cls, const struct AttestationResultMessage *msg) { size_t msg_len; size_t attr_len; msg_len = ntohs (msg->header.size); - attr_len = ntohs (msg->attr_len); - if (msg_len != sizeof(struct AttributeResultMessage) + attr_len) + attr_len = ntohs (msg->attestation_len); + if (msg_len != sizeof(struct AttestationResultMessage) + attr_len) { GNUNET_break (0); return GNUNET_SYSERR; @@ -669,26 +788,27 @@ check_attestation_result (void *cls, const struct AttributeResultMessage *msg) /** * Handle an incoming message of type - * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT + * #GNUNET_MESSAGE_TYPE_RECLAIM_attestation_RESULT * * @param cls * @param msg the message we received */ static void -handle_attestation_result (void *cls, const struct AttributeResultMessage *msg) +handle_attestation_result (void *cls, const struct + AttestationResultMessage *msg) { static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; struct GNUNET_RECLAIM_Handle *h = cls; - struct GNUNET_RECLAIM_AttributeIterator *it; + struct GNUNET_RECLAIM_AttestationIterator *it; struct GNUNET_RECLAIM_Operation *op; - size_t attr_len; + size_t att_len; uint32_t r_id = ntohl (msg->id); - attr_len = ntohs (msg->attr_len); + att_len = ntohs (msg->attestation_len); LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attestation result.\n"); - for (it = h->it_head; NULL != it; it = it->next) + for (it = h->ait_head; NULL != it; it = it->next) if (it->r_id == r_id) break; for (op = h->op_head; NULL != op; op = op->next) @@ -710,12 +830,12 @@ handle_attestation_result (void *cls, const struct AttributeResultMessage *msg) { if (NULL != it->finish_cb) it->finish_cb (it->finish_cb_cls); - free_it (it); + free_ait (it); } if (NULL != op) { - if (NULL != op->ar_cb) - op->ar_cb (op->cls, NULL, NULL, NULL, NULL); + if (NULL != op->at_cb) + op->at_cb (op->cls, NULL, NULL); GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); free_op (op); } @@ -723,126 +843,19 @@ handle_attestation_result (void *cls, const struct AttributeResultMessage *msg) } { - struct GNUNET_RECLAIM_ATTESTATION_Claim *attr; - attr = GNUNET_RECLAIM_ATTESTATION_deserialize ((char *) &msg[1], attr_len); + struct GNUNET_RECLAIM_Attestation *att; + att = GNUNET_RECLAIM_attestation_deserialize ((char *) &msg[1], att_len); if (NULL != it) { if (NULL != it->proc) - it->proc (it->proc_cls, &msg->identity, NULL, attr, NULL); + it->proc (it->proc_cls, &msg->identity, att); } else if (NULL != op) { - if (NULL != op->ar_cb) - op->ar_cb (op->cls, &msg->identity, NULL, attr, NULL); + if (NULL != op->at_cb) + op->at_cb (op->cls, &msg->identity, att); } - GNUNET_free (attr); - return; - } - GNUNET_assert (0); -} - - -/** - * Handle an incoming message of type - * #GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT - * - * @param cls - * @param msg the message we received - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -static int -check_reference_result (void *cls, const struct ReferenceResultMessage *msg) -{ - size_t msg_len; - size_t attr_len; - size_t ref_len; - - msg_len = ntohs (msg->header.size); - attr_len = ntohs (msg->attest_len); - ref_len = ntohs (msg->ref_len); - if (msg_len != sizeof(struct ReferenceResultMessage) + attr_len + ref_len) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - return GNUNET_OK; -} - - -/** -* Handle an incoming message of type -* #GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT -* -* @param cls -* @param msg the message we received -*/ -static void -handle_reference_result (void *cls, const struct ReferenceResultMessage *msg) -{ - static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; - struct GNUNET_RECLAIM_Handle *h = cls; - struct GNUNET_RECLAIM_AttributeIterator *it; - struct GNUNET_RECLAIM_Operation *op; - size_t attest_len; - size_t ref_len; - uint32_t r_id = ntohl (msg->id); - attest_len = ntohs (msg->attest_len); - ref_len = ntohs (msg->ref_len); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing reference result.\n"); - for (it = h->it_head; NULL != it; it = it->next) - if (it->r_id == r_id) - break; - for (op = h->op_head; NULL != op; op = op->next) - if (op->r_id == r_id) - break; - if ((NULL == it) && (NULL == op)) - return; - - if ((0 == - (memcmp (&msg->identity, &identity_dummy, sizeof(identity_dummy))))) - { - if ((NULL == it) && (NULL == op)) - { - GNUNET_break (0); - force_reconnect (h); - return; - } - if (NULL != it) - { - if (NULL != it->finish_cb) - it->finish_cb (it->finish_cb_cls); - free_it (it); - } - if (NULL != op) - { - if (NULL != op->ar_cb) - op->ar_cb (op->cls, NULL, NULL, NULL, NULL); - GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); - free_op (op); - } - return; - } - - { - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *ref; - struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; - attest = GNUNET_RECLAIM_ATTESTATION_deserialize ((char *) &msg[1], - attest_len); - ref = GNUNET_RECLAIM_ATTESTATION_REF_deserialize ((char *) &msg[1] - + attest_len, - ref_len); - if (NULL != it) - { - if (NULL != it->proc) - it->proc (it->proc_cls, &msg->identity, NULL, attest, ref); - } - else if (NULL != op) - { - if (NULL != op->ar_cb) - op->ar_cb (op->cls, &msg->identity, NULL, attest, ref); - } - GNUNET_free (ref); - GNUNET_free (attest); + GNUNET_free (att); return; } GNUNET_assert (0); @@ -969,11 +982,7 @@ reconnect (struct GNUNET_RECLAIM_Handle *h) h), GNUNET_MQ_hd_var_size (attestation_result, GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT, - struct AttributeResultMessage, - h), - GNUNET_MQ_hd_var_size (reference_result, - GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT, - struct ReferenceResultMessage, + struct AttestationResultMessage, h), GNUNET_MQ_hd_fixed_size (ticket_result, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, @@ -1083,7 +1092,7 @@ struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attribute_store ( struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, + const struct GNUNET_RECLAIM_Attribute *attr, const struct GNUNET_TIME_Relative *exp_interval, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls) @@ -1098,7 +1107,7 @@ GNUNET_RECLAIM_attribute_store ( op->cls = cont_cls; op->r_id = h->r_id_gen++; GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); + attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (attr); op->env = GNUNET_MQ_msg_extra (sam, attr_len, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE); @@ -1106,7 +1115,7 @@ GNUNET_RECLAIM_attribute_store ( sam->id = htonl (op->r_id); sam->exp = GNUNET_htonll (exp_interval->rel_value_us); - GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &sam[1]); + GNUNET_RECLAIM_attribute_serialize (attr, (char *) &sam[1]); sam->attr_len = htons (attr_len); if (NULL != h->mq) @@ -1130,7 +1139,7 @@ struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attribute_delete ( struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, + const struct GNUNET_RECLAIM_Attribute *attr, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls) { @@ -1144,13 +1153,13 @@ GNUNET_RECLAIM_attribute_delete ( op->cls = cont_cls; op->r_id = h->r_id_gen++; GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); + attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (attr); op->env = GNUNET_MQ_msg_extra (dam, attr_len, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE); dam->identity = *pkey; dam->id = htonl (op->r_id); - GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &dam[1]); + GNUNET_RECLAIM_attribute_serialize (attr, (char *) &dam[1]); dam->attr_len = htons (attr_len); if (NULL != h->mq) @@ -1175,7 +1184,7 @@ struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attestation_store ( struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr, + const struct GNUNET_RECLAIM_Attestation *attr, const struct GNUNET_TIME_Relative *exp_interval, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls) @@ -1190,7 +1199,7 @@ GNUNET_RECLAIM_attestation_store ( op->cls = cont_cls; op->r_id = h->r_id_gen++; GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - attr_len = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (attr); + attr_len = GNUNET_RECLAIM_attestation_serialize_get_size (attr); op->env = GNUNET_MQ_msg_extra (sam, attr_len, GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_STORE); @@ -1198,7 +1207,7 @@ GNUNET_RECLAIM_attestation_store ( sam->id = htonl (op->r_id); sam->exp = GNUNET_htonll (exp_interval->rel_value_us); - GNUNET_RECLAIM_ATTESTATION_serialize (attr, (char *) &sam[1]); + GNUNET_RECLAIM_attestation_serialize (attr, (char *) &sam[1]); sam->attr_len = htons (attr_len); if (NULL != h->mq) @@ -1222,7 +1231,7 @@ struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attestation_delete ( struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr, + const struct GNUNET_RECLAIM_Attestation *attr, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls) { @@ -1236,105 +1245,13 @@ GNUNET_RECLAIM_attestation_delete ( op->cls = cont_cls; op->r_id = h->r_id_gen++; GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - attr_len = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (attr); + attr_len = GNUNET_RECLAIM_attestation_serialize_get_size (attr); op->env = GNUNET_MQ_msg_extra (dam, attr_len, GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_DELETE); dam->identity = *pkey; dam->id = htonl (op->r_id); - GNUNET_RECLAIM_ATTESTATION_serialize (attr, (char *) &dam[1]); - - dam->attr_len = htons (attr_len); - if (NULL != h->mq) - GNUNET_MQ_send_copy (h->mq, op->env); - return op; -} - - -/** - * Store an attestation reference. If the reference is already present, - * it is replaced with the new reference. - * - * @param h handle to the re:claimID service - * @param pkey private key of the identity - * @param attr the reference value - * @param exp_interval the relative expiration interval for the reference - * @param cont continuation to call when done - * @param cont_cls closure for @a cont - * @return handle to abort the request - */ -struct GNUNET_RECLAIM_Operation * -GNUNET_RECLAIM_attestation_reference_store ( - struct GNUNET_RECLAIM_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr, - const struct GNUNET_TIME_Relative *exp_interval, - GNUNET_RECLAIM_ContinuationWithStatus cont, - void *cont_cls) -{ - struct GNUNET_RECLAIM_Operation *op; - struct AttributeStoreMessage *sam; - size_t attr_len; - op = GNUNET_new (struct GNUNET_RECLAIM_Operation); - op->h = h; - op->as_cb = cont; - op->cls = cont_cls; - op->r_id = h->r_id_gen++; - GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - attr_len = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (attr); - op->env = GNUNET_MQ_msg_extra (sam, - attr_len, - GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_STORE); - sam->identity = *pkey; - sam->id = htonl (op->r_id); - sam->exp = GNUNET_htonll (exp_interval->rel_value_us); - - GNUNET_RECLAIM_ATTESTATION_REF_serialize (attr, (char *) &sam[1]); - - sam->attr_len = htons (attr_len); - if (NULL != h->mq) - GNUNET_MQ_send_copy (h->mq, op->env); - return op; -} - - -/** - * Delete an attestation reference. Tickets used to share this reference are updated - * accordingly. - * - * @param h handle to the re:claimID service - * @param pkey Private key of the identity to delete the reference from - * @param attr The reference - * @param cont Continuation to call when done - * @param cont_cls Closure for @a cont - * @return handle Used to to abort the request - */ -struct GNUNET_RECLAIM_Operation * -GNUNET_RECLAIM_attestation_reference_delete ( - struct GNUNET_RECLAIM_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr, - GNUNET_RECLAIM_ContinuationWithStatus cont, - void *cont_cls) -{ - - struct GNUNET_RECLAIM_Operation *op; - struct AttributeDeleteMessage *dam; - size_t attr_len; - - op = GNUNET_new (struct GNUNET_RECLAIM_Operation); - op->h = h; - op->as_cb = cont; - op->cls = cont_cls; - op->r_id = h->r_id_gen++; - GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - attr_len = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (attr); - op->env = GNUNET_MQ_msg_extra (dam, - attr_len, - GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_DELETE); - dam->identity = *pkey; - dam->id = htonl (op->r_id); - GNUNET_RECLAIM_ATTESTATION_REF_serialize (attr, (char *) &dam[1]); + GNUNET_RECLAIM_attestation_serialize (attr, (char *) &dam[1]); dam->attr_len = htons (attr_len); if (NULL != h->mq) @@ -1470,7 +1387,7 @@ GNUNET_RECLAIM_ticket_issue ( struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, + const struct GNUNET_RECLAIM_AttributeList *attrs, GNUNET_RECLAIM_TicketCallback cb, void *cb_cls) { @@ -1485,7 +1402,7 @@ GNUNET_RECLAIM_ticket_issue ( op->cls = cb_cls; op->r_id = h->r_id_gen++; GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); + attr_len = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs); op->env = GNUNET_MQ_msg_extra (tim, attr_len, GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET); @@ -1493,7 +1410,7 @@ GNUNET_RECLAIM_ticket_issue ( tim->rp = *rp; tim->id = htonl (op->r_id); - GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, (char *) &tim[1]); + GNUNET_RECLAIM_attribute_list_serialize (attrs, (char *) &tim[1]); tim->attr_len = htons (attr_len); if (NULL != h->mq) -- cgit v1.2.3