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"
47 static char* attr_name;
52 static char* attr_value;
57 static char* issue_attrs;
62 static char* consume_ticket;
67 static char* revoke_ticket;
72 static char* ego_name;
77 static struct GNUNET_IDENTITY_Handle *identity_handle;
82 static struct GNUNET_IDENTITY_PROVIDER_Handle *idp_handle;
87 static struct GNUNET_IDENTITY_PROVIDER_Operation *idp_op;
92 static struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *attr_iterator;
97 static struct GNUNET_CRYPTO_AbeMasterKey *abe_key;
102 static const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
107 static struct GNUNET_CRYPTO_EcdsaPublicKey rp_key;
112 static struct GNUNET_IDENTITY_PROVIDER_Ticket ticket;
117 static struct GNUNET_IDENTITY_PROVIDER_AttributeList *attr_list;
120 do_cleanup(void *cls)
122 if (NULL != attr_iterator)
123 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (attr_iterator);
124 if (NULL != idp_handle)
125 GNUNET_IDENTITY_PROVIDER_disconnect (idp_handle);
126 if (NULL != identity_handle)
127 GNUNET_IDENTITY_disconnect (identity_handle);
129 GNUNET_free (abe_key);
130 if (NULL != attr_list)
131 GNUNET_free (attr_list);
135 ticket_issue_cb (void* cls,
136 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket)
139 if (NULL != ticket) {
140 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
141 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
144 GNUNET_free (ticket_str);
146 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
150 store_attr_cont (void *cls,
154 if (GNUNET_SYSERR == success) {
155 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
158 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
159 "Successfully added identity attribute %s=%s\n",
160 attr_name, attr_value);
162 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
166 process_attrs (void *cls,
167 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
168 const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr)
170 if (NULL == identity)
172 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
175 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
176 "%s: %s\n", attr->name, (char*)attr->data);
181 iter_error (void *cls)
183 attr_iterator = NULL;
184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
185 "Failed to iterate over attributes\n");
186 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
190 process_rvk (void *cls, int success, const char* msg)
192 if (GNUNET_OK != success)
193 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
194 "Revocation failed.\n");
196 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
197 "Revocation successful.\n");
198 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
202 iter_finished (void *cls)
204 struct GNUNET_IDENTITY_PROVIDER_Attribute *attr;
206 attr_iterator = NULL;
209 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
215 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_issue (idp_handle,
225 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume (idp_handle,
234 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_revoke (idp_handle,
241 attr = GNUNET_IDENTITY_PROVIDER_attribute_new (attr_name,
242 GNUNET_IDENTITY_PROVIDER_AT_STRING,
244 strlen (attr_value));
245 idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle,
256 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
257 const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr)
259 struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le;
265 attrs_tmp = GNUNET_strdup (issue_attrs);
266 attr_str = strtok (attrs_tmp, ",");
267 while (NULL != attr_str) {
268 if (0 != strcmp (attr_str, attr->name)) {
269 attr_str = strtok (NULL, ",");
272 le = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry);
273 le->attribute = GNUNET_IDENTITY_PROVIDER_attribute_new (attr->name,
274 attr->attribute_type,
277 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
278 attr_list->list_tail,
282 GNUNET_free (attrs_tmp);
284 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
285 "%s: %s\n", attr->name, (char*)attr->data);
287 GNUNET_IDENTITY_PROVIDER_get_attributes_next (attr_iterator);
292 struct GNUNET_IDENTITY_Ego *ego,
298 if (0 != strcmp (name, ego_name))
300 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
303 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
306 if (NULL != consume_ticket)
307 GNUNET_STRINGS_string_to_data (consume_ticket,
308 strlen (consume_ticket),
310 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
311 if (NULL != revoke_ticket)
312 GNUNET_STRINGS_string_to_data (revoke_ticket,
313 strlen (revoke_ticket),
315 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
318 attr_list = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeList);
320 attr_iterator = GNUNET_IDENTITY_PROVIDER_get_attributes_start (idp_handle,
336 const struct GNUNET_CONFIGURATION_Handle *c)
339 if (NULL == ego_name)
341 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
342 _("Ego is required\n"));
346 idp_handle = GNUNET_IDENTITY_PROVIDER_connect (c);
348 identity_handle = GNUNET_IDENTITY_connect (c,
357 main(int argc, char *const argv[])
359 struct GNUNET_GETOPT_CommandLineOption options[] = {
361 GNUNET_GETOPT_option_string ('a',
364 gettext_noop ("Add attribute"),
367 GNUNET_GETOPT_option_string ('V',
370 gettext_noop ("Attribute value"),
372 GNUNET_GETOPT_option_string ('e',
375 gettext_noop ("Ego"),
377 GNUNET_GETOPT_option_string ('r',
380 gettext_noop ("Audience (relying party)"),
382 GNUNET_GETOPT_option_flag ('D',
384 gettext_noop ("List attributes for Ego"),
386 GNUNET_GETOPT_option_string ('i',
389 gettext_noop ("Issue a ticket"),
391 GNUNET_GETOPT_option_string ('C',
394 gettext_noop ("Consume a ticket"),
396 GNUNET_GETOPT_option_string ('R',
399 gettext_noop ("Revoke a ticket"),
401 GNUNET_GETOPT_OPTION_END
403 return GNUNET_PROGRAM_run (argc, argv, "ct",