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 do_cleanup(void *cls)
132 if (NULL != attr_iterator)
133 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (attr_iterator);
134 if (NULL != idp_handle)
135 GNUNET_IDENTITY_PROVIDER_disconnect (idp_handle);
136 if (NULL != identity_handle)
137 GNUNET_IDENTITY_disconnect (identity_handle);
139 GNUNET_free (abe_key);
140 if (NULL != attr_list)
141 GNUNET_free (attr_list);
145 ticket_issue_cb (void* cls,
146 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket)
149 if (NULL != ticket) {
150 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
151 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
154 GNUNET_free (ticket_str);
156 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
160 store_attr_cont (void *cls,
164 if (GNUNET_SYSERR == success) {
165 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
168 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
172 process_attrs (void *cls,
173 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
174 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr)
177 if (NULL == identity)
179 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
187 value_str = GNUNET_IDENTITY_ATTRIBUTE_value_to_string (attr->type,
190 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
191 "%s: %s\n", attr->name, value_str);
196 iter_error (void *cls)
198 attr_iterator = NULL;
199 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
200 "Failed to iterate over attributes\n");
201 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
205 process_rvk (void *cls, int success, const char* msg)
207 if (GNUNET_OK != success)
209 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
210 "Revocation failed.\n");
213 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
217 iter_finished (void *cls)
219 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *claim;
224 attr_iterator = NULL;
227 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
233 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_issue (idp_handle,
243 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume (idp_handle,
252 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_revoke (idp_handle,
259 if (NULL == type_str)
260 type = GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING;
262 type = GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (type_str);
264 GNUNET_assert (GNUNET_SYSERR != GNUNET_IDENTITY_ATTRIBUTE_string_to_value (type,
268 claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr_name,
272 idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle,
283 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
284 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr)
286 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le;
292 attrs_tmp = GNUNET_strdup (issue_attrs);
293 attr_str = strtok (attrs_tmp, ",");
294 while (NULL != attr_str) {
295 if (0 != strcmp (attr_str, attr->name)) {
296 attr_str = strtok (NULL, ",");
299 le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry);
300 le->claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr->name,
304 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
305 attr_list->list_tail,
309 GNUNET_free (attrs_tmp);
311 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
312 "%s: %s\n", attr->name, (char*)attr->data);
314 GNUNET_IDENTITY_PROVIDER_get_attributes_next (attr_iterator);
319 struct GNUNET_IDENTITY_Ego *ego,
325 if (0 != strcmp (name, ego_name))
327 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
330 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
333 if (NULL != consume_ticket)
334 GNUNET_STRINGS_string_to_data (consume_ticket,
335 strlen (consume_ticket),
337 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
338 if (NULL != revoke_ticket)
339 GNUNET_STRINGS_string_to_data (revoke_ticket,
340 strlen (revoke_ticket),
342 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
345 attr_list = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList);
347 attr_iterator = GNUNET_IDENTITY_PROVIDER_get_attributes_start (idp_handle,
363 const struct GNUNET_CONFIGURATION_Handle *c)
366 if (NULL == ego_name)
368 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
369 _("Ego is required\n"));
373 idp_handle = GNUNET_IDENTITY_PROVIDER_connect (c);
375 identity_handle = GNUNET_IDENTITY_connect (c,
384 main(int argc, char *const argv[])
386 struct GNUNET_GETOPT_CommandLineOption options[] = {
388 GNUNET_GETOPT_option_string ('a',
391 gettext_noop ("Add attribute"),
394 GNUNET_GETOPT_option_string ('V',
397 gettext_noop ("Attribute value"),
399 GNUNET_GETOPT_option_string ('e',
402 gettext_noop ("Ego"),
404 GNUNET_GETOPT_option_string ('r',
407 gettext_noop ("Audience (relying party)"),
409 GNUNET_GETOPT_option_flag ('D',
411 gettext_noop ("List attributes for Ego"),
413 GNUNET_GETOPT_option_string ('i',
416 gettext_noop ("Issue a ticket"),
418 GNUNET_GETOPT_option_string ('C',
421 gettext_noop ("Consume a ticket"),
423 GNUNET_GETOPT_option_string ('R',
426 gettext_noop ("Revoke a ticket"),
428 GNUNET_GETOPT_option_string ('t',
431 gettext_noop ("Type of attribute"),
433 GNUNET_GETOPT_OPTION_END
435 GNUNET_PROGRAM_run (argc, argv, "ct",