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_service.h"
31 #include "gnunet_signatures.h"
46 static char* attr_name;
51 static char* attr_value;
56 static char* ego_name;
61 static struct GNUNET_IDENTITY_Handle *identity_handle;
66 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
71 static struct GNUNET_NAMESTORE_ZoneIterator *ns_iterator;
76 static struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
81 static struct GNUNET_CRYPTO_AbeMasterKey *abe_key;
87 GNUNET_NAMESTORE_cancel (ns_qe);
88 if (NULL != ns_iterator)
89 GNUNET_NAMESTORE_zone_iteration_stop (ns_iterator);
90 if (NULL != namestore_handle)
91 GNUNET_NAMESTORE_disconnect (namestore_handle);
92 if (NULL != identity_handle)
93 GNUNET_IDENTITY_disconnect (identity_handle);
95 GNUNET_free (abe_key);
99 ns_error_cb (void *cls)
102 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
109 store_attr_cont (void *cls,
114 if (GNUNET_SYSERR == success) {
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
118 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
119 "Sucessfully added identity attribute %s=%s\n",
120 attr_name, attr_value);
122 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
126 store_abe_cont (void *cls,
131 if (GNUNET_SYSERR == success) {
132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
135 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
136 "Bootstrapped ABE master key. Please run command again.\n");
138 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
142 iter_error (void *cls)
145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
146 "Failed to iterate over attributes\n");
147 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
151 iter_finished (void *cls)
154 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
159 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
161 unsigned int rd_count,
162 const struct GNUNET_GNSRECORD_Data *rd)
164 struct GNUNET_CRYPTO_AbeKey *key;
168 for (i=0;i<rd_count;i++) {
169 if (GNUNET_GNSRECORD_TYPE_ID_ATTR != rd[i].record_type)
171 attrs[0] = (char*)label;
173 key = GNUNET_CRYPTO_cpabe_create_key (abe_key,
175 GNUNET_CRYPTO_cpabe_decrypt (rd[i].data,
178 (void**)&attr_value);
179 GNUNET_CRYPTO_cpabe_delete_key (key);
180 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
181 "%s: %s\n", label, attr_value);
183 GNUNET_NAMESTORE_zone_iterator_next (ns_iterator);
187 abe_lookup_cb (void *cls,
188 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
190 unsigned int rd_count,
191 const struct GNUNET_GNSRECORD_Data *rd)
193 struct GNUNET_GNSRECORD_Data new_record;
194 struct GNUNET_CRYPTO_AbeMasterKey *new_key;
198 for (i=0;i<rd_count;i++) {
199 if (GNUNET_GNSRECORD_TYPE_ABE_MASTER != rd[i].record_type)
201 abe_key = GNUNET_CRYPTO_cpabe_deserialize_master_key (rd[i].data,
204 if (NULL == abe_key) {
205 new_key = GNUNET_CRYPTO_cpabe_create_master_key ();
206 size = GNUNET_CRYPTO_cpabe_serialize_master_key (new_key,
207 (void**)&new_record.data);
208 new_record.data_size = size;
209 new_record.record_type = GNUNET_GNSRECORD_TYPE_ABE_MASTER;
210 new_record.expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us;
211 new_record.flags = GNUNET_GNSRECORD_RF_PRIVATE | GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
212 ns_qe = GNUNET_NAMESTORE_records_store (namestore_handle,
222 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
227 ns_iterator = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
238 size = GNUNET_CRYPTO_cpabe_encrypt (attr_value,
239 strlen (attr_value) + 1,
242 (void**)&new_record.data);
243 new_record.data_size = size;
244 new_record.record_type = GNUNET_GNSRECORD_TYPE_ID_ATTR;
245 new_record.expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us;
246 new_record.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
248 ns_qe = GNUNET_NAMESTORE_records_store (namestore_handle,
259 struct GNUNET_IDENTITY_Ego *ego,
263 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
266 if (0 != strcmp (name, ego_name))
268 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
269 ns_qe = GNUNET_NAMESTORE_records_lookup (namestore_handle,
282 const struct GNUNET_CONFIGURATION_Handle *c)
285 if (NULL == ego_name)
287 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
288 _("Ego is required\n"));
292 if ((NULL == attr_name) && !list && !init)
296 if ((NULL == attr_value) && !list && !init)
298 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
299 _("Value is required\n"));
303 namestore_handle = GNUNET_NAMESTORE_connect (c);
305 identity_handle = GNUNET_IDENTITY_connect (c,
314 main(int argc, char *const argv[])
316 struct GNUNET_GETOPT_CommandLineOption options[] = {
318 GNUNET_GETOPT_option_string ('a',
321 gettext_noop ("Add attribute"),
324 GNUNET_GETOPT_option_string ('V',
327 gettext_noop ("Attribute value"),
329 GNUNET_GETOPT_option_string ('e',
332 gettext_noop ("Ego"),
334 GNUNET_GETOPT_option_flag ('D',
336 gettext_noop ("List attributes for Ego"),
338 GNUNET_GETOPT_option_flag ('i',
340 gettext_noop ("Initialize attribute store"),
342 GNUNET_GETOPT_OPTION_END
344 return GNUNET_PROGRAM_run (argc, argv, "ct",