From 6e43cf789e24fb014e55d3af2adba8c6848272a7 Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Tue, 4 Feb 2020 18:42:04 +0100 Subject: [PATCH] Refactoring reclaim attestations --- src/include/gnunet_gnsrecord_lib.h | 12 +- src/include/gnunet_reclaim_attribute_lib.h | 337 ++++---- ...ibute_plugin.h => gnunet_reclaim_plugin.h} | 127 ++- src/include/gnunet_reclaim_service.h | 66 +- src/reclaim-attribute/Makefile.am | 21 +- .../plugin_reclaim_attestation_jwt.c | 182 +++++ .../plugin_reclaim_attribute_basic.c | 180 +++++ .../plugin_reclaim_attribute_gnuid.c | 290 ------- src/reclaim-attribute/reclaim_attestation.c | 502 ++++++++++++ src/reclaim-attribute/reclaim_attestation.h | 64 ++ src/reclaim-attribute/reclaim_attribute.c | 720 +++--------------- src/reclaim-attribute/reclaim_attribute.h | 34 +- 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 +++++------ 25 files changed, 2085 insertions(+), 3052 deletions(-) rename src/include/{gnunet_reclaim_attribute_plugin.h => gnunet_reclaim_plugin.h} (50%) create mode 100644 src/reclaim-attribute/plugin_reclaim_attestation_jwt.c create mode 100644 src/reclaim-attribute/plugin_reclaim_attribute_basic.c delete mode 100644 src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c create mode 100644 src/reclaim-attribute/reclaim_attestation.c create mode 100644 src/reclaim-attribute/reclaim_attestation.h diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h index 797c71380..e06dcebc7 100644 --- a/src/include/gnunet_gnsrecord_lib.h +++ b/src/include/gnunet_gnsrecord_lib.h @@ -95,7 +95,7 @@ extern "C" { /** * Record type for identity attributes (of RECLAIM). */ -#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR 65544 +#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE 65544 /** * Record type for local ticket references @@ -123,7 +123,7 @@ extern "C" { /** * Record type for reclaim records */ -#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF 65550 +#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF 65550 /** * Record type for RECLAIM master @@ -141,14 +141,14 @@ extern "C" { #define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT 65553 /** - * Record type for reclaim identity attestation + * Record type for an attribute attestation */ -#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR 65554 +#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION 65554 /** - * Record type for reclaim identity references + * Record type for an attestation reference in a ticket */ -#define GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE 65555 +#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF 65555 /** diff --git a/src/include/gnunet_reclaim_attribute_lib.h b/src/include/gnunet_reclaim_attribute_lib.h index 93b4f8a13..937a4d8f4 100644 --- a/src/include/gnunet_reclaim_attribute_lib.h +++ b/src/include/gnunet_reclaim_attribute_lib.h @@ -77,30 +77,37 @@ struct GNUNET_RECLAIM_Identifier static const struct GNUNET_RECLAIM_Identifier GNUNET_RECLAIM_ID_ZERO; #define GNUNET_RECLAIM_id_is_equal(a,b) ((0 == \ - memcmp (a,\ - b,\ - sizeof (GNUNET_RECLAIM_ID_ZERO))) ?\ - GNUNET_YES : GNUNET_NO) + memcmp (a, \ + b, \ + sizeof (GNUNET_RECLAIM_ID_ZERO))) \ + ? \ + GNUNET_YES : GNUNET_NO) -#define GNUNET_RECLAIM_id_is_zero(a) GNUNET_RECLAIM_id_is_equal(a,\ - &GNUNET_RECLAIM_ID_ZERO) +#define GNUNET_RECLAIM_id_is_zero(a) GNUNET_RECLAIM_id_is_equal (a, \ + & \ + GNUNET_RECLAIM_ID_ZERO) #define GNUNET_RECLAIM_id_generate(id) \ - (GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,\ - id,\ + (GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, \ + id, \ sizeof (GNUNET_RECLAIM_ID_ZERO))) /** * An attribute. */ -struct GNUNET_RECLAIM_ATTRIBUTE_Claim +struct GNUNET_RECLAIM_Attribute { /** * ID */ struct GNUNET_RECLAIM_Identifier id; + /** + * Referenced ID of Attestation (may be 0 if self-attested) + */ + struct GNUNET_RECLAIM_Identifier attestation; + /** * Type of Claim */ @@ -110,6 +117,7 @@ struct GNUNET_RECLAIM_ATTRIBUTE_Claim * Flags */ uint32_t flag; + /** * The name of the attribute. Note "name" must never be individually * free'd @@ -132,7 +140,7 @@ struct GNUNET_RECLAIM_ATTRIBUTE_Claim /** * An attestation. */ -struct GNUNET_RECLAIM_ATTESTATION_Claim +struct GNUNET_RECLAIM_Attestation { /** * ID @@ -168,81 +176,77 @@ struct GNUNET_RECLAIM_ATTESTATION_Claim const void *data; }; + /** - * A reference to an Attestatiom. + * A list of GNUNET_RECLAIM_Attribute structures. */ -struct GNUNET_RECLAIM_ATTESTATION_REFERENCE +struct GNUNET_RECLAIM_AttributeList { /** - * ID + * List head */ - struct GNUNET_RECLAIM_Identifier id; + struct GNUNET_RECLAIM_AttributeListEntry *list_head; /** - * Referenced ID of Attestation + * List tail */ - struct GNUNET_RECLAIM_Identifier id_attest; + struct GNUNET_RECLAIM_AttributeListEntry *list_tail; +}; + +struct GNUNET_RECLAIM_AttributeListEntry +{ /** - * The name of the attribute/attestation reference value. Note "name" must never be individually - * free'd + * DLL */ - const char *name; + struct GNUNET_RECLAIM_AttributeListEntry *prev; /** - * The name of the attribute/attestation reference value. Note "name" must never be individually - * free'd + * DLL + */ + struct GNUNET_RECLAIM_AttributeListEntry *next; + + /** + * The attribute claim */ - const char *reference_value; + struct GNUNET_RECLAIM_Attribute *attribute; + }; /** - * A list of GNUNET_RECLAIM_ATTRIBUTE_Claim structures. + * A list of GNUNET_RECLAIM_Attestation structures. */ -struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList +struct GNUNET_RECLAIM_AttestationList { /** * List head */ - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_head; + struct GNUNET_RECLAIM_AttestationListEntry *list_head; /** * List tail */ - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_tail; + struct GNUNET_RECLAIM_AttestationListEntry *list_tail; }; -struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry +struct GNUNET_RECLAIM_AttestationListEntry { /** * DLL */ - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *prev; + struct GNUNET_RECLAIM_AttestationListEntry *prev; /** * DLL */ - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *next; + struct GNUNET_RECLAIM_AttestationListEntry *next; /** - * The attribute claim + * The attestation */ - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; - /** - * The attestation claim - */ - struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; + struct GNUNET_RECLAIM_Attestation *attestation; - /** - * The reference - */ - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference; -}; - -struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType -{ - uint32_t type; }; @@ -250,16 +254,18 @@ struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType * Create a new attribute claim. * * @param attr_name the attribute name + * @param attestation ID of the attestation (may be NULL) * @param type the attribute type - * @param data the attribute value + * @param data the attribute value. Must be the mapped name if attestation not NULL * @param data_size the attribute value size * @return the new attribute */ -struct GNUNET_RECLAIM_ATTRIBUTE_Claim * -GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name, - uint32_t type, - const void *data, - size_t data_size); +struct GNUNET_RECLAIM_Attribute * +GNUNET_RECLAIM_attribute_new (const char *attr_name, + const struct GNUNET_RECLAIM_Identifier *attestation, + uint32_t type, + const void *data, + size_t data_size); /** @@ -269,8 +275,8 @@ GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name, * @return the required buffer size */ size_t -GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size ( - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs); +GNUNET_RECLAIM_attribute_list_serialize_get_size ( + const struct GNUNET_RECLAIM_AttributeList *attrs); /** @@ -279,22 +285,25 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size ( * @param attrs list to destroy */ void -GNUNET_RECLAIM_ATTRIBUTE_list_destroy ( - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs); +GNUNET_RECLAIM_attribute_list_destroy ( + struct GNUNET_RECLAIM_AttributeList *attrs); /** * Add a new attribute to a claim list * + * @param attrs the attribute list to add to * @param attr_name the name of the new attribute claim + * @param attestation attestation ID (may be NULL) * @param type the type of the claim * @param data claim payload * @param data_size claim payload size */ void -GNUNET_RECLAIM_ATTRIBUTE_list_add ( - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, +GNUNET_RECLAIM_attribute_list_add ( + struct GNUNET_RECLAIM_AttributeList *attrs, const char *attr_name, + const struct GNUNET_RECLAIM_Identifier *attestation, uint32_t type, const void *data, size_t data_size); @@ -308,8 +317,8 @@ GNUNET_RECLAIM_ATTRIBUTE_list_add ( * @return length of serialized data */ size_t -GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, +GNUNET_RECLAIM_attribute_list_serialize ( + const struct GNUNET_RECLAIM_AttributeList *attrs, char *result); @@ -320,17 +329,8 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( * @param data_size the length of the serialized data * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller */ -struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * -GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size); - -/** - * Count attestations in claim list - * - * @param attrs list - */ -int -GNUNET_RECLAIM_ATTRIBUTE_list_count_attest ( - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs); +struct GNUNET_RECLAIM_AttributeList * +GNUNET_RECLAIM_attribute_list_deserialize (const char *data, size_t data_size); /** * Get required size for serialization buffer @@ -339,8 +339,8 @@ GNUNET_RECLAIM_ATTRIBUTE_list_count_attest ( * @return the required buffer size */ size_t -GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size ( - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr); +GNUNET_RECLAIM_attribute_serialize_get_size ( + const struct GNUNET_RECLAIM_Attribute *attr); /** @@ -351,9 +351,8 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size ( * @return length of serialized data */ size_t -GNUNET_RECLAIM_ATTRIBUTE_serialize ( - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - char *result); +GNUNET_RECLAIM_attribute_serialize (const struct GNUNET_RECLAIM_Attribute *attr, + char *result); /** @@ -364,8 +363,8 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize ( * * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller */ -struct GNUNET_RECLAIM_ATTRIBUTE_Claim * -GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size); +struct GNUNET_RECLAIM_Attribute * +GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size); /** @@ -373,9 +372,9 @@ GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size); * @param attrs claim list to copy * @return copied claim list */ -struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * -GNUNET_RECLAIM_ATTRIBUTE_list_dup ( - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs); +struct GNUNET_RECLAIM_AttributeList * +GNUNET_RECLAIM_attribute_list_dup ( + const struct GNUNET_RECLAIM_AttributeList *attrs); /** @@ -385,7 +384,7 @@ GNUNET_RECLAIM_ATTRIBUTE_list_dup ( * @return corresponding number, UINT32_MAX on error */ uint32_t -GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename); +GNUNET_RECLAIM_attribute_typename_to_number (const char *typename); /** * Convert human-readable version of a 'claim' of an attribute to the binary @@ -398,7 +397,7 @@ GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename); * @return #GNUNET_OK on success */ int -GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, +GNUNET_RECLAIM_attribute_string_to_value (uint32_t type, const char *s, void **data, size_t *data_size); @@ -413,11 +412,10 @@ GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, * @return NULL on error, otherwise human-readable representation of the claim */ char * -GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, +GNUNET_RECLAIM_attribute_value_to_string (uint32_t type, const void *data, size_t data_size); - /** * Convert a type number to the corresponding type string * @@ -425,35 +423,92 @@ GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, * @return corresponding typestring, NULL on error */ const char * -GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type); - -/** - * Get required size for serialization buffer - * FIXME: - * 1. The naming convention is violated here. - * It should GNUNET_RECLAIM_ATTRIBUTE_. - * It might make sense to refactor attestations into a separate folder. - * 2. The struct should be called GNUNET_RECLAIM_ATTESTATION_Data or - * GNUNET_RECLAIM_ATTRIBUTE_Attestation depending on location in source. - * - * @param attr the attestation to serialize +GNUNET_RECLAIM_attribute_number_to_typename (uint32_t type); + + +/** + * Get required size for serialization buffer + * + * @param attrs the attribute list to serialize + * @return the required buffer size + */ +size_t +GNUNET_RECLAIM_attestation_list_serialize_get_size ( + const struct GNUNET_RECLAIM_AttestationList *attestations); + + +/** + * Destroy claim list + * + * @param attrs list to destroy + */ +void +GNUNET_RECLAIM_attestation_list_destroy ( + struct GNUNET_RECLAIM_AttestationList *attestations); + + +/** + * Add a new attribute to a claim list + * + * @param attr_name the name of the new attribute claim + * @param type the type of the claim + * @param data claim payload + * @param data_size claim payload size + */ +void +GNUNET_RECLAIM_attestation_list_add ( + struct GNUNET_RECLAIM_AttestationList *attrs, + const char *att_name, + uint32_t type, + const void *data, + size_t data_size); + + +/** + * Serialize an attribute list + * + * @param attrs the attribute list to serialize + * @param result the serialized attribute + * @return length of serialized data + */ +size_t +GNUNET_RECLAIM_attestation_list_serialize ( + const struct GNUNET_RECLAIM_AttestationList *attrs, + char *result); + + +/** + * Deserialize an attribute list + * + * @param data the serialized attribute list + * @param data_size the length of the serialized data + * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller + */ +struct GNUNET_RECLAIM_AttestationList * +GNUNET_RECLAIM_attestation_list_deserialize (const char *data, + size_t data_size); + + + +/** + * @param attestation the attestation to serialize * @return the required buffer size */ size_t -GNUNET_RECLAIM_ATTESTATION_serialize_get_size ( - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr); +GNUNET_RECLAIM_attestation_serialize_get_size ( + const struct GNUNET_RECLAIM_Attestation *attestation); /** * Serialize an attestation * - * @param attr the attestation to serialize + * @param attestation the attestation to serialize * @param result the serialized attestation * @return length of serialized data */ size_t -GNUNET_RECLAIM_ATTESTATION_serialize ( - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr, +GNUNET_RECLAIM_attestation_serialize ( + const struct GNUNET_RECLAIM_Attestation *attestation, char *result); @@ -465,24 +520,24 @@ GNUNET_RECLAIM_ATTESTATION_serialize ( * * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller */ -struct GNUNET_RECLAIM_ATTESTATION_Claim * -GNUNET_RECLAIM_ATTESTATION_deserialize (const char *data, size_t data_size); +struct GNUNET_RECLAIM_Attestation * +GNUNET_RECLAIM_attestation_deserialize (const char *data, size_t data_size); /** - * Create a new attestation. - * - * @param attr_name the attestation name - * @param type the attestation type - * @param data the attestation value - * @param data_size the attestation value size - * @return the new attestation - */ -struct GNUNET_RECLAIM_ATTESTATION_Claim * -GNUNET_RECLAIM_ATTESTATION_claim_new (const char *attr_name, - uint32_t type, - const void *data, - size_t data_size); + * Create a new attestation. + * + * @param name the attestation name + * @param type the attestation type + * @param data the attestation value + * @param data_size the attestation value size + * @return the new attestation + */ +struct GNUNET_RECLAIM_Attestation * +GNUNET_RECLAIM_attestation_new (const char *name, + uint32_t type, + const void *data, + size_t data_size); /** * Convert the 'claim' of an attestation to a string @@ -493,7 +548,7 @@ GNUNET_RECLAIM_ATTESTATION_claim_new (const char *attr_name, * @return NULL on error, otherwise human-readable representation of the claim */ char * -GNUNET_RECLAIM_ATTESTATION_value_to_string (uint32_t type, +GNUNET_RECLAIM_attestation_value_to_string (uint32_t type, const void *data, size_t data_size); @@ -508,7 +563,7 @@ GNUNET_RECLAIM_ATTESTATION_value_to_string (uint32_t type, * @return #GNUNET_OK on success */ int -GNUNET_RECLAIM_ATTESTATION_string_to_value (uint32_t type, +GNUNET_RECLAIM_attestation_string_to_value (uint32_t type, const char *s, void **data, size_t *data_size); @@ -520,7 +575,7 @@ GNUNET_RECLAIM_ATTESTATION_string_to_value (uint32_t type, * @return corresponding typestring, NULL on error */ const char * -GNUNET_RECLAIM_ATTESTATION_number_to_typename (uint32_t type); +GNUNET_RECLAIM_attestation_number_to_typename (uint32_t type); /** * Convert an attestation type name to the corresponding number @@ -529,52 +584,8 @@ GNUNET_RECLAIM_ATTESTATION_number_to_typename (uint32_t type); * @return corresponding number, UINT32_MAX on error */ uint32_t -GNUNET_RECLAIM_ATTESTATION_typename_to_number (const char *typename); - -/** - * Create a new attestation reference. - * - * @param attr_name the referenced claim name - * @param ref_value the claim name in the attestation - * @return the new reference - */ -struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * -GNUNET_RECLAIM_ATTESTATION_reference_new (const char *attr_name, - const char *ref_value); - - -/** - * Get required size for serialization buffer - * - * @param attr the reference to serialize - * @return the required buffer size - */ -size_t -GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size ( - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr); +GNUNET_RECLAIM_attestation_typename_to_number (const char *typename); -/** - * Serialize a reference - * - * @param attr the reference to serialize - * @param result the serialized reference - * @return length of serialized data - */ -size_t -GNUNET_RECLAIM_ATTESTATION_REF_serialize ( - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr, - char *result); - -/** - * Deserialize a reference - * - * @param data the serialized reference - * @param data_size the length of the serialized data - * - * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller - */ -struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * -GNUNET_RECLAIM_ATTESTATION_REF_deserialize (const char *data, size_t data_size); #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/include/gnunet_reclaim_attribute_plugin.h b/src/include/gnunet_reclaim_plugin.h similarity index 50% rename from src/include/gnunet_reclaim_attribute_plugin.h rename to src/include/gnunet_reclaim_plugin.h index e61cca5b2..4dd5252d2 100644 --- a/src/include/gnunet_reclaim_attribute_plugin.h +++ b/src/include/gnunet_reclaim_plugin.h @@ -27,8 +27,8 @@ * @defgroup reclaim-attribute-plugin reclaim plugin API for attributes/claims * @{ */ -#ifndef GNUNET_RECLAIM_ATTRIBUTE_PLUGIN_H -#define GNUNET_RECLAIM_ATTRIBUTE_PLUGIN_H +#ifndef GNUNET_RECLAIM_AttributePLUGIN_H +#define GNUNET_RECLAIM_AttributePLUGIN_H #include "gnunet_util_lib.h" #include "gnunet_reclaim_attribute_lib.h" @@ -51,7 +51,7 @@ extern "C" { * @param data_size number of bytes in @a data * @return NULL on error, otherwise human-readable representation of the value */ -typedef char *(*GNUNET_RECLAIM_ATTRIBUTE_ValueToStringFunction) ( +typedef char *(*GNUNET_RECLAIM_AttributeValueToStringFunction) ( void *cls, uint32_t type, const void *data, @@ -70,7 +70,7 @@ typedef char *(*GNUNET_RECLAIM_ATTRIBUTE_ValueToStringFunction) ( * @param data_size set to number of bytes in @a data * @return #GNUNET_OK on success */ -typedef int (*GNUNET_RECLAIM_ATTRIBUTE_StringToValueFunction) ( +typedef int (*GNUNET_RECLAIM_AttributeStringToValueFunction) ( void *cls, uint32_t type, const char *s, @@ -86,7 +86,7 @@ typedef int (*GNUNET_RECLAIM_ATTRIBUTE_StringToValueFunction) ( * @param typename name to convert * @return corresponding number, UINT32_MAX on error */ -typedef uint32_t (*GNUNET_RECLAIM_ATTRIBUTE_TypenameToNumberFunction) ( +typedef uint32_t (*GNUNET_RECLAIM_AttributeTypenameToNumberFunction) ( void *cls, const char *typename); @@ -99,16 +99,79 @@ typedef uint32_t (*GNUNET_RECLAIM_ATTRIBUTE_TypenameToNumberFunction) ( * @param type number of a type to convert * @return corresponding typestring, NULL on error */ -typedef const char *(*GNUNET_RECLAIM_ATTRIBUTE_NumberToTypenameFunction) ( +typedef const char *(*GNUNET_RECLAIM_AttributeNumberToTypenameFunction) ( void *cls, uint32_t type); +/** + * Function called to convert the binary value @a data of an attribute of + * type @a type to a human-readable string. + * + * @param cls closure + * @param type type of the attribute + * @param data value in binary encoding + * @param data_size number of bytes in @a data + * @return NULL on error, otherwise human-readable representation of the value + */ +typedef char *(*GNUNET_RECLAIM_AttestationValueToStringFunction) ( + void *cls, + uint32_t type, + const void *data, + size_t data_size); + + +/** + * Function called to convert human-readable version of the value @a s + * of an attribute of type @a type to the respective binary + * representation. + * + * @param cls closure + * @param type type of the attribute + * @param s human-readable string + * @param data set to value in binary encoding (will be allocated) + * @param data_size set to number of bytes in @a data + * @return #GNUNET_OK on success + */ +typedef int (*GNUNET_RECLAIM_AttestationStringToValueFunction) ( + void *cls, + uint32_t type, + const char *s, + void **data, + size_t *data_size); + + +/** + * Function called to convert a type name to the + * corresponding number. + * + * @param cls closure + * @param typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +typedef uint32_t (*GNUNET_RECLAIM_AttestationTypenameToNumberFunction) ( + void *cls, + const char *typename); + + +/** + * Function called to convert a type number (i.e. 1) to the + * corresponding type string + * + * @param cls closure + * @param type number of a type to convert + * @return corresponding typestring, NULL on error + */ +typedef const char *(*GNUNET_RECLAIM_AttestationNumberToTypenameFunction) ( + void *cls, + uint32_t type); + + /** * Each plugin is required to return a pointer to a struct of this * type as the return value from its entry point. */ -struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions +struct GNUNET_RECLAIM_AttributePluginFunctions { /** * Closure for all of the callbacks. @@ -118,52 +181,60 @@ struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions /** * Conversion to string. */ - GNUNET_RECLAIM_ATTRIBUTE_ValueToStringFunction value_to_string; + GNUNET_RECLAIM_AttributeValueToStringFunction value_to_string; /** * Conversion to binary. */ - GNUNET_RECLAIM_ATTRIBUTE_StringToValueFunction string_to_value; + GNUNET_RECLAIM_AttributeStringToValueFunction string_to_value; /** * Typename to number. */ - GNUNET_RECLAIM_ATTRIBUTE_TypenameToNumberFunction typename_to_number; + GNUNET_RECLAIM_AttributeTypenameToNumberFunction typename_to_number; /** * Number to typename. */ - GNUNET_RECLAIM_ATTRIBUTE_NumberToTypenameFunction number_to_typename; + GNUNET_RECLAIM_AttributeNumberToTypenameFunction number_to_typename; +}; + +/** + * Each plugin is required to return a pointer to a struct of this + * type as the return value from its entry point. + */ +struct GNUNET_RECLAIM_AttestationPluginFunctions +{ /** - * FIXME: It is odd that attestation functions are withing the attribute - * plugin. An attribute type may be backed by an attestation, but not - * necessarily. - * Maybe it would make more sense to refactor this into an attestation - * plugin? - * - * Attestation Conversion to string. + * Closure for all of the callbacks. */ - GNUNET_RECLAIM_ATTRIBUTE_ValueToStringFunction value_to_string_attest; + void *cls; /** - * Attestation Conversion to binary. - */ - GNUNET_RECLAIM_ATTRIBUTE_StringToValueFunction string_to_value_attest; + * Conversion to string. + */ + GNUNET_RECLAIM_AttestationValueToStringFunction value_to_string; /** - * Attestation Typename to number. - */ - GNUNET_RECLAIM_ATTRIBUTE_TypenameToNumberFunction typename_to_number_attest; + * Conversion to binary. + */ + GNUNET_RECLAIM_AttestationStringToValueFunction string_to_value; /** - * Attestation Number to typename. - */ - GNUNET_RECLAIM_ATTRIBUTE_NumberToTypenameFunction number_to_typename_attest; + * Typename to number. + */ + GNUNET_RECLAIM_AttestationTypenameToNumberFunction typename_to_number; + + /** + * Number to typename. + */ + GNUNET_RECLAIM_AttestationNumberToTypenameFunction number_to_typename; }; + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h index b20809a49..4ead87003 100644 --- a/src/include/gnunet_reclaim_service.h +++ b/src/include/gnunet_reclaim_service.h @@ -114,12 +114,24 @@ typedef void (*GNUNET_RECLAIM_ContinuationWithStatus) (void *cls, * @param cls The callback closure * @param identity The identity authoritative over the attributes * @param attr The attribute + * @param attestation The attestation for the attribute (may be NULL) */ typedef void (*GNUNET_RECLAIM_AttributeResult) ( 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 *attestation); + + +/** + * Callback used to notify the client of attestation results. + * + * @param cls The callback closure + * @param identity The identity authoritative over the attributes + * @param attr The attribute + */ +typedef void (*GNUNET_RECLAIM_AttestationResult) ( + void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, + const struct GNUNET_RECLAIM_Attestation *attestation); /** @@ -148,7 +160,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); @@ -169,7 +181,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 *attestation, const struct GNUNET_TIME_Relative *exp_interval, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); @@ -190,7 +202,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); /** @@ -208,28 +220,10 @@ 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); -/** - * 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); /** * List all attributes for a local identity. * This MUST lock the `struct GNUNET_RECLAIM_Handle` @@ -262,26 +256,6 @@ GNUNET_RECLAIM_get_attributes_start ( GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); -/** - * 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); /** * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start @@ -324,7 +298,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); diff --git a/src/reclaim-attribute/Makefile.am b/src/reclaim-attribute/Makefile.am index 490e77398..a1c220340 100644 --- a/src/reclaim-attribute/Makefile.am +++ b/src/reclaim-attribute/Makefile.am @@ -17,7 +17,8 @@ lib_LTLIBRARIES = \ libgnunetreclaimattribute_la_SOURCES = \ reclaim_attribute.h \ - reclaim_attribute.c + reclaim_attribute.c \ + reclaim_attestation.c libgnunetreclaimattribute_la_LIBADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) @@ -27,15 +28,23 @@ libgnunetreclaimattribute_la_LDFLAGS = \ plugin_LTLIBRARIES = \ - libgnunet_plugin_reclaim_attribute_gnuid.la + libgnunet_plugin_reclaim_attribute_basic.la \ + libgnunet_plugin_reclaim_attestation_jwt.la -libgnunet_plugin_reclaim_attribute_gnuid_la_SOURCES = \ - plugin_reclaim_attribute_gnuid.c -libgnunet_plugin_reclaim_attribute_gnuid_la_LIBADD = \ +libgnunet_plugin_reclaim_attribute_basic_la_SOURCES = \ + plugin_reclaim_attribute_basic.c +libgnunet_plugin_reclaim_attribute_basic_la_LIBADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(LTLIBINTL) -libgnunet_plugin_reclaim_attribute_gnuid_la_LDFLAGS = \ +libgnunet_plugin_reclaim_attribute_basic_la_LDFLAGS = \ $(GN_PLUGIN_LDFLAGS) +libgnunet_plugin_reclaim_attestation_jwt_la_SOURCES = \ + plugin_reclaim_attestation_jwt.c +libgnunet_plugin_reclaim_attestation_jwt_la_LIBADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(LTLIBINTL) +libgnunet_plugin_reclaim_attestation_jwt_la_LDFLAGS = \ + $(GN_PLUGIN_LDFLAGS) diff --git a/src/reclaim-attribute/plugin_reclaim_attestation_jwt.c b/src/reclaim-attribute/plugin_reclaim_attestation_jwt.c new file mode 100644 index 000000000..eb6043a66 --- /dev/null +++ b/src/reclaim-attribute/plugin_reclaim_attestation_jwt.c @@ -0,0 +1,182 @@ +/* + This file is part of GNUnet + Copyright (C) 2013, 2014, 2016 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later + */ + +/** + * @file reclaim-attribute/plugin_reclaim_attestation_gnuid.c + * @brief reclaim-attribute-plugin-gnuid attribute plugin to provide the API for + * fundamental + * attribute types. + * + * @author Martin Schanzenbach + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_reclaim_plugin.h" +#include + + +/** + * Convert the 'value' of an attestation to a string. + * + * @param cls closure, unused + * @param type type of the attestation + * @param data value in binary encoding + * @param data_size number of bytes in @a data + * @return NULL on error, otherwise human-readable representation of the value + */ +static char * +jwt_value_to_string (void *cls, + uint32_t type, + const void *data, + size_t data_size) +{ + switch (type) + { + case GNUNET_RECLAIM_ATTESTATION_TYPE_JWT: + return GNUNET_strndup (data, data_size); + + default: + return NULL; + } +} + + +/** + * Convert human-readable version of a 'value' of an attestation to the binary + * representation. + * + * @param cls closure, unused + * @param type type of the attestation + * @param s human-readable string + * @param data set to value in binary encoding (will be allocated) + * @param data_size set to number of bytes in @a data + * @return #GNUNET_OK on success + */ +static int +jwt_string_to_value (void *cls, + uint32_t type, + const char *s, + void **data, + size_t *data_size) +{ + if (NULL == s) + return GNUNET_SYSERR; + switch (type) + { + case GNUNET_RECLAIM_ATTESTATION_TYPE_JWT: + *data = GNUNET_strdup (s); + *data_size = strlen (s); + return GNUNET_OK; + + default: + return GNUNET_SYSERR; + } +} + + +/** + * Mapping of attestation type numbers to human-readable + * attestation type names. + */ +static struct +{ + const char *name; + uint32_t number; +} jwt_attest_name_map[] = { { "JWT", GNUNET_RECLAIM_ATTESTATION_TYPE_JWT }, + { NULL, UINT32_MAX } }; + +/** + * Convert a type name to the corresponding number. + * + * @param cls closure, unused + * @param jwt_typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +static uint32_t +jwt_typename_to_number (void *cls, const char *jwt_typename) +{ + unsigned int i; + + i = 0; + while ((NULL != jwt_attest_name_map[i].name) && + (0 != strcasecmp (jwt_typename, jwt_attest_name_map[i].name))) + i++; + return jwt_attest_name_map[i].number; +} + + +/** + * Convert a type number (i.e. 1) to the corresponding type string + * + * @param cls closure, unused + * @param type number of a type to convert + * @return corresponding typestring, NULL on error + */ +static const char * +jwt_number_to_typename (void *cls, uint32_t type) +{ + unsigned int i; + + i = 0; + while ((NULL != jwt_attest_name_map[i].name) && (type != + jwt_attest_name_map[i]. + number)) + i++; + return jwt_attest_name_map[i].name; +} + + +/** + * Entry point for the plugin. + * + * @param cls NULL + * @return the exported block API + */ +void * +libgnunet_plugin_reclaim_attestation_jwt_init (void *cls) +{ + struct GNUNET_RECLAIM_AttestationPluginFunctions *api; + + api = GNUNET_new (struct GNUNET_RECLAIM_AttestationPluginFunctions); + api->value_to_string = &jwt_value_to_string; + api->string_to_value = &jwt_string_to_value; + api->typename_to_number = &jwt_typename_to_number; + api->number_to_typename = &jwt_number_to_typename; + return api; +} + + +/** + * Exit point from the plugin. + * + * @param cls the return value from #libgnunet_plugin_block_test_init() + * @return NULL + */ +void * +libgnunet_plugin_reclaim_attestation_jwt_done (void *cls) +{ + struct GNUNET_RECLAIM_AttestationPluginFunctions *api = cls; + + GNUNET_free (api); + return NULL; +} + + +/* end of plugin_reclaim_attestation_type_gnuid.c */ diff --git a/src/reclaim-attribute/plugin_reclaim_attribute_basic.c b/src/reclaim-attribute/plugin_reclaim_attribute_basic.c new file mode 100644 index 000000000..47fdd5f11 --- /dev/null +++ b/src/reclaim-attribute/plugin_reclaim_attribute_basic.c @@ -0,0 +1,180 @@ +/* + This file is part of GNUnet + Copyright (C) 2013, 2014, 2016 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later + */ + +/** + * @file reclaim-attribute/plugin_reclaim_attribute_gnuid.c + * @brief reclaim-attribute-plugin-gnuid attribute plugin to provide the API for + * fundamental + * attribute types. + * + * @author Martin Schanzenbach + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_reclaim_plugin.h" +#include + + +/** + * Convert the 'value' of an attribute to a string. + * + * @param cls closure, unused + * @param type type of the attribute + * @param data value in binary encoding + * @param data_size number of bytes in @a data + * @return NULL on error, otherwise human-readable representation of the value + */ +static char * +basic_value_to_string (void *cls, + uint32_t type, + const void *data, + size_t data_size) +{ + switch (type) + { + case GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING: + return GNUNET_strndup (data, data_size); + + default: + return NULL; + } +} + + +/** + * Convert human-readable version of a 'value' of an attribute to the binary + * representation. + * + * @param cls closure, unused + * @param type type of the attribute + * @param s human-readable string + * @param data set to value in binary encoding (will be allocated) + * @param data_size set to number of bytes in @a data + * @return #GNUNET_OK on success + */ +static int +basic_string_to_value (void *cls, + uint32_t type, + const char *s, + void **data, + size_t *data_size) +{ + if (NULL == s) + return GNUNET_SYSERR; + switch (type) + { + case GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING: + *data = GNUNET_strdup (s); + *data_size = strlen (s); + return GNUNET_OK; + + default: + return GNUNET_SYSERR; + } +} + +/** + * Mapping of attribute type numbers to human-readable + * attribute type names. + */ +static struct +{ + const char *name; + uint32_t number; +} basic_name_map[] = { { "STRING", GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING }, + { NULL, UINT32_MAX } }; + + +/** + * Convert a type name to the corresponding number. + * + * @param cls closure, unused + * @param basic_typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +static uint32_t +basic_typename_to_number (void *cls, const char *basic_typename) +{ + unsigned int i; + + i = 0; + while ((NULL != basic_name_map[i].name) && + (0 != strcasecmp (basic_typename, basic_name_map[i].name))) + i++; + return basic_name_map[i].number; +} + + +/** + * Convert a type number (i.e. 1) to the corresponding type string + * + * @param cls closure, unused + * @param type number of a type to convert + * @return corresponding typestring, NULL on error + */ +static const char * +basic_number_to_typename (void *cls, uint32_t type) +{ + unsigned int i; + + i = 0; + while ((NULL != basic_name_map[i].name) && (type != basic_name_map[i].number)) + i++; + return basic_name_map[i].name; +} + + +/** + * Entry point for the plugin. + * + * @param cls NULL + * @return the exported block API + */ +void * +libgnunet_plugin_reclaim_attribute_basic_init (void *cls) +{ + struct GNUNET_RECLAIM_AttributePluginFunctions *api; + + api = GNUNET_new (struct GNUNET_RECLAIM_AttributePluginFunctions); + api->value_to_string = &basic_value_to_string; + api->string_to_value = &basic_string_to_value; + api->typename_to_number = &basic_typename_to_number; + api->number_to_typename = &basic_number_to_typename; + return api; +} + + +/** + * Exit point from the plugin. + * + * @param cls the return value from #libgnunet_plugin_block_test_init() + * @return NULL + */ +void * +libgnunet_plugin_reclaim_attribute_basic_done (void *cls) +{ + struct GNUNET_RECLAIM_AttributePluginFunctions *api = cls; + + GNUNET_free (api); + return NULL; +} + + +/* end of plugin_reclaim_attribute_type_gnuid.c */ diff --git a/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c b/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c deleted file mode 100644 index ade2a27bb..000000000 --- a/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - This file is part of GNUnet - Copyright (C) 2013, 2014, 2016 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - SPDX-License-Identifier: AGPL3.0-or-later - */ - -/** - * @file reclaim-attribute/plugin_reclaim_attribute_gnuid.c - * @brief reclaim-attribute-plugin-gnuid attribute plugin to provide the API for - * fundamental - * attribute types. - * - * @author Martin Schanzenbach - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_reclaim_attribute_plugin.h" -#include - - -/** - * Convert the 'value' of an attribute to a string. - * - * @param cls closure, unused - * @param type type of the attribute - * @param data value in binary encoding - * @param data_size number of bytes in @a data - * @return NULL on error, otherwise human-readable representation of the value - */ -static char * -gnuid_value_to_string (void *cls, - uint32_t type, - const void *data, - size_t data_size) -{ - switch (type) - { - case GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING: - return GNUNET_strndup (data, data_size); - - default: - return NULL; - } -} - - -/** - * Convert human-readable version of a 'value' of an attribute to the binary - * representation. - * - * @param cls closure, unused - * @param type type of the attribute - * @param s human-readable string - * @param data set to value in binary encoding (will be allocated) - * @param data_size set to number of bytes in @a data - * @return #GNUNET_OK on success - */ -static int -gnuid_string_to_value (void *cls, - uint32_t type, - const char *s, - void **data, - size_t *data_size) -{ - if (NULL == s) - return GNUNET_SYSERR; - switch (type) - { - case GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING: - *data = GNUNET_strdup (s); - *data_size = strlen (s); - return GNUNET_OK; - - default: - return GNUNET_SYSERR; - } -} - -/** - * Convert the 'value' of an attestation to a string. - * - * @param cls closure, unused - * @param type type of the attestation - * @param data value in binary encoding - * @param data_size number of bytes in @a data - * @return NULL on error, otherwise human-readable representation of the value - */ -static char * -gnuid_value_to_string_attest (void *cls, - uint32_t type, - const void *data, - size_t data_size) -{ - switch (type) - { - case GNUNET_RECLAIM_ATTESTATION_TYPE_JWT: - return GNUNET_strndup (data, data_size); - - default: - return NULL; - } -} - - -/** - * Convert human-readable version of a 'value' of an attestation to the binary - * representation. - * - * @param cls closure, unused - * @param type type of the attestation - * @param s human-readable string - * @param data set to value in binary encoding (will be allocated) - * @param data_size set to number of bytes in @a data - * @return #GNUNET_OK on success - */ -static int -gnuid_string_to_value_attest (void *cls, - uint32_t type, - const char *s, - void **data, - size_t *data_size) -{ - if (NULL == s) - return GNUNET_SYSERR; - switch (type) - { - case GNUNET_RECLAIM_ATTESTATION_TYPE_JWT: - *data = GNUNET_strdup (s); - *data_size = strlen (s); - return GNUNET_OK; - - default: - return GNUNET_SYSERR; - } -} - -/** - * Mapping of attribute type numbers to human-readable - * attribute type names. - */ -static struct -{ - const char *name; - uint32_t number; -} gnuid_name_map[] = { { "STRING", GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING }, - { NULL, UINT32_MAX } }; - -/** - * Mapping of attestation type numbers to human-readable - * attestation type names. - */ -static struct -{ - const char *name; - uint32_t number; -} gnuid_attest_name_map[] = { { "JWT", GNUNET_RECLAIM_ATTESTATION_TYPE_JWT }, - { NULL, UINT32_MAX } }; - -/** - * Convert a type name to the corresponding number. - * - * @param cls closure, unused - * @param gnuid_typename name to convert - * @return corresponding number, UINT32_MAX on error - */ -static uint32_t -gnuid_typename_to_number (void *cls, const char *gnuid_typename) -{ - unsigned int i; - - i = 0; - while ((NULL != gnuid_name_map[i].name) && - (0 != strcasecmp (gnuid_typename, gnuid_name_map[i].name))) - i++; - return gnuid_name_map[i].number; -} - - -/** - * Convert a type number (i.e. 1) to the corresponding type string - * - * @param cls closure, unused - * @param type number of a type to convert - * @return corresponding typestring, NULL on error - */ -static const char * -gnuid_number_to_typename (void *cls, uint32_t type) -{ - unsigned int i; - - i = 0; - while ((NULL != gnuid_name_map[i].name) && (type != gnuid_name_map[i].number)) - i++; - return gnuid_name_map[i].name; -} - -/** - * Convert a type name to the corresponding number. - * - * @param cls closure, unused - * @param gnuid_typename name to convert - * @return corresponding number, UINT32_MAX on error - */ -static uint32_t -gnuid_typename_to_number_attest (void *cls, const char *gnuid_typename) -{ - unsigned int i; - - i = 0; - while ((NULL != gnuid_attest_name_map[i].name) && - (0 != strcasecmp (gnuid_typename, gnuid_attest_name_map[i].name))) - i++; - return gnuid_attest_name_map[i].number; -} - -/** - * Convert a type number (i.e. 1) to the corresponding type string - * - * @param cls closure, unused - * @param type number of a type to convert - * @return corresponding typestring, NULL on error - */ -static const char * -gnuid_number_to_typename_attest (void *cls, uint32_t type) -{ - unsigned int i; - - i = 0; - while ((NULL != gnuid_attest_name_map[i].name) && (type != - gnuid_attest_name_map[i]. - number)) - i++; - return gnuid_attest_name_map[i].name; -} - -/** - * Entry point for the plugin. - * - * @param cls NULL - * @return the exported block API - */ -void * -libgnunet_plugin_reclaim_attribute_gnuid_init (void *cls) -{ - struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api; - - api = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions); - api->value_to_string = &gnuid_value_to_string; - api->string_to_value = &gnuid_string_to_value; - api->typename_to_number = &gnuid_typename_to_number; - api->number_to_typename = &gnuid_number_to_typename; - api->value_to_string_attest = &gnuid_value_to_string_attest; - api->string_to_value_attest = &gnuid_string_to_value_attest; - api->typename_to_number_attest = &gnuid_typename_to_number_attest; - api->number_to_typename_attest = &gnuid_number_to_typename_attest; - return api; -} - - -/** - * Exit point from the plugin. - * - * @param cls the return value from #libgnunet_plugin_block_test_init() - * @return NULL - */ -void * -libgnunet_plugin_reclaim_attribute_gnuid_done (void *cls) -{ - struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = cls; - - GNUNET_free (api); - return NULL; -} - - -/* end of plugin_reclaim_attribute_type_gnuid.c */ diff --git a/src/reclaim-attribute/reclaim_attestation.c b/src/reclaim-attribute/reclaim_attestation.c new file mode 100644 index 000000000..1a7776719 --- /dev/null +++ b/src/reclaim-attribute/reclaim_attestation.c @@ -0,0 +1,502 @@ +/* + This file is part of GNUnet + Copyright (C) 2010-2015 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later + */ + +/** + * @file reclaim-attribute/reclaim_attestation.c + * @brief helper library to manage identity attribute attestations + * @author Martin Schanzenbach + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_reclaim_plugin.h" +#include "reclaim_attestation.h" + + +/** + * Handle for a plugin + */ +struct Plugin +{ + /** + * Name of the plugin + */ + char *library_name; + + /** + * Plugin API + */ + struct GNUNET_RECLAIM_AttestationPluginFunctions *api; +}; + + +/** + * Plugins + */ +static struct Plugin **attest_plugins; + + +/** + * Number of plugins + */ +static unsigned int num_plugins; + + +/** + * Init canary + */ +static int initialized; + + +/** + * Add a plugin + * + * @param cls closure + * @param library_name name of the API library + * @param lib_ret the plugin API pointer + */ +static void +add_plugin (void *cls, const char *library_name, void *lib_ret) +{ + struct GNUNET_RECLAIM_AttestationPluginFunctions *api = lib_ret; + struct Plugin *plugin; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Loading attestation plugin `%s'\n", + library_name); + plugin = GNUNET_new (struct Plugin); + plugin->api = api; + plugin->library_name = GNUNET_strdup (library_name); + GNUNET_array_append (attest_plugins, num_plugins, plugin); +} + + +/** + * Load plugins + */ +static void +init () +{ + if (GNUNET_YES == initialized) + return; + initialized = GNUNET_YES; + GNUNET_PLUGIN_load_all ("libgnunet_plugin_reclaim_attestation_", + NULL, + &add_plugin, + NULL); +} + + +/** + * Convert an attestation type name to the corresponding number + * + * @param typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +uint32_t +GNUNET_RECLAIM_attestation_typename_to_number (const char *typename) +{ + unsigned int i; + struct Plugin *plugin; + uint32_t ret; + init (); + for (i = 0; i < num_plugins; i++) + { + plugin = attest_plugins[i]; + if (UINT32_MAX != + (ret = plugin->api->typename_to_number (plugin->api->cls, + typename))) + return ret; + } + return UINT32_MAX; +} + + +/** + * Convert an attestation type number to the corresponding attestation type string + * + * @param type number of a type + * @return corresponding typestring, NULL on error + */ +const char * +GNUNET_RECLAIM_attestation_number_to_typename (uint32_t type) +{ + unsigned int i; + struct Plugin *plugin; + const char *ret; + + init (); + for (i = 0; i < num_plugins; i++) + { + plugin = attest_plugins[i]; + if (NULL != + (ret = plugin->api->number_to_typename (plugin->api->cls, type))) + return ret; + } + return NULL; +} + + +/** + * Convert human-readable version of a 'claim' of an attestation to the binary + * representation + * + * @param type type of the claim + * @param s human-readable string + * @param data set to value in binary encoding (will be allocated) + * @param data_size set to number of bytes in @a data + * @return #GNUNET_OK on success + */ +int +GNUNET_RECLAIM_attestation_string_to_value (uint32_t type, + const char *s, + void **data, + size_t *data_size) +{ + unsigned int i; + struct Plugin *plugin; + + init (); + for (i = 0; i < num_plugins; i++) + { + plugin = attest_plugins[i]; + if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, + type, + s, + data, + data_size)) + return GNUNET_OK; + } + return GNUNET_SYSERR; +} + + +/** + * Convert the 'claim' of an attestation to a string + * + * @param type the type of attestation + * @param data claim in binary encoding + * @param data_size number of bytes in @a data + * @return NULL on error, otherwise human-readable representation of the claim + */ +char * +GNUNET_RECLAIM_attestation_value_to_string (uint32_t type, + const void *data, + size_t data_size) +{ + unsigned int i; + struct Plugin *plugin; + char *ret; + + init (); + for (i = 0; i < num_plugins; i++) + { + plugin = attest_plugins[i]; + if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, + type, + data, + data_size))) + return ret; + } + return NULL; +} + + +/** + * Create a new attestation. + * + * @param attr_name the attestation name + * @param type the attestation type + * @param data the attestation value + * @param data_size the attestation value size + * @return the new attestation + */ +struct GNUNET_RECLAIM_Attestation * +GNUNET_RECLAIM_attestation_new (const char *attr_name, + uint32_t type, + const void *data, + size_t data_size) +{ + struct GNUNET_RECLAIM_Attestation *attr; + char *write_ptr; + char *attr_name_tmp = GNUNET_strdup (attr_name); + + GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); + + attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attestation) + + strlen (attr_name_tmp) + 1 + data_size); + attr->type = type; + attr->data_size = data_size; + attr->flag = 0; + write_ptr = (char *) &attr[1]; + GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1); + attr->name = write_ptr; + write_ptr += strlen (attr->name) + 1; + GNUNET_memcpy (write_ptr, data, data_size); + attr->data = write_ptr; + GNUNET_free (attr_name_tmp); + return attr; +} + + +/** + * Get required size for serialization buffer + * + * @param attrs the attribute list to serialize + * @return the required buffer size + */ +size_t +GNUNET_RECLAIM_attestation_list_serialize_get_size ( + const struct GNUNET_RECLAIM_AttestationList *attestations) +{ + struct GNUNET_RECLAIM_AttestationListEntry *le; + size_t len = 0; + + for (le = attestations->list_head; NULL != le; le = le->next) + { + GNUNET_assert (NULL != le->attestation); + len += GNUNET_RECLAIM_attestation_serialize_get_size (le->attestation); + len += sizeof(struct GNUNET_RECLAIM_AttestationListEntry); + } + return len; +} + + +/** + * Serialize an attribute list + * + * @param attrs the attribute list to serialize + * @param result the serialized attribute + * @return length of serialized data + */ +size_t +GNUNET_RECLAIM_attestation_list_serialize ( + const struct GNUNET_RECLAIM_AttestationList *attestations, + char *result) +{ + struct GNUNET_RECLAIM_AttestationListEntry *le; + size_t len; + size_t total_len; + char *write_ptr; + write_ptr = result; + total_len = 0; + for (le = attestations->list_head; NULL != le; le = le->next) + { + GNUNET_assert (NULL != le->attestation); + len = GNUNET_RECLAIM_attestation_serialize (le->attestation, write_ptr); + total_len += len; + write_ptr += len; + } + return total_len; +} + + +/** + * Deserialize an attestation list + * + * @param data the serialized attribute list + * @param data_size the length of the serialized data + * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller + */ +struct GNUNET_RECLAIM_AttestationList * +GNUNET_RECLAIM_attestation_list_deserialize (const char *data, size_t data_size) +{ + struct GNUNET_RECLAIM_AttestationList *al; + struct GNUNET_RECLAIM_AttestationListEntry *ale; + size_t att_len; + const char *read_ptr; + + al = GNUNET_new (struct GNUNET_RECLAIM_AttestationList); + + if ((data_size < sizeof(struct + Attestation) + + sizeof(struct GNUNET_RECLAIM_AttestationListEntry))) + return al; + + read_ptr = data; + while (((data + data_size) - read_ptr) >= sizeof(struct Attestation)) + { + ale = GNUNET_new (struct GNUNET_RECLAIM_AttestationListEntry); + ale->attestation = + GNUNET_RECLAIM_attestation_deserialize (read_ptr, + data_size - (read_ptr - data)); + GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale); + att_len = GNUNET_RECLAIM_attestation_serialize_get_size (ale->attestation); + read_ptr += att_len; + } + return al; +} + + +/** + * Make a (deep) copy of the attestation list + * @param attrs claim list to copy + * @return copied claim list + */ +struct GNUNET_RECLAIM_AttestationList * +GNUNET_RECLAIM_attestation_list_dup ( + const struct GNUNET_RECLAIM_AttestationList *al) +{ + struct GNUNET_RECLAIM_AttestationListEntry *ale; + struct GNUNET_RECLAIM_AttestationListEntry *result_ale; + struct GNUNET_RECLAIM_AttestationList *result; + + result = GNUNET_new (struct GNUNET_RECLAIM_AttestationList); + for (ale = al->list_head; NULL != ale; ale = ale->next) + { + result_ale = GNUNET_new (struct GNUNET_RECLAIM_AttestationListEntry); + GNUNET_assert (NULL != ale->attestation); + result_ale->attestation = + GNUNET_RECLAIM_attestation_new (ale->attestation->name, + ale->attestation->type, + ale->attestation->data, + ale->attestation->data_size); + result_ale->attestation->id = ale->attestation->id; + GNUNET_CONTAINER_DLL_insert (result->list_head, + result->list_tail, + result_ale); + } + return result; +} + + +/** + * Destroy attestation list + * + * @param attrs list to destroy + */ +void +GNUNET_RECLAIM_attestation_list_destroy ( + struct GNUNET_RECLAIM_AttestationList *al) +{ + struct GNUNET_RECLAIM_AttestationListEntry *ale; + struct GNUNET_RECLAIM_AttestationListEntry *tmp_ale; + + for (ale = al->list_head; NULL != ale; ale = ale->next) + { + if (NULL != ale->attestation) + GNUNET_free (ale->attestation); + tmp_ale = ale; + ale = ale->next; + GNUNET_free (tmp_ale); + } + GNUNET_free (al); +} + + +/** + * Get required size for serialization buffer + * + * @param attr the attestation to serialize + * @return the required buffer size + */ +size_t +GNUNET_RECLAIM_attestation_serialize_get_size ( + const struct GNUNET_RECLAIM_Attestation *attestation) +{ + return sizeof(struct Attestation) + strlen (attestation->name) + + attestation->data_size; +} + + +/** + * Serialize an attestation + * + * @param attr the attestation to serialize + * @param result the serialized attestation + * @return length of serialized data + */ +size_t +GNUNET_RECLAIM_attestation_serialize ( + const struct GNUNET_RECLAIM_Attestation *attestation, + char *result) +{ + size_t data_len_ser; + size_t name_len; + struct Attestation *atts; + char *write_ptr; + + atts = (struct Attestation *) result; + atts->attestation_type = htons (attestation->type); + atts->attestation_flag = htonl (attestation->flag); + atts->attestation_id = attestation->id; + name_len = strlen (attestation->name); + atts->name_len = htons (name_len); + write_ptr = (char *) &atts[1]; + GNUNET_memcpy (write_ptr, attestation->name, name_len); + write_ptr += name_len; + // TODO plugin-ize + // data_len_ser = plugin->serialize_attribute_value (attr, + // &attr_ser[1]); + data_len_ser = attestation->data_size; + GNUNET_memcpy (write_ptr, attestation->data, attestation->data_size); + atts->data_size = htons (data_len_ser); + + return sizeof(struct Attestation) + strlen (attestation->name) + + attestation->data_size; +} + + +/** + * Deserialize an attestation + * + * @param data the serialized attestation + * @param data_size the length of the serialized data + * + * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller + */ +struct GNUNET_RECLAIM_Attestation * +GNUNET_RECLAIM_attestation_deserialize (const char *data, size_t data_size) +{ + struct GNUNET_RECLAIM_Attestation *attestation; + struct Attestation *atts; + size_t data_len; + size_t name_len; + char *write_ptr; + + if (data_size < sizeof(struct Attestation)) + return NULL; + + atts = (struct Attestation *) data; + data_len = ntohs (atts->data_size); + name_len = ntohs (atts->name_len); + if (data_size < sizeof(struct Attestation) + data_len + name_len) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Buffer too small to deserialize\n"); + return NULL; + } + attestation = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attestation) + + data_len + name_len + 1); + attestation->type = ntohs (atts->attestation_type); + attestation->flag = ntohl (atts->attestation_flag); + attestation->id = atts->attestation_id; + attestation->data_size = data_len; + + write_ptr = (char *) &attestation[1]; + GNUNET_memcpy (write_ptr, &atts[1], name_len); + write_ptr[name_len] = '\0'; + attestation->name = write_ptr; + + write_ptr += name_len + 1; + GNUNET_memcpy (write_ptr, (char *) &atts[1] + name_len, + attestation->data_size); + attestation->data = write_ptr; + return attestation; +} diff --git a/src/reclaim-attribute/reclaim_attestation.h b/src/reclaim-attribute/reclaim_attestation.h new file mode 100644 index 000000000..5747d8896 --- /dev/null +++ b/src/reclaim-attribute/reclaim_attestation.h @@ -0,0 +1,64 @@ +/* + This file is part of GNUnet. + Copyright (C) 2012-2015 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/** + * @author Martin Schanzenbach + * @file reclaim-attribute/reclaim_attestation.h + * @brief GNUnet reclaim identity attribute attestations + * + */ +#ifndef RECLAIM_ATTESTATION_H +#define RECLAIM_ATTESTATION_H + +#include "gnunet_reclaim_service.h" + +/** + * Serialized attestation claim + */ +struct Attestation +{ + /** + * Attestation type + */ + uint32_t attestation_type; + + /** + * Attestation flag + */ + uint32_t attestation_flag; + + /** + * Attestation ID + */ + struct GNUNET_RECLAIM_Identifier attestation_id; + + /** + * Name length + */ + uint32_t name_len; + + /** + * Data size + */ + uint32_t data_size; + + // followed by data_size Attestation value data +}; + +#endif diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c index 07d8200c6..936f9cb75 100644 --- a/src/reclaim-attribute/reclaim_attribute.c +++ b/src/reclaim-attribute/reclaim_attribute.c @@ -25,7 +25,7 @@ */ #include "platform.h" #include "gnunet_util_lib.h" -#include "gnunet_reclaim_attribute_plugin.h" +#include "gnunet_reclaim_plugin.h" #include "reclaim_attribute.h" @@ -42,7 +42,7 @@ struct Plugin /** * Plugin API */ - struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api; + struct GNUNET_RECLAIM_AttributePluginFunctions *api; }; @@ -74,7 +74,7 @@ static int initialized; static void add_plugin (void *cls, const char *library_name, void *lib_ret) { - struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = lib_ret; + struct GNUNET_RECLAIM_AttributePluginFunctions *api = lib_ret; struct Plugin *plugin; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -110,7 +110,7 @@ init () * @return corresponding number, UINT32_MAX on error */ uint32_t -GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename) +GNUNET_RECLAIM_attribute_typename_to_number (const char *typename) { unsigned int i; struct Plugin *plugin; @@ -135,7 +135,7 @@ GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename) * @return corresponding typestring, NULL on error */ const char * -GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type) +GNUNET_RECLAIM_attribute_number_to_typename (uint32_t type) { unsigned int i; struct Plugin *plugin; @@ -164,7 +164,7 @@ GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type) * @return #GNUNET_OK on success */ int -GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, +GNUNET_RECLAIM_attribute_string_to_value (uint32_t type, const char *s, void **data, size_t *data_size) @@ -196,7 +196,7 @@ GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, * @return NULL on error, otherwise human-readable representation of the claim */ char * -GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, +GNUNET_RECLAIM_attribute_value_to_string (uint32_t type, const void *data, size_t data_size) { @@ -217,140 +217,34 @@ GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, return NULL; } -/** - * Convert an attestation type name to the corresponding number - * - * @param typename name to convert - * @return corresponding number, UINT32_MAX on error - */ -uint32_t -GNUNET_RECLAIM_ATTESTATION_typename_to_number (const char *typename) -{ - unsigned int i; - struct Plugin *plugin; - uint32_t ret; - init (); - for (i = 0; i < num_plugins; i++) - { - plugin = attr_plugins[i]; - if (UINT32_MAX != - (ret = plugin->api->typename_to_number_attest (plugin->api->cls, - typename))) - return ret; - } - return UINT32_MAX; -} - -/** - * Convert an attestation type number to the corresponding attestation type string - * - * @param type number of a type - * @return corresponding typestring, NULL on error - */ -const char * -GNUNET_RECLAIM_ATTESTATION_number_to_typename (uint32_t type) -{ - unsigned int i; - struct Plugin *plugin; - const char *ret; - - init (); - for (i = 0; i < num_plugins; i++) - { - plugin = attr_plugins[i]; - if (NULL != - (ret = plugin->api->number_to_typename_attest (plugin->api->cls, type))) - return ret; - } - return NULL; -} -/** - * Convert human-readable version of a 'claim' of an attestation to the binary - * representation - * - * @param type type of the claim - * @param s human-readable string - * @param data set to value in binary encoding (will be allocated) - * @param data_size set to number of bytes in @a data - * @return #GNUNET_OK on success - */ -int -GNUNET_RECLAIM_ATTESTATION_string_to_value (uint32_t type, - const char *s, - void **data, - size_t *data_size) -{ - unsigned int i; - struct Plugin *plugin; - - init (); - for (i = 0; i < num_plugins; i++) - { - plugin = attr_plugins[i]; - if (GNUNET_OK == plugin->api->string_to_value_attest (plugin->api->cls, - type, - s, - data, - data_size)) - return GNUNET_OK; - } - return GNUNET_SYSERR; -} - - -/** - * Convert the 'claim' of an attestation to a string - * - * @param type the type of attestation - * @param data claim in binary encoding - * @param data_size number of bytes in @a data - * @return NULL on error, otherwise human-readable representation of the claim - */ -char * -GNUNET_RECLAIM_ATTESTATION_value_to_string (uint32_t type, - const void *data, - size_t data_size) -{ - unsigned int i; - struct Plugin *plugin; - char *ret; - - init (); - for (i = 0; i < num_plugins; i++) - { - plugin = attr_plugins[i]; - if (NULL != (ret = plugin->api->value_to_string_attest (plugin->api->cls, - type, - data, - data_size))) - return ret; - } - return NULL; -} /** * Create a new attribute. * * @param attr_name the attribute name + * @param attestation attestation ID of the attribute (maybe NULL) * @param type the attribute type * @param data the attribute value * @param data_size the attribute value size * @return the new attribute */ -struct GNUNET_RECLAIM_ATTRIBUTE_Claim * -GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name, - uint32_t type, - const void *data, - size_t data_size) +struct GNUNET_RECLAIM_Attribute * +GNUNET_RECLAIM_attribute_new (const char *attr_name, + const struct GNUNET_RECLAIM_Identifier *attestation, + uint32_t type, + const void *data, + size_t data_size) { - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; + struct GNUNET_RECLAIM_Attribute *attr; char *write_ptr; char *attr_name_tmp = GNUNET_strdup (attr_name); GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); - attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute) + strlen (attr_name_tmp) + 1 + data_size); + if (NULL != attestation) + attr->attestation = *attestation; attr->type = type; attr->data_size = data_size; attr->flag = 0; @@ -364,76 +258,6 @@ GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name, return attr; } -/** - * Create a new attestation. - * - * @param attr_name the attestation name - * @param type the attestation type - * @param data the attestation value - * @param data_size the attestation value size - * @return the new attestation - */ -struct GNUNET_RECLAIM_ATTESTATION_Claim * -GNUNET_RECLAIM_ATTESTATION_claim_new (const char *attr_name, - uint32_t type, - const void *data, - size_t data_size) -{ - struct GNUNET_RECLAIM_ATTESTATION_Claim *attr; - char *write_ptr; - char *attr_name_tmp = GNUNET_strdup (attr_name); - - GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); - - attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTESTATION_Claim) - + strlen (attr_name_tmp) + 1 + data_size); - attr->type = type; - attr->data_size = data_size; - attr->flag = 0; - write_ptr = (char *) &attr[1]; - GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1); - attr->name = write_ptr; - write_ptr += strlen (attr->name) + 1; - GNUNET_memcpy (write_ptr, data, data_size); - attr->data = write_ptr; - GNUNET_free (attr_name_tmp); - return attr; -} - -/** - * Create a new attestation reference. - * - * @param attr_name the referenced claim name - * @param ref_value the claim name in the attestation - * @return the new reference - */ -struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * -GNUNET_RECLAIM_ATTESTATION_reference_new (const char *attr_name, - const char *ref_value) -{ - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr; - char *write_ptr; - char *attr_name_tmp = GNUNET_strdup (attr_name); - char *ref_value_tmp = GNUNET_strdup (ref_value); - - GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); - GNUNET_STRINGS_utf8_tolower (ref_value, ref_value_tmp); - - attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE) - + strlen (attr_name_tmp) + strlen (ref_value_tmp) + 2); - - write_ptr = (char *) &attr[1]; - GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1); - attr->name = write_ptr; - - write_ptr += strlen (attr_name) + 1; - GNUNET_memcpy (write_ptr, ref_value_tmp, strlen (ref_value_tmp) + 1); - attr->reference_value = write_ptr; - - GNUNET_free (attr_name_tmp); - GNUNET_free (ref_value_tmp); - return attr; -} /** * Add a new attribute to a claim list @@ -444,21 +268,23 @@ GNUNET_RECLAIM_ATTESTATION_reference_new (const char *attr_name, * @param data_size claim payload size */ void -GNUNET_RECLAIM_ATTRIBUTE_list_add ( - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *claim_list, +GNUNET_RECLAIM_attribute_list_add ( + struct GNUNET_RECLAIM_AttributeList *al, const char *attr_name, + const struct GNUNET_RECLAIM_Identifier *attestation, uint32_t type, const void *data, size_t data_size) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; - - le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - le->claim = - GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size); - GNUNET_CONTAINER_DLL_insert (claim_list->list_head, - claim_list->list_tail, - le); + struct GNUNET_RECLAIM_AttributeListEntry *ale; + + ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); + ale->attribute = + GNUNET_RECLAIM_attribute_new (attr_name, attestation, + type, data, data_size); + GNUNET_CONTAINER_DLL_insert (al->list_head, + al->list_tail, + ale); } @@ -469,36 +295,17 @@ GNUNET_RECLAIM_ATTRIBUTE_list_add ( * @return the required buffer size */ size_t -GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size ( - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) +GNUNET_RECLAIM_attribute_list_serialize_get_size ( + const struct GNUNET_RECLAIM_AttributeList *al) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_RECLAIM_AttributeListEntry *ale; size_t len = 0; - for (le = attrs->list_head; NULL != le; le = le->next) + for (ale = al->list_head; NULL != ale; ale = ale->next) { - if (NULL != le->claim) - { - len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - len += GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); - } - else if (NULL != le->attest ) - { - len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - len += GNUNET_RECLAIM_ATTESTATION_serialize_get_size (le->attest); - } - else if (NULL != le->reference) - { - len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - len += GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (le->reference); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unserialized Claim List Entry Type for size not known.\n"); - break; - } - len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); + GNUNET_assert (NULL != ale->attribute); + len += GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute); + len += sizeof(struct GNUNET_RECLAIM_AttributeListEntry); } return len; } @@ -512,58 +319,22 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size ( * @return length of serialized data */ size_t -GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, +GNUNET_RECLAIM_attribute_list_serialize ( + const struct GNUNET_RECLAIM_AttributeList *al, char *result) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_RECLAIM_AttributeListEntry *ale; size_t len; size_t total_len; char *write_ptr; write_ptr = result; total_len = 0; - for (le = attrs->list_head; NULL != le; le = le->next) + for (ale = al->list_head; NULL != ale; ale = ale->next) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *list_type; - if (NULL != le->claim) - { - list_type = (struct - GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) write_ptr; - list_type->type = htons (1); - total_len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - write_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - len = GNUNET_RECLAIM_ATTRIBUTE_serialize (le->claim, write_ptr); - total_len += len; - write_ptr += len; - } - else if (NULL != le->attest ) - { - list_type = (struct - GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) write_ptr; - list_type->type = htons (2); - total_len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - write_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - len = GNUNET_RECLAIM_ATTESTATION_serialize (le->attest, write_ptr); - total_len += len; - write_ptr += len; - } - else if (NULL != le->reference) - { - list_type = (struct - GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) write_ptr; - list_type->type = htons (3); - total_len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - write_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - len = GNUNET_RECLAIM_ATTESTATION_REF_serialize (le->reference, write_ptr); - total_len += len; - write_ptr += len; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unserialized Claim List Entry Type not known.\n"); - continue; - } + GNUNET_assert (NULL != ale->attribute); + len = GNUNET_RECLAIM_attribute_serialize (ale->attribute, write_ptr); + total_len += len; + write_ptr += len; } return total_len; } @@ -576,85 +347,30 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( * @param data_size the length of the serialized data * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller */ -struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * -GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size) +struct GNUNET_RECLAIM_AttributeList * +GNUNET_RECLAIM_attribute_list_deserialize (const char *data, size_t data_size) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_RECLAIM_AttributeList *al; + struct GNUNET_RECLAIM_AttributeListEntry *ale; size_t attr_len; const char *read_ptr; - if ((data_size < sizeof(struct Attribute) + sizeof(struct - GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry)) - && (data_size < sizeof(struct - Attestation) - + sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry)) && - (data_size < sizeof(struct Attestation_Reference) + sizeof(struct - GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry)) ) - return NULL; - - attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); + al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); + if (data_size < sizeof(struct Attribute) + sizeof(struct + GNUNET_RECLAIM_AttributeListEntry)) + return al; read_ptr = data; while (((data + data_size) - read_ptr) >= sizeof(struct Attribute)) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *list_type; - list_type = (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) read_ptr; - if (1 == ntohs (list_type->type)) - { - le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - read_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - if (((data + data_size) - read_ptr) < sizeof(struct Attribute)) - break; - le->attest = NULL; - le->reference = NULL; - le->claim = - GNUNET_RECLAIM_ATTRIBUTE_deserialize (read_ptr, - data_size - (read_ptr - data)); - GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); - attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); - read_ptr += attr_len; - } - else if (2 == ntohs (list_type->type)) - { - le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - read_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - if (((data + data_size) - read_ptr) < sizeof(struct Attestation)) - break; - le->claim = NULL; - le->reference = NULL; - le->attest = - GNUNET_RECLAIM_ATTESTATION_deserialize (read_ptr, - data_size - (read_ptr - data)); - GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); - attr_len = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (le->attest); - read_ptr += attr_len; - } - else if (3 == ntohs (list_type->type)) - { - le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - read_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); - if (((data + data_size) - read_ptr) < sizeof(struct - Attestation_Reference)) - break; - le->claim = NULL; - le->attest = NULL; - le->reference = - GNUNET_RECLAIM_ATTESTATION_REF_deserialize (read_ptr, - data_size - (read_ptr - - data)); - GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); - attr_len = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size ( - le->reference); - read_ptr += attr_len; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Serialized Claim List Entry Type not known.\n"); - break; - } + ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); + ale->attribute = + GNUNET_RECLAIM_attribute_deserialize (read_ptr, + data_size - (read_ptr - data)); + GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale); + attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute); + read_ptr += attr_len; } - return attrs; + return al; } @@ -663,57 +379,33 @@ GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size) * @param attrs claim list to copy * @return copied claim list */ -struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * -GNUNET_RECLAIM_ATTRIBUTE_list_dup ( - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) +struct GNUNET_RECLAIM_AttributeList * +GNUNET_RECLAIM_attribute_list_dup ( + const struct GNUNET_RECLAIM_AttributeList *al) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *result_le; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *result; + struct GNUNET_RECLAIM_AttributeListEntry *ale; + struct GNUNET_RECLAIM_AttributeListEntry *result_ale; + struct GNUNET_RECLAIM_AttributeList *result; - result = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); - if (NULL == attrs->list_head) + result = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); + for (ale = al->list_head; NULL != ale; ale = ale->next) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Duplicating empty List\n"); - } - for (le = attrs->list_head; NULL != le; le = le->next) - { - result_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - result_le->claim = NULL; - result_le->attest = NULL; - result_le->reference = NULL; - if (NULL != le->claim) - { - result_le->claim = - GNUNET_RECLAIM_ATTRIBUTE_claim_new (le->claim->name, - le->claim->type, - le->claim->data, - le->claim->data_size); - - result_le->claim->id = le->claim->id; - result_le->claim->flag = le->claim->flag; - } - if ( NULL != le->attest) - { - result_le->attest = GNUNET_RECLAIM_ATTESTATION_claim_new ( - le->attest->name, - le->attest->type, - le->attest->data, - le->attest-> - data_size); - result_le->attest->id = le->attest->id; - } - if (NULL !=le->reference) + result_ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); + GNUNET_assert (NULL != ale->attribute); { - result_le->reference = GNUNET_RECLAIM_ATTESTATION_reference_new ( - le->reference->name, - le->reference->reference_value); - result_le->reference->id = le->reference->id; - result_le->reference->id_attest = le->reference->id_attest; + result_ale->attribute = + GNUNET_RECLAIM_attribute_new (ale->attribute->name, + &ale->attribute->attestation, + ale->attribute->type, + ale->attribute->data, + ale->attribute->data_size); + + result_ale->attribute->id = ale->attribute->id; + result_ale->attribute->flag = ale->attribute->flag; } GNUNET_CONTAINER_DLL_insert (result->list_head, result->list_tail, - result_le); + result_ale); } return result; } @@ -725,45 +417,24 @@ GNUNET_RECLAIM_ATTRIBUTE_list_dup ( * @param attrs list to destroy */ void -GNUNET_RECLAIM_ATTRIBUTE_list_destroy ( - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) +GNUNET_RECLAIM_attribute_list_destroy ( + struct GNUNET_RECLAIM_AttributeList *al) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *tmp_le; + struct GNUNET_RECLAIM_AttributeListEntry *ale; + struct GNUNET_RECLAIM_AttributeListEntry *tmp_ale; - for (le = attrs->list_head; NULL != le; le = le->next) + for (ale = al->list_head; NULL != ale; ale = ale->next) { - if (NULL != le->claim) - GNUNET_free (le->claim); - if (NULL != le->attest) - GNUNET_free (le->attest); - if (NULL != le->reference) - GNUNET_free (le->reference); - tmp_le = le; - le = le->next; - GNUNET_free (tmp_le); + if (NULL != ale->attribute) + GNUNET_free (ale->attribute); + tmp_ale = ale; + ale = ale->next; + GNUNET_free (tmp_ale); } - GNUNET_free (attrs); + GNUNET_free (al); } -/** - * Count attestations in claim list - * - * @param attrs list - */ -int -GNUNET_RECLAIM_ATTRIBUTE_list_count_attest ( - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) -{ - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; - int i = 0; - for (le = attrs->list_head; NULL != le; le = le->next) - { - if (NULL != le->attest) - i++; - } - return i; -} + /** * Get required size for serialization buffer * @@ -771,8 +442,8 @@ GNUNET_RECLAIM_ATTRIBUTE_list_count_attest ( * @return the required buffer size */ size_t -GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size ( - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) +GNUNET_RECLAIM_attribute_serialize_get_size ( + const struct GNUNET_RECLAIM_Attribute *attr) { return sizeof(struct Attribute) + strlen (attr->name) + attr->data_size; } @@ -786,8 +457,8 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size ( * @return length of serialized data */ size_t -GNUNET_RECLAIM_ATTRIBUTE_serialize ( - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, +GNUNET_RECLAIM_attribute_serialize ( + const struct GNUNET_RECLAIM_Attribute *attr, char *result) { size_t data_len_ser; @@ -823,10 +494,10 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize ( * * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller */ -struct GNUNET_RECLAIM_ATTRIBUTE_Claim * -GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size) +struct GNUNET_RECLAIM_Attribute * +GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size) { - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; + struct GNUNET_RECLAIM_Attribute *attr; struct Attribute *attr_ser; size_t data_len; size_t name_len; @@ -844,7 +515,7 @@ GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size) "Buffer too small to deserialize\n"); return NULL; } - attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute) + data_len + name_len + 1); attr->type = ntohs (attr_ser->attribute_type); attr->flag = ntohl (attr_ser->attribute_flag); @@ -863,193 +534,4 @@ GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size) } -/** - * Get required size for serialization buffer - * - * @param attr the attestation to serialize - * @return the required buffer size - */ -size_t -GNUNET_RECLAIM_ATTESTATION_serialize_get_size ( - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr) -{ - return sizeof(struct Attestation) + strlen (attr->name) + attr->data_size; -} - -/** - * Serialize an attestation - * - * @param attr the attestation to serialize - * @param result the serialized attestation - * @return length of serialized data - */ -size_t -GNUNET_RECLAIM_ATTESTATION_serialize ( - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr, - char *result) -{ - size_t data_len_ser; - size_t name_len; - struct Attestation *attr_ser; - char *write_ptr; - - attr_ser = (struct Attestation *) result; - attr_ser->attestation_type = htons (attr->type); - attr_ser->attestation_flag = htonl (attr->flag); - attr_ser->attestation_id = attr->id; - name_len = strlen (attr->name); - attr_ser->name_len = htons (name_len); - write_ptr = (char *) &attr_ser[1]; - GNUNET_memcpy (write_ptr, attr->name, name_len); - write_ptr += name_len; - // TODO plugin-ize - // data_len_ser = plugin->serialize_attribute_value (attr, - // &attr_ser[1]); - data_len_ser = attr->data_size; - GNUNET_memcpy (write_ptr, attr->data, attr->data_size); - attr_ser->data_size = htons (data_len_ser); - - return sizeof(struct Attestation) + strlen (attr->name) + attr->data_size; -} - -/** - * Deserialize an attestation - * - * @param data the serialized attestation - * @param data_size the length of the serialized data - * - * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller - */ -struct GNUNET_RECLAIM_ATTESTATION_Claim * -GNUNET_RECLAIM_ATTESTATION_deserialize (const char *data, size_t data_size) -{ - struct GNUNET_RECLAIM_ATTESTATION_Claim *attr; - struct Attestation *attr_ser; - size_t data_len; - size_t name_len; - char *write_ptr; - - if (data_size < sizeof(struct Attestation)) - return NULL; - - attr_ser = (struct Attestation *) data; - data_len = ntohs (attr_ser->data_size); - name_len = ntohs (attr_ser->name_len); - if (data_size < sizeof(struct Attestation) + data_len + name_len) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Buffer too small to deserialize\n"); - return NULL; - } - attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTESTATION_Claim) - + data_len + name_len + 1); - attr->type = ntohs (attr_ser->attestation_type); - attr->flag = ntohl (attr_ser->attestation_flag); - attr->id = attr_ser->attestation_id; - attr->data_size = data_len; - - write_ptr = (char *) &attr[1]; - GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); - write_ptr[name_len] = '\0'; - attr->name = write_ptr; - - write_ptr += name_len + 1; - GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, attr->data_size); - attr->data = write_ptr; - return attr; -} - -/** - * Get required size for serialization buffer - * - * @param attr the reference to serialize - * @return the required buffer size - */ -size_t -GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size ( - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr) -{ - return sizeof(struct Attestation_Reference) + strlen (attr->name) + strlen ( - attr->reference_value); -} - - -/** - * Serialize a reference - * - * @param attr the reference to serialize - * @param result the serialized reference - * @return length of serialized data - */ -size_t -GNUNET_RECLAIM_ATTESTATION_REF_serialize ( - const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr, - char *result) -{ - size_t name_len; - size_t refval_len; - struct Attestation_Reference *attr_ser; - char *write_ptr; - attr_ser = (struct Attestation_Reference *) result; - attr_ser->reference_id = attr->id; - attr_ser->attestation_id = attr->id_attest; - name_len = strlen (attr->name); - refval_len = strlen (attr->reference_value); - attr_ser->name_len = htons (name_len); - attr_ser->ref_value_len = htons (refval_len); - write_ptr = (char *) &attr_ser[1]; - GNUNET_memcpy (write_ptr, attr->name, name_len); - write_ptr += name_len; - GNUNET_memcpy (write_ptr, attr->reference_value, refval_len); - - return sizeof(struct Attestation_Reference) + strlen (attr->name) + strlen ( - attr->reference_value); -} - - -/** - * Deserialize a reference - * - * @param data the serialized reference - * @param data_size the length of the serialized data - * - * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller - */ -struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * -GNUNET_RECLAIM_ATTESTATION_REF_deserialize (const char *data, size_t data_size) -{ - struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr; - struct Attestation_Reference *attr_ser; - size_t name_len; - size_t refval_len; - char *write_ptr; - - if (data_size < sizeof(struct Attestation_Reference)) - return NULL; - attr_ser = (struct Attestation_Reference *) data; - name_len = ntohs (attr_ser->name_len); - refval_len = ntohs (attr_ser->ref_value_len); - if (data_size < sizeof(struct Attestation_Reference) + refval_len + name_len) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Buffer too small to deserialize\n"); - return NULL; - } - attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE) - + refval_len + name_len + 2); - - attr->id = attr_ser->reference_id; - attr->id_attest = attr_ser->attestation_id; - - write_ptr = (char *) &attr[1]; - GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); - write_ptr[name_len] = '\0'; - attr->name = write_ptr; - - write_ptr += name_len + 1; - GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, refval_len); - write_ptr[refval_len] = '\0'; - attr->reference_value = write_ptr; - return attr; -} /* end of reclaim_attribute.c */ diff --git a/src/reclaim-attribute/reclaim_attribute.h b/src/reclaim-attribute/reclaim_attribute.h index 0746df48e..e54b210b9 100644 --- a/src/reclaim-attribute/reclaim_attribute.h +++ b/src/reclaim-attribute/reclaim_attribute.h @@ -48,6 +48,11 @@ struct Attribute */ struct GNUNET_RECLAIM_Identifier attribute_id; + /** + * Attestation ID + */ + struct GNUNET_RECLAIM_Identifier attestation_id; + /** * Name length */ @@ -94,33 +99,4 @@ struct Attestation // followed by data_size Attestation value data }; -/** - * Serialized attestation reference - */ -struct Attestation_Reference -{ - /** - * Reference ID - */ - struct GNUNET_RECLAIM_Identifier reference_id; - - /** - * The ID of the referenced attestation - */ - struct GNUNET_RECLAIM_Identifier attestation_id; - - /** - * Claim Name length - */ - uint32_t name_len; - - /** - * Length of the referenced value - */ - uint32_t ref_value_len; - - - // followed by the name and referenced value -}; - #endif 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) -- 2.25.1