2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @author Martin Schanzenbach
22 * @file src/reclaim/gnunet-reclaim.c
23 * @brief Identity Provider utility
29 #include "gnunet_util_lib.h"
31 #include "gnunet_identity_service.h"
32 #include "gnunet_namestore_service.h"
33 #include "gnunet_reclaim_service.h"
34 #include "gnunet_signatures.h"
53 static char *attr_name;
58 static char *attr_value;
63 static char *issue_attrs;
68 static char *consume_ticket;
73 static char *type_str;
78 static char *revoke_ticket;
83 static int list_tickets;
88 static char *ego_name;
93 static struct GNUNET_IDENTITY_Handle *identity_handle;
98 static struct GNUNET_RECLAIM_Handle *reclaim_handle;
103 static struct GNUNET_RECLAIM_Operation *reclaim_op;
108 static struct GNUNET_RECLAIM_AttributeIterator *attr_iterator;
113 static struct GNUNET_RECLAIM_TicketIterator *ticket_iterator;
118 static struct GNUNET_CRYPTO_AbeMasterKey *abe_key;
123 static const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
128 static struct GNUNET_CRYPTO_EcdsaPublicKey rp_key;
133 static struct GNUNET_RECLAIM_Ticket ticket;
138 static struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list;
141 * Attribute expiration interval
143 static struct GNUNET_TIME_Relative exp_interval;
148 static struct GNUNET_SCHEDULER_Task *timeout;
153 static struct GNUNET_SCHEDULER_Task *cleanup_task;
158 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
163 static char *attr_delete;
166 * Claim object to delete
168 static struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr_to_delete;
171 do_cleanup (void *cls)
175 GNUNET_SCHEDULER_cancel (timeout);
176 if (NULL != reclaim_op)
177 GNUNET_RECLAIM_cancel (reclaim_op);
178 if (NULL != attr_iterator)
179 GNUNET_RECLAIM_get_attributes_stop (attr_iterator);
180 if (NULL != ticket_iterator)
181 GNUNET_RECLAIM_ticket_iteration_stop (ticket_iterator);
182 if (NULL != reclaim_handle)
183 GNUNET_RECLAIM_disconnect (reclaim_handle);
184 if (NULL != identity_handle)
185 GNUNET_IDENTITY_disconnect (identity_handle);
187 GNUNET_free (abe_key);
188 if (NULL != attr_list)
189 GNUNET_free (attr_list);
190 if (NULL != attr_to_delete)
191 GNUNET_free (attr_to_delete);
195 ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
202 GNUNET_STRINGS_data_to_string_alloc (ticket,
204 struct GNUNET_RECLAIM_Ticket));
205 printf ("%s\n", ticket_str);
206 GNUNET_free (ticket_str);
208 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
212 store_attr_cont (void *cls, int32_t success, const char *emsg)
215 if (GNUNET_SYSERR == success)
217 fprintf (stderr, "%s\n", emsg);
219 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
223 process_attrs (void *cls,
224 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
225 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
229 const char *attr_type;
231 if (NULL == identity)
234 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
242 value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
245 attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
246 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t));
248 "Name: %s; Value: %s (%s); Version %u; ID: %s\n",
258 ticket_iter_err (void *cls)
260 ticket_iterator = NULL;
261 fprintf (stderr, "Failed to iterate over tickets\n");
262 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
266 ticket_iter_fin (void *cls)
268 ticket_iterator = NULL;
269 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
273 ticket_iter (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
280 GNUNET_STRINGS_data_to_string_alloc (&ticket->audience,
282 GNUNET_CRYPTO_EcdsaPublicKey));
283 ref = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t));
285 GNUNET_STRINGS_data_to_string_alloc (ticket,
286 sizeof (struct GNUNET_RECLAIM_Ticket));
287 fprintf (stdout, "Ticket: %s | ID: %s | Audience: %s\n", tkt, ref, aud);
291 GNUNET_RECLAIM_ticket_iteration_next (ticket_iterator);
295 iter_error (void *cls)
297 attr_iterator = NULL;
298 fprintf (stderr, "Failed to iterate over attributes\n");
299 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
303 timeout_task (void *cls)
307 fprintf (stderr, "Timeout\n");
308 if (NULL == cleanup_task)
309 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
313 process_rvk (void *cls, int success, const char *msg)
316 if (GNUNET_OK != success)
318 fprintf (stderr, "Revocation failed.\n");
321 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
326 process_delete (void *cls, int success, const char *msg)
329 if (GNUNET_OK != success)
331 fprintf (stderr, "Deletion failed.\n");
334 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
339 iter_finished (void *cls)
345 attr_iterator = NULL;
348 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
354 reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle,
364 reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle,
369 timeout = GNUNET_SCHEDULER_add_delayed (
370 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
377 reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle,
386 if (NULL == attr_to_delete)
388 fprintf (stdout, "No such attribute ``%s''\n", attr_delete);
391 reclaim_op = GNUNET_RECLAIM_attribute_delete (reclaim_handle,
400 if (NULL == type_str)
401 type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING;
403 type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str);
405 GNUNET_assert (GNUNET_SYSERR !=
406 GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type,
414 claim->data_size = data_size;
419 GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size);
421 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle,
431 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
436 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
437 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
439 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
444 const char *attr_type;
446 if ((NULL != attr_name) && (NULL != claim))
448 if (0 == strcasecmp (attr_name, attr->name))
450 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
456 else if (issue_attrs)
458 attrs_tmp = GNUNET_strdup (issue_attrs);
459 attr_str = strtok (attrs_tmp, ",");
460 while (NULL != attr_str)
462 if (0 != strcasecmp (attr_str, attr->name))
464 attr_str = strtok (NULL, ",");
467 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
468 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
472 le->claim->version = attr->version;
473 le->claim->id = attr->id;
474 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
475 attr_list->list_tail,
479 GNUNET_free (attrs_tmp);
481 else if (attr_delete && (NULL == attr_to_delete))
483 label = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t));
484 if (0 == strcasecmp (attr_delete, label))
486 attr_to_delete = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
490 attr_to_delete->id = attr->id;
496 attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
499 attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
500 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t));
502 "Name: %s; Value: %s (%s); Version %u; ID: %s\n",
510 GNUNET_RECLAIM_get_attributes_next (attr_iterator);
518 fprintf (stderr, "Ego %s not found\n", ego_name);
519 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
525 ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle,
538 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp, strlen (rp), &rp_key))
540 fprintf (stderr, "%s is not a public key!\n", rp);
541 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
544 if (NULL != consume_ticket)
545 GNUNET_STRINGS_string_to_data (consume_ticket,
546 strlen (consume_ticket),
548 sizeof (struct GNUNET_RECLAIM_Ticket));
549 if (NULL != revoke_ticket)
550 GNUNET_STRINGS_string_to_data (revoke_ticket,
551 strlen (revoke_ticket),
553 sizeof (struct GNUNET_RECLAIM_Ticket));
555 attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
557 attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle,
567 static int init = GNUNET_YES;
571 struct GNUNET_IDENTITY_Ego *ego,
577 if (GNUNET_YES == init)
584 if (0 != strcmp (name, ego_name))
586 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
594 const struct GNUNET_CONFIGURATION_Handle *c)
597 if (NULL == ego_name)
600 fprintf (stderr, _ ("Ego is required\n"));
604 if ((NULL == attr_value) && (NULL != attr_name))
607 fprintf (stderr, _ ("Attribute value missing!\n"));
611 if ((NULL == rp) && (NULL != issue_attrs))
614 fprintf (stderr, _ ("Requesting party key is required!\n"));
618 reclaim_handle = GNUNET_RECLAIM_connect (c);
620 identity_handle = GNUNET_IDENTITY_connect (c, &ego_cb, NULL);
625 main (int argc, char *const argv[])
627 exp_interval = GNUNET_TIME_UNIT_HOURS;
628 struct GNUNET_GETOPT_CommandLineOption options[] = {
630 GNUNET_GETOPT_option_string ('a',
633 gettext_noop ("Add an attribute NAME"),
635 GNUNET_GETOPT_option_string ('d',
638 gettext_noop ("Delete the attribute with ID"),
640 GNUNET_GETOPT_option_string ('V',
643 gettext_noop ("The attribute VALUE"),
645 GNUNET_GETOPT_option_string ('e',
648 gettext_noop ("The EGO to use"),
650 GNUNET_GETOPT_option_string ('r',
654 "Specify the relying party for issue"),
656 GNUNET_GETOPT_option_flag ('D',
658 gettext_noop ("List attributes for EGO"),
660 GNUNET_GETOPT_option_string (
665 "Issue a ticket for a set of attributes separated by comma"),
667 GNUNET_GETOPT_option_string ('C',
670 gettext_noop ("Consume a ticket"),
672 GNUNET_GETOPT_option_string ('R',
675 gettext_noop ("Revoke a ticket"),
677 GNUNET_GETOPT_option_string ('t',
680 gettext_noop ("Type of attribute"),
682 GNUNET_GETOPT_option_flag ('T',
684 gettext_noop ("List tickets of ego"),
686 GNUNET_GETOPT_option_relative_time ('E',
690 "Expiration interval of the attribute"),
693 GNUNET_GETOPT_OPTION_END};
694 if (GNUNET_OK != GNUNET_PROGRAM_run (argc,
697 _ ("re:claimID command line tool"),