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
28 #include "gnunet_util_lib.h"
29 #include "gnunet_namestore_service.h"
30 #include "gnunet_reclaim_service.h"
31 #include "gnunet_identity_service.h"
32 #include "gnunet_signatures.h"
52 static char* attr_name;
57 static char* attr_value;
62 static char* issue_attrs;
67 static char* consume_ticket;
72 static char* type_str;
77 static char* revoke_ticket;
82 static char* ego_name;
87 static struct GNUNET_IDENTITY_Handle *identity_handle;
92 static struct GNUNET_RECLAIM_Handle *reclaim_handle;
97 static struct GNUNET_RECLAIM_Operation *reclaim_op;
102 static struct GNUNET_RECLAIM_AttributeIterator *attr_iterator;
107 static struct GNUNET_CRYPTO_AbeMasterKey *abe_key;
112 static const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
117 static struct GNUNET_CRYPTO_EcdsaPublicKey rp_key;
122 static struct GNUNET_RECLAIM_Ticket ticket;
127 static struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list;
130 * Attribute expiration interval
132 static struct GNUNET_TIME_Relative exp_interval;
137 static struct GNUNET_SCHEDULER_Task *timeout;
142 static struct GNUNET_SCHEDULER_Task *cleanup_task;
147 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
150 do_cleanup(void *cls)
154 GNUNET_SCHEDULER_cancel (timeout);
155 if (NULL != reclaim_op)
156 GNUNET_RECLAIM_cancel (reclaim_op);
157 if (NULL != attr_iterator)
158 GNUNET_RECLAIM_get_attributes_stop (attr_iterator);
159 if (NULL != reclaim_handle)
160 GNUNET_RECLAIM_disconnect (reclaim_handle);
161 if (NULL != identity_handle)
162 GNUNET_IDENTITY_disconnect (identity_handle);
164 GNUNET_free (abe_key);
165 if (NULL != attr_list)
166 GNUNET_free (attr_list);
170 ticket_issue_cb (void* cls,
171 const struct GNUNET_RECLAIM_Ticket *ticket)
175 if (NULL != ticket) {
176 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
177 sizeof (struct GNUNET_RECLAIM_Ticket));
180 GNUNET_free (ticket_str);
182 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
186 store_attr_cont (void *cls,
191 if (GNUNET_SYSERR == success) {
195 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
199 process_attrs (void *cls,
200 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
201 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
204 const char* attr_type;
206 if (NULL == identity)
209 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
217 value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
220 attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
222 "%s: %s [%s,v%u,id=%lu]\n",
223 attr->name, value_str, attr_type, attr->version, attr->id);
228 iter_error (void *cls)
230 attr_iterator = NULL;
232 "Failed to iterate over attributes\n");
233 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
237 timeout_task (void *cls)
243 if (NULL == cleanup_task)
244 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
248 process_rvk (void *cls, int success, const char* msg)
251 if (GNUNET_OK != success)
254 "Revocation failed.\n");
257 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
261 iter_finished (void *cls)
267 attr_iterator = NULL;
270 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
276 reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle,
286 reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle,
291 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
298 reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle,
307 if (NULL == type_str)
308 type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING;
310 type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str);
312 GNUNET_assert (GNUNET_SYSERR != GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type,
320 claim->data_size = data_size;
324 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name,
329 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle,
339 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
344 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
345 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
347 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
350 const char *attr_type;
352 if ((NULL != attr_name) && (NULL != claim))
354 if (0 == strcasecmp (attr_name, attr->name))
356 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
362 else if (issue_attrs)
364 attrs_tmp = GNUNET_strdup (issue_attrs);
365 attr_str = strtok (attrs_tmp, ",");
366 while (NULL != attr_str) {
367 if (0 != strcasecmp (attr_str, attr->name)) {
368 attr_str = strtok (NULL, ",");
371 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
372 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
376 le->claim->version = attr->version;
377 le->claim->id = attr->id;
378 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
379 attr_list->list_tail,
383 GNUNET_free (attrs_tmp);
387 attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
390 attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
392 "%s: %s [%s,v%u,id=%lu]\n",
393 attr->name, attr_str, attr_type, attr->version, attr->id);
395 GNUNET_RECLAIM_get_attributes_next (attr_iterator);
399 start_get_attributes ()
404 "Ego %s not found\n", ego_name);
405 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
410 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
413 if (NULL != consume_ticket)
414 GNUNET_STRINGS_string_to_data (consume_ticket,
415 strlen (consume_ticket),
417 sizeof (struct GNUNET_RECLAIM_Ticket));
418 if (NULL != revoke_ticket)
419 GNUNET_STRINGS_string_to_data (revoke_ticket,
420 strlen (revoke_ticket),
422 sizeof (struct GNUNET_RECLAIM_Ticket));
424 attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
426 attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle,
438 static int init = GNUNET_YES;
442 struct GNUNET_IDENTITY_Ego *ego,
447 if (GNUNET_YES == init) {
449 start_get_attributes();
453 if (0 != strcmp (name, ego_name))
455 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
463 const struct GNUNET_CONFIGURATION_Handle *c)
466 if (NULL == ego_name)
470 _("Ego is required\n"));
474 if ( (NULL == attr_value) && (NULL != attr_name) )
478 _("Attribute value missing!\n"));
482 if ( (NULL == rp) && (NULL != issue_attrs) )
486 _("Requesting party key is required!\n"));
490 reclaim_handle = GNUNET_RECLAIM_connect (c);
492 identity_handle = GNUNET_IDENTITY_connect (c,
501 main(int argc, char *const argv[])
503 exp_interval = GNUNET_TIME_UNIT_HOURS;
504 struct GNUNET_GETOPT_CommandLineOption options[] = {
506 GNUNET_GETOPT_option_string ('a',
509 gettext_noop ("Add an attribute NAME"),
512 GNUNET_GETOPT_option_string ('V',
515 gettext_noop ("The attribute VALUE"),
517 GNUNET_GETOPT_option_string ('e',
520 gettext_noop ("The EGO to use"),
522 GNUNET_GETOPT_option_string ('r',
525 gettext_noop ("Specify the relying party for issue"),
527 GNUNET_GETOPT_option_flag ('D',
529 gettext_noop ("List attributes for EGO"),
531 GNUNET_GETOPT_option_string ('i',
534 gettext_noop ("Issue a ticket for a set of attributes separated by comma"),
536 GNUNET_GETOPT_option_string ('C',
539 gettext_noop ("Consume a ticket"),
541 GNUNET_GETOPT_option_string ('R',
544 gettext_noop ("Revoke a ticket"),
546 GNUNET_GETOPT_option_string ('t',
549 gettext_noop ("Type of attribute"),
551 GNUNET_GETOPT_option_relative_time ('E',
554 gettext_noop ("Expiration interval of the attribute"),
557 GNUNET_GETOPT_OPTION_END
559 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",