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]\n", attr->name, value_str, attr_type, attr->version);
227 iter_error (void *cls)
229 attr_iterator = NULL;
231 "Failed to iterate over attributes\n");
232 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
236 timeout_task (void *cls)
242 if (NULL == cleanup_task)
243 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
247 process_rvk (void *cls, int success, const char* msg)
250 if (GNUNET_OK != success)
253 "Revocation failed.\n");
256 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
260 iter_finished (void *cls)
266 attr_iterator = NULL;
269 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
275 reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle,
285 reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle,
290 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
297 reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle,
306 if (NULL == type_str)
307 type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING;
309 type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str);
311 GNUNET_assert (GNUNET_SYSERR != GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type,
319 claim->data_size = data_size;
323 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name,
328 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle,
338 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
343 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
344 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
346 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
349 const char *attr_type;
351 if ((NULL != attr_name) && (NULL != claim))
353 if (0 == strcasecmp (attr_name, attr->name))
355 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
361 else if (issue_attrs)
363 attrs_tmp = GNUNET_strdup (issue_attrs);
364 attr_str = strtok (attrs_tmp, ",");
365 while (NULL != attr_str) {
366 if (0 != strcasecmp (attr_str, attr->name)) {
367 attr_str = strtok (NULL, ",");
370 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
371 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
375 le->claim->version = attr->version;
376 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
377 attr_list->list_tail,
381 GNUNET_free (attrs_tmp);
385 attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
388 attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
390 "%s: %s [%s,v%u]\n", attr->name, attr_str, attr_type, attr->version);
392 GNUNET_RECLAIM_get_attributes_next (attr_iterator);
396 start_get_attributes ()
401 "Ego %s not found\n", ego_name);
402 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
407 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
410 if (NULL != consume_ticket)
411 GNUNET_STRINGS_string_to_data (consume_ticket,
412 strlen (consume_ticket),
414 sizeof (struct GNUNET_RECLAIM_Ticket));
415 if (NULL != revoke_ticket)
416 GNUNET_STRINGS_string_to_data (revoke_ticket,
417 strlen (revoke_ticket),
419 sizeof (struct GNUNET_RECLAIM_Ticket));
421 attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
423 attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle,
435 static int init = GNUNET_YES;
439 struct GNUNET_IDENTITY_Ego *ego,
444 if (GNUNET_YES == init) {
446 start_get_attributes();
450 if (0 != strcmp (name, ego_name))
452 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
460 const struct GNUNET_CONFIGURATION_Handle *c)
463 if (NULL == ego_name)
467 _("Ego is required\n"));
471 if ( (NULL == attr_value) && (NULL != attr_name) )
475 _("Attribute value missing!\n"));
479 if ( (NULL == rp) && (NULL != issue_attrs) )
483 _("Requesting party key is required!\n"));
487 reclaim_handle = GNUNET_RECLAIM_connect (c);
489 identity_handle = GNUNET_IDENTITY_connect (c,
498 main(int argc, char *const argv[])
500 exp_interval = GNUNET_TIME_UNIT_HOURS;
501 struct GNUNET_GETOPT_CommandLineOption options[] = {
503 GNUNET_GETOPT_option_string ('a',
506 gettext_noop ("Add attribute"),
509 GNUNET_GETOPT_option_string ('V',
512 gettext_noop ("Attribute value"),
514 GNUNET_GETOPT_option_string ('e',
517 gettext_noop ("Ego"),
519 GNUNET_GETOPT_option_string ('r',
522 gettext_noop ("Audience (relying party)"),
524 GNUNET_GETOPT_option_flag ('D',
526 gettext_noop ("List attributes for Ego"),
528 GNUNET_GETOPT_option_string ('i',
531 gettext_noop ("Issue a ticket"),
533 GNUNET_GETOPT_option_string ('C',
536 gettext_noop ("Consume a ticket"),
538 GNUNET_GETOPT_option_string ('R',
541 gettext_noop ("Revoke a ticket"),
543 GNUNET_GETOPT_option_string ('t',
546 gettext_noop ("Type of attribute"),
548 GNUNET_GETOPT_option_relative_time ('E',
551 gettext_noop ("Expiration interval of the attribute"),
554 GNUNET_GETOPT_OPTION_END
556 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",