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;
135 do_cleanup(void *cls)
137 if (NULL != attr_iterator)
138 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (attr_iterator);
139 if (NULL != idp_handle)
140 GNUNET_IDENTITY_PROVIDER_disconnect (idp_handle);
141 if (NULL != identity_handle)
142 GNUNET_IDENTITY_disconnect (identity_handle);
144 GNUNET_free (abe_key);
145 if (NULL != attr_list)
146 GNUNET_free (attr_list);
150 ticket_issue_cb (void* cls,
151 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket)
154 if (NULL != ticket) {
155 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
156 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
159 GNUNET_free (ticket_str);
161 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
165 store_attr_cont (void *cls,
169 if (GNUNET_SYSERR == success) {
170 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
173 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
177 process_attrs (void *cls,
178 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
179 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr)
182 if (NULL == identity)
184 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
192 value_str = GNUNET_IDENTITY_ATTRIBUTE_value_to_string (attr->type,
195 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
196 "%s: %s\n", attr->name, value_str);
201 iter_error (void *cls)
203 attr_iterator = NULL;
204 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
205 "Failed to iterate over attributes\n");
206 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
210 process_rvk (void *cls, int success, const char* msg)
212 if (GNUNET_OK != success)
214 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
215 "Revocation failed.\n");
218 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
222 iter_finished (void *cls)
224 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *claim;
229 attr_iterator = NULL;
232 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
238 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_issue (idp_handle,
248 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume (idp_handle,
257 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_revoke (idp_handle,
264 if (NULL == type_str)
265 type = GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING;
267 type = GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (type_str);
269 GNUNET_assert (GNUNET_SYSERR != GNUNET_IDENTITY_ATTRIBUTE_string_to_value (type,
273 claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr_name,
277 idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle,
289 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
290 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr)
292 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le;
298 attrs_tmp = GNUNET_strdup (issue_attrs);
299 attr_str = strtok (attrs_tmp, ",");
300 while (NULL != attr_str) {
301 if (0 != strcmp (attr_str, attr->name)) {
302 attr_str = strtok (NULL, ",");
305 le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry);
306 le->claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr->name,
310 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
311 attr_list->list_tail,
315 GNUNET_free (attrs_tmp);
317 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
318 "%s: %s\n", attr->name, (char*)attr->data);
320 GNUNET_IDENTITY_PROVIDER_get_attributes_next (attr_iterator);
325 struct GNUNET_IDENTITY_Ego *ego,
331 if (0 != strcmp (name, ego_name))
333 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
336 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
339 if (NULL != consume_ticket)
340 GNUNET_STRINGS_string_to_data (consume_ticket,
341 strlen (consume_ticket),
343 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
344 if (NULL != revoke_ticket)
345 GNUNET_STRINGS_string_to_data (revoke_ticket,
346 strlen (revoke_ticket),
348 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
351 attr_list = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList);
353 attr_iterator = GNUNET_IDENTITY_PROVIDER_get_attributes_start (idp_handle,
369 const struct GNUNET_CONFIGURATION_Handle *c)
372 if (NULL == ego_name)
374 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
375 _("Ego is required\n"));
379 idp_handle = GNUNET_IDENTITY_PROVIDER_connect (c);
381 identity_handle = GNUNET_IDENTITY_connect (c,
390 main(int argc, char *const argv[])
392 exp_interval = GNUNET_TIME_UNIT_HOURS;
393 struct GNUNET_GETOPT_CommandLineOption options[] = {
395 GNUNET_GETOPT_option_string ('a',
398 gettext_noop ("Add attribute"),
401 GNUNET_GETOPT_option_string ('V',
404 gettext_noop ("Attribute value"),
406 GNUNET_GETOPT_option_string ('e',
409 gettext_noop ("Ego"),
411 GNUNET_GETOPT_option_string ('r',
414 gettext_noop ("Audience (relying party)"),
416 GNUNET_GETOPT_option_flag ('D',
418 gettext_noop ("List attributes for Ego"),
420 GNUNET_GETOPT_option_string ('i',
423 gettext_noop ("Issue a ticket"),
425 GNUNET_GETOPT_option_string ('C',
428 gettext_noop ("Consume a ticket"),
430 GNUNET_GETOPT_option_string ('R',
433 gettext_noop ("Revoke a ticket"),
435 GNUNET_GETOPT_option_string ('t',
438 gettext_noop ("Type of attribute"),
440 GNUNET_GETOPT_option_relative_time ('E',
443 gettext_noop ("Expiration interval of the attribute"),
446 GNUNET_GETOPT_OPTION_END
448 return (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "ct",