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/>.
19 * @author Martin Schanzenbach
20 * @file src/reclaim/gnunet-reclaim.c
21 * @brief Identity Provider utility
26 #include "gnunet_util_lib.h"
27 #include "gnunet_namestore_service.h"
28 #include "gnunet_reclaim_service.h"
29 #include "gnunet_identity_service.h"
30 #include "gnunet_signatures.h"
50 static char* attr_name;
55 static char* attr_value;
60 static char* issue_attrs;
65 static char* consume_ticket;
70 static char* type_str;
75 static char* revoke_ticket;
80 static char* ego_name;
85 static struct GNUNET_IDENTITY_Handle *identity_handle;
90 static struct GNUNET_RECLAIM_Handle *reclaim_handle;
95 static struct GNUNET_RECLAIM_Operation *reclaim_op;
100 static struct GNUNET_RECLAIM_AttributeIterator *attr_iterator;
105 static struct GNUNET_CRYPTO_AbeMasterKey *abe_key;
110 static const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
115 static struct GNUNET_CRYPTO_EcdsaPublicKey rp_key;
120 static struct GNUNET_RECLAIM_Ticket ticket;
125 static struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list;
128 * Attribute expiration interval
130 static struct GNUNET_TIME_Relative exp_interval;
135 static struct GNUNET_SCHEDULER_Task *timeout;
140 static struct GNUNET_SCHEDULER_Task *cleanup_task;
145 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
148 do_cleanup(void *cls)
152 GNUNET_SCHEDULER_cancel (timeout);
153 if (NULL != reclaim_op)
154 GNUNET_RECLAIM_cancel (reclaim_op);
155 if (NULL != attr_iterator)
156 GNUNET_RECLAIM_get_attributes_stop (attr_iterator);
157 if (NULL != reclaim_handle)
158 GNUNET_RECLAIM_disconnect (reclaim_handle);
159 if (NULL != identity_handle)
160 GNUNET_IDENTITY_disconnect (identity_handle);
162 GNUNET_free (abe_key);
163 if (NULL != attr_list)
164 GNUNET_free (attr_list);
168 ticket_issue_cb (void* cls,
169 const struct GNUNET_RECLAIM_Ticket *ticket)
173 if (NULL != ticket) {
174 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
175 sizeof (struct GNUNET_RECLAIM_Ticket));
178 GNUNET_free (ticket_str);
180 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
184 store_attr_cont (void *cls,
189 if (GNUNET_SYSERR == success) {
190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
193 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
197 process_attrs (void *cls,
198 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
199 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
202 if (NULL == identity)
205 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
213 value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
216 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
217 "%s: %s\n", attr->name, value_str);
222 iter_error (void *cls)
224 attr_iterator = NULL;
225 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
226 "Failed to iterate over attributes\n");
227 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
231 timeout_task (void *cls)
235 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
237 if (NULL == cleanup_task)
238 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
242 process_rvk (void *cls, int success, const char* msg)
245 if (GNUNET_OK != success)
247 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
248 "Revocation failed.\n");
251 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
255 iter_finished (void *cls)
261 attr_iterator = NULL;
264 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
270 reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle,
280 reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle,
285 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
292 reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle,
301 if (NULL == type_str)
302 type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING;
304 type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str);
306 GNUNET_assert (GNUNET_SYSERR != GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type,
314 claim->data_size = data_size;
318 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name,
323 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle,
333 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
338 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
339 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
341 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
344 const char *attr_type;
346 if ((NULL != attr_name) && (NULL != claim))
348 if (0 == strcasecmp (attr_name, attr->name))
350 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
356 else if (issue_attrs)
358 attrs_tmp = GNUNET_strdup (issue_attrs);
359 attr_str = strtok (attrs_tmp, ",");
360 while (NULL != attr_str) {
361 if (0 != strcasecmp (attr_str, attr->name)) {
362 attr_str = strtok (NULL, ",");
365 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
366 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
370 le->claim->version = attr->version;
371 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
372 attr_list->list_tail,
376 GNUNET_free (attrs_tmp);
380 attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
383 attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
385 "%s\t%s\t%u\t%s\n", attr->name, attr_type, attr->version, attr_str);
387 GNUNET_RECLAIM_get_attributes_next (attr_iterator);
391 start_get_attributes ()
395 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
396 "Ego %s not found\n", ego_name);
397 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
402 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
405 if (NULL != consume_ticket)
406 GNUNET_STRINGS_string_to_data (consume_ticket,
407 strlen (consume_ticket),
409 sizeof (struct GNUNET_RECLAIM_Ticket));
410 if (NULL != revoke_ticket)
411 GNUNET_STRINGS_string_to_data (revoke_ticket,
412 strlen (revoke_ticket),
414 sizeof (struct GNUNET_RECLAIM_Ticket));
418 "Name\tType\tVersion\tValue\n");
420 attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
422 attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle,
434 static int init = GNUNET_YES;
438 struct GNUNET_IDENTITY_Ego *ego,
443 if (GNUNET_YES == init) {
445 start_get_attributes();
449 if (0 != strcmp (name, ego_name))
451 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
459 const struct GNUNET_CONFIGURATION_Handle *c)
462 if (NULL == ego_name)
465 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
466 _("Ego is required\n"));
470 if ( (NULL == attr_value) && (NULL != attr_name) )
473 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
474 _("Attribute value missing!\n"));
478 if ( (NULL == rp) && (NULL != issue_attrs) )
481 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
482 _("Requesting party key is required!\n"));
486 reclaim_handle = GNUNET_RECLAIM_connect (c);
488 identity_handle = GNUNET_IDENTITY_connect (c,
497 main(int argc, char *const argv[])
499 exp_interval = GNUNET_TIME_UNIT_HOURS;
500 struct GNUNET_GETOPT_CommandLineOption options[] = {
502 GNUNET_GETOPT_option_string ('a',
505 gettext_noop ("Add attribute"),
508 GNUNET_GETOPT_option_string ('V',
511 gettext_noop ("Attribute value"),
513 GNUNET_GETOPT_option_string ('e',
516 gettext_noop ("Ego"),
518 GNUNET_GETOPT_option_string ('r',
521 gettext_noop ("Audience (relying party)"),
523 GNUNET_GETOPT_option_flag ('D',
525 gettext_noop ("List attributes for Ego"),
527 GNUNET_GETOPT_option_string ('i',
530 gettext_noop ("Issue a ticket"),
532 GNUNET_GETOPT_option_string ('C',
535 gettext_noop ("Consume a ticket"),
537 GNUNET_GETOPT_option_string ('R',
540 gettext_noop ("Revoke a ticket"),
542 GNUNET_GETOPT_option_string ('t',
545 gettext_noop ("Type of attribute"),
547 GNUNET_GETOPT_option_relative_time ('E',
550 gettext_noop ("Expiration interval of the attribute"),
553 GNUNET_GETOPT_OPTION_END
555 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",