diff options
author | jospaeth <spaethj@in.tum.de> | 2020-08-10 18:45:30 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-08-10 18:45:30 +0200 |
commit | f2fb911d529db3787b15e39b8a41e081ea626e41 (patch) | |
tree | 606d866cc25a4b8b4bb6deead07bc6282df16b94 /src/escrow/plugin_escrow_gns.c | |
parent | b2ebdaca4d0d3a4f1fac2f2f83cdedf4123a43b8 (diff) | |
download | gnunet-f2fb911d529db3787b15e39b8a41e081ea626e41.tar.gz gnunet-f2fb911d529db3787b15e39b8a41e081ea626e41.zip |
continue start_gns_escrow, add user secret string
Diffstat (limited to 'src/escrow/plugin_escrow_gns.c')
-rw-r--r-- | src/escrow/plugin_escrow_gns.c | 168 |
1 files changed, 142 insertions, 26 deletions
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c index 8859275c6..2d3343389 100644 --- a/src/escrow/plugin_escrow_gns.c +++ b/src/escrow/plugin_escrow_gns.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "gnunet_escrow_plugin.h" | 30 | #include "gnunet_escrow_plugin.h" |
31 | #include "escrow_plugin_helper.h" | 31 | #include "escrow_plugin_helper.h" |
32 | #include "gnunet_namestore_service.h" | 32 | #include "gnunet_namestore_service.h" |
33 | #include "gnunet_gnsrecord_lib.h" | ||
33 | #include "../identity/identity.h" | 34 | #include "../identity/identity.h" |
34 | #include <sss.h> | 35 | #include <sss.h> |
35 | #include <inttypes.h> | 36 | #include <inttypes.h> |
@@ -75,6 +76,30 @@ struct PkEntry | |||
75 | * private key | 76 | * private key |
76 | */ | 77 | */ |
77 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 78 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; |
79 | |||
80 | /** | ||
81 | * index of the respective share | ||
82 | */ | ||
83 | uint8_t i; | ||
84 | }; | ||
85 | |||
86 | |||
87 | struct NamestoreQueueEntry | ||
88 | { | ||
89 | /** | ||
90 | * DLL | ||
91 | */ | ||
92 | struct NamestoreQueueEntry *prev; | ||
93 | |||
94 | /** | ||
95 | * DLL | ||
96 | */ | ||
97 | struct NamestoreQueueEntry *next; | ||
98 | |||
99 | /** | ||
100 | * Namestore queue entry | ||
101 | */ | ||
102 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; | ||
78 | }; | 103 | }; |
79 | 104 | ||
80 | 105 | ||
@@ -137,6 +162,11 @@ struct ESCROW_GnsPluginOperation | |||
137 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 162 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; |
138 | 163 | ||
139 | /** | 164 | /** |
165 | * User secret string | ||
166 | */ | ||
167 | char *userSecret; | ||
168 | |||
169 | /** | ||
140 | * DLL head for identity operations | 170 | * DLL head for identity operations |
141 | */ | 171 | */ |
142 | struct IdentityOperationEntry *id_ops_head; | 172 | struct IdentityOperationEntry *id_ops_head; |
@@ -155,6 +185,16 @@ struct ESCROW_GnsPluginOperation | |||
155 | * DLL tail for escrow private keys | 185 | * DLL tail for escrow private keys |
156 | */ | 186 | */ |
157 | struct PkEntry *escrow_pks_tail; | 187 | struct PkEntry *escrow_pks_tail; |
188 | |||
189 | /** | ||
190 | * DLL head for namestore queue entries | ||
191 | */ | ||
192 | struct NamestoreQueueEntry *ns_qes_head; | ||
193 | |||
194 | /** | ||
195 | * DLL tail for namestore queue entries | ||
196 | */ | ||
197 | struct NamestoreQueueEntry *ns_qes_tail; | ||
158 | }; | 198 | }; |
159 | 199 | ||
160 | /** | 200 | /** |
@@ -178,6 +218,7 @@ cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
178 | struct ESCROW_GnsPluginOperation *p_op; | 218 | struct ESCROW_GnsPluginOperation *p_op; |
179 | struct IdentityOperationEntry *curr_id_op; | 219 | struct IdentityOperationEntry *curr_id_op; |
180 | struct PkEntry *curr_pk; | 220 | struct PkEntry *curr_pk; |
221 | struct NamestoreQueueEntry *curr_ns_qe; | ||
181 | 222 | ||
182 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | 223 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; |
183 | 224 | ||
@@ -190,6 +231,8 @@ cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
190 | GNUNET_free (p_op->ego_wrap); | 231 | GNUNET_free (p_op->ego_wrap); |
191 | if (NULL != p_op->verify_wrap) | 232 | if (NULL != p_op->verify_wrap) |
192 | GNUNET_free (p_op->verify_wrap); | 233 | GNUNET_free (p_op->verify_wrap); |
234 | if (NULL != p_op->userSecret) | ||
235 | GNUNET_free (p_op->userSecret); | ||
193 | /* clean up identity operation list */ | 236 | /* clean up identity operation list */ |
194 | for (curr_id_op = p_op->id_ops_head; NULL != curr_id_op; curr_id_op = curr_id_op->next) | 237 | for (curr_id_op = p_op->id_ops_head; NULL != curr_id_op; curr_id_op = curr_id_op->next) |
195 | { | 238 | { |
@@ -208,6 +251,16 @@ cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
208 | curr_pk); | 251 | curr_pk); |
209 | GNUNET_free (curr_pk); | 252 | GNUNET_free (curr_pk); |
210 | } | 253 | } |
254 | /* clean up namestore operation list */ | ||
255 | for (curr_ns_qe = p_op->ns_qes_head; NULL != curr_ns_qe; curr_ns_qe = curr_ns_qe->next) | ||
256 | { | ||
257 | GNUNET_CONTAINER_DLL_remove (p_op->ns_qes_head, | ||
258 | p_op->ns_qes_tail, | ||
259 | curr_ns_qe); | ||
260 | // also frees the curr_ns_qe->ns_qe | ||
261 | GNUNET_NAMESTORE_cancel (curr_ns_qe->ns_qe); | ||
262 | GNUNET_free (curr_ns_qe); | ||
263 | } | ||
211 | /* disconnect from namestore service */ | 264 | /* disconnect from namestore service */ |
212 | GNUNET_NAMESTORE_disconnect (p_op->ns_h); | 265 | GNUNET_NAMESTORE_disconnect (p_op->ns_h); |
213 | GNUNET_free (p_op); | 266 | GNUNET_free (p_op); |
@@ -243,29 +296,92 @@ split_private_key (struct ESCROW_GnsPluginOperation *p_op) | |||
243 | } | 296 | } |
244 | 297 | ||
245 | 298 | ||
246 | void | 299 | static void |
247 | distribute_keyshares (struct ESCROW_GnsPluginOperation *p_op, | 300 | keyshare_distribution_finished (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) |
301 | { | ||
302 | struct ESCROW_GnsPluginOperation *p_op; | ||
303 | struct GNUNET_ESCROW_Anchor *anchor; | ||
304 | int anchorDataSize; | ||
305 | |||
306 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | ||
307 | |||
308 | // TODO: implement | ||
309 | anchorDataSize = 0; // TODO! | ||
310 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize); | ||
311 | |||
312 | p_op->anchor_wrap->escrowAnchor = anchor; | ||
313 | |||
314 | /* call the continuation */ | ||
315 | start_cont (plugin_op_wrap); | ||
316 | } | ||
317 | |||
318 | |||
319 | static void | ||
320 | keyshare_distributed (void *cls, | ||
321 | int32_t success, | ||
322 | const char *emsg) | ||
323 | { | ||
324 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
325 | struct ESCROW_GnsPluginOperation *p_op; | ||
326 | |||
327 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | ||
328 | |||
329 | if (GNUNET_SYSERR == success) | ||
330 | { | ||
331 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
332 | "Failed to store keyshare %s\n", | ||
333 | emsg); | ||
334 | p_op->anchor_wrap->escrowAnchor = NULL; | ||
335 | p_op->cont (p_op->anchor_wrap); | ||
336 | // this also cancels all running namestore operations | ||
337 | cleanup_plugin_operation (plugin_op_wrap); | ||
338 | } | ||
339 | |||
340 | // TODO: remove qe from list, check if all namestore operations are finished | ||
341 | keyshare_distribution_finished (plugin_op_wrap); | ||
342 | } | ||
343 | |||
344 | |||
345 | static int | ||
346 | distribute_keyshares (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | ||
248 | sss_Keyshare *keyshares) | 347 | sss_Keyshare *keyshares) |
249 | { | 348 | { |
349 | struct ESCROW_GnsPluginOperation *p_op; | ||
250 | struct GNUNET_NAMESTORE_Handle *ns_h; | 350 | struct GNUNET_NAMESTORE_Handle *ns_h; |
351 | struct NamestoreQueueEntry *curr_ns_qe; | ||
251 | struct PkEntry *curr_pk; | 352 | struct PkEntry *curr_pk; |
252 | char *curr_label; | 353 | char *curr_label; |
354 | struct GNUNET_GNSRECORD_Data curr_rd[1]; | ||
355 | |||
356 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | ||
253 | 357 | ||
254 | ns_h = GNUNET_NAMESTORE_connect (p_op->h->cfg); | 358 | ns_h = GNUNET_NAMESTORE_connect (p_op->h->cfg); |
255 | p_op->ns_h = ns_h; | 359 | p_op->ns_h = ns_h; |
256 | 360 | ||
257 | for (curr_pk = p_op->escrow_pks_head; NULL != curr_pk; curr_pk = curr_pk->next) | 361 | for (curr_pk = p_op->escrow_pks_head; NULL != curr_pk; curr_pk = curr_pk->next) |
258 | { | 362 | { |
259 | // TODO: implement | 363 | curr_label = NULL; // TODO: which label |
260 | curr_label = NULL; | 364 | curr_ns_qe = GNUNET_new (struct NamestoreQueueEntry); |
261 | GNUNET_NAMESTORE_records_store (ns_h, | 365 | |
262 | curr_pk->pk, | 366 | curr_rd[0].data_size = sizeof (sss_Keyshare); |
263 | curr_label, | 367 | curr_rd[0].data = keyshares[curr_pk->i]; |
264 | 0, | 368 | curr_rd[0].record_type = GNUNET_GNSRECORD_TYPE_ATTRIBUTE; // TODO: type |
265 | NULL, | 369 | curr_rd[0].flags = GNUNET_GNSRECORD_RF_NONE; // TODO: flags |
266 | NULL, | 370 | curr_rd[0].expiration_time = 0; // TODO: expiration time |
267 | NULL); | 371 | |
372 | curr_ns_qe->ns_qe = GNUNET_NAMESTORE_records_store (ns_h, | ||
373 | curr_pk->pk, | ||
374 | curr_label, | ||
375 | 1, | ||
376 | curr_rd, | ||
377 | &keyshare_distributed, | ||
378 | plugin_op_wrap); | ||
379 | GNUNET_CONTAINER_DLL_insert_tail (p_op->ns_qes_head, | ||
380 | p_op->ns_qes_tail, | ||
381 | curr_ns_qe); | ||
268 | } | 382 | } |
383 | |||
384 | return GNUNET_OK; | ||
269 | } | 385 | } |
270 | 386 | ||
271 | 387 | ||
@@ -274,8 +390,6 @@ escrow_ids_finished (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
274 | { | 390 | { |
275 | struct ESCROW_GnsPluginOperation *p_op; | 391 | struct ESCROW_GnsPluginOperation *p_op; |
276 | sss_Keyshare *keyshares; | 392 | sss_Keyshare *keyshares; |
277 | struct GNUNET_ESCROW_Anchor *anchor; | ||
278 | int anchorDataSize; | ||
279 | 393 | ||
280 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 394 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
281 | 395 | ||
@@ -284,22 +398,20 @@ escrow_ids_finished (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
284 | if (NULL == keyshares) | 398 | if (NULL == keyshares) |
285 | { | 399 | { |
286 | p_op->anchor_wrap->escrowAnchor = NULL; | 400 | p_op->anchor_wrap->escrowAnchor = NULL; |
287 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, p_op); | 401 | start_cont (plugin_op_wrap); |
288 | return; | 402 | return; |
289 | } | 403 | } |
290 | 404 | ||
291 | /* distribute the shares to the identities */ | 405 | /* distribute the shares to the identities */ |
292 | distribute_keyshares (p_op, keyshares); | 406 | if (GNUNET_OK != distribute_keyshares (plugin_op_wrap, keyshares)) |
293 | 407 | { | |
294 | // TODO: implement | 408 | p_op->anchor_wrap->escrowAnchor = NULL; |
295 | anchorDataSize = 0; // TODO! | 409 | start_cont (plugin_op_wrap); |
296 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize); | 410 | return; |
411 | } | ||
297 | 412 | ||
298 | p_op->anchor_wrap->escrowAnchor = anchor; | 413 | /* operation continues in keyshare_distribution_finished |
299 | 414 | after all keyshares have been distributed */ | |
300 | /* call the continuation */ | ||
301 | p_op->cont (p_op->anchor_wrap); | ||
302 | cleanup_plugin_operation (plugin_op_wrap); | ||
303 | } | 415 | } |
304 | 416 | ||
305 | 417 | ||
@@ -448,7 +560,7 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
448 | 560 | ||
449 | for (uint8_t i = 0; i < p_op->shares; i++) | 561 | for (uint8_t i = 0; i < p_op->shares; i++) |
450 | { | 562 | { |
451 | curr_pk = derive_private_key (name, NULL, i); // TODO: password | 563 | curr_pk = derive_private_key (name, p_op->userSecret, i); |
452 | curr_name = get_escrow_id_name (name, i); | 564 | curr_name = get_escrow_id_name (name, i); |
453 | 565 | ||
454 | // check if the escrow identity already exists | 566 | // check if the escrow identity already exists |
@@ -466,6 +578,7 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
466 | // the escrow id already exists, so insert the pk into our list | 578 | // the escrow id already exists, so insert the pk into our list |
467 | curr_pk_entry = GNUNET_new (struct PkEntry); | 579 | curr_pk_entry = GNUNET_new (struct PkEntry); |
468 | curr_pk_entry->pk = curr_pk; | 580 | curr_pk_entry->pk = curr_pk; |
581 | curr_pk_entry->i = i; | ||
469 | GNUNET_CONTAINER_DLL_insert (p_op->escrow_pks_head, | 582 | GNUNET_CONTAINER_DLL_insert (p_op->escrow_pks_head, |
470 | p_op->escrow_pks_tail, | 583 | p_op->escrow_pks_tail, |
471 | curr_pk_entry); | 584 | curr_pk_entry); |
@@ -493,6 +606,7 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
493 | * | 606 | * |
494 | * @param h the handle for the escrow component | 607 | * @param h the handle for the escrow component |
495 | * @param ego the identity ego containing the private key | 608 | * @param ego the identity ego containing the private key |
609 | * @param userSecret the user secret (e.g. for derivation of escrow identities) | ||
496 | * @param cb the function called upon completion | 610 | * @param cb the function called upon completion |
497 | * @param op_id unique ID of the respective ESCROW_Operation | 611 | * @param op_id unique ID of the respective ESCROW_Operation |
498 | * | 612 | * |
@@ -501,6 +615,7 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
501 | struct ESCROW_PluginOperationWrapper * | 615 | struct ESCROW_PluginOperationWrapper * |
502 | start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | 616 | start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, |
503 | struct GNUNET_IDENTITY_Ego *ego, | 617 | struct GNUNET_IDENTITY_Ego *ego, |
618 | char *userSecret, | ||
504 | GNUNET_SCHEDULER_TaskCallback cb, | 619 | GNUNET_SCHEDULER_TaskCallback cb, |
505 | uint32_t op_id) | 620 | uint32_t op_id) |
506 | { | 621 | { |
@@ -525,13 +640,14 @@ start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
525 | w->op_id = op_id; | 640 | w->op_id = op_id; |
526 | p_op->anchor_wrap = w; | 641 | p_op->anchor_wrap = w; |
527 | 642 | ||
528 | if (NULL == ego) | 643 | if (NULL == ego || NULL == userSecret) |
529 | { | 644 | { |
530 | w->escrowAnchor = NULL; | 645 | w->escrowAnchor = NULL; |
531 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); | 646 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); |
532 | return plugin_op_wrap; | 647 | return plugin_op_wrap; |
533 | } | 648 | } |
534 | p_op->pk = GNUNET_IDENTITY_ego_get_private_key (ego); | 649 | p_op->pk = GNUNET_IDENTITY_ego_get_private_key (ego); |
650 | p_op->userSecret = userSecret; | ||
535 | 651 | ||
536 | // get config | 652 | // get config |
537 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg, | 653 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (h->cfg, |