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* revoke_ticket;
77 static char* ego_name;
82 static struct GNUNET_IDENTITY_Handle *identity_handle;
87 static struct GNUNET_IDENTITY_PROVIDER_Handle *idp_handle;
92 static struct GNUNET_IDENTITY_PROVIDER_Operation *idp_op;
97 static struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *attr_iterator;
102 static struct GNUNET_CRYPTO_AbeMasterKey *abe_key;
107 static const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
112 static struct GNUNET_CRYPTO_EcdsaPublicKey rp_key;
117 static struct GNUNET_IDENTITY_PROVIDER_Ticket ticket;
122 static struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attr_list;
125 do_cleanup(void *cls)
127 if (NULL != attr_iterator)
128 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (attr_iterator);
129 if (NULL != idp_handle)
130 GNUNET_IDENTITY_PROVIDER_disconnect (idp_handle);
131 if (NULL != identity_handle)
132 GNUNET_IDENTITY_disconnect (identity_handle);
134 GNUNET_free (abe_key);
135 if (NULL != attr_list)
136 GNUNET_free (attr_list);
140 ticket_issue_cb (void* cls,
141 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket)
144 if (NULL != ticket) {
145 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
146 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
149 GNUNET_free (ticket_str);
151 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
155 store_attr_cont (void *cls,
159 if (GNUNET_SYSERR == success) {
160 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
163 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
167 process_attrs (void *cls,
168 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
169 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr)
172 if (NULL == identity)
174 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
182 claim = GNUNET_IDENTITY_ATTRIBUTE_claim_to_string (attr->type,
185 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
186 "%s: %s\n", attr->name, claim);
191 iter_error (void *cls)
193 attr_iterator = NULL;
194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
195 "Failed to iterate over attributes\n");
196 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
200 process_rvk (void *cls, int success, const char* msg)
202 if (GNUNET_OK != success)
204 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
205 "Revocation failed.\n");
208 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
212 iter_finished (void *cls)
214 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr;
216 attr_iterator = NULL;
219 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
225 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_issue (idp_handle,
235 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume (idp_handle,
244 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_revoke (idp_handle,
251 attr = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr_name,
252 GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING,
254 strlen (attr_value) + 1);
255 idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle,
266 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
267 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr)
269 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le;
275 attrs_tmp = GNUNET_strdup (issue_attrs);
276 attr_str = strtok (attrs_tmp, ",");
277 while (NULL != attr_str) {
278 if (0 != strcmp (attr_str, attr->name)) {
279 attr_str = strtok (NULL, ",");
282 le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry);
283 le->claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr->name,
287 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
288 attr_list->list_tail,
292 GNUNET_free (attrs_tmp);
294 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
295 "%s: %s\n", attr->name, (char*)attr->data);
297 GNUNET_IDENTITY_PROVIDER_get_attributes_next (attr_iterator);
302 struct GNUNET_IDENTITY_Ego *ego,
308 if (0 != strcmp (name, ego_name))
310 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
313 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
316 if (NULL != consume_ticket)
317 GNUNET_STRINGS_string_to_data (consume_ticket,
318 strlen (consume_ticket),
320 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
321 if (NULL != revoke_ticket)
322 GNUNET_STRINGS_string_to_data (revoke_ticket,
323 strlen (revoke_ticket),
325 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
328 attr_list = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList);
330 attr_iterator = GNUNET_IDENTITY_PROVIDER_get_attributes_start (idp_handle,
346 const struct GNUNET_CONFIGURATION_Handle *c)
349 if (NULL == ego_name)
351 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
352 _("Ego is required\n"));
356 idp_handle = GNUNET_IDENTITY_PROVIDER_connect (c);
358 identity_handle = GNUNET_IDENTITY_connect (c,
367 main(int argc, char *const argv[])
369 struct GNUNET_GETOPT_CommandLineOption options[] = {
371 GNUNET_GETOPT_option_string ('a',
374 gettext_noop ("Add attribute"),
377 GNUNET_GETOPT_option_string ('V',
380 gettext_noop ("Attribute value"),
382 GNUNET_GETOPT_option_string ('e',
385 gettext_noop ("Ego"),
387 GNUNET_GETOPT_option_string ('r',
390 gettext_noop ("Audience (relying party)"),
392 GNUNET_GETOPT_option_flag ('D',
394 gettext_noop ("List attributes for Ego"),
396 GNUNET_GETOPT_option_string ('i',
399 gettext_noop ("Issue a ticket"),
401 GNUNET_GETOPT_option_string ('C',
404 gettext_noop ("Consume a ticket"),
406 GNUNET_GETOPT_option_string ('R',
409 gettext_noop ("Revoke a ticket"),
411 GNUNET_GETOPT_OPTION_END
413 GNUNET_PROGRAM_run (argc, argv, "ct",