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* ego_name;
67 static struct GNUNET_IDENTITY_Handle *identity_handle;
72 static struct GNUNET_IDENTITY_PROVIDER_Handle *idp_handle;
77 static struct GNUNET_IDENTITY_PROVIDER_Operation *idp_op;
82 static struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *attr_iterator;
87 static struct GNUNET_CRYPTO_AbeMasterKey *abe_key;
92 static const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
97 static struct GNUNET_CRYPTO_EcdsaPublicKey rp_key;
103 static struct GNUNET_IDENTITY_PROVIDER_AttributeList *attr_list;
106 do_cleanup(void *cls)
108 if (NULL != attr_iterator)
109 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (attr_iterator);
110 if (NULL != idp_handle)
111 GNUNET_IDENTITY_PROVIDER_disconnect (idp_handle);
112 if (NULL != identity_handle)
113 GNUNET_IDENTITY_disconnect (identity_handle);
115 GNUNET_free (abe_key);
116 if (NULL != attr_list)
117 GNUNET_free (attr_list);
121 ticket_issue_cb (void* cls,
122 const struct GNUNET_IDENTITY_PROVIDER_Ticket2 *ticket)
125 if (NULL != ticket) {
126 ticket_str = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd,
128 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
131 GNUNET_free (ticket_str);
133 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
137 store_attr_cont (void *cls,
141 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
142 "Store continuation\n");
144 if (GNUNET_SYSERR == success) {
145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
148 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
149 "Sucessfully added identity attribute %s=%s\n",
150 attr_name, attr_value);
152 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
156 iter_error (void *cls)
158 attr_iterator = NULL;
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 "Failed to iterate over attributes\n");
161 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
165 iter_finished (void *cls)
167 struct GNUNET_IDENTITY_PROVIDER_Attribute *attr;
169 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
170 "Attribute collection finished!\n");
171 attr_iterator = NULL;
173 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
178 idp_op = GNUNET_IDENTITY_PROVIDER_idp_ticket_issue (idp_handle,
186 attr = GNUNET_IDENTITY_PROVIDER_attribute_new (attr_name,
187 GNUNET_IDENTITY_PROVIDER_AT_STRING,
189 strlen (attr_value));
190 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
191 "Adding attribute\n");
193 idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle,
204 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
205 const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr)
207 struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le;
213 attrs_tmp = GNUNET_strdup (issue_attrs);
214 attr_str = strtok (attrs_tmp, ",");
215 while (NULL != attr_str) {
216 if (0 != strcmp (attr_str, attr->name)) {
217 attr_str = strtok (NULL, ",");
220 le = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry);
221 le->attribute = GNUNET_IDENTITY_PROVIDER_attribute_new (attr->name,
222 attr->attribute_type,
225 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
226 attr_list->list_tail,
230 GNUNET_free (attrs_tmp);
232 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
233 "%s: %s\n", attr->name, (char*)attr->data);
235 GNUNET_IDENTITY_PROVIDER_get_attributes_next (attr_iterator);
240 struct GNUNET_IDENTITY_Ego *ego,
246 if (0 != strcmp (name, ego_name))
248 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
251 GNUNET_CRYPTO_ecdsa_public_key_from_string (rp,
255 attr_list = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeList);
257 attr_iterator = GNUNET_IDENTITY_PROVIDER_get_attributes_start (idp_handle,
273 const struct GNUNET_CONFIGURATION_Handle *c)
276 if (NULL == ego_name)
278 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
279 _("Ego is required\n"));
283 idp_handle = GNUNET_IDENTITY_PROVIDER_connect (c);
285 identity_handle = GNUNET_IDENTITY_connect (c,
294 main(int argc, char *const argv[])
296 struct GNUNET_GETOPT_CommandLineOption options[] = {
298 GNUNET_GETOPT_option_string ('a',
301 gettext_noop ("Add attribute"),
304 GNUNET_GETOPT_option_string ('V',
307 gettext_noop ("Attribute value"),
309 GNUNET_GETOPT_option_string ('e',
312 gettext_noop ("Ego"),
314 GNUNET_GETOPT_option_string ('r',
317 gettext_noop ("Audience (relying party)"),
319 GNUNET_GETOPT_option_flag ('D',
321 gettext_noop ("List attributes for Ego"),
323 GNUNET_GETOPT_option_string ('i',
326 gettext_noop ("Issue a ticket"),
328 GNUNET_GETOPT_OPTION_END
330 return GNUNET_PROGRAM_run (argc, argv, "ct",