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) {
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 const char* attr_type;
204 if (NULL == identity)
207 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
215 value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
218 attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
220 "%s: %s [%s,v%u]\n", attr->name, value_str, attr_type, attr->version);
225 iter_error (void *cls)
227 attr_iterator = NULL;
229 "Failed to iterate over attributes\n");
230 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
234 timeout_task (void *cls)
240 if (NULL == cleanup_task)
241 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
245 process_rvk (void *cls, int success, const char* msg)
248 if (GNUNET_OK != success)
251 "Revocation failed.\n");
254 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
258 iter_finished (void *cls)
264 attr_iterator = NULL;
267 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
273 reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle,
283 reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle,
288 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
295 reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle,
304 if (NULL == type_str)
305 type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING;
307 type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str);
309 GNUNET_assert (GNUNET_SYSERR != GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type,
317 claim->data_size = data_size;
321 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name,
326 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle,
336 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
341 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
342 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
344 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
347 const char *attr_type;
349 if ((NULL != attr_name) && (NULL != claim))
351 if (0 == strcasecmp (attr_name, attr->name))
353 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
359 else if (issue_attrs)
361 attrs_tmp = GNUNET_strdup (issue_attrs);
362 attr_str = strtok (attrs_tmp, ",");
363 while (NULL != attr_str) {
364 if (0 != strcasecmp (attr_str, attr->name)) {
365 attr_str = strtok (NULL, ",");
368 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
369 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
373 le->claim->version = attr->version;
374 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
375 attr_list->list_tail,
379 GNUNET_free (attrs_tmp);
383 attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
386 attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
388 "%s: %s [%s,v%u]\n", attr->name, attr_str, attr_type, attr->version);
390 GNUNET_RECLAIM_get_attributes_next (attr_iterator);
394 start_get_attributes ()
399 "Ego %s not found\n", ego_name);
400 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
405 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
408 if (NULL != consume_ticket)
409 GNUNET_STRINGS_string_to_data (consume_ticket,
410 strlen (consume_ticket),
412 sizeof (struct GNUNET_RECLAIM_Ticket));
413 if (NULL != revoke_ticket)
414 GNUNET_STRINGS_string_to_data (revoke_ticket,
415 strlen (revoke_ticket),
417 sizeof (struct GNUNET_RECLAIM_Ticket));
419 attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
421 attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle,
433 static int init = GNUNET_YES;
437 struct GNUNET_IDENTITY_Ego *ego,
442 if (GNUNET_YES == init) {
444 start_get_attributes();
448 if (0 != strcmp (name, ego_name))
450 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
458 const struct GNUNET_CONFIGURATION_Handle *c)
461 if (NULL == ego_name)
465 _("Ego is required\n"));
469 if ( (NULL == attr_value) && (NULL != attr_name) )
473 _("Attribute value missing!\n"));
477 if ( (NULL == rp) && (NULL != issue_attrs) )
481 _("Requesting party key is required!\n"));
485 reclaim_handle = GNUNET_RECLAIM_connect (c);
487 identity_handle = GNUNET_IDENTITY_connect (c,
496 main(int argc, char *const argv[])
498 exp_interval = GNUNET_TIME_UNIT_HOURS;
499 struct GNUNET_GETOPT_CommandLineOption options[] = {
501 GNUNET_GETOPT_option_string ('a',
504 gettext_noop ("Add attribute"),
507 GNUNET_GETOPT_option_string ('V',
510 gettext_noop ("Attribute value"),
512 GNUNET_GETOPT_option_string ('e',
515 gettext_noop ("Ego"),
517 GNUNET_GETOPT_option_string ('r',
520 gettext_noop ("Audience (relying party)"),
522 GNUNET_GETOPT_option_flag ('D',
524 gettext_noop ("List attributes for Ego"),
526 GNUNET_GETOPT_option_string ('i',
529 gettext_noop ("Issue a ticket"),
531 GNUNET_GETOPT_option_string ('C',
534 gettext_noop ("Consume a ticket"),
536 GNUNET_GETOPT_option_string ('R',
539 gettext_noop ("Revoke a ticket"),
541 GNUNET_GETOPT_option_string ('t',
544 gettext_noop ("Type of attribute"),
546 GNUNET_GETOPT_option_relative_time ('E',
549 gettext_noop ("Expiration interval of the attribute"),
552 GNUNET_GETOPT_OPTION_END
554 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",