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;
138 do_cleanup(void *cls)
141 GNUNET_SCHEDULER_cancel (timeout);
142 if (NULL != reclaim_op)
143 GNUNET_RECLAIM_cancel (reclaim_op);
144 if (NULL != attr_iterator)
145 GNUNET_RECLAIM_get_attributes_stop (attr_iterator);
146 if (NULL != reclaim_handle)
147 GNUNET_RECLAIM_disconnect (reclaim_handle);
148 if (NULL != identity_handle)
149 GNUNET_IDENTITY_disconnect (identity_handle);
151 GNUNET_free (abe_key);
152 if (NULL != attr_list)
153 GNUNET_free (attr_list);
157 ticket_issue_cb (void* cls,
158 const struct GNUNET_RECLAIM_Ticket *ticket)
162 if (NULL != ticket) {
163 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
164 sizeof (struct GNUNET_RECLAIM_Ticket));
167 GNUNET_free (ticket_str);
169 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
173 store_attr_cont (void *cls,
178 if (GNUNET_SYSERR == success) {
179 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
182 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
186 process_attrs (void *cls,
187 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
188 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
191 if (NULL == identity)
194 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
202 value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
205 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
206 "%s: %s\n", attr->name, value_str);
211 iter_error (void *cls)
213 attr_iterator = NULL;
214 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
215 "Failed to iterate over attributes\n");
216 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
220 timeout_task (void *cls)
224 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
226 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
230 process_rvk (void *cls, int success, const char* msg)
233 if (GNUNET_OK != success)
235 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
236 "Revocation failed.\n");
239 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
243 iter_finished (void *cls)
245 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
250 attr_iterator = NULL;
253 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
259 reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle,
269 reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle,
274 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
281 reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle,
290 if (NULL == type_str)
291 type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING;
293 type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str);
295 GNUNET_assert (GNUNET_SYSERR != GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type,
299 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name,
303 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle,
311 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
316 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
317 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
319 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
325 attrs_tmp = GNUNET_strdup (issue_attrs);
326 attr_str = strtok (attrs_tmp, ",");
327 while (NULL != attr_str) {
328 if (0 != strcmp (attr_str, attr->name)) {
329 attr_str = strtok (NULL, ",");
332 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
333 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
337 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
338 attr_list->list_tail,
342 GNUNET_free (attrs_tmp);
344 attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
347 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
348 "%s: %s\n", attr->name, attr_str);
350 GNUNET_RECLAIM_get_attributes_next (attr_iterator);
354 ego_iter_finished (void *cls)
358 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
359 "Ego %s not found\n", ego_name);
360 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
365 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
368 if (NULL != consume_ticket)
369 GNUNET_STRINGS_string_to_data (consume_ticket,
370 strlen (consume_ticket),
372 sizeof (struct GNUNET_RECLAIM_Ticket));
373 if (NULL != revoke_ticket)
374 GNUNET_STRINGS_string_to_data (revoke_ticket,
375 strlen (revoke_ticket),
377 sizeof (struct GNUNET_RECLAIM_Ticket));
380 attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
382 attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle,
394 static int init = GNUNET_YES;
398 struct GNUNET_IDENTITY_Ego *ego,
403 if (GNUNET_YES == init) {
405 GNUNET_SCHEDULER_add_now (&ego_iter_finished, NULL);
409 if (0 != strcmp (name, ego_name))
411 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
419 const struct GNUNET_CONFIGURATION_Handle *c)
422 if (NULL == ego_name)
425 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
426 _("Ego is required\n"));
430 if ( (NULL == attr_value) && (NULL != attr_name) )
433 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
434 _("Attribute value missing!\n"));
438 if ( (NULL == rp) && (NULL != issue_attrs) )
441 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
442 _("Requesting party key is required!\n"));
446 reclaim_handle = GNUNET_RECLAIM_connect (c);
448 identity_handle = GNUNET_IDENTITY_connect (c,
457 main(int argc, char *const argv[])
459 exp_interval = GNUNET_TIME_UNIT_HOURS;
460 struct GNUNET_GETOPT_CommandLineOption options[] = {
462 GNUNET_GETOPT_option_string ('a',
465 gettext_noop ("Add attribute"),
468 GNUNET_GETOPT_option_string ('V',
471 gettext_noop ("Attribute value"),
473 GNUNET_GETOPT_option_string ('e',
476 gettext_noop ("Ego"),
478 GNUNET_GETOPT_option_string ('r',
481 gettext_noop ("Audience (relying party)"),
483 GNUNET_GETOPT_option_flag ('D',
485 gettext_noop ("List attributes for Ego"),
487 GNUNET_GETOPT_option_string ('i',
490 gettext_noop ("Issue a ticket"),
492 GNUNET_GETOPT_option_string ('C',
495 gettext_noop ("Consume a ticket"),
497 GNUNET_GETOPT_option_string ('R',
500 gettext_noop ("Revoke a ticket"),
502 GNUNET_GETOPT_option_string ('t',
505 gettext_noop ("Type of attribute"),
507 GNUNET_GETOPT_option_relative_time ('E',
510 gettext_noop ("Expiration interval of the attribute"),
513 GNUNET_GETOPT_OPTION_END
515 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",