diff options
author | jospaeth <spaethj@in.tum.de> | 2020-08-14 17:00:41 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-08-14 17:00:41 +0200 |
commit | 40b6d8bb8bbb36588318be02a6e7a130dfc3ee88 (patch) | |
tree | dea89b921dec63dcb69f937c7816d4f933bba407 /src/escrow/plugin_escrow_gns.c | |
parent | d08272011c55477a455d7ad0c316a5b8a98d69b3 (diff) | |
download | gnunet-40b6d8bb8bbb36588318be02a6e7a130dfc3ee88.tar.gz gnunet-40b6d8bb8bbb36588318be02a6e7a130dfc3ee88.zip |
fix some bugs in gns escrow, add pk derivation
Diffstat (limited to 'src/escrow/plugin_escrow_gns.c')
-rw-r--r-- | src/escrow/plugin_escrow_gns.c | 255 |
1 files changed, 175 insertions, 80 deletions
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c index aa5875dff..26bbcc06b 100644 --- a/src/escrow/plugin_escrow_gns.c +++ b/src/escrow/plugin_escrow_gns.c | |||
@@ -57,6 +57,21 @@ struct IdentityOperationEntry | |||
57 | * Private key of the respective ego | 57 | * Private key of the respective ego |
58 | */ | 58 | */ |
59 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 59 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; |
60 | |||
61 | /** | ||
62 | * Name of the respective ego | ||
63 | */ | ||
64 | const char *name; | ||
65 | |||
66 | /** | ||
67 | * Index of the respective share | ||
68 | */ | ||
69 | uint8_t i; | ||
70 | |||
71 | /** | ||
72 | * The plugin operation that started the identity operation | ||
73 | */ | ||
74 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap; | ||
60 | }; | 75 | }; |
61 | 76 | ||
62 | 77 | ||
@@ -100,6 +115,11 @@ struct NamestoreQueueEntry | |||
100 | * Namestore queue entry | 115 | * Namestore queue entry |
101 | */ | 116 | */ |
102 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; | 117 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; |
118 | |||
119 | /** | ||
120 | * Plugin operation that called the namestore operation | ||
121 | */ | ||
122 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap; | ||
103 | }; | 123 | }; |
104 | 124 | ||
105 | 125 | ||
@@ -164,7 +184,7 @@ struct ESCROW_GnsPluginOperation | |||
164 | /** | 184 | /** |
165 | * User secret string | 185 | * User secret string |
166 | */ | 186 | */ |
167 | char *userSecret; | 187 | const char *userSecret; |
168 | 188 | ||
169 | /** | 189 | /** |
170 | * DLL head for identity operations | 190 | * DLL head for identity operations |
@@ -216,9 +236,9 @@ void | |||
216 | cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | 236 | cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) |
217 | { | 237 | { |
218 | struct ESCROW_GnsPluginOperation *p_op; | 238 | struct ESCROW_GnsPluginOperation *p_op; |
219 | struct IdentityOperationEntry *curr_id_op; | 239 | struct IdentityOperationEntry *curr_id_op, *next_id_op; |
220 | struct PkEntry *curr_pk; | 240 | struct PkEntry *curr_pk, *next_pk; |
221 | struct NamestoreQueueEntry *curr_ns_qe; | 241 | struct NamestoreQueueEntry *curr_ns_qe, *next_ns_qe; |
222 | 242 | ||
223 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | 243 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; |
224 | 244 | ||
@@ -231,39 +251,41 @@ cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
231 | GNUNET_free (p_op->ego_wrap); | 251 | GNUNET_free (p_op->ego_wrap); |
232 | if (NULL != p_op->verify_wrap) | 252 | if (NULL != p_op->verify_wrap) |
233 | GNUNET_free (p_op->verify_wrap); | 253 | GNUNET_free (p_op->verify_wrap); |
234 | if (NULL != p_op->userSecret) | ||
235 | GNUNET_free (p_op->userSecret); | ||
236 | /* clean up identity operation list */ | 254 | /* clean up identity operation list */ |
237 | for (curr_id_op = p_op->id_ops_head; NULL != curr_id_op; curr_id_op = curr_id_op->next) | 255 | for (curr_id_op = p_op->id_ops_head; NULL != curr_id_op; curr_id_op = next_id_op) |
238 | { | 256 | { |
239 | GNUNET_CONTAINER_DLL_remove (p_op->id_ops_head, | 257 | GNUNET_CONTAINER_DLL_remove (p_op->id_ops_head, |
240 | p_op->id_ops_tail, | 258 | p_op->id_ops_tail, |
241 | curr_id_op); | 259 | curr_id_op); |
242 | GNUNET_IDENTITY_cancel (curr_id_op->id_op); | 260 | GNUNET_IDENTITY_cancel (curr_id_op->id_op); |
243 | GNUNET_free (curr_id_op->id_op); | 261 | next_id_op = curr_id_op->next; |
244 | GNUNET_free (curr_id_op); | 262 | GNUNET_free (curr_id_op); |
245 | } | 263 | } |
246 | /* clean up escrow pk list */ | 264 | /* clean up escrow pk list */ |
247 | for (curr_pk = p_op->escrow_pks_head; NULL != curr_pk; curr_pk = curr_pk->next) | 265 | for (curr_pk = p_op->escrow_pks_head; NULL != curr_pk; curr_pk = next_pk) |
248 | { | 266 | { |
249 | GNUNET_CONTAINER_DLL_remove (p_op->escrow_pks_head, | 267 | GNUNET_CONTAINER_DLL_remove (p_op->escrow_pks_head, |
250 | p_op->escrow_pks_tail, | 268 | p_op->escrow_pks_tail, |
251 | curr_pk); | 269 | curr_pk); |
270 | next_pk = curr_pk->next; | ||
252 | GNUNET_free (curr_pk); | 271 | GNUNET_free (curr_pk); |
253 | } | 272 | } |
254 | /* clean up namestore operation list */ | 273 | /* 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) | 274 | for (curr_ns_qe = p_op->ns_qes_head; NULL != curr_ns_qe; curr_ns_qe = next_ns_qe) |
256 | { | 275 | { |
257 | GNUNET_CONTAINER_DLL_remove (p_op->ns_qes_head, | 276 | GNUNET_CONTAINER_DLL_remove (p_op->ns_qes_head, |
258 | p_op->ns_qes_tail, | 277 | p_op->ns_qes_tail, |
259 | curr_ns_qe); | 278 | curr_ns_qe); |
260 | // also frees the curr_ns_qe->ns_qe | 279 | // also frees the curr_ns_qe->ns_qe |
261 | GNUNET_NAMESTORE_cancel (curr_ns_qe->ns_qe); | 280 | GNUNET_NAMESTORE_cancel (curr_ns_qe->ns_qe); |
281 | next_ns_qe = curr_ns_qe->next; | ||
262 | GNUNET_free (curr_ns_qe); | 282 | GNUNET_free (curr_ns_qe); |
263 | } | 283 | } |
264 | /* disconnect from namestore service */ | 284 | /* disconnect from namestore service */ |
265 | if (NULL != p_op->ns_h) | 285 | if (NULL != p_op->ns_h) |
266 | GNUNET_NAMESTORE_disconnect (p_op->ns_h); | 286 | GNUNET_NAMESTORE_disconnect (p_op->ns_h); |
287 | if (NULL != p_op->sched_task) | ||
288 | GNUNET_SCHEDULER_cancel (p_op->sched_task); | ||
267 | GNUNET_free (p_op); | 289 | GNUNET_free (p_op); |
268 | GNUNET_free (plugin_op_wrap); | 290 | GNUNET_free (plugin_op_wrap); |
269 | } | 291 | } |
@@ -304,6 +326,8 @@ keyshare_distribution_finished (struct ESCROW_PluginOperationWrapper *plugin_op_ | |||
304 | struct GNUNET_ESCROW_Anchor *anchor; | 326 | struct GNUNET_ESCROW_Anchor *anchor; |
305 | int anchorDataSize; | 327 | int anchorDataSize; |
306 | 328 | ||
329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All keyshares distributed\n"); | ||
330 | |||
307 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 331 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
308 | 332 | ||
309 | anchorDataSize = strlen(p_op->userSecret) + 1; | 333 | anchorDataSize = strlen(p_op->userSecret) + 1; |
@@ -324,9 +348,13 @@ keyshare_distributed (void *cls, | |||
324 | int32_t success, | 348 | int32_t success, |
325 | const char *emsg) | 349 | const char *emsg) |
326 | { | 350 | { |
327 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | 351 | struct NamestoreQueueEntry *ns_qe = cls; |
352 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap; | ||
328 | struct ESCROW_GnsPluginOperation *p_op; | 353 | struct ESCROW_GnsPluginOperation *p_op; |
329 | 354 | ||
355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Keyshare distributed\n"); | ||
356 | |||
357 | plugin_op_wrap = ns_qe->plugin_op_wrap; | ||
330 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 358 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
331 | 359 | ||
332 | if (GNUNET_SYSERR == success) | 360 | if (GNUNET_SYSERR == success) |
@@ -341,8 +369,29 @@ keyshare_distributed (void *cls, | |||
341 | cleanup_plugin_operation (plugin_op_wrap); | 369 | cleanup_plugin_operation (plugin_op_wrap); |
342 | } | 370 | } |
343 | 371 | ||
344 | // TODO: remove qe from list, check if all namestore operations are finished | 372 | // remove qe from list, check if all namestore operations are finished |
345 | keyshare_distribution_finished (plugin_op_wrap); | 373 | GNUNET_CONTAINER_DLL_remove (p_op->ns_qes_head, |
374 | p_op->ns_qes_tail, | ||
375 | ns_qe); | ||
376 | GNUNET_free (ns_qe); | ||
377 | if (NULL == p_op->ns_qes_head) | ||
378 | keyshare_distribution_finished (plugin_op_wrap); | ||
379 | } | ||
380 | |||
381 | |||
382 | static char * | ||
383 | get_label (const char *userSecret) | ||
384 | { | ||
385 | char *label; | ||
386 | struct GNUNET_HashCode hash; | ||
387 | struct GNUNET_CRYPTO_HashAsciiEncoded hashEnc; | ||
388 | |||
389 | // the label is the hash of the userSecret | ||
390 | GNUNET_CRYPTO_hash (userSecret, strlen (userSecret), &hash); | ||
391 | GNUNET_CRYPTO_hash_to_enc (&hash, &hashEnc); | ||
392 | label = GNUNET_strdup ((char *)hashEnc.encoding); | ||
393 | |||
394 | return label; | ||
346 | } | 395 | } |
347 | 396 | ||
348 | 397 | ||
@@ -357,6 +406,8 @@ distribute_keyshares (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
357 | char *curr_label; | 406 | char *curr_label; |
358 | struct GNUNET_GNSRECORD_Data curr_rd[1]; | 407 | struct GNUNET_GNSRECORD_Data curr_rd[1]; |
359 | 408 | ||
409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Distributing keyshares\n"); | ||
410 | |||
360 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 411 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
361 | 412 | ||
362 | ns_h = GNUNET_NAMESTORE_connect (p_op->h->cfg); | 413 | ns_h = GNUNET_NAMESTORE_connect (p_op->h->cfg); |
@@ -364,25 +415,28 @@ distribute_keyshares (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
364 | 415 | ||
365 | for (curr_pk = p_op->escrow_pks_head; NULL != curr_pk; curr_pk = curr_pk->next) | 416 | for (curr_pk = p_op->escrow_pks_head; NULL != curr_pk; curr_pk = curr_pk->next) |
366 | { | 417 | { |
367 | curr_label = NULL; // TODO: which label | 418 | curr_label = get_label (p_op->userSecret); |
368 | curr_ns_qe = GNUNET_new (struct NamestoreQueueEntry); | 419 | curr_ns_qe = GNUNET_new (struct NamestoreQueueEntry); |
369 | 420 | ||
370 | curr_rd[0].data_size = sizeof (sss_Keyshare); | 421 | curr_rd[0].data_size = sizeof (sss_Keyshare); |
371 | curr_rd[0].data = keyshares[curr_pk->i]; | 422 | curr_rd[0].data = keyshares[curr_pk->i]; |
372 | curr_rd[0].record_type = GNUNET_GNSRECORD_TYPE_ATTRIBUTE; // TODO: type | 423 | curr_rd[0].record_type = GNUNET_GNSRECORD_TYPE_ESCROW_KEYSHARE; |
373 | curr_rd[0].flags = GNUNET_GNSRECORD_RF_NONE; // TODO: flags | 424 | curr_rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
374 | curr_rd[0].expiration_time = 0; // TODO: expiration time | 425 | // TODO: config param? |
426 | curr_rd[0].expiration_time = 30 * 24 * GNUNET_TIME_relative_get_hour_().rel_value_us; | ||
375 | 427 | ||
428 | curr_ns_qe->plugin_op_wrap = plugin_op_wrap; | ||
376 | curr_ns_qe->ns_qe = GNUNET_NAMESTORE_records_store (ns_h, | 429 | curr_ns_qe->ns_qe = GNUNET_NAMESTORE_records_store (ns_h, |
377 | curr_pk->pk, | 430 | curr_pk->pk, |
378 | curr_label, | 431 | curr_label, |
379 | 1, | 432 | 1, |
380 | curr_rd, | 433 | curr_rd, |
381 | &keyshare_distributed, | 434 | &keyshare_distributed, |
382 | plugin_op_wrap); | 435 | curr_ns_qe); |
383 | GNUNET_CONTAINER_DLL_insert_tail (p_op->ns_qes_head, | 436 | GNUNET_CONTAINER_DLL_insert_tail (p_op->ns_qes_head, |
384 | p_op->ns_qes_tail, | 437 | p_op->ns_qes_tail, |
385 | curr_ns_qe); | 438 | curr_ns_qe); |
439 | GNUNET_free (curr_label); | ||
386 | } | 440 | } |
387 | 441 | ||
388 | return GNUNET_OK; | 442 | return GNUNET_OK; |
@@ -395,6 +449,8 @@ escrow_ids_finished (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
395 | struct ESCROW_GnsPluginOperation *p_op; | 449 | struct ESCROW_GnsPluginOperation *p_op; |
396 | sss_Keyshare *keyshares; | 450 | sss_Keyshare *keyshares; |
397 | 451 | ||
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All escrow identities created\n"); | ||
453 | |||
398 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 454 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
399 | 455 | ||
400 | /* split the private key (SSS) */ | 456 | /* split the private key (SSS) */ |
@@ -426,11 +482,14 @@ escrow_id_created (void *cls, | |||
426 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 482 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
427 | const char *emsg) | 483 | const char *emsg) |
428 | { | 484 | { |
429 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | 485 | struct IdentityOperationEntry *id_op = cls; |
486 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap; | ||
430 | struct ESCROW_GnsPluginOperation *p_op; | 487 | struct ESCROW_GnsPluginOperation *p_op; |
431 | struct IdentityOperationEntry *curr_id_op; | ||
432 | struct PkEntry *pk_entry; | 488 | struct PkEntry *pk_entry; |
433 | 489 | ||
490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Escrow identity %d created\n", id_op->i); | ||
491 | |||
492 | plugin_op_wrap = id_op->plugin_op_wrap; | ||
434 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 493 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
435 | 494 | ||
436 | if (NULL == pk) | 495 | if (NULL == pk) |
@@ -452,24 +511,21 @@ escrow_id_created (void *cls, | |||
452 | } | 511 | } |
453 | 512 | ||
454 | /* escrow identity successfully created */ | 513 | /* escrow identity successfully created */ |
455 | for (curr_id_op = p_op->id_ops_head; NULL != curr_id_op; curr_id_op = curr_id_op->next) | 514 | GNUNET_CONTAINER_DLL_remove (p_op->id_ops_head, |
456 | { | 515 | p_op->id_ops_tail, |
457 | if (pk == curr_id_op->pk) | 516 | id_op); |
458 | { | ||
459 | GNUNET_CONTAINER_DLL_remove (p_op->id_ops_head, | ||
460 | p_op->id_ops_tail, | ||
461 | curr_id_op); | ||
462 | GNUNET_free (curr_id_op); | ||
463 | break; | ||
464 | } | ||
465 | } | ||
466 | 517 | ||
467 | /* insert pk into our list */ | 518 | /* insert pk into our list */ |
468 | pk_entry = GNUNET_new (struct PkEntry); | 519 | pk_entry = GNUNET_new (struct PkEntry); |
520 | pk_entry->pk = pk; | ||
521 | pk_entry->i = id_op->i; | ||
469 | GNUNET_CONTAINER_DLL_insert_tail (p_op->escrow_pks_head, | 522 | GNUNET_CONTAINER_DLL_insert_tail (p_op->escrow_pks_head, |
470 | p_op->escrow_pks_tail, | 523 | p_op->escrow_pks_tail, |
471 | pk_entry); | 524 | pk_entry); |
472 | 525 | ||
526 | GNUNET_free (id_op); | ||
527 | |||
528 | /* check if this was the last id_op */ | ||
473 | p_op->escrow_id_counter++; | 529 | p_op->escrow_id_counter++; |
474 | if (p_op->escrow_id_counter == p_op->shares) | 530 | if (p_op->escrow_id_counter == p_op->shares) |
475 | { | 531 | { |
@@ -533,7 +589,9 @@ escrow_id_exists (const char *name, | |||
533 | { | 589 | { |
534 | if (0 == strcmp (name, curr->identifier)) | 590 | if (0 == strcmp (name, curr->identifier)) |
535 | { | 591 | { |
536 | if (curr->ego->pk.d == pk->d) // TODO: correct equality check? | 592 | if (0 == memcmp (&curr->ego->pk, |
593 | pk, | ||
594 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | ||
537 | return GNUNET_YES; | 595 | return GNUNET_YES; |
538 | else // the escrow id's name exists for an ego, but the pk is wrong | 596 | else // the escrow id's name exists for an ego, but the pk is wrong |
539 | return GNUNET_SYSERR; | 597 | return GNUNET_SYSERR; |
@@ -546,11 +604,60 @@ escrow_id_exists (const char *name, | |||
546 | 604 | ||
547 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * | 605 | static struct GNUNET_CRYPTO_EcdsaPrivateKey * |
548 | derive_private_key (const char *name, | 606 | derive_private_key (const char *name, |
549 | void *password, | 607 | const char *password, |
550 | uint8_t i) | 608 | uint8_t i) |
551 | { | 609 | { |
552 | // TODO: derive key | 610 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; |
553 | return NULL; | 611 | static const char ctx[] = "gnunet-escrow-id-ctx"; |
612 | |||
613 | pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | ||
614 | GNUNET_CRYPTO_kdf (pk, | ||
615 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | ||
616 | ctx, strlen (ctx), | ||
617 | password, strlen (password), | ||
618 | name, strlen (name), | ||
619 | &i, 1, | ||
620 | NULL); | ||
621 | |||
622 | pk->d[0] &= 248; | ||
623 | pk->d[31] &= 127; | ||
624 | pk->d[31] |= 64; | ||
625 | |||
626 | return pk; | ||
627 | } | ||
628 | |||
629 | |||
630 | static void | ||
631 | handle_existing_wrong_ego_deletion (void *cls, | ||
632 | const char *emsg) | ||
633 | { | ||
634 | struct IdentityOperationEntry *curr_id_op = cls; | ||
635 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap; | ||
636 | struct ESCROW_GnsPluginOperation *p_op; | ||
637 | |||
638 | plugin_op_wrap = curr_id_op->plugin_op_wrap; | ||
639 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | ||
640 | |||
641 | if (NULL != emsg) | ||
642 | { | ||
643 | fprintf (stderr, | ||
644 | "Identity create operation returned with error: %s\n", | ||
645 | emsg); | ||
646 | p_op->anchor_wrap->emsg = _ ("Identity delete of wrong existing ego failed!\n"); | ||
647 | p_op->anchor_wrap->escrowAnchor = NULL; | ||
648 | p_op->cont (p_op->anchor_wrap); | ||
649 | // this also cancels all running identity operations | ||
650 | cleanup_plugin_operation (plugin_op_wrap); | ||
651 | return; | ||
652 | } | ||
653 | |||
654 | /* no error occured, so create the new identity */ | ||
655 | // the IdentityOperationEntry is reused, so only the id_op is updated | ||
656 | curr_id_op->id_op = GNUNET_IDENTITY_create (identity_handle, | ||
657 | curr_id_op->name, | ||
658 | curr_id_op->pk, | ||
659 | &escrow_id_created, | ||
660 | curr_id_op); | ||
554 | } | 661 | } |
555 | 662 | ||
556 | 663 | ||
@@ -565,6 +672,8 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
565 | struct PkEntry *curr_pk_entry; | 672 | struct PkEntry *curr_pk_entry; |
566 | int exists_ret; | 673 | int exists_ret; |
567 | 674 | ||
675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating escrow identities\n"); | ||
676 | |||
568 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 677 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
569 | 678 | ||
570 | for (uint8_t i = 0; i < p_op->shares; i++) | 679 | for (uint8_t i = 0; i < p_op->shares; i++) |
@@ -576,13 +685,19 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
576 | exists_ret = escrow_id_exists (curr_name, curr_pk); | 685 | exists_ret = escrow_id_exists (curr_name, curr_pk); |
577 | if (GNUNET_SYSERR == exists_ret) | 686 | if (GNUNET_SYSERR == exists_ret) |
578 | { | 687 | { |
579 | p_op->anchor_wrap->escrowAnchor = NULL; | 688 | /* an ego with identifier name but the wrong pk exists, delete it first */ |
580 | p_op->anchor_wrap->emsg = _ ("An escrow identity with the same name \ | 689 | curr_id_op = GNUNET_new (struct IdentityOperationEntry); |
581 | but wrong pk already exists!\n"); | 690 | curr_id_op->pk = curr_pk; |
582 | p_op->cont (p_op->anchor_wrap); | 691 | curr_id_op->name = name; |
583 | // this also cancels all running identity operations | 692 | curr_id_op->i = i; |
584 | cleanup_plugin_operation (plugin_op_wrap); | 693 | curr_id_op->plugin_op_wrap = plugin_op_wrap; |
585 | return; | 694 | curr_id_op->id_op = GNUNET_IDENTITY_delete (identity_handle, |
695 | name, | ||
696 | &handle_existing_wrong_ego_deletion, | ||
697 | curr_id_op); | ||
698 | GNUNET_CONTAINER_DLL_insert (p_op->id_ops_head, | ||
699 | p_op->id_ops_tail, | ||
700 | curr_id_op); | ||
586 | } | 701 | } |
587 | else if (GNUNET_YES == exists_ret) | 702 | else if (GNUNET_YES == exists_ret) |
588 | { | 703 | { |
@@ -599,14 +714,17 @@ but wrong pk already exists!\n"); | |||
599 | /* store the identity operation in our list */ | 714 | /* store the identity operation in our list */ |
600 | curr_id_op = GNUNET_new (struct IdentityOperationEntry); | 715 | curr_id_op = GNUNET_new (struct IdentityOperationEntry); |
601 | curr_id_op->pk = curr_pk; | 716 | curr_id_op->pk = curr_pk; |
717 | curr_id_op->name = name; | ||
718 | curr_id_op->i = i; | ||
719 | curr_id_op->plugin_op_wrap = plugin_op_wrap; | ||
602 | curr_id_op->id_op = GNUNET_IDENTITY_create (identity_handle, | 720 | curr_id_op->id_op = GNUNET_IDENTITY_create (identity_handle, |
603 | curr_name, | 721 | curr_name, |
604 | curr_pk, | 722 | curr_pk, |
605 | &escrow_id_created, | 723 | &escrow_id_created, |
606 | plugin_op_wrap); | 724 | curr_id_op); |
607 | GNUNET_CONTAINER_DLL_insert (p_op->id_ops_head, | 725 | GNUNET_CONTAINER_DLL_insert (p_op->id_ops_head, |
608 | p_op->id_ops_tail, | 726 | p_op->id_ops_tail, |
609 | curr_id_op); | 727 | curr_id_op); |
610 | } | 728 | } |
611 | } | 729 | } |
612 | } | 730 | } |
@@ -626,7 +744,7 @@ but wrong pk already exists!\n"); | |||
626 | struct ESCROW_PluginOperationWrapper * | 744 | struct ESCROW_PluginOperationWrapper * |
627 | start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | 745 | start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, |
628 | struct GNUNET_IDENTITY_Ego *ego, | 746 | struct GNUNET_IDENTITY_Ego *ego, |
629 | char *userSecret, | 747 | const char *userSecret, |
630 | GNUNET_SCHEDULER_TaskCallback cb, | 748 | GNUNET_SCHEDULER_TaskCallback cb, |
631 | uint32_t op_id) | 749 | uint32_t op_id) |
632 | { | 750 | { |
@@ -635,6 +753,8 @@ start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
635 | struct ESCROW_Plugin_AnchorContinuationWrapper *w; | 753 | struct ESCROW_Plugin_AnchorContinuationWrapper *w; |
636 | unsigned long long shares, share_threshold; | 754 | unsigned long long shares, share_threshold; |
637 | 755 | ||
756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting GNS escrow\n"); | ||
757 | |||
638 | // create a new GNS plugin operation (in a wrapper) and insert it into the DLL | 758 | // create a new GNS plugin operation (in a wrapper) and insert it into the DLL |
639 | plugin_op_wrap = GNUNET_new (struct ESCROW_PluginOperationWrapper); | 759 | plugin_op_wrap = GNUNET_new (struct ESCROW_PluginOperationWrapper); |
640 | plugin_op_wrap->plugin_op = GNUNET_new (struct ESCROW_GnsPluginOperation); | 760 | plugin_op_wrap->plugin_op = GNUNET_new (struct ESCROW_GnsPluginOperation); |
@@ -755,6 +875,12 @@ verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
755 | return plugin_op_wrap; | 875 | return plugin_op_wrap; |
756 | } | 876 | } |
757 | 877 | ||
878 | void | ||
879 | ego_created (const struct GNUNET_IDENTITY_Ego *ego) | ||
880 | { | ||
881 | return; | ||
882 | } | ||
883 | |||
758 | 884 | ||
759 | /** | 885 | /** |
760 | * Restore the key from GNS escrow | 886 | * Restore the key from GNS escrow |
@@ -870,9 +996,6 @@ void | |||
870 | cancel_gns_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | 996 | cancel_gns_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) |
871 | { | 997 | { |
872 | struct ESCROW_PluginOperationWrapper *curr; | 998 | struct ESCROW_PluginOperationWrapper *curr; |
873 | struct ESCROW_GnsPluginOperation *p_op; | ||
874 | struct IdentityOperationEntry *curr_id_op; | ||
875 | struct PkEntry *curr_pk; | ||
876 | 999 | ||
877 | for (curr = ph.plugin_op_head; NULL != curr; curr = curr->next) | 1000 | for (curr = ph.plugin_op_head; NULL != curr; curr = curr->next) |
878 | { | 1001 | { |
@@ -881,37 +1004,7 @@ cancel_gns_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
881 | GNUNET_CONTAINER_DLL_remove (ph.plugin_op_head, | 1004 | GNUNET_CONTAINER_DLL_remove (ph.plugin_op_head, |
882 | ph.plugin_op_tail, | 1005 | ph.plugin_op_tail, |
883 | curr); | 1006 | curr); |
884 | p_op = (struct ESCROW_GnsPluginOperation *)curr->plugin_op; | 1007 | cleanup_plugin_operation (curr); |
885 | |||
886 | /* clean up the identity operation list */ | ||
887 | for (curr_id_op = p_op->id_ops_head; NULL != curr_id_op; curr_id_op = curr_id_op->next) | ||
888 | { | ||
889 | GNUNET_CONTAINER_DLL_remove (p_op->id_ops_head, | ||
890 | p_op->id_ops_tail, | ||
891 | curr_id_op); | ||
892 | GNUNET_IDENTITY_cancel (curr_id_op->id_op); | ||
893 | GNUNET_free (curr_id_op); | ||
894 | } | ||
895 | |||
896 | /* clean up the escrow pk list */ | ||
897 | for (curr_pk = p_op->escrow_pks_head; NULL != curr_pk; curr_pk = curr_pk->next) | ||
898 | { | ||
899 | GNUNET_CONTAINER_DLL_remove (p_op->escrow_pks_head, | ||
900 | p_op->escrow_pks_tail, | ||
901 | curr_pk); | ||
902 | GNUNET_free (curr_pk); | ||
903 | } | ||
904 | |||
905 | if (NULL != p_op->ns_h) | ||
906 | { | ||
907 | GNUNET_NAMESTORE_disconnect (p_op->ns_h); | ||
908 | p_op->ns_h = NULL; | ||
909 | } | ||
910 | |||
911 | if (NULL != p_op->sched_task) | ||
912 | GNUNET_SCHEDULER_cancel (p_op->sched_task); | ||
913 | GNUNET_free (p_op); | ||
914 | GNUNET_free (curr); | ||
915 | return; | 1008 | return; |
916 | } | 1009 | } |
917 | } | 1010 | } |
@@ -947,11 +1040,13 @@ libgnunet_plugin_escrow_gns_init (void *cls) | |||
947 | api->restore_key = &restore_gns_key_escrow; | 1040 | api->restore_key = &restore_gns_key_escrow; |
948 | api->get_status = &gns_get_status; | 1041 | api->get_status = &gns_get_status; |
949 | api->anchor_string_to_data = &gns_anchor_string_to_data; | 1042 | api->anchor_string_to_data = &gns_anchor_string_to_data; |
1043 | api->anchor_data_to_string = &gns_anchor_data_to_string; | ||
950 | api->cancel_plugin_operation = &cancel_gns_operation; | 1044 | api->cancel_plugin_operation = &cancel_gns_operation; |
951 | 1045 | ||
952 | ph.state = ESCROW_PLUGIN_STATE_INIT; | 1046 | ph.state = ESCROW_PLUGIN_STATE_INIT; |
953 | ph.id_init_cont = &gns_cont_init; | 1047 | ph.id_init_cont = &gns_cont_init; |
954 | 1048 | ||
1049 | ph.ego_create_cont = &ego_created; | ||
955 | identity_handle = GNUNET_IDENTITY_connect (cfg, | 1050 | identity_handle = GNUNET_IDENTITY_connect (cfg, |
956 | &ESCROW_list_ego, | 1051 | &ESCROW_list_ego, |
957 | &ph); | 1052 | &ph); |