diff options
Diffstat (limited to 'src/escrow/plugin_escrow_gns.c')
-rw-r--r-- | src/escrow/plugin_escrow_gns.c | 81 |
1 files changed, 60 insertions, 21 deletions
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c index f9a68728d..94ce175c5 100644 --- a/src/escrow/plugin_escrow_gns.c +++ b/src/escrow/plugin_escrow_gns.c | |||
@@ -37,12 +37,6 @@ | |||
37 | #include <inttypes.h> | 37 | #include <inttypes.h> |
38 | 38 | ||
39 | 39 | ||
40 | /* declare this function here, as it is used by other functions above the definition */ | ||
41 | char * | ||
42 | gns_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h, | ||
43 | struct GNUNET_ESCROW_Anchor *escrowAnchor); | ||
44 | |||
45 | |||
46 | /** | 40 | /** |
47 | * Continuation with a private key (used for restore_private_key) | 41 | * Continuation with a private key (used for restore_private_key) |
48 | */ | 42 | */ |
@@ -534,6 +528,7 @@ keyshare_distribution_finished (void *cls) | |||
534 | anchorDataSize = strlen(p_op->userSecret) + 1; | 528 | anchorDataSize = strlen(p_op->userSecret) + 1; |
535 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize); | 529 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize); |
536 | anchor->method = GNUNET_ESCROW_KEY_GNS; | 530 | anchor->method = GNUNET_ESCROW_KEY_GNS; |
531 | anchor->egoName = GNUNET_strdup (p_op->ego->name); | ||
537 | anchor->size = anchorDataSize; | 532 | anchor->size = anchorDataSize; |
538 | GNUNET_memcpy (&anchor[1], p_op->userSecret, anchorDataSize); | 533 | GNUNET_memcpy (&anchor[1], p_op->userSecret, anchorDataSize); |
539 | 534 | ||
@@ -1311,6 +1306,18 @@ timeout_gns_request (void *cls) | |||
1311 | } | 1306 | } |
1312 | 1307 | ||
1313 | 1308 | ||
1309 | static char * | ||
1310 | get_user_secret_from_anchor (const struct GNUNET_ESCROW_Anchor *anchor) | ||
1311 | { | ||
1312 | char *userSecret; | ||
1313 | |||
1314 | userSecret = GNUNET_malloc (anchor->size); | ||
1315 | GNUNET_memcpy (userSecret, &anchor[1], anchor->size); | ||
1316 | |||
1317 | return userSecret; | ||
1318 | } | ||
1319 | |||
1320 | |||
1314 | static void | 1321 | static void |
1315 | restore_private_key (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | 1322 | restore_private_key (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, |
1316 | struct GNUNET_ESCROW_Anchor *escrowAnchor, | 1323 | struct GNUNET_ESCROW_Anchor *escrowAnchor, |
@@ -1449,7 +1456,7 @@ verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
1449 | p_op->cont = cb; | 1456 | p_op->cont = cb; |
1450 | p_op->ego = ego; | 1457 | p_op->ego = ego; |
1451 | p_op->egoName = GNUNET_strdup (ego->name); | 1458 | p_op->egoName = GNUNET_strdup (ego->name); |
1452 | p_op->userSecret = gns_anchor_data_to_string (h, escrowAnchor); | 1459 | p_op->userSecret = get_user_secret_from_anchor (escrowAnchor); |
1453 | 1460 | ||
1454 | w = GNUNET_new (struct ESCROW_Plugin_VerifyContinuationWrapper); | 1461 | w = GNUNET_new (struct ESCROW_Plugin_VerifyContinuationWrapper); |
1455 | w->h = h; | 1462 | w->h = h; |
@@ -1463,6 +1470,13 @@ verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
1463 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); | 1470 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); |
1464 | return plugin_op_wrap; | 1471 | return plugin_op_wrap; |
1465 | } | 1472 | } |
1473 | if (0 != strcmp (ego->name, escrowAnchor->egoName)) | ||
1474 | { | ||
1475 | w->verificationResult = GNUNET_ESCROW_INVALID; | ||
1476 | w->emsg = _ ("This anchor was not created when putting ego that in escrow!\n"); | ||
1477 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); | ||
1478 | return plugin_op_wrap; | ||
1479 | } | ||
1466 | 1480 | ||
1467 | /* load config */ | 1481 | /* load config */ |
1468 | if (GNUNET_OK != load_keyshare_config (plugin_op_wrap)) | 1482 | if (GNUNET_OK != load_keyshare_config (plugin_op_wrap)) |
@@ -1569,8 +1583,7 @@ restore_ego_from_pk (void *cls, | |||
1569 | * Restore the key from GNS escrow | 1583 | * Restore the key from GNS escrow |
1570 | * | 1584 | * |
1571 | * @param h the handle for the escrow component | 1585 | * @param h the handle for the escrow component |
1572 | * @param escrowAnchor the escrow anchor needed to restore the key | 1586 | * @param anchor the escrow anchor needed to restore the key |
1573 | * @param egoName the name of the ego to restore | ||
1574 | * @param cb the function called upon completion | 1587 | * @param cb the function called upon completion |
1575 | * @param op_id unique ID of the respective ESCROW_Operation | 1588 | * @param op_id unique ID of the respective ESCROW_Operation |
1576 | * | 1589 | * |
@@ -1578,8 +1591,7 @@ restore_ego_from_pk (void *cls, | |||
1578 | */ | 1591 | */ |
1579 | struct ESCROW_PluginOperationWrapper * | 1592 | struct ESCROW_PluginOperationWrapper * |
1580 | restore_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | 1593 | restore_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, |
1581 | struct GNUNET_ESCROW_Anchor *escrowAnchor, | 1594 | struct GNUNET_ESCROW_Anchor *anchor, |
1582 | const char *egoName, | ||
1583 | GNUNET_SCHEDULER_TaskCallback cb, | 1595 | GNUNET_SCHEDULER_TaskCallback cb, |
1584 | uint32_t op_id) | 1596 | uint32_t op_id) |
1585 | { | 1597 | { |
@@ -1598,18 +1610,18 @@ restore_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
1598 | p_op->h = h; | 1610 | p_op->h = h; |
1599 | // set cont here (has to be scheduled from the IDENTITY service when it finished) | 1611 | // set cont here (has to be scheduled from the IDENTITY service when it finished) |
1600 | p_op->cont = cb; | 1612 | p_op->cont = cb; |
1601 | p_op->egoName = GNUNET_strdup (egoName); | 1613 | p_op->egoName = GNUNET_strdup (anchor->egoName); |
1602 | p_op->userSecret = gns_anchor_data_to_string (h, escrowAnchor); | 1614 | p_op->userSecret = get_user_secret_from_anchor (anchor); |
1603 | 1615 | ||
1604 | w = GNUNET_new (struct ESCROW_Plugin_EgoContinuationWrapper); | 1616 | w = GNUNET_new (struct ESCROW_Plugin_EgoContinuationWrapper); |
1605 | w->h = h; | 1617 | w->h = h; |
1606 | w->op_id = op_id; | 1618 | w->op_id = op_id; |
1607 | p_op->ego_wrap = w; | 1619 | p_op->ego_wrap = w; |
1608 | 1620 | ||
1609 | if (NULL == escrowAnchor) | 1621 | if (NULL == anchor) |
1610 | { | 1622 | { |
1611 | w->ego = NULL; | 1623 | w->ego = NULL; |
1612 | w->emsg = _ ("ESCROW_get was called with escrowAnchor == NULL!\n"); | 1624 | w->emsg = _ ("ESCROW_get was called with anchor == NULL!\n"); |
1613 | // schedule handle_restore_error, which calls the callback and cleans up | 1625 | // schedule handle_restore_error, which calls the callback and cleans up |
1614 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&handle_restore_error, plugin_op_wrap); | 1626 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&handle_restore_error, plugin_op_wrap); |
1615 | return plugin_op_wrap; | 1627 | return plugin_op_wrap; |
@@ -1620,7 +1632,7 @@ restore_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
1620 | return plugin_op_wrap; | 1632 | return plugin_op_wrap; |
1621 | 1633 | ||
1622 | restore_private_key (plugin_op_wrap, | 1634 | restore_private_key (plugin_op_wrap, |
1623 | escrowAnchor, | 1635 | anchor, |
1624 | &restore_ego_from_pk, | 1636 | &restore_ego_from_pk, |
1625 | plugin_op_wrap); | 1637 | plugin_op_wrap); |
1626 | 1638 | ||
@@ -1649,7 +1661,8 @@ gns_get_status (struct GNUNET_ESCROW_Handle *h, | |||
1649 | * | 1661 | * |
1650 | * @param anchorString the encoded escrow anchor string | 1662 | * @param anchorString the encoded escrow anchor string |
1651 | * | 1663 | * |
1652 | * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct | 1664 | * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct, |
1665 | * NULL if we failed to parse the string | ||
1653 | */ | 1666 | */ |
1654 | struct GNUNET_ESCROW_Anchor * | 1667 | struct GNUNET_ESCROW_Anchor * |
1655 | gns_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, | 1668 | gns_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, |
@@ -1657,13 +1670,34 @@ gns_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, | |||
1657 | { | 1670 | { |
1658 | struct GNUNET_ESCROW_Anchor *anchor; | 1671 | struct GNUNET_ESCROW_Anchor *anchor; |
1659 | uint32_t data_size; | 1672 | uint32_t data_size; |
1673 | char *anchorStringCopy, *ptr, *egoNameCopy; | ||
1674 | char delimiter[] = ":"; | ||
1675 | |||
1676 | anchorStringCopy = GNUNET_strdup (anchorString); | ||
1660 | 1677 | ||
1661 | data_size = strlen (anchorString) + 1; | 1678 | // split the string at the first occurrence of the delimiter |
1679 | ptr = strtok (anchorStringCopy, delimiter); | ||
1680 | egoNameCopy = GNUNET_strdup (ptr); | ||
1681 | ptr = strtok (NULL, delimiter); | ||
1662 | 1682 | ||
1683 | if (NULL == ptr) | ||
1684 | { | ||
1685 | // delimiter was not found | ||
1686 | GNUNET_free (egoNameCopy); | ||
1687 | GNUNET_free (anchorStringCopy); | ||
1688 | return NULL; | ||
1689 | } | ||
1690 | |||
1691 | data_size = strlen (ptr) + 1; | ||
1663 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + data_size); | 1692 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + data_size); |
1664 | anchor->size = data_size; | 1693 | anchor->size = data_size; |
1694 | anchor->egoName = egoNameCopy; | ||
1695 | anchor->method = GNUNET_ESCROW_KEY_GNS; | ||
1696 | |||
1665 | // TODO: deserialize? | 1697 | // TODO: deserialize? |
1666 | GNUNET_memcpy (&anchor[1], anchorString, data_size); | 1698 | GNUNET_memcpy (&anchor[1], ptr, data_size); |
1699 | |||
1700 | GNUNET_free (anchorStringCopy); | ||
1667 | 1701 | ||
1668 | return anchor; | 1702 | return anchor; |
1669 | } | 1703 | } |
@@ -1682,9 +1716,14 @@ gns_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h, | |||
1682 | struct GNUNET_ESCROW_Anchor *escrowAnchor) | 1716 | struct GNUNET_ESCROW_Anchor *escrowAnchor) |
1683 | { | 1717 | { |
1684 | char *anchorString; | 1718 | char *anchorString; |
1719 | size_t egoNameSize; | ||
1720 | |||
1721 | egoNameSize = strlen (escrowAnchor->egoName); | ||
1685 | 1722 | ||
1686 | anchorString = GNUNET_malloc (escrowAnchor->size); | 1723 | anchorString = GNUNET_malloc (egoNameSize + 1 + escrowAnchor->size); |
1687 | GNUNET_memcpy (anchorString, &escrowAnchor[1], escrowAnchor->size); | 1724 | GNUNET_memcpy (anchorString, escrowAnchor->egoName, egoNameSize); |
1725 | anchorString[egoNameSize] = ':'; | ||
1726 | GNUNET_memcpy (anchorString + egoNameSize + 1, &escrowAnchor[1], escrowAnchor->size); | ||
1688 | 1727 | ||
1689 | return anchorString; | 1728 | return anchorString; |
1690 | } | 1729 | } |