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* ego_name;
72 static struct GNUNET_IDENTITY_Handle *identity_handle;
77 static struct GNUNET_IDENTITY_PROVIDER_Handle *idp_handle;
82 static struct GNUNET_IDENTITY_PROVIDER_Operation *idp_op;
87 static struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *attr_iterator;
92 static struct GNUNET_CRYPTO_AbeMasterKey *abe_key;
97 static const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
102 static struct GNUNET_CRYPTO_EcdsaPublicKey rp_key;
107 static struct GNUNET_IDENTITY_PROVIDER_Ticket ticket;
112 static struct GNUNET_IDENTITY_PROVIDER_AttributeList *attr_list;
115 do_cleanup(void *cls)
117 if (NULL != attr_iterator)
118 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (attr_iterator);
119 if (NULL != idp_handle)
120 GNUNET_IDENTITY_PROVIDER_disconnect (idp_handle);
121 if (NULL != identity_handle)
122 GNUNET_IDENTITY_disconnect (identity_handle);
124 GNUNET_free (abe_key);
125 if (NULL != attr_list)
126 GNUNET_free (attr_list);
130 ticket_issue_cb (void* cls,
131 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket)
134 if (NULL != ticket) {
135 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
136 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
139 GNUNET_free (ticket_str);
141 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
145 store_attr_cont (void *cls,
149 if (GNUNET_SYSERR == success) {
150 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
153 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
154 "Successfully added identity attribute %s=%s\n",
155 attr_name, attr_value);
157 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
161 process_attrs (void *cls,
162 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
163 const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr)
165 if (NULL == identity)
167 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
170 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
171 "%s: %s\n", attr->name, (char*)attr->data);
176 iter_error (void *cls)
178 attr_iterator = NULL;
179 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
180 "Failed to iterate over attributes\n");
181 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
185 iter_finished (void *cls)
187 struct GNUNET_IDENTITY_PROVIDER_Attribute *attr;
189 attr_iterator = NULL;
191 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
196 idp_op = GNUNET_IDENTITY_PROVIDER_idp_ticket_issue (idp_handle,
204 if (consume_ticket) {
205 idp_op = GNUNET_IDENTITY_PROVIDER_rp_ticket_consume (idp_handle,
212 attr = GNUNET_IDENTITY_PROVIDER_attribute_new (attr_name,
213 GNUNET_IDENTITY_PROVIDER_AT_STRING,
215 strlen (attr_value));
216 idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle,
227 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
228 const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr)
230 struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le;
236 attrs_tmp = GNUNET_strdup (issue_attrs);
237 attr_str = strtok (attrs_tmp, ",");
238 while (NULL != attr_str) {
239 if (0 != strcmp (attr_str, attr->name)) {
240 attr_str = strtok (NULL, ",");
243 le = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry);
244 le->attribute = GNUNET_IDENTITY_PROVIDER_attribute_new (attr->name,
245 attr->attribute_type,
248 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
249 attr_list->list_tail,
253 GNUNET_free (attrs_tmp);
255 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
256 "%s: %s\n", attr->name, (char*)attr->data);
258 GNUNET_IDENTITY_PROVIDER_get_attributes_next (attr_iterator);
263 struct GNUNET_IDENTITY_Ego *ego,
269 if (0 != strcmp (name, ego_name))
271 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
274 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
277 if (NULL != consume_ticket)
278 GNUNET_STRINGS_string_to_data (consume_ticket,
279 strlen (consume_ticket),
281 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
283 attr_list = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeList);
285 attr_iterator = GNUNET_IDENTITY_PROVIDER_get_attributes_start (idp_handle,
301 const struct GNUNET_CONFIGURATION_Handle *c)
304 if (NULL == ego_name)
306 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
307 _("Ego is required\n"));
311 idp_handle = GNUNET_IDENTITY_PROVIDER_connect (c);
313 identity_handle = GNUNET_IDENTITY_connect (c,
322 main(int argc, char *const argv[])
324 struct GNUNET_GETOPT_CommandLineOption options[] = {
326 GNUNET_GETOPT_option_string ('a',
329 gettext_noop ("Add attribute"),
332 GNUNET_GETOPT_option_string ('V',
335 gettext_noop ("Attribute value"),
337 GNUNET_GETOPT_option_string ('e',
340 gettext_noop ("Ego"),
342 GNUNET_GETOPT_option_string ('r',
345 gettext_noop ("Audience (relying party)"),
347 GNUNET_GETOPT_option_flag ('D',
349 gettext_noop ("List attributes for Ego"),
351 GNUNET_GETOPT_option_string ('i',
354 gettext_noop ("Issue a ticket"),
356 GNUNET_GETOPT_option_string ('C',
359 gettext_noop ("Consume a ticket"),
361 GNUNET_GETOPT_OPTION_END
363 return GNUNET_PROGRAM_run (argc, argv, "ct",