diff options
Diffstat (limited to 'src/escrow/plugin_escrow_gns.c')
-rw-r--r-- | src/escrow/plugin_escrow_gns.c | 139 |
1 files changed, 110 insertions, 29 deletions
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c index 908c7bb44..6889d1dd0 100644 --- a/src/escrow/plugin_escrow_gns.c +++ b/src/escrow/plugin_escrow_gns.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include "gnunet_namestore_service.h" | 32 | #include "gnunet_namestore_service.h" |
33 | #include "gnunet_gns_service.h" | 33 | #include "gnunet_gns_service.h" |
34 | #include "gnunet_gnsrecord_lib.h" | 34 | #include "gnunet_gnsrecord_lib.h" |
35 | #include "../identity/identity.h" | 35 | #include "escrow.h" |
36 | #include <sss.h> | 36 | #include <sss.h> |
37 | #include <inttypes.h> | 37 | #include <inttypes.h> |
38 | 38 | ||
@@ -287,6 +287,11 @@ struct ESCROW_GnsPluginOperation | |||
287 | struct GNUNET_IDENTITY_Ego *ego; | 287 | struct GNUNET_IDENTITY_Ego *ego; |
288 | 288 | ||
289 | /** | 289 | /** |
290 | * The anchor | ||
291 | */ | ||
292 | const struct GNUNET_ESCROW_Anchor *anchor; | ||
293 | |||
294 | /** | ||
290 | * The name of the ego | 295 | * The name of the ego |
291 | */ | 296 | */ |
292 | char *egoName; | 297 | char *egoName; |
@@ -526,21 +531,15 @@ keyshare_distribution_finished (void *cls) | |||
526 | { | 531 | { |
527 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | 532 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; |
528 | struct ESCROW_GnsPluginOperation *p_op; | 533 | struct ESCROW_GnsPluginOperation *p_op; |
529 | struct GNUNET_ESCROW_Anchor *anchor; | ||
530 | int anchorDataSize; | ||
531 | 534 | ||
532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All keyshares distributed\n"); | 535 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All keyshares distributed\n"); |
533 | 536 | ||
534 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 537 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
535 | 538 | ||
536 | anchorDataSize = strlen(p_op->userSecret) + 1; | 539 | p_op->anchor_wrap->anchor = ESCROW_build_anchor (GNUNET_ESCROW_KEY_GNS, |
537 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize); | 540 | p_op->egoName, |
538 | anchor->method = GNUNET_ESCROW_KEY_GNS; | 541 | p_op->userSecret, |
539 | anchor->egoName = GNUNET_strdup (p_op->ego->name); | 542 | strlen (p_op->userSecret)); |
540 | anchor->size = anchorDataSize; | ||
541 | GNUNET_memcpy (&anchor[1], p_op->userSecret, anchorDataSize); | ||
542 | |||
543 | p_op->anchor_wrap->anchor = anchor; | ||
544 | 543 | ||
545 | /* update escrow status, i.e. set the last escrow method */ | 544 | /* update escrow status, i.e. set the last escrow method */ |
546 | ESCROW_update_escrow_status_put (p_op->h, p_op->ego, "gns"); | 545 | ESCROW_update_escrow_status_put (p_op->h, p_op->ego, "gns"); |
@@ -803,7 +802,7 @@ escrow_id_exists (const char *name, | |||
803 | { | 802 | { |
804 | if (0 == strcmp (name, curr->identifier)) | 803 | if (0 == strcmp (name, curr->identifier)) |
805 | { | 804 | { |
806 | if (0 == memcmp (&curr->ego->pk, | 805 | if (0 == memcmp (GNUNET_IDENTITY_ego_get_private_key (curr->ego), |
807 | pk, | 806 | pk, |
808 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 807 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) |
809 | return GNUNET_YES; | 808 | return GNUNET_YES; |
@@ -1034,6 +1033,9 @@ continue_start (void *cls) | |||
1034 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | 1033 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; |
1035 | struct ESCROW_GnsPluginOperation *p_op; | 1034 | struct ESCROW_GnsPluginOperation *p_op; |
1036 | struct GNUNET_TIME_Relative delay; | 1035 | struct GNUNET_TIME_Relative delay; |
1036 | struct GNUNET_CRYPTO_EcdsaPublicKey ego_pub; | ||
1037 | struct EgoEntry *ego_entry; | ||
1038 | char *pub_keystring; | ||
1037 | 1039 | ||
1038 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 1040 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
1039 | 1041 | ||
@@ -1044,12 +1046,34 @@ continue_start (void *cls) | |||
1044 | return; | 1046 | return; |
1045 | } | 1047 | } |
1046 | 1048 | ||
1049 | GNUNET_IDENTITY_ego_get_public_key (p_op->ego, &ego_pub); | ||
1050 | pub_keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&ego_pub); | ||
1051 | for (ego_entry = ph.ego_head; NULL != ego_entry; ego_entry = ego_entry->next) | ||
1052 | if (0 == strcmp (pub_keystring, ego_entry->keystring)) | ||
1053 | break; | ||
1054 | |||
1055 | GNUNET_free (pub_keystring); | ||
1056 | if (NULL == ego_entry) | ||
1057 | { | ||
1058 | p_op->anchor_wrap->anchor = NULL; | ||
1059 | p_op->anchor_wrap->emsg = _ ("Identity was not found in plugin!\n"); | ||
1060 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); | ||
1061 | return; | ||
1062 | } | ||
1063 | |||
1064 | p_op->egoName = GNUNET_strdup (ego_entry->identifier); | ||
1065 | |||
1047 | /* load config */ | 1066 | /* load config */ |
1048 | if (GNUNET_OK != load_keyshare_config (plugin_op_wrap)) | 1067 | if (GNUNET_OK != load_keyshare_config (plugin_op_wrap)) |
1068 | { | ||
1069 | p_op->anchor_wrap->anchor = NULL; | ||
1070 | p_op->anchor_wrap->emsg = _ ("Failed to load keyshare configuration parameters!\n"); | ||
1071 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); | ||
1049 | return; | 1072 | return; |
1073 | } | ||
1050 | 1074 | ||
1051 | /* create the escrow identities */ | 1075 | /* create the escrow identities */ |
1052 | create_escrow_identities (plugin_op_wrap, p_op->ego->name); | 1076 | create_escrow_identities (plugin_op_wrap, p_op->egoName); |
1053 | 1077 | ||
1054 | /* operation continues in escrow_ids_finished | 1078 | /* operation continues in escrow_ids_finished |
1055 | after all escrow identities are created */ | 1079 | after all escrow identities are created */ |
@@ -1431,6 +1455,66 @@ verify_restored_pk (void *cls, | |||
1431 | } | 1455 | } |
1432 | 1456 | ||
1433 | 1457 | ||
1458 | static void | ||
1459 | continue_verify (void *cls) | ||
1460 | { | ||
1461 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
1462 | struct ESCROW_GnsPluginOperation *p_op; | ||
1463 | struct GNUNET_TIME_Relative delay; | ||
1464 | struct GNUNET_CRYPTO_EcdsaPublicKey ego_pub; | ||
1465 | struct EgoEntry *ego_entry; | ||
1466 | char *pub_keystring; | ||
1467 | |||
1468 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | ||
1469 | |||
1470 | if (ESCROW_PLUGIN_STATE_POST_INIT != ph.state) | ||
1471 | { | ||
1472 | delay.rel_value_us = 100 * GNUNET_TIME_relative_get_millisecond_().rel_value_us; | ||
1473 | GNUNET_SCHEDULER_add_delayed (delay, &continue_verify, plugin_op_wrap); | ||
1474 | return; | ||
1475 | } | ||
1476 | |||
1477 | GNUNET_IDENTITY_ego_get_public_key (p_op->ego, &ego_pub); | ||
1478 | pub_keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&ego_pub); | ||
1479 | for (ego_entry = ph.ego_head; NULL != ego_entry; ego_entry = ego_entry->next) | ||
1480 | if (0 == strcmp (pub_keystring, ego_entry->keystring)) | ||
1481 | break; | ||
1482 | |||
1483 | GNUNET_free (pub_keystring); | ||
1484 | if (NULL == ego_entry) | ||
1485 | { | ||
1486 | p_op->verify_wrap->verificationResult = GNUNET_ESCROW_INVALID; | ||
1487 | p_op->verify_wrap->emsg = _ ("Identity was not found in plugin!\n"); | ||
1488 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); | ||
1489 | return; | ||
1490 | } | ||
1491 | |||
1492 | p_op->egoName = GNUNET_strdup (ego_entry->identifier); | ||
1493 | |||
1494 | if (0 != strcmp (p_op->egoName, p_op->anchor->egoName)) | ||
1495 | { | ||
1496 | p_op->verify_wrap->verificationResult = GNUNET_ESCROW_INVALID; | ||
1497 | p_op->verify_wrap->emsg = _ ("This anchor was not created when putting that ego in escrow!\n"); | ||
1498 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); | ||
1499 | return; | ||
1500 | } | ||
1501 | |||
1502 | /* load config */ | ||
1503 | if (GNUNET_OK != load_keyshare_config (plugin_op_wrap)) | ||
1504 | { | ||
1505 | p_op->verify_wrap->verificationResult = GNUNET_ESCROW_INVALID; | ||
1506 | p_op->verify_wrap->emsg = _ ("Failed to load keyshare configuration parameters!\n"); | ||
1507 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); | ||
1508 | return; | ||
1509 | } | ||
1510 | |||
1511 | restore_private_key (plugin_op_wrap, | ||
1512 | p_op->anchor, | ||
1513 | &verify_restored_pk, | ||
1514 | plugin_op_wrap); | ||
1515 | } | ||
1516 | |||
1517 | |||
1434 | /** | 1518 | /** |
1435 | * Verify the GNS escrow of the key | 1519 | * Verify the GNS escrow of the key |
1436 | * | 1520 | * |
@@ -1452,6 +1536,7 @@ verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
1452 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap; | 1536 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap; |
1453 | struct ESCROW_GnsPluginOperation *p_op; | 1537 | struct ESCROW_GnsPluginOperation *p_op; |
1454 | struct ESCROW_Plugin_VerifyContinuationWrapper *w; | 1538 | struct ESCROW_Plugin_VerifyContinuationWrapper *w; |
1539 | struct GNUNET_TIME_Relative delay; | ||
1455 | 1540 | ||
1456 | // create a new GNS plugin operation (in a wrapper) and insert it into the DLL | 1541 | // create a new GNS plugin operation (in a wrapper) and insert it into the DLL |
1457 | plugin_op_wrap = GNUNET_new (struct ESCROW_PluginOperationWrapper); | 1542 | plugin_op_wrap = GNUNET_new (struct ESCROW_PluginOperationWrapper); |
@@ -1464,7 +1549,7 @@ verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
1464 | p_op->h = h; | 1549 | p_op->h = h; |
1465 | p_op->cont = cb; | 1550 | p_op->cont = cb; |
1466 | p_op->ego = ego; | 1551 | p_op->ego = ego; |
1467 | p_op->egoName = GNUNET_strdup (ego->name); | 1552 | p_op->anchor = anchor; |
1468 | 1553 | ||
1469 | w = GNUNET_new (struct ESCROW_Plugin_VerifyContinuationWrapper); | 1554 | w = GNUNET_new (struct ESCROW_Plugin_VerifyContinuationWrapper); |
1470 | w->h = h; | 1555 | w->h = h; |
@@ -1485,22 +1570,16 @@ verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
1485 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); | 1570 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); |
1486 | return plugin_op_wrap; | 1571 | return plugin_op_wrap; |
1487 | } | 1572 | } |
1488 | if (0 != strcmp (ego->name, anchor->egoName)) | 1573 | |
1574 | if (ESCROW_PLUGIN_STATE_POST_INIT == ph.state) | ||
1489 | { | 1575 | { |
1490 | w->verificationResult = GNUNET_ESCROW_INVALID; | 1576 | continue_verify (plugin_op_wrap); |
1491 | w->emsg = _ ("This anchor was not created when putting that ego in escrow!\n"); | 1577 | } |
1492 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); | 1578 | else |
1493 | return plugin_op_wrap; | 1579 | { |
1580 | delay.rel_value_us = 200 * GNUNET_TIME_relative_get_millisecond_().rel_value_us; | ||
1581 | GNUNET_SCHEDULER_add_delayed (delay, &continue_verify, plugin_op_wrap); | ||
1494 | } | 1582 | } |
1495 | |||
1496 | /* load config */ | ||
1497 | if (GNUNET_OK != load_keyshare_config (plugin_op_wrap)) | ||
1498 | return plugin_op_wrap; | ||
1499 | |||
1500 | restore_private_key (plugin_op_wrap, | ||
1501 | anchor, | ||
1502 | &verify_restored_pk, | ||
1503 | plugin_op_wrap); | ||
1504 | 1583 | ||
1505 | return plugin_op_wrap; | 1584 | return plugin_op_wrap; |
1506 | } | 1585 | } |
@@ -1513,7 +1592,8 @@ ego_created (struct GNUNET_IDENTITY_Ego *ego) | |||
1513 | struct ESCROW_GnsPluginOperation *curr_p_op; | 1592 | struct ESCROW_GnsPluginOperation *curr_p_op; |
1514 | char *ego_pk_string, *curr_pk_string; | 1593 | char *ego_pk_string, *curr_pk_string; |
1515 | 1594 | ||
1516 | ego_pk_string = GNUNET_CRYPTO_ecdsa_private_key_to_string (&ego->pk); | 1595 | ego_pk_string = GNUNET_CRYPTO_ecdsa_private_key_to_string ( |
1596 | GNUNET_IDENTITY_ego_get_private_key (ego)); | ||
1517 | 1597 | ||
1518 | for (curr = ph.plugin_op_head; NULL != curr; curr = curr->next) | 1598 | for (curr = ph.plugin_op_head; NULL != curr; curr = curr->next) |
1519 | { | 1599 | { |
@@ -1626,6 +1706,7 @@ restore_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
1626 | // set cont here (has to be scheduled from the IDENTITY service when it finished) | 1706 | // set cont here (has to be scheduled from the IDENTITY service when it finished) |
1627 | p_op->cont = cb; | 1707 | p_op->cont = cb; |
1628 | p_op->egoName = GNUNET_strdup (anchor->egoName); | 1708 | p_op->egoName = GNUNET_strdup (anchor->egoName); |
1709 | p_op->anchor = anchor; | ||
1629 | 1710 | ||
1630 | w = GNUNET_new (struct ESCROW_Plugin_EgoContinuationWrapper); | 1711 | w = GNUNET_new (struct ESCROW_Plugin_EgoContinuationWrapper); |
1631 | w->h = h; | 1712 | w->h = h; |