aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2017-07-09 16:15:09 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2017-07-09 16:15:09 +0200
commited42d471aa6b5bf42bfc8e9186e69ab4c0ebc6ff (patch)
tree1a975c53bb76da706c80dba655d2ae40e992e22f
parentae3380b0cc18e3d06631aa5fec348f5dc5a940c9 (diff)
downloadgnunet-ed42d471aa6b5bf42bfc8e9186e69ab4c0ebc6ff.tar.gz
gnunet-ed42d471aa6b5bf42bfc8e9186e69ab4c0ebc6ff.zip
-add attr list
-rw-r--r--src/identity-provider/gnunet-idp.c138
1 files changed, 120 insertions, 18 deletions
diff --git a/src/identity-provider/gnunet-idp.c b/src/identity-provider/gnunet-idp.c
index 0dd565da6..017e0dbb5 100644
--- a/src/identity-provider/gnunet-idp.c
+++ b/src/identity-provider/gnunet-idp.c
@@ -31,6 +31,11 @@
31#include "gnunet_signatures.h" 31#include "gnunet_signatures.h"
32 32
33/** 33/**
34 * List attribute flag
35 */
36static int list;
37
38/**
34 * The attribute 39 * The attribute
35 */ 40 */
36static char* attr_name; 41static char* attr_name;
@@ -56,6 +61,11 @@ static struct GNUNET_IDENTITY_Handle *identity_handle;
56static struct GNUNET_NAMESTORE_Handle *namestore_handle; 61static struct GNUNET_NAMESTORE_Handle *namestore_handle;
57 62
58/** 63/**
64 * Namestore iterator
65 */
66static struct GNUNET_NAMESTORE_ZoneIterator *ns_iterator;
67
68/**
59 * Namestore queue 69 * Namestore queue
60 */ 70 */
61static struct GNUNET_NAMESTORE_QueueEntry *ns_qe; 71static struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
@@ -70,6 +80,8 @@ do_cleanup(void *cls)
70{ 80{
71 if (NULL != ns_qe) 81 if (NULL != ns_qe)
72 GNUNET_NAMESTORE_cancel (ns_qe); 82 GNUNET_NAMESTORE_cancel (ns_qe);
83 if (NULL != ns_iterator)
84 GNUNET_NAMESTORE_zone_iteration_stop (ns_iterator);
73 if (NULL != namestore_handle) 85 if (NULL != namestore_handle)
74 GNUNET_NAMESTORE_disconnect (namestore_handle); 86 GNUNET_NAMESTORE_disconnect (namestore_handle);
75 if (NULL != identity_handle) 87 if (NULL != identity_handle)
@@ -104,6 +116,58 @@ store_attr_cont (void *cls,
104} 116}
105 117
106static void 118static void
119store_abe_cont (void *cls,
120 int32_t success,
121 const char*emsg)
122{
123 if (GNUNET_SYSERR == success) {
124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
125 "%s\n", emsg);
126 } else {
127 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
128 "Bootstrapped ABE master key. Please run command again.\n");
129 }
130 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
131}
132
133static void
134iter_error (void *cls)
135{
136 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
137 "Failed to iterate over attributes\n");
138 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
139}
140
141static void
142iter_finished (void *cls)
143{
144 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
145}
146
147static void
148iter_cb (void *cls,
149 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
150 const char *label,
151 unsigned int rd_count,
152 const struct GNUNET_GNSRECORD_Data *rd)
153{
154 int i;
155 char *attr_value;
156
157 for (i=0;i<rd_count;i++) {
158 if (GNUNET_GNSRECORD_TYPE_ID_ATTR != rd[i].record_type)
159 continue;
160 GNUNET_CRYPTO_cpabe_decrypt_master (rd[i].data,
161 rd[i].data_size,
162 abe_key,
163 &attr_value);
164 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
165 "%s: %s\n", label, attr_value);
166 }
167 GNUNET_NAMESTORE_zone_iterator_next (ns_iterator);
168}
169
170static void
107abe_lookup_cb (void *cls, 171abe_lookup_cb (void *cls,
108 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 172 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
109 const char *label, 173 const char *label,
@@ -111,6 +175,7 @@ abe_lookup_cb (void *cls,
111 const struct GNUNET_GNSRECORD_Data *rd) 175 const struct GNUNET_GNSRECORD_Data *rd)
112{ 176{
113 struct GNUNET_GNSRECORD_Data new_record; 177 struct GNUNET_GNSRECORD_Data new_record;
178 struct GNUNET_CRYPTO_AbeMasterKey *new_key;
114 int i; 179 int i;
115 ssize_t size; 180 ssize_t size;
116 181
@@ -121,7 +186,32 @@ abe_lookup_cb (void *cls,
121 rd[i].data_size); 186 rd[i].data_size);
122 } 187 }
123 if (NULL == abe_key) { 188 if (NULL == abe_key) {
124 GNUNET_SCHEDULER_add_now (do_error, NULL); 189 new_key = GNUNET_CRYPTO_cpabe_create_master_key ();
190 size = GNUNET_CRYPTO_cpabe_serialize_master_key (new_key,
191 (void**)&new_record.data);
192 new_record.data_size = size;
193 new_record.record_type = GNUNET_GNSRECORD_TYPE_ABE_MASTER;
194 new_record.expiration_time = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us;
195 new_record.flags = GNUNET_GNSRECORD_RF_PRIVATE;
196 ns_qe = GNUNET_NAMESTORE_records_store (namestore_handle,
197 zone,
198 "+",
199 1,
200 &new_record,
201 &store_abe_cont,
202 NULL);
203 return;
204 }
205
206 if (list) {
207 ns_iterator = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
208 zone,
209 &iter_error,
210 NULL,
211 &iter_cb,
212 NULL,
213 &iter_finished,
214 NULL);
125 return; 215 return;
126 } 216 }
127 217
@@ -129,10 +219,10 @@ abe_lookup_cb (void *cls,
129 strlen (attr_value) + 1, 219 strlen (attr_value) + 1,
130 attr_name, 220 attr_name,
131 abe_key, 221 abe_key,
132 new_record.data); 222 (void**)&new_record.data);
133 new_record.data_size = size; 223 new_record.data_size = size;
134 new_record.record_type = GNUNET_GNSRECORD_TYPE_ABE_ID_ATTR; 224 new_record.record_type = GNUNET_GNSRECORD_TYPE_ID_ATTR;
135 new_record.expiration_time = GNUNET_TIME_UNIT_HOURS; 225 new_record.expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us;
136 new_record.flags = GNUNET_GNSRECORD_RF_NONE; 226 new_record.flags = GNUNET_GNSRECORD_RF_NONE;
137 227
138 ns_qe = GNUNET_NAMESTORE_records_store (namestore_handle, 228 ns_qe = GNUNET_NAMESTORE_records_store (namestore_handle,
@@ -150,7 +240,7 @@ ego_cb (void *cls,
150 void **ctx, 240 void **ctx,
151 const char *name) 241 const char *name)
152{ 242{
153 struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey; 243 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
154 if (0 != strcmp (name, ego_name)) 244 if (0 != strcmp (name, ego_name))
155 return; 245 return;
156 pkey = GNUNET_IDENTITY_ego_get_private_key (ego); 246 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
@@ -170,27 +260,29 @@ run (void *cls,
170 const struct GNUNET_CONFIGURATION_Handle *c) 260 const struct GNUNET_CONFIGURATION_Handle *c)
171{ 261{
172 262
173 if (NULL == attr_name)
174 {
175 return;
176 }
177 if (NULL == ego_name) 263 if (NULL == ego_name)
178 { 264 {
179 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 265 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
180 _("Ego is required\n")); 266 _("Ego is required\n"));
181 return; 267 return;
268 }
269
270 if ((NULL == attr_name) && !list)
271 {
272 return;
182 } 273 }
183 if (NULL == attr_value) 274 if ((NULL == attr_value) && !list)
184 { 275 {
185 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 276 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
186 _("Value is required\n")); 277 _("Value is required\n"));
187 return; 278 return;
188 } 279 }
189 namestore_handle = GNUNET_NAMESTORE_connect (cfgfile); 280
281 namestore_handle = GNUNET_NAMESTORE_connect (c);
190 //Get Ego 282 //Get Ego
191 identity_handle = GNUNE_IDENTITY_connect (cfgfile, 283 identity_handle = GNUNET_IDENTITY_connect (c,
192 &ego_cb, 284 &ego_cb,
193 NULL); 285 NULL);
194 286
195 287
196} 288}
@@ -207,10 +299,20 @@ main(int argc, char *const argv[])
207 gettext_noop ("Add attribute"), 299 gettext_noop ("Add attribute"),
208 &attr_name), 300 &attr_name),
209 301
210 GNUNET_GETOPT_option_flag ('V', 302 GNUNET_GETOPT_option_string ('V',
211 "value", 303 "value",
212 gettext_noop ("Attribute value"), 304 NULL,
213 &attr_value), 305 gettext_noop ("Attribute value"),
306 &attr_value),
307 GNUNET_GETOPT_option_string ('e',
308 "ego",
309 NULL,
310 gettext_noop ("Ego"),
311 &ego_name),
312 GNUNET_GETOPT_option_flag ('l',
313 "list",
314 gettext_noop ("List attributes for Ego"),
315 &list),
214 316
215 GNUNET_GETOPT_OPTION_END 317 GNUNET_GETOPT_OPTION_END
216 }; 318 };