From 41d086c02574e08a820612faf2cfb6e68049b316 Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Sat, 13 Apr 2019 11:33:41 +0200 Subject: RECLAIM: less unneccessary crypto; syntax and build fixes --- src/Makefile.am | 2 +- src/include/gnunet_gnsrecord_lib.h | 168 +++++------ src/reclaim/gnunet-reclaim.c | 411 ++++++++++----------------- src/reclaim/gnunet-service-reclaim.c | 12 +- src/reclaim/gnunet-service-reclaim_tickets.c | 205 +++---------- src/reclaim/gnunet-service-reclaim_tickets.h | 77 +++-- src/reclaim/plugin_gnsrecord_reclaim.c | 118 ++++---- 7 files changed, 335 insertions(+), 658 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index b16792e15..6eaafdeee 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,7 +17,7 @@ if HAVE_EXPERIMENTAL reclaim if HAVE_ABE EXP_DIR += \ - abe \ + abe endif if HAVE_JSON EXP_DIR += \ diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h index 27228c0bc..8b3a6b720 100644 --- a/src/include/gnunet_gnsrecord_lib.h +++ b/src/include/gnunet_gnsrecord_lib.h @@ -35,9 +35,8 @@ #define GNUNET_GNSRECORD_LIB_H #ifdef __cplusplus -extern "C" -{ -#if 0 /* keep Emacsens' auto-indent happy */ +extern "C" { +#if 0 /* keep Emacsens' auto-indent happy */ } #endif #endif @@ -125,7 +124,7 @@ extern "C" /** * Record type for reclaim records */ -#define GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ 65550 +#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF 65550 /** * Record type for RECLAIM master @@ -145,8 +144,7 @@ extern "C" /** * Flags that can be set for a record. */ -enum GNUNET_GNSRECORD_Flags -{ +enum GNUNET_GNSRECORD_Flags { /** * No special options. @@ -177,17 +175,17 @@ enum GNUNET_GNSRECORD_Flags */ GNUNET_GNSRECORD_RF_SHADOW_RECORD = 16 - /** - * When comparing flags for record equality for removal, - * which flags should must match (in addition to the type, - * name, expiration value and data of the record)? All flags - * that are not listed here will be ignored for this purpose. - * (for example, we don't expect that users will remember to - * pass the '--private' option when removing a record from - * the namestore, hence we don't require this particular option - * to match upon removal). See also - * #GNUNET_GNSRECORD_records_cmp. - */ +/** + * When comparing flags for record equality for removal, + * which flags should must match (in addition to the type, + * name, expiration value and data of the record)? All flags + * that are not listed here will be ignored for this purpose. + * (for example, we don't expect that users will remember to + * pass the '--private' option when removing a record from + * the namestore, hence we don't require this particular option + * to match upon removal). See also + * #GNUNET_GNSRECORD_records_cmp. + */ #define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION) }; @@ -195,8 +193,7 @@ enum GNUNET_GNSRECORD_Flags /** * A GNS record. */ -struct GNUNET_GNSRECORD_Data -{ +struct GNUNET_GNSRECORD_Data { /** * Binary value stored in the DNS record. Note: "data" must never @@ -234,8 +231,7 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Data stored in a PLACE record. */ -struct GNUNET_GNSRECORD_PlaceData -{ +struct GNUNET_GNSRECORD_PlaceData { /** * Public key of the place. */ @@ -258,8 +254,7 @@ struct GNUNET_GNSRECORD_PlaceData /** * Information we have in an encrypted block with record data (i.e. in the DHT). */ -struct GNUNET_GNSRECORD_Block -{ +struct GNUNET_GNSRECORD_Block { /** * Signature of the block. @@ -296,8 +291,7 @@ struct GNUNET_GNSRECORD_Block * records do not require a separate network request, thus making TLSA * records inseparable from the "main" A/AAAA/VPN/etc. records. */ -struct GNUNET_GNSRECORD_BoxRecord -{ +struct GNUNET_GNSRECORD_BoxRecord { /** * Protocol of the boxed record (6 = TCP, 17 = UDP, etc.). @@ -316,7 +310,6 @@ struct GNUNET_GNSRECORD_BoxRecord uint32_t record_type GNUNET_PACKED; /* followed by the 'original' record */ - }; /** @@ -326,8 +319,7 @@ struct GNUNET_GNSRECORD_BoxRecord * the namespace the record belongs to. * It is exclusively found under the label ``+''. */ -struct GNUNET_GNSRECORD_ReverseRecord -{ +struct GNUNET_GNSRECORD_ReverseRecord { /** * The public key of the namespace the is delegating to our namespace */ @@ -351,11 +343,8 @@ GNUNET_NETWORK_STRUCT_END * @param rd_count number of entries in @a rd array * @param rd array of records with data to store */ -typedef void -(*GNUNET_GNSRECORD_RecordCallback) (void *cls, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd); - +typedef void (*GNUNET_GNSRECORD_RecordCallback) ( + void *cls, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); /* ***************** API related to GNSRECORD plugins ************** */ @@ -369,10 +358,8 @@ typedef void * @param data_size number of bytes in @a data * @return NULL on error, otherwise human-readable representation of the value */ -char * -GNUNET_GNSRECORD_value_to_string (uint32_t type, - const void *data, - size_t data_size); +char *GNUNET_GNSRECORD_value_to_string (uint32_t type, const void *data, + size_t data_size); /** @@ -385,11 +372,8 @@ GNUNET_GNSRECORD_value_to_string (uint32_t type, * @param data_size set to number of bytes in @a data * @return #GNUNET_OK on success */ -int -GNUNET_GNSRECORD_string_to_value (uint32_t type, - const char *s, - void **data, - size_t *data_size); +int GNUNET_GNSRECORD_string_to_value (uint32_t type, const char *s, void **data, + size_t *data_size); /** @@ -398,8 +382,7 @@ GNUNET_GNSRECORD_string_to_value (uint32_t type, * @param dns_typename name to convert * @return corresponding number, UINT32_MAX on error */ -uint32_t -GNUNET_GNSRECORD_typename_to_number (const char *dns_typename); +uint32_t GNUNET_GNSRECORD_typename_to_number (const char *dns_typename); /** @@ -408,8 +391,7 @@ GNUNET_GNSRECORD_typename_to_number (const char *dns_typename); * @param type number of a type to convert * @return corresponding typestring, NULL on error */ -const char * -GNUNET_GNSRECORD_number_to_typename (uint32_t type); +const char *GNUNET_GNSRECORD_number_to_typename (uint32_t type); /* convenience APIs for serializing / deserializing GNS records */ @@ -424,7 +406,7 @@ GNUNET_GNSRECORD_number_to_typename (uint32_t type); */ ssize_t GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd); + const struct GNUNET_GNSRECORD_Data *rd); /** @@ -438,9 +420,8 @@ GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, */ ssize_t GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd, - size_t dest_size, - char *dest); + const struct GNUNET_GNSRECORD_Data *rd, + size_t dest_size, char *dest); /** @@ -452,17 +433,14 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, * @param dest where to put the data * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int -GNUNET_GNSRECORD_records_deserialize (size_t len, - const char *src, - unsigned int rd_count, - struct GNUNET_GNSRECORD_Data *dest); +int GNUNET_GNSRECORD_records_deserialize (size_t len, const char *src, + unsigned int rd_count, + struct GNUNET_GNSRECORD_Data *dest); /* ******* general APIs relating to blocks, records and labels ******** */ - /** * Test if a given record is expired. * @@ -470,8 +448,7 @@ GNUNET_GNSRECORD_records_deserialize (size_t len, * @return #GNUNET_YES if the record is expired, * #GNUNET_NO if not */ -int -GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd); +int GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd); /** @@ -479,8 +456,7 @@ GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd); * @param src source string * @return converted result */ -char * -GNUNET_GNSRECORD_string_to_lowercase (const char *src); +char *GNUNET_GNSRECORD_string_to_lowercase (const char *src); /** @@ -489,10 +465,10 @@ GNUNET_GNSRECORD_string_to_lowercase (const char *src); * NOT reentrant! * * @param z public key of a zone - * @return string form; will be overwritten by next call to #GNUNET_GNSRECORD_z2s. + * @return string form; will be overwritten by next call to + * #GNUNET_GNSRECORD_z2s. */ -const char * -GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z); +const char *GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z); /** @@ -518,9 +494,8 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); * @param pkey set to a public key on the eliptic curve * @return #GNUNET_SYSERR if @a zkey has the wrong syntax */ -int -GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, - struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); +int GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, + struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); /** @@ -530,10 +505,9 @@ GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, * @param label label of the record * @param query hash to use for the query */ -void -GNUNET_GNSRECORD_query_from_private_key (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, - const char *label, - struct GNUNET_HashCode *query); +void GNUNET_GNSRECORD_query_from_private_key ( + const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, + struct GNUNET_HashCode *query); /** @@ -543,10 +517,9 @@ GNUNET_GNSRECORD_query_from_private_key (const struct GNUNET_CRYPTO_EcdsaPrivate * @param label label of the record * @param query hash to use for the query */ -void -GNUNET_GNSRECORD_query_from_public_key (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, - const char *label, - struct GNUNET_HashCode *query); +void GNUNET_GNSRECORD_query_from_public_key ( + const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label, + struct GNUNET_HashCode *query); /** @@ -558,12 +531,10 @@ GNUNET_GNSRECORD_query_from_public_key (const struct GNUNET_CRYPTO_EcdsaPublicKe * @param rd record data * @param rd_count number of records in @a rd */ -struct GNUNET_GNSRECORD_Block * -GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, - struct GNUNET_TIME_Absolute expire, - const char *label, - const struct GNUNET_GNSRECORD_Data *rd, - unsigned int rd_count); +struct GNUNET_GNSRECORD_Block *GNUNET_GNSRECORD_block_create ( + const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, + struct GNUNET_TIME_Absolute expire, const char *label, + const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count); /** @@ -577,12 +548,10 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, * @param rd record data * @param rd_count number of records in @a rd */ -struct GNUNET_GNSRECORD_Block * -GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, - struct GNUNET_TIME_Absolute expire, - const char *label, - const struct GNUNET_GNSRECORD_Data *rd, - unsigned int rd_count); +struct GNUNET_GNSRECORD_Block *GNUNET_GNSRECORD_block_create2 ( + const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, + struct GNUNET_TIME_Absolute expire, const char *label, + const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count); /** @@ -592,8 +561,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, * @param block block to verify * @return #GNUNET_OK if the signature is valid */ -int -GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); +int GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); /** @@ -607,12 +575,10 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was * not well-formed */ -int -GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, - const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, - const char *label, - GNUNET_GNSRECORD_RecordCallback proc, - void *proc_cls); +int GNUNET_GNSRECORD_block_decrypt ( + const struct GNUNET_GNSRECORD_Block *block, + const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, const char *label, + GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); /** @@ -622,9 +588,8 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, * @param b another record * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not. */ -int -GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, - const struct GNUNET_GNSRECORD_Data *b); +int GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, + const struct GNUNET_GNSRECORD_Data *b); /** @@ -636,12 +601,11 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, * @param rd array of records * @return absolute expiration time */ -struct GNUNET_TIME_Absolute -GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd); +struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time ( + unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); -#if 0 /* keep Emacsens' auto-indent happy */ +#if 0 /* keep Emacsens' auto-indent happy */ { #endif #ifdef __cplusplus @@ -650,4 +614,4 @@ GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, #endif -/** @} */ /* end of group */ +/** @} */ /* end of group */ diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index c36955a04..790813eec 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.c @@ -23,14 +23,15 @@ * @brief Identity Provider utility * */ - #include "platform.h" +#include + #include "gnunet_util_lib.h" + +#include "gnunet_identity_service.h" #include "gnunet_namestore_service.h" #include "gnunet_reclaim_service.h" -#include "gnunet_identity_service.h" #include "gnunet_signatures.h" - /** * return value */ @@ -44,37 +45,37 @@ static int list; /** * Relying party */ -static char* rp; +static char *rp; /** * The attribute */ -static char* attr_name; +static char *attr_name; /** * Attribute value */ -static char* attr_value; +static char *attr_value; /** * Attributes to issue */ -static char* issue_attrs; +static char *issue_attrs; /** * Ticket to consume */ -static char* consume_ticket; +static char *consume_ticket; /** * Attribute type */ -static char* type_str; +static char *type_str; /** * Ticket to revoke */ -static char* revoke_ticket; +static char *revoke_ticket; /** * Ticket listing @@ -84,7 +85,7 @@ static int list_tickets; /** * Ego name */ -static char* ego_name; +static char *ego_name; /** * Identity handle @@ -156,8 +157,7 @@ static struct GNUNET_SCHEDULER_Task *cleanup_task; */ struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; -static void -do_cleanup(void *cls) +static void do_cleanup (void *cls) { cleanup_task = NULL; if (NULL != timeout) @@ -178,196 +178,146 @@ do_cleanup(void *cls) GNUNET_free (attr_list); } -static void -ticket_issue_cb (void* cls, - const struct GNUNET_RECLAIM_Ticket *ticket) +static void ticket_issue_cb (void *cls, + const struct GNUNET_RECLAIM_Ticket *ticket) { - char* ticket_str; + char *ticket_str; reclaim_op = NULL; if (NULL != ticket) { - ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket, - sizeof (struct GNUNET_RECLAIM_Ticket)); - printf("%s\n", - ticket_str); + ticket_str = GNUNET_STRINGS_data_to_string_alloc ( + ticket, sizeof (struct GNUNET_RECLAIM_Ticket)); + printf ("%s\n", ticket_str); GNUNET_free (ticket_str); } cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } -static void -store_attr_cont (void *cls, - int32_t success, - const char*emsg) +static void store_attr_cont (void *cls, int32_t success, const char *emsg) { reclaim_op = NULL; if (GNUNET_SYSERR == success) { - fprintf (stderr, - "%s\n", emsg); + fprintf (stderr, "%s\n", emsg); } cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } -static void -process_attrs (void *cls, - const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) +static void process_attrs (void *cls, + const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, + const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) { char *value_str; - const char* attr_type; + const char *attr_type; - if (NULL == identity) - { + if (NULL == identity) { reclaim_op = NULL; cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); return; } - if (NULL == attr) - { + if (NULL == attr) { ret = 1; return; } - value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, - attr->data, + 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); - fprintf (stdout, - "%s: %s [%s,v%u,id=%lu]\n", - attr->name, value_str, attr_type, attr->version, attr->id); + fprintf (stdout, "%s: %s [%s,v%u,id=%" PRIu64 "]\n", attr->name, value_str, + attr_type, attr->version, attr->id); } -static void -ticket_iter_err (void *cls) +static void ticket_iter_err (void *cls) { ticket_iterator = NULL; - fprintf (stderr, - "Failed to iterate over tickets\n"); + fprintf (stderr, "Failed to iterate over tickets\n"); cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } -static void -ticket_iter_fin (void *cls) +static void ticket_iter_fin (void *cls) { ticket_iterator = NULL; cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } -static void -ticket_iter (void *cls, - const struct GNUNET_RECLAIM_Ticket *ticket) +static void ticket_iter (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) { - fprintf (stdout, - "Found ticket\n"); + fprintf (stdout, "Found ticket\n"); GNUNET_RECLAIM_ticket_iteration_next (ticket_iterator); } -static void -iter_error (void *cls) +static void iter_error (void *cls) { attr_iterator = NULL; - fprintf (stderr, - "Failed to iterate over attributes\n"); + fprintf (stderr, "Failed to iterate over attributes\n"); cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } -static void -timeout_task (void *cls) +static void timeout_task (void *cls) { timeout = NULL; ret = 1; - fprintf (stderr, - "Timeout\n"); + fprintf (stderr, "Timeout\n"); if (NULL == cleanup_task) cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } -static void -process_rvk (void *cls, int success, const char* msg) +static void process_rvk (void *cls, int success, const char *msg) { reclaim_op = NULL; - if (GNUNET_OK != success) - { - fprintf (stderr, - "Revocation failed.\n"); + if (GNUNET_OK != success) { + fprintf (stderr, "Revocation failed.\n"); ret = 1; } cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } -static void -iter_finished (void *cls) +static void iter_finished (void *cls) { char *data; size_t data_size; int type; attr_iterator = NULL; - if (list) - { + if (list) { cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); return; } - if (issue_attrs) - { - reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle, - pkey, - &rp_key, - attr_list, - &ticket_issue_cb, - NULL); + if (issue_attrs) { + reclaim_op = GNUNET_RECLAIM_ticket_issue ( + reclaim_handle, pkey, &rp_key, attr_list, &ticket_issue_cb, NULL); return; } - if (consume_ticket) - { - reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle, - pkey, - &ticket, - &process_attrs, - NULL); - timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), - &timeout_task, - NULL); + if (consume_ticket) { + reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle, pkey, &ticket, + &process_attrs, NULL); + timeout = GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), + &timeout_task, NULL); return; } - if (revoke_ticket) - { - reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle, - pkey, - &ticket, - &process_rvk, - NULL); + if (revoke_ticket) { + reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle, pkey, &ticket, + &process_rvk, NULL); return; } - if (attr_name) - { + if (attr_name) { if (NULL == type_str) type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; else type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); - GNUNET_assert (GNUNET_SYSERR != GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, - attr_value, - (void**)&data, - &data_size)); - if (NULL != claim) - { + GNUNET_assert (GNUNET_SYSERR != + GNUNET_RECLAIM_ATTRIBUTE_string_to_value ( + type, attr_value, (void **)&data, &data_size)); + if (NULL != claim) { claim->type = type; claim->data = data; claim->data_size = data_size; + } else { + claim = + GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size); } - else - { - claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, - type, - data, - data_size); - } - reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle, - pkey, - claim, - &exp_interval, - &store_attr_cont, - NULL); + reclaim_op = GNUNET_RECLAIM_attribute_store ( + reclaim_handle, pkey, claim, &exp_interval, &store_attr_cont, NULL); GNUNET_free (data); GNUNET_free (claim); return; @@ -375,28 +325,21 @@ iter_finished (void *cls) cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } -static void -iter_cb (void *cls, - const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) +static void iter_cb (void *cls, + const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, + const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) { struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; char *attrs_tmp; char *attr_str; const char *attr_type; - if ((NULL != attr_name) && (NULL != claim)) - { - if (0 == strcasecmp (attr_name, attr->name)) - { - claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, - attr->type, - attr->data, - attr->data_size); + if ((NULL != attr_name) && (NULL != claim)) { + if (0 == strcasecmp (attr_name, attr->name)) { + claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, attr->type, + attr->data, attr->data_size); } - } - else if (issue_attrs) - { + } else if (issue_attrs) { attrs_tmp = GNUNET_strdup (issue_attrs); attr_str = strtok (attrs_tmp, ","); while (NULL != attr_str) { @@ -405,92 +348,62 @@ iter_cb (void *cls, 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 = GNUNET_RECLAIM_ATTRIBUTE_claim_new ( + attr->name, attr->type, attr->data, attr->data_size); le->claim->version = attr->version; le->claim->id = attr->id; - GNUNET_CONTAINER_DLL_insert (attr_list->list_head, - attr_list->list_tail, + GNUNET_CONTAINER_DLL_insert (attr_list->list_head, attr_list->list_tail, le); break; } GNUNET_free (attrs_tmp); - } - else if (list) - { - attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, - attr->data, + } else if (list) { + 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); - fprintf (stdout, - "%s: %s [%s,v%u,id=%lu]\n", - attr->name, attr_str, attr_type, attr->version, attr->id); + fprintf (stdout, "%s: %s [%s,v%u,id=%" PRIu64 "]\n", attr->name, attr_str, + attr_type, attr->version, attr->id); } GNUNET_RECLAIM_get_attributes_next (attr_iterator); } -static void -start_process () +static void start_process () { - if (NULL == pkey) - { - fprintf (stderr, - "Ego %s not found\n", ego_name); + if (NULL == pkey) { + fprintf (stderr, "Ego %s not found\n", ego_name); cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); return; } - if (list_tickets) - { - ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle, - pkey, - &ticket_iter_err, - NULL, - &ticket_iter, - NULL, - &ticket_iter_fin, - NULL); + if (list_tickets) { + ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start ( + reclaim_handle, pkey, &ticket_iter_err, NULL, &ticket_iter, NULL, + &ticket_iter_fin, NULL); return; } if (NULL != rp) - GNUNET_CRYPTO_ecdsa_public_key_from_string (rp, - strlen (rp), - &rp_key); + GNUNET_CRYPTO_ecdsa_public_key_from_string (rp, strlen (rp), &rp_key); if (NULL != consume_ticket) - GNUNET_STRINGS_string_to_data (consume_ticket, - strlen (consume_ticket), + GNUNET_STRINGS_string_to_data (consume_ticket, strlen (consume_ticket), &ticket, sizeof (struct GNUNET_RECLAIM_Ticket)); if (NULL != revoke_ticket) - GNUNET_STRINGS_string_to_data (revoke_ticket, - strlen (revoke_ticket), + GNUNET_STRINGS_string_to_data (revoke_ticket, strlen (revoke_ticket), &ticket, sizeof (struct GNUNET_RECLAIM_Ticket)); attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); claim = NULL; - attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle, - pkey, - &iter_error, - NULL, - &iter_cb, - NULL, - &iter_finished, - NULL); - - + attr_iterator = GNUNET_RECLAIM_get_attributes_start ( + reclaim_handle, pkey, &iter_error, NULL, &iter_cb, NULL, &iter_finished, + NULL); } static int init = GNUNET_YES; -static void -ego_cb (void *cls, - struct GNUNET_IDENTITY_Ego *ego, - void **ctx, - const char *name) +static void ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, + const char *name) { if (NULL == name) { if (GNUNET_YES == init) { @@ -505,113 +418,75 @@ ego_cb (void *cls, } -static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +static void run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { ret = 0; - if (NULL == ego_name) - { + if (NULL == ego_name) { ret = 1; - fprintf (stderr, - _("Ego is required\n")); + fprintf (stderr, _ ("Ego is required\n")); return; } - if ( (NULL == attr_value) && (NULL != attr_name) ) - { + if ((NULL == attr_value) && (NULL != attr_name)) { ret = 1; - fprintf (stderr, - _("Attribute value missing!\n")); + fprintf (stderr, _ ("Attribute value missing!\n")); return; } - if ( (NULL == rp) && (NULL != issue_attrs) ) - { + if ((NULL == rp) && (NULL != issue_attrs)) { ret = 1; - fprintf (stderr, - _("Requesting party key is required!\n")); + fprintf (stderr, _ ("Requesting party key is required!\n")); return; } reclaim_handle = GNUNET_RECLAIM_connect (c); - //Get Ego - identity_handle = GNUNET_IDENTITY_connect (c, - &ego_cb, - NULL); - - + // Get Ego + identity_handle = GNUNET_IDENTITY_connect (c, &ego_cb, NULL); } -int -main(int argc, char *const argv[]) +int main (int argc, char *const argv[]) { exp_interval = GNUNET_TIME_UNIT_HOURS; struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_string ('a', - "add", - "NAME", - gettext_noop ("Add an attribute NAME"), - &attr_name), - - GNUNET_GETOPT_option_string ('V', - "value", - "VALUE", - gettext_noop ("The attribute VALUE"), - &attr_value), - GNUNET_GETOPT_option_string ('e', - "ego", - "EGO", - gettext_noop ("The EGO to use"), - &ego_name), - GNUNET_GETOPT_option_string ('r', - "rp", - "RP", - gettext_noop ("Specify the relying party for issue"), - &rp), - GNUNET_GETOPT_option_flag ('D', - "dump", - gettext_noop ("List attributes for EGO"), - &list), - GNUNET_GETOPT_option_string ('i', - "issue", - "A1,A2,...", - gettext_noop ("Issue a ticket for a set of attributes separated by comma"), - &issue_attrs), - GNUNET_GETOPT_option_string ('C', - "consume", - "TICKET", - gettext_noop ("Consume a ticket"), - &consume_ticket), - GNUNET_GETOPT_option_string ('R', - "revoke", - "TICKET", - gettext_noop ("Revoke a ticket"), - &revoke_ticket), - GNUNET_GETOPT_option_string ('t', - "type", - "TYPE", - gettext_noop ("Type of attribute"), - &type_str), - GNUNET_GETOPT_option_flag ('T', - "tickets", - gettext_noop ("List tickets of ego"), - &list_tickets), - GNUNET_GETOPT_option_relative_time ('E', - "expiration", - "INTERVAL", - gettext_noop ("Expiration interval of the attribute"), - &exp_interval), - - GNUNET_GETOPT_OPTION_END - }; - if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct", - "ct", options, - &run, NULL)) + GNUNET_GETOPT_option_string ('a', "add", "NAME", + gettext_noop ("Add an attribute NAME"), + &attr_name), + + GNUNET_GETOPT_option_string ('V', "value", "VALUE", + gettext_noop ("The attribute VALUE"), + &attr_value), + GNUNET_GETOPT_option_string ('e', "ego", "EGO", + gettext_noop ("The EGO to use"), &ego_name), + GNUNET_GETOPT_option_string ( + 'r', "rp", "RP", gettext_noop ("Specify the relying party for issue"), + &rp), + GNUNET_GETOPT_option_flag ( + 'D', "dump", gettext_noop ("List attributes for EGO"), &list), + GNUNET_GETOPT_option_string ( + 'i', "issue", "A1,A2,...", + gettext_noop ( + "Issue a ticket for a set of attributes separated by comma"), + &issue_attrs), + GNUNET_GETOPT_option_string ('C', "consume", "TICKET", + gettext_noop ("Consume a ticket"), + &consume_ticket), + GNUNET_GETOPT_option_string ('R', "revoke", "TICKET", + gettext_noop ("Revoke a ticket"), + &revoke_ticket), + GNUNET_GETOPT_option_string ( + 't', "type", "TYPE", gettext_noop ("Type of attribute"), &type_str), + GNUNET_GETOPT_option_flag ( + 'T', "tickets", gettext_noop ("List tickets of ego"), &list_tickets), + GNUNET_GETOPT_option_relative_time ( + 'E', "expiration", "INTERVAL", + gettext_noop ("Expiration interval of the attribute"), &exp_interval), + + GNUNET_GETOPT_OPTION_END}; + if (GNUNET_OK != + GNUNET_PROGRAM_run (argc, argv, "ct", "ct", options, &run, NULL)) return 1; else return ret; diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index 51d8554e2..fa3236af4 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c @@ -23,6 +23,10 @@ * @brief reclaim Service * */ +#include "platform.h" + +#include "gnunet_util_lib.h" + #include "gnunet-service-reclaim_tickets.h" #include "gnunet_constants.h" #include "gnunet_gnsrecord_lib.h" @@ -32,8 +36,6 @@ #include "gnunet_reclaim_attribute_lib.h" #include "gnunet_reclaim_plugin.h" #include "gnunet_signatures.h" -#include "gnunet_util_lib.h" -#include "platform.h" #include "reclaim.h" /** @@ -804,7 +806,7 @@ ticket_reissue_proc (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket, code_record[0].data = authz_record_data; code_record[0].data_size = authz_record_len; code_record[0].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; - code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ; + code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF; code_record[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); @@ -924,8 +926,8 @@ static void reenc_next_attribute (void *cls) /* First check if attribute still exists */ label = GNUNET_STRINGS_data_to_string_alloc (&rh->attrs->list_head->claim->id, sizeof (uint64_t)); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ID: %lu\n", - rh->attrs->list_head->claim->id); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Name: %s\n", + rh->attrs->list_head->claim->name); rh->ns_qe = GNUNET_NAMESTORE_records_lookup ( nsh, &rh->identity, label, &check_attr_error, rh, &check_attr_cb, rh); GNUNET_free (label); diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c index 54e5659a4..16e831e22 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.c +++ b/src/reclaim/gnunet-service-reclaim_tickets.c @@ -236,28 +236,6 @@ static struct GNUNET_GNS_Handle *gns; /* Handle to the statistics service */ static struct GNUNET_STATISTICS_Handle *stats; -static int create_sym_key_from_ecdh ( - const struct GNUNET_HashCode *new_key_hash, - struct GNUNET_CRYPTO_SymmetricSessionKey *skey, - struct GNUNET_CRYPTO_SymmetricInitializationVector *iv) -{ - struct GNUNET_CRYPTO_HashAsciiEncoded new_key_hash_str; - - GNUNET_CRYPTO_hash_to_enc (new_key_hash, &new_key_hash_str); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating symmetric rsa key from %s\n", - (char *)&new_key_hash_str); - static const char ctx_key[] = "gnuid-aes-ctx-key"; - GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), - new_key_hash, sizeof (struct GNUNET_HashCode), ctx_key, - strlen (ctx_key), NULL, 0); - static const char ctx_iv[] = "gnuid-aes-ctx-iv"; - GNUNET_CRYPTO_kdf ( - iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector), - new_key_hash, sizeof (struct GNUNET_HashCode), ctx_iv, strlen (ctx_iv), - NULL, 0); - return GNUNET_OK; -} - /** * Cleanup ticket consume handle @@ -351,67 +329,32 @@ static void lookup_authz_cb (void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd) { struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; - struct GNUNET_HashCode new_key_hash; - struct GNUNET_CRYPTO_SymmetricSessionKey enc_key; - struct GNUNET_CRYPTO_SymmetricInitializationVector enc_iv; - struct GNUNET_CRYPTO_EcdhePublicKey *ecdh_key; struct ParallelLookup *parallel_lookup; - size_t size; - char *buf; - char *attr_lbl; - char *lbls; + char *lbl; cth->lookup_request = NULL; - if (1 != rd_count) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Number of keys %d != 1.", rd_count); - cth->cb (cth->cb_cls, NULL, NULL, GNUNET_SYSERR, "Number of keys %d != 1."); - cleanup_cth (cth); - return; - } - // Decrypt - ecdh_key = (struct GNUNET_CRYPTO_EcdhePublicKey *)rd->data; - - buf = GNUNET_malloc (rd->data_size - - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); - - // Calculate symmetric key from ecdh parameters - GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdsa_ecdh ( - &cth->identity, ecdh_key, &new_key_hash)); - create_sym_key_from_ecdh (&new_key_hash, &enc_key, &enc_iv); - size = GNUNET_CRYPTO_symmetric_decrypt ( - rd->data + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), - rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), &enc_key, - &enc_iv, buf); - - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Decrypted bytes: %zd Expected bytes: %zd\n", size, - rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); GNUNET_STATISTICS_update ( stats, "reclaim_authz_lookup_time_total", GNUNET_TIME_absolute_get_duration (cth->lookup_start_time).rel_value_us, GNUNET_YES); GNUNET_STATISTICS_update (stats, "reclaim_authz_lookups_count", 1, GNUNET_YES); - lbls = GNUNET_strdup (buf); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Attributes found %s\n", lbls); - for (attr_lbl = strtok (lbls, ","); NULL != attr_lbl; - attr_lbl = strtok (NULL, ",")) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Looking up %s\n", attr_lbl); + for (int i = 0; i < rd_count; i++) { + lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Attribute ref found %s\n", lbl); parallel_lookup = GNUNET_new (struct ParallelLookup); parallel_lookup->handle = cth; - parallel_lookup->label = GNUNET_strdup (attr_lbl); + parallel_lookup->label = lbl; parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get (); parallel_lookup->lookup_request = GNUNET_GNS_lookup ( - gns, attr_lbl, &cth->ticket.identity, - GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, GNUNET_GNS_LO_DEFAULT, - &process_parallel_lookup_result, parallel_lookup); + gns, lbl, &cth->ticket.identity, GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, + GNUNET_GNS_LO_DEFAULT, &process_parallel_lookup_result, + parallel_lookup); GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, cth->parallel_lookups_tail, parallel_lookup); } - GNUNET_free (lbls); - GNUNET_free (buf); cth->kill_task = GNUNET_SCHEDULER_add_delayed ( GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3), &abort_parallel_lookups, cth); @@ -439,7 +382,7 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, label); cth->lookup_start_time = GNUNET_TIME_absolute_get (); cth->lookup_request = GNUNET_GNS_lookup ( - gns, label, &cth->ticket.identity, GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ, + gns, label, &cth->ticket.identity, GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF, GNUNET_GNS_LO_DEFAULT, &lookup_authz_cb, cth); GNUNET_free (label); return cth; @@ -500,19 +443,11 @@ static void update_ticket_refs (void *cls) struct TicketIssueHandle *handle = cls; struct GNUNET_GNSRECORD_Data refs_rd[handle->ticket_ref_num]; struct TicketReference *tr; - char *buf; - size_t buf_size; tr = handle->ticket_refs_head; for (int i = 0; i < handle->ticket_ref_num; i++) { - buf_size = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (tr->attrs); - buf_size += sizeof (struct GNUNET_RECLAIM_Ticket); - buf = GNUNET_malloc (buf_size); - memcpy (buf, &tr->ticket, sizeof (struct GNUNET_RECLAIM_Ticket)); - GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( - tr->attrs, buf + sizeof (struct GNUNET_RECLAIM_Ticket)); - refs_rd[i].data = buf; - refs_rd[i].data_size = buf_size; + refs_rd[i].data = &tr->ticket; + refs_rd[i].data_size = sizeof (struct GNUNET_RECLAIM_Ticket); refs_rd[i].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; refs_rd[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF; refs_rd[i].flags = @@ -523,8 +458,6 @@ static void update_ticket_refs (void *cls) handle->ns_qe = GNUNET_NAMESTORE_records_store ( nsh, &handle->identity, GNUNET_GNS_EMPTY_LABEL_AT, handle->ticket_ref_num, refs_rd, &store_ticket_refs_cont, handle); - for (int i = 0; i < handle->ticket_ref_num; i++) - GNUNET_free ((char *)refs_rd[i].data); } @@ -535,8 +468,7 @@ static void ticket_lookup_cb (void *cls, { struct TicketIssueHandle *handle = cls; struct TicketReference *tr; - const char *attr_data; - size_t attr_data_len; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received tickets from local namestore.\n"); handle->ns_qe = NULL; @@ -551,10 +483,6 @@ static void ticket_lookup_cb (void *cls, GNUNET_free (tr); continue; } - attr_data = rd[i].data + sizeof (struct GNUNET_RECLAIM_Ticket); - attr_data_len = rd[i].data_size - sizeof (struct GNUNET_RECLAIM_Ticket); - tr->attrs = - GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attr_data, attr_data_len); GNUNET_CONTAINER_DLL_insert (handle->ticket_refs_head, handle->ticket_refs_tail, tr); handle->ticket_ref_num++; @@ -568,6 +496,10 @@ static void ticket_lookup_cb (void *cls, GNUNET_SCHEDULER_add_now (&update_ticket_refs, handle); } + +/** + * TODO maybe we should cleanup the ATTRREFS here? + */ static void ticket_lookup_error_cb (void *cls) { struct TicketIssueHandle *handle = cls; @@ -595,93 +527,36 @@ static void store_ticket_issue_cont (void *cls, int32_t success, } -static int -serialize_authz_record (const struct GNUNET_RECLAIM_Ticket *ticket, - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, - struct GNUNET_CRYPTO_EcdhePrivateKey **ecdh_privkey, - char **result) +static void issue_ticket (struct TicketIssueHandle *ih) { - struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey; struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; - struct GNUNET_CRYPTO_SymmetricSessionKey skey; - struct GNUNET_CRYPTO_SymmetricInitializationVector iv; - struct GNUNET_HashCode new_key_hash; - ssize_t enc_size; - char *enc_keyinfo; - char *buf; - char *write_ptr; - char attrs_str_len; + struct GNUNET_GNSRECORD_Data *attrs_record; char *label; - - GNUNET_assert (NULL != attrs->list_head); - attrs_str_len = 0; - for (le = attrs->list_head; NULL != le; le = le->next) { - attrs_str_len += 15 + 1; // TODO propery calculate - } - buf = GNUNET_malloc (attrs_str_len); - write_ptr = buf; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing attributes\n"); - for (le = attrs->list_head; NULL != le; le = le->next) { - label = - GNUNET_STRINGS_data_to_string_alloc (&le->claim->id, sizeof (uint64_t)); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding attribute to record: %s\n", - label); - - GNUNET_memcpy (write_ptr, label, strlen (label)); - write_ptr[strlen (label)] = ','; - write_ptr += strlen (label) + 1; - GNUNET_free (label); + size_t list_len = 0; + int i; + + for (le = ih->attrs->list_head; NULL != le; le = le->next) + 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) { + attrs_record[i].data = &le->claim->id; + attrs_record[i].data_size = sizeof (le->claim->id); + attrs_record[i].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; + attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF; + attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; } - write_ptr--; - write_ptr[0] = '\0'; // replace last , with a 0-terminator - // ECDH keypair E = eG - *ecdh_privkey = GNUNET_CRYPTO_ecdhe_key_create (); - GNUNET_CRYPTO_ecdhe_key_get_public (*ecdh_privkey, &ecdh_pubkey); - enc_keyinfo = GNUNET_malloc (attrs_str_len); - // Derived key K = H(eB) - GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdh_ecdsa (*ecdh_privkey, - &ticket->audience, - &new_key_hash)); - create_sym_key_from_ecdh (&new_key_hash, &skey, &iv); - enc_size = GNUNET_CRYPTO_symmetric_encrypt (buf, attrs_str_len, &skey, &iv, - enc_keyinfo); - *result = - GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) + enc_size); - GNUNET_memcpy (*result, &ecdh_pubkey, - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); - GNUNET_memcpy (*result + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), - enc_keyinfo, enc_size); - GNUNET_free (enc_keyinfo); - GNUNET_free (buf); - return sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) + enc_size; -} - - -static void issue_ticket (struct TicketIssueHandle *ih) -{ - struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; - struct GNUNET_GNSRECORD_Data code_record[1]; - char *authz_record_data; - size_t authz_record_len; - char *label; - - // TODO rename function - authz_record_len = serialize_authz_record ( - &ih->ticket, ih->attrs, &ecdhe_privkey, &authz_record_data); - code_record[0].data = authz_record_data; - code_record[0].data_size = authz_record_len; - code_record[0].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; - code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ; - code_record[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; label = GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd, sizeof (uint64_t)); // Publish record - ih->ns_qe = GNUNET_NAMESTORE_records_store ( - nsh, &ih->identity, label, 1, code_record, &store_ticket_issue_cont, ih); - GNUNET_free (ecdhe_privkey); + ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh, &ih->identity, label, + list_len, attrs_record, + &store_ticket_issue_cont, ih); + GNUNET_free (attrs_record); GNUNET_free (label); - GNUNET_free (authz_record_data); } @@ -759,8 +634,6 @@ collect_tickets_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, { struct RECLAIM_TICKETS_Iterator *iter = cls; struct TicketReference *tr; - size_t attr_data_len; - const char *attr_data; iter->ns_qe = NULL; for (int i = 0; i < rd_count; i++) { @@ -774,10 +647,6 @@ collect_tickets_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, GNUNET_free (tr); continue; } - attr_data = rd[i].data + sizeof (struct GNUNET_RECLAIM_Ticket); - attr_data_len = rd[i].data_size - sizeof (struct GNUNET_RECLAIM_Ticket); - tr->attrs = - GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attr_data, attr_data_len); GNUNET_CONTAINER_DLL_insert (iter->tickets_head, iter->tickets_tail, tr); } run_ticket_iteration_round (iter); diff --git a/src/reclaim/gnunet-service-reclaim_tickets.h b/src/reclaim/gnunet-service-reclaim_tickets.h index 43bb902fd..ab0947865 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.h +++ b/src/reclaim/gnunet-service-reclaim_tickets.h @@ -29,16 +29,18 @@ #define GNUNET_SERVICE_RECLAIM_TICKETS_H #include "platform.h" + #include "gnunet_util_lib.h" + #include "gnunet_constants.h" -#include "gnunet_protocols.h" -#include "gnunet_gnsrecord_lib.h" #include "gnunet_gns_service.h" +#include "gnunet_gnsrecord_lib.h" #include "gnunet_namestore_service.h" -#include "gnunet_statistics_service.h" -#include "gnunet_reclaim_plugin.h" +#include "gnunet_protocols.h" #include "gnunet_reclaim_attribute_lib.h" +#include "gnunet_reclaim_plugin.h" #include "gnunet_signatures.h" +#include "gnunet_statistics_service.h" #include "reclaim.h" struct RECLAIM_TICKETS_Iterator; @@ -50,9 +52,8 @@ struct RECLAIM_TICKETS_ConsumeHandle; * @param cls closure * @param ticket the ticket */ -typedef void -(*RECLAIM_TICKETS_TicketIter) (void *cls, - struct GNUNET_RECLAIM_Ticket *ticket); +typedef void (*RECLAIM_TICKETS_TicketIter) ( + void *cls, struct GNUNET_RECLAIM_Ticket *ticket); /** @@ -60,57 +61,45 @@ typedef void * * @param cls closure * @param ticket the ticket - * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) - * #GNUNET_OK on success + * @param success #GNUNET_SYSERR on failure (including timeout/queue + * drop/failure to validate) #GNUNET_OK on success * @param emsg NULL on success, otherwise an error message */ -typedef void -(*RECLAIM_TICKETS_TicketResult) (void *cls, - struct GNUNET_RECLAIM_Ticket *ticket, - uint32_t success, - const char *emsg); +typedef void (*RECLAIM_TICKETS_TicketResult) ( + void *cls, struct GNUNET_RECLAIM_Ticket *ticket, uint32_t success, + const char *emsg); -typedef void -(*RECLAIM_TICKETS_ConsumeCallback) (void *cls, - const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *l, - uint32_t success, - const char *emsg); +typedef void (*RECLAIM_TICKETS_ConsumeCallback) ( + void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, + const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *l, uint32_t success, + const char *emsg); -struct RECLAIM_TICKETS_ConsumeHandle* +struct RECLAIM_TICKETS_ConsumeHandle * RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, - const struct GNUNET_RECLAIM_Ticket *ticket, - RECLAIM_TICKETS_ConsumeCallback cb, - void* cb_cls); + const struct GNUNET_RECLAIM_Ticket *ticket, + RECLAIM_TICKETS_ConsumeCallback cb, void *cb_cls); -void -RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth); +void 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_CRYPTO_EcdsaPublicKey *audience, - RECLAIM_TICKETS_TicketResult cb, - void* cb_cls); +void RECLAIM_TICKETS_issue ( + const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, + const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, + const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, + RECLAIM_TICKETS_TicketResult cb, void *cb_cls); -void -RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter); +void RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter); -void -RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter); +void RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter); -struct RECLAIM_TICKETS_Iterator* -RECLAIM_TICKETS_iteration_start (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, - RECLAIM_TICKETS_TicketIter cb, - void* cb_cls); +struct RECLAIM_TICKETS_Iterator *RECLAIM_TICKETS_iteration_start ( + const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, + RECLAIM_TICKETS_TicketIter cb, void *cb_cls); -int -RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c); +int RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c); -void -RECLAIM_TICKETS_deinit (void); +void RECLAIM_TICKETS_deinit (void); #endif diff --git a/src/reclaim/plugin_gnsrecord_reclaim.c b/src/reclaim/plugin_gnsrecord_reclaim.c index 2f075d8b9..612fec3bd 100644 --- a/src/reclaim/plugin_gnsrecord_reclaim.c +++ b/src/reclaim/plugin_gnsrecord_reclaim.c @@ -24,11 +24,12 @@ * @author Martin Schanzenbach */ #include "platform.h" + #include "gnunet_util_lib.h" + #include "gnunet_gnsrecord_lib.h" #include "gnunet_gnsrecord_plugin.h" - /** * Convert the 'value' of a record to a string. * @@ -38,25 +39,21 @@ * @param data_size number of bytes in @a data * @return NULL on error, otherwise human-readable representation of the value */ -static char * -value_to_string (void *cls, - uint32_t type, - const void *data, - size_t data_size) +static char *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_AUTHZ: - case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF: - case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: - return GNUNET_STRINGS_data_to_string_alloc (data, data_size); - default: - return NULL; + 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_TICKETREF: + case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: + return GNUNET_STRINGS_data_to_string_alloc (data, data_size); + default: + return NULL; } } @@ -72,36 +69,25 @@ value_to_string (void *cls, * @param data_size set to number of bytes in @a data * @return #GNUNET_OK on success */ -static int -string_to_value (void *cls, - uint32_t type, - const char *s, - void **data, - size_t *data_size) +static int 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_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_AUTHZ: - case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: - case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF: - return GNUNET_STRINGS_string_to_data (s, - strlen (s), - *data, - *data_size); - default: - 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_MASTER: + case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF: + return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); + default: + return GNUNET_SYSERR; } } @@ -114,14 +100,13 @@ static struct { const char *name; uint32_t number; } name_map[] = { - { "RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR }, - { "RECLAIM_AUTHZ", GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ }, - { "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_TICKETREF", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF }, - { NULL, UINT32_MAX } -}; + {"RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR}, + {"RECLAIM_ATTR_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_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_TICKETREF", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF}, + {NULL, UINT32_MAX}}; /** @@ -131,15 +116,13 @@ static struct { * @param dns_typename name to convert * @return corresponding number, UINT32_MAX on error */ -static uint32_t -typename_to_number (void *cls, - const char *dns_typename) +static uint32_t typename_to_number (void *cls, const char *dns_typename) { unsigned int i; - i=0; - while ( (NULL != name_map[i].name) && - (0 != strcasecmp (dns_typename, name_map[i].name)) ) + i = 0; + while ((NULL != name_map[i].name) && + (0 != strcasecmp (dns_typename, name_map[i].name))) i++; return name_map[i].number; } @@ -152,15 +135,12 @@ typename_to_number (void *cls, * @param type number of a type to convert * @return corresponding typestring, NULL on error */ -static const char * -number_to_typename (void *cls, - uint32_t type) +static const char *number_to_typename (void *cls, uint32_t type) { unsigned int i; - i=0; - while ( (NULL != name_map[i].name) && - (type != name_map[i].number) ) + i = 0; + while ((NULL != name_map[i].name) && (type != name_map[i].number)) i++; return name_map[i].name; } @@ -172,8 +152,7 @@ number_to_typename (void *cls, * @param cls NULL * @return the exported block API */ -void * -libgnunet_plugin_gnsrecord_reclaim_init (void *cls) +void *libgnunet_plugin_gnsrecord_reclaim_init (void *cls) { struct GNUNET_GNSRECORD_PluginFunctions *api; @@ -192,8 +171,7 @@ libgnunet_plugin_gnsrecord_reclaim_init (void *cls) * @param cls the return value from #libgnunet_plugin_block_test_init * @return NULL */ -void * -libgnunet_plugin_gnsrecord_reclaim_done (void *cls) +void *libgnunet_plugin_gnsrecord_reclaim_done (void *cls) { struct GNUNET_GNSRECORD_PluginFunctions *api = cls; -- cgit v1.2.3