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;
143 do_cleanup(void *cls)
147 GNUNET_SCHEDULER_cancel (timeout);
148 if (NULL != reclaim_op)
149 GNUNET_RECLAIM_cancel (reclaim_op);
150 if (NULL != attr_iterator)
151 GNUNET_RECLAIM_get_attributes_stop (attr_iterator);
152 if (NULL != reclaim_handle)
153 GNUNET_RECLAIM_disconnect (reclaim_handle);
154 if (NULL != identity_handle)
155 GNUNET_IDENTITY_disconnect (identity_handle);
157 GNUNET_free (abe_key);
158 if (NULL != attr_list)
159 GNUNET_free (attr_list);
163 ticket_issue_cb (void* cls,
164 const struct GNUNET_RECLAIM_Ticket *ticket)
168 if (NULL != ticket) {
169 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
170 sizeof (struct GNUNET_RECLAIM_Ticket));
173 GNUNET_free (ticket_str);
175 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
179 store_attr_cont (void *cls,
184 if (GNUNET_SYSERR == success) {
185 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
188 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
192 process_attrs (void *cls,
193 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
194 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
197 if (NULL == identity)
200 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
208 value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
211 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
212 "%s: %s\n", attr->name, value_str);
217 iter_error (void *cls)
219 attr_iterator = NULL;
220 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
221 "Failed to iterate over attributes\n");
222 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
226 timeout_task (void *cls)
230 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
232 if (NULL == cleanup_task)
233 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
237 process_rvk (void *cls, int success, const char* msg)
240 if (GNUNET_OK != success)
242 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
243 "Revocation failed.\n");
246 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
250 iter_finished (void *cls)
252 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
257 attr_iterator = NULL;
260 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
266 reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle,
276 reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle,
281 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
288 reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle,
297 if (NULL == type_str)
298 type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING;
300 type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str);
302 GNUNET_assert (GNUNET_SYSERR != GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type,
306 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name,
310 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle,
318 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
323 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
324 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
326 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
332 attrs_tmp = GNUNET_strdup (issue_attrs);
333 attr_str = strtok (attrs_tmp, ",");
334 while (NULL != attr_str) {
335 if (0 != strcmp (attr_str, attr->name)) {
336 attr_str = strtok (NULL, ",");
339 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
340 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
344 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
345 attr_list->list_tail,
349 GNUNET_free (attrs_tmp);
351 attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
354 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
355 "%s: %s\n", attr->name, attr_str);
357 GNUNET_RECLAIM_get_attributes_next (attr_iterator);
361 start_get_attributes ()
365 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
366 "Ego %s not found\n", ego_name);
367 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
372 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
375 if (NULL != consume_ticket)
376 GNUNET_STRINGS_string_to_data (consume_ticket,
377 strlen (consume_ticket),
379 sizeof (struct GNUNET_RECLAIM_Ticket));
380 if (NULL != revoke_ticket)
381 GNUNET_STRINGS_string_to_data (revoke_ticket,
382 strlen (revoke_ticket),
384 sizeof (struct GNUNET_RECLAIM_Ticket));
387 attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
389 attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle,
401 static int init = GNUNET_YES;
405 struct GNUNET_IDENTITY_Ego *ego,
410 if (GNUNET_YES == init) {
412 start_get_attributes();
416 if (0 != strcmp (name, ego_name))
418 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
426 const struct GNUNET_CONFIGURATION_Handle *c)
429 if (NULL == ego_name)
432 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
433 _("Ego is required\n"));
437 if ( (NULL == attr_value) && (NULL != attr_name) )
440 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
441 _("Attribute value missing!\n"));
445 if ( (NULL == rp) && (NULL != issue_attrs) )
448 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
449 _("Requesting party key is required!\n"));
453 reclaim_handle = GNUNET_RECLAIM_connect (c);
455 identity_handle = GNUNET_IDENTITY_connect (c,
464 main(int argc, char *const argv[])
466 exp_interval = GNUNET_TIME_UNIT_HOURS;
467 struct GNUNET_GETOPT_CommandLineOption options[] = {
469 GNUNET_GETOPT_option_string ('a',
472 gettext_noop ("Add attribute"),
475 GNUNET_GETOPT_option_string ('V',
478 gettext_noop ("Attribute value"),
480 GNUNET_GETOPT_option_string ('e',
483 gettext_noop ("Ego"),
485 GNUNET_GETOPT_option_string ('r',
488 gettext_noop ("Audience (relying party)"),
490 GNUNET_GETOPT_option_flag ('D',
492 gettext_noop ("List attributes for Ego"),
494 GNUNET_GETOPT_option_string ('i',
497 gettext_noop ("Issue a ticket"),
499 GNUNET_GETOPT_option_string ('C',
502 gettext_noop ("Consume a ticket"),
504 GNUNET_GETOPT_option_string ('R',
507 gettext_noop ("Revoke a ticket"),
509 GNUNET_GETOPT_option_string ('t',
512 gettext_noop ("Type of attribute"),
514 GNUNET_GETOPT_option_relative_time ('E',
517 gettext_noop ("Expiration interval of the attribute"),
520 GNUNET_GETOPT_OPTION_END
522 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",