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 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
345 "%s: %s\n", attr->name, (char*)attr->data);
347 GNUNET_RECLAIM_get_attributes_next (attr_iterator);
351 ego_iter_finished (void *cls)
355 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
356 "Ego %s not found\n", ego_name);
361 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
364 if (NULL != consume_ticket)
365 GNUNET_STRINGS_string_to_data (consume_ticket,
366 strlen (consume_ticket),
368 sizeof (struct GNUNET_RECLAIM_Ticket));
369 if (NULL != revoke_ticket)
370 GNUNET_STRINGS_string_to_data (revoke_ticket,
371 strlen (revoke_ticket),
373 sizeof (struct GNUNET_RECLAIM_Ticket));
376 attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
378 attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle,
390 static int init = GNUNET_YES;
394 struct GNUNET_IDENTITY_Ego *ego,
399 if (GNUNET_YES == init) {
401 GNUNET_SCHEDULER_add_now (&ego_iter_finished, NULL);
405 if (0 != strcmp (name, ego_name))
407 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
415 const struct GNUNET_CONFIGURATION_Handle *c)
418 if (NULL == ego_name)
421 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
422 _("Ego is required\n"));
426 if ( (NULL == attr_value) && (NULL != attr_name) )
429 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
430 _("Attribute value missing!\n"));
434 if ( (NULL == rp) && (NULL != issue_attrs) )
437 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
438 _("Requesting party key is required!\n"));
442 reclaim_handle = GNUNET_RECLAIM_connect (c);
444 identity_handle = GNUNET_IDENTITY_connect (c,
453 main(int argc, char *const argv[])
455 exp_interval = GNUNET_TIME_UNIT_HOURS;
456 struct GNUNET_GETOPT_CommandLineOption options[] = {
458 GNUNET_GETOPT_option_string ('a',
461 gettext_noop ("Add attribute"),
464 GNUNET_GETOPT_option_string ('V',
467 gettext_noop ("Attribute value"),
469 GNUNET_GETOPT_option_string ('e',
472 gettext_noop ("Ego"),
474 GNUNET_GETOPT_option_string ('r',
477 gettext_noop ("Audience (relying party)"),
479 GNUNET_GETOPT_option_flag ('D',
481 gettext_noop ("List attributes for Ego"),
483 GNUNET_GETOPT_option_string ('i',
486 gettext_noop ("Issue a ticket"),
488 GNUNET_GETOPT_option_string ('C',
491 gettext_noop ("Consume a ticket"),
493 GNUNET_GETOPT_option_string ('R',
496 gettext_noop ("Revoke a ticket"),
498 GNUNET_GETOPT_option_string ('t',
501 gettext_noop ("Type of attribute"),
503 GNUNET_GETOPT_option_relative_time ('E',
506 gettext_noop ("Expiration interval of the attribute"),
509 GNUNET_GETOPT_OPTION_END
511 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",