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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @author Martin Schanzenbach
22 * @file src/identity-provider/gnunet-idp.c
23 * @brief Identity Provider utility
28 #include "gnunet_util_lib.h"
29 #include "gnunet_namestore_service.h"
30 #include "gnunet_identity_provider_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_IDENTITY_PROVIDER_Handle *idp_handle;
97 static struct GNUNET_IDENTITY_PROVIDER_Operation *idp_op;
102 static struct GNUNET_IDENTITY_PROVIDER_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_IDENTITY_PROVIDER_Ticket ticket;
127 static struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attr_list;
130 * Attribute expiration interval
132 static struct GNUNET_TIME_Relative exp_interval;
137 static struct GNUNET_SCHEDULER_Task *timeout;
140 do_cleanup(void *cls)
143 GNUNET_SCHEDULER_cancel (timeout);
145 GNUNET_IDENTITY_PROVIDER_cancel (idp_op);
146 if (NULL != attr_iterator)
147 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (attr_iterator);
148 if (NULL != idp_handle)
149 GNUNET_IDENTITY_PROVIDER_disconnect (idp_handle);
150 if (NULL != identity_handle)
151 GNUNET_IDENTITY_disconnect (identity_handle);
153 GNUNET_free (abe_key);
154 if (NULL != attr_list)
155 GNUNET_free (attr_list);
159 ticket_issue_cb (void* cls,
160 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket)
164 if (NULL != ticket) {
165 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
166 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
169 GNUNET_free (ticket_str);
171 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
175 store_attr_cont (void *cls,
180 if (GNUNET_SYSERR == success) {
181 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
184 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
188 process_attrs (void *cls,
189 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
190 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr)
193 if (NULL == identity)
196 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
204 value_str = GNUNET_IDENTITY_ATTRIBUTE_value_to_string (attr->type,
207 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
208 "%s: %s\n", attr->name, value_str);
213 iter_error (void *cls)
215 attr_iterator = NULL;
216 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
217 "Failed to iterate over attributes\n");
218 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
222 timeout_task (void *cls)
226 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
228 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
232 process_rvk (void *cls, int success, const char* msg)
235 if (GNUNET_OK != success)
237 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
238 "Revocation failed.\n");
241 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
245 iter_finished (void *cls)
247 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *claim;
252 attr_iterator = NULL;
255 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
261 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_issue (idp_handle,
271 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume (idp_handle,
276 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
283 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_revoke (idp_handle,
292 if (NULL == type_str)
293 type = GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING;
295 type = GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (type_str);
297 GNUNET_assert (GNUNET_SYSERR != GNUNET_IDENTITY_ATTRIBUTE_string_to_value (type,
301 claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr_name,
305 idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle,
313 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
318 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
319 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr)
321 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le;
327 attrs_tmp = GNUNET_strdup (issue_attrs);
328 attr_str = strtok (attrs_tmp, ",");
329 while (NULL != attr_str) {
330 if (0 != strcmp (attr_str, attr->name)) {
331 attr_str = strtok (NULL, ",");
334 le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry);
335 le->claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr->name,
339 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
340 attr_list->list_tail,
344 GNUNET_free (attrs_tmp);
346 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
347 "%s: %s\n", attr->name, (char*)attr->data);
349 GNUNET_IDENTITY_PROVIDER_get_attributes_next (attr_iterator);
353 ego_iter_finished (void *cls)
357 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
358 "Ego %s not found\n", ego_name);
363 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
366 if (NULL != consume_ticket)
367 GNUNET_STRINGS_string_to_data (consume_ticket,
368 strlen (consume_ticket),
370 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
371 if (NULL != revoke_ticket)
372 GNUNET_STRINGS_string_to_data (revoke_ticket,
373 strlen (revoke_ticket),
375 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
378 attr_list = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList);
380 attr_iterator = GNUNET_IDENTITY_PROVIDER_get_attributes_start (idp_handle,
392 static int init = GNUNET_YES;
396 struct GNUNET_IDENTITY_Ego *ego,
401 if (GNUNET_YES == init) {
403 GNUNET_SCHEDULER_add_now (&ego_iter_finished, NULL);
407 if (0 != strcmp (name, ego_name))
409 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
417 const struct GNUNET_CONFIGURATION_Handle *c)
420 if (NULL == ego_name)
423 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
424 _("Ego is required\n"));
428 if ( (NULL == attr_value) && (NULL != attr_name) )
431 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
432 _("Attribute value missing!\n"));
436 if ( (NULL == rp) && (NULL != issue_attrs) )
439 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
440 _("Requesting party key is required!\n"));
444 idp_handle = GNUNET_IDENTITY_PROVIDER_connect (c);
446 identity_handle = GNUNET_IDENTITY_connect (c,
455 main(int argc, char *const argv[])
457 exp_interval = GNUNET_TIME_UNIT_HOURS;
458 struct GNUNET_GETOPT_CommandLineOption options[] = {
460 GNUNET_GETOPT_option_string ('a',
463 gettext_noop ("Add attribute"),
466 GNUNET_GETOPT_option_string ('V',
469 gettext_noop ("Attribute value"),
471 GNUNET_GETOPT_option_string ('e',
474 gettext_noop ("Ego"),
476 GNUNET_GETOPT_option_string ('r',
479 gettext_noop ("Audience (relying party)"),
481 GNUNET_GETOPT_option_flag ('D',
483 gettext_noop ("List attributes for Ego"),
485 GNUNET_GETOPT_option_string ('i',
488 gettext_noop ("Issue a ticket"),
490 GNUNET_GETOPT_option_string ('C',
493 gettext_noop ("Consume a ticket"),
495 GNUNET_GETOPT_option_string ('R',
498 gettext_noop ("Revoke a ticket"),
500 GNUNET_GETOPT_option_string ('t',
503 gettext_noop ("Type of attribute"),
505 GNUNET_GETOPT_option_relative_time ('E',
508 gettext_noop ("Expiration interval of the attribute"),
511 GNUNET_GETOPT_OPTION_END
513 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",