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_PROVIDER_AttributeList *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_PROVIDER_Attribute *attr)
171 if (NULL == identity)
173 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
181 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
182 "%s: %s\n", attr->name, (char*)attr->data);
187 iter_error (void *cls)
189 attr_iterator = NULL;
190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
191 "Failed to iterate over attributes\n");
192 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
196 process_rvk (void *cls, int success, const char* msg)
198 if (GNUNET_OK != success)
200 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
201 "Revocation failed.\n");
204 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
208 iter_finished (void *cls)
210 struct GNUNET_IDENTITY_PROVIDER_Attribute *attr;
212 attr_iterator = NULL;
215 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
221 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_issue (idp_handle,
231 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume (idp_handle,
240 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_revoke (idp_handle,
247 attr = GNUNET_IDENTITY_PROVIDER_attribute_new (attr_name,
248 GNUNET_IDENTITY_PROVIDER_AT_STRING,
250 strlen (attr_value) + 1);
251 idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle,
262 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
263 const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr)
265 struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le;
271 attrs_tmp = GNUNET_strdup (issue_attrs);
272 attr_str = strtok (attrs_tmp, ",");
273 while (NULL != attr_str) {
274 if (0 != strcmp (attr_str, attr->name)) {
275 attr_str = strtok (NULL, ",");
278 le = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry);
279 le->attribute = GNUNET_IDENTITY_PROVIDER_attribute_new (attr->name,
280 attr->attribute_type,
283 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
284 attr_list->list_tail,
288 GNUNET_free (attrs_tmp);
290 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
291 "%s: %s\n", attr->name, (char*)attr->data);
293 GNUNET_IDENTITY_PROVIDER_get_attributes_next (attr_iterator);
298 struct GNUNET_IDENTITY_Ego *ego,
304 if (0 != strcmp (name, ego_name))
306 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
309 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
312 if (NULL != consume_ticket)
313 GNUNET_STRINGS_string_to_data (consume_ticket,
314 strlen (consume_ticket),
316 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
317 if (NULL != revoke_ticket)
318 GNUNET_STRINGS_string_to_data (revoke_ticket,
319 strlen (revoke_ticket),
321 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
324 attr_list = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeList);
326 attr_iterator = GNUNET_IDENTITY_PROVIDER_get_attributes_start (idp_handle,
342 const struct GNUNET_CONFIGURATION_Handle *c)
345 if (NULL == ego_name)
347 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
348 _("Ego is required\n"));
352 idp_handle = GNUNET_IDENTITY_PROVIDER_connect (c);
354 identity_handle = GNUNET_IDENTITY_connect (c,
363 main(int argc, char *const argv[])
365 struct GNUNET_GETOPT_CommandLineOption options[] = {
367 GNUNET_GETOPT_option_string ('a',
370 gettext_noop ("Add attribute"),
373 GNUNET_GETOPT_option_string ('V',
376 gettext_noop ("Attribute value"),
378 GNUNET_GETOPT_option_string ('e',
381 gettext_noop ("Ego"),
383 GNUNET_GETOPT_option_string ('r',
386 gettext_noop ("Audience (relying party)"),
388 GNUNET_GETOPT_option_flag ('D',
390 gettext_noop ("List attributes for Ego"),
392 GNUNET_GETOPT_option_string ('i',
395 gettext_noop ("Issue a ticket"),
397 GNUNET_GETOPT_option_string ('C',
400 gettext_noop ("Consume a ticket"),
402 GNUNET_GETOPT_option_string ('R',
405 gettext_noop ("Revoke a ticket"),
407 GNUNET_GETOPT_OPTION_END
409 GNUNET_PROGRAM_run (argc, argv, "ct",