aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/escrow/escrow_api.c11
-rw-r--r--src/escrow/gnunet-escrow.c45
-rw-r--r--src/escrow/plugin_escrow_anastasis.c51
-rw-r--r--src/escrow/plugin_escrow_gns.c81
-rw-r--r--src/escrow/plugin_escrow_plaintext.c66
-rwxr-xr-xsrc/escrow/test_gns_escrow.sh2
-rwxr-xr-xsrc/escrow/test_plaintext_escrow.sh2
-rw-r--r--src/include/gnunet_escrow_lib.h14
-rw-r--r--src/include/gnunet_escrow_plugin.h9
9 files changed, 188 insertions, 93 deletions
diff --git a/src/escrow/escrow_api.c b/src/escrow/escrow_api.c
index ddbf6a2b7..e35ba3e9e 100644
--- a/src/escrow/escrow_api.c
+++ b/src/escrow/escrow_api.c
@@ -295,8 +295,7 @@ handle_restore_key_result (void *cls)
295 * Get the escrowed data back 295 * Get the escrowed data back
296 * 296 *
297 * @param h the handle for the escrow component 297 * @param h the handle for the escrow component
298 * @param escrowAnchor the escrow anchor returned by the GNUNET_ESCROW_put method 298 * @param anchor the escrow anchor returned by the GNUNET_ESCROW_put method
299 * @param egoName the name of the ego to get back
300 * @param method the escrow method to use 299 * @param method the escrow method to use
301 * @param cb function to call with the restored ego on completion 300 * @param cb function to call with the restored ego on completion
302 * @param cb_cls closure for @a cb 301 * @param cb_cls closure for @a cb
@@ -305,8 +304,7 @@ handle_restore_key_result (void *cls)
305 */ 304 */
306struct GNUNET_ESCROW_Operation * 305struct GNUNET_ESCROW_Operation *
307GNUNET_ESCROW_get (struct GNUNET_ESCROW_Handle *h, 306GNUNET_ESCROW_get (struct GNUNET_ESCROW_Handle *h,
308 struct GNUNET_ESCROW_Anchor *escrowAnchor, 307 struct GNUNET_ESCROW_Anchor *anchor,
309 const char *egoName,
310 enum GNUNET_ESCROW_Key_Escrow_Method method, 308 enum GNUNET_ESCROW_Key_Escrow_Method method,
311 GNUNET_ESCROW_EgoContinuation cb, 309 GNUNET_ESCROW_EgoContinuation cb,
312 void *cb_cls) 310 void *cb_cls)
@@ -323,7 +321,7 @@ GNUNET_ESCROW_get (struct GNUNET_ESCROW_Handle *h,
323 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 321 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
324 322
325 api = init_plugin (h, method); 323 api = init_plugin (h, method);
326 op->plugin_op_wrap = api->restore_key (h, escrowAnchor, egoName, &handle_restore_key_result, op->id); 324 op->plugin_op_wrap = api->restore_key (h, anchor, &handle_restore_key_result, op->id);
327 325
328 return op; 326 return op;
329} 327}
@@ -420,7 +418,8 @@ GNUNET_ESCROW_get_status (struct GNUNET_ESCROW_Handle *h,
420 * @param anchorString the encoded escrow anchor string 418 * @param anchorString the encoded escrow anchor string
421 * @param method the escrow method to use 419 * @param method the escrow method to use
422 * 420 *
423 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct 421 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct,
422 * NULL if we failed to parse the string
424 */ 423 */
425struct GNUNET_ESCROW_Anchor * 424struct GNUNET_ESCROW_Anchor *
426GNUNET_ESCROW_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, 425GNUNET_ESCROW_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h,
diff --git a/src/escrow/gnunet-escrow.c b/src/escrow/gnunet-escrow.c
index 23fa5d061..b212247e4 100644
--- a/src/escrow/gnunet-escrow.c
+++ b/src/escrow/gnunet-escrow.c
@@ -63,7 +63,7 @@ static char *verify_ego;
63/** 63/**
64 * -G option 64 * -G option
65 */ 65 */
66static char *get_ego; 66static int get_flag;
67 67
68/** 68/**
69 * -S option 69 * -S option
@@ -172,11 +172,6 @@ do_cleanup (void *cls)
172 GNUNET_free (verify_ego); 172 GNUNET_free (verify_ego);
173 verify_ego = NULL; 173 verify_ego = NULL;
174 } 174 }
175 if (NULL != get_ego)
176 {
177 GNUNET_free (get_ego);
178 get_ego = NULL;
179 }
180 if (NULL != status_ego) 175 if (NULL != status_ego)
181 { 176 {
182 GNUNET_free (status_ego); 177 GNUNET_free (status_ego);
@@ -313,18 +308,10 @@ start_process ()
313 return; 308 return;
314 } 309 }
315 /* get */ 310 /* get */
316 if (NULL != get_ego) 311 if (GNUNET_YES == get_flag)
317 { 312 {
318 if (NULL != ego)
319 {
320 ret = 1;
321 fprintf (stderr, "The name %s is already in use for an ego\n", get_ego);
322 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
323 return;
324 }
325 escrow_op = GNUNET_ESCROW_get (escrow_handle, 313 escrow_op = GNUNET_ESCROW_get (escrow_handle,
326 anchor, 314 anchor,
327 get_ego,
328 method, 315 method,
329 &get_cb, 316 &get_cb,
330 NULL); 317 NULL);
@@ -388,7 +375,7 @@ ego_cb (void *cls,
388 } 375 }
389 return; 376 return;
390 } 377 }
391 if (0 != strcmp (name, ego_name)) 378 if (NULL != ego_name && 0 != strcmp (name, ego_name))
392 return; 379 return;
393 ego = e; 380 ego = e;
394} 381}
@@ -414,7 +401,7 @@ run (void *cls,
414 401
415 if (NULL != put_ego) 402 if (NULL != put_ego)
416 { 403 {
417 if (NULL != verify_ego || NULL != get_ego || NULL != status_ego) 404 if (NULL != verify_ego || GNUNET_YES == get_flag || NULL != status_ego)
418 { 405 {
419 ret = 1; 406 ret = 1;
420 fprintf (stderr, _ ("-P may only be used without -V, -G or -S!\n")); 407 fprintf (stderr, _ ("-P may only be used without -V, -G or -S!\n"));
@@ -425,7 +412,7 @@ run (void *cls,
425 } 412 }
426 else if (NULL != verify_ego) 413 else if (NULL != verify_ego)
427 { 414 {
428 if (NULL != get_ego || NULL != status_ego) 415 if (GNUNET_YES == get_flag || NULL != status_ego)
429 { 416 {
430 ret = 1; 417 ret = 1;
431 fprintf (stderr, _ ("-V may only be used without -P, -G or -S!\n")); 418 fprintf (stderr, _ ("-V may only be used without -P, -G or -S!\n"));
@@ -440,7 +427,7 @@ run (void *cls,
440 } 427 }
441 ego_name = verify_ego; 428 ego_name = verify_ego;
442 } 429 }
443 else if (NULL != get_ego) 430 else if (GNUNET_YES == get_flag)
444 { 431 {
445 if (NULL != status_ego) 432 if (NULL != status_ego)
446 { 433 {
@@ -455,7 +442,7 @@ run (void *cls,
455 fprintf (stderr, _ ("-a is needed for -G!\n")); 442 fprintf (stderr, _ ("-a is needed for -G!\n"));
456 return; 443 return;
457 } 444 }
458 ego_name = get_ego; 445 ego_name = NULL;
459 } 446 }
460 else if (NULL != status_ego) 447 else if (NULL != status_ego)
461 { 448 {
@@ -480,7 +467,7 @@ run (void *cls,
480 else 467 else
481 { 468 {
482 ret = 1; 469 ret = 1;
483 fprintf (stderr, _ ("unknown method name!")); 470 fprintf (stderr, _ ("unknown method name!\n"));
484 return; 471 return;
485 } 472 }
486 473
@@ -492,6 +479,13 @@ run (void *cls,
492 anchor = GNUNET_ESCROW_anchor_string_to_data (escrow_handle, 479 anchor = GNUNET_ESCROW_anchor_string_to_data (escrow_handle,
493 anchor_string, 480 anchor_string,
494 method); 481 method);
482 if (NULL == anchor)
483 {
484 ret = 1;
485 fprintf (stderr, _ ("failed to parse anchor string!\n"));
486 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
487 return;
488 }
495 } 489 }
496 490
497 /* connect to identity service in order to get the egos */ 491 /* connect to identity service in order to get the egos */
@@ -513,11 +507,10 @@ main (int argc, char *const argv[])
513 "NAME", 507 "NAME",
514 gettext_noop ("Verify the escrow of the ego NAME"), 508 gettext_noop ("Verify the escrow of the ego NAME"),
515 &verify_ego), 509 &verify_ego),
516 GNUNET_GETOPT_option_string ('G', 510 GNUNET_GETOPT_option_flag ('G',
517 "get", 511 "get",
518 "NAME", 512 gettext_noop ("Get an ego back from escrow"),
519 gettext_noop ("Get the ego NAME back from escrow"), 513 &get_flag),
520 &get_ego),
521 GNUNET_GETOPT_option_string ('S', 514 GNUNET_GETOPT_option_string ('S',
522 "status", 515 "status",
523 "NAME", 516 "NAME",
diff --git a/src/escrow/plugin_escrow_anastasis.c b/src/escrow/plugin_escrow_anastasis.c
index c0be1f50f..b3029f885 100644
--- a/src/escrow/plugin_escrow_anastasis.c
+++ b/src/escrow/plugin_escrow_anastasis.c
@@ -110,8 +110,7 @@ verify_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h,
110 * Restore the key from Anastasis escrow 110 * Restore the key from Anastasis escrow
111 * 111 *
112 * @param h the handle for the escrow component 112 * @param h the handle for the escrow component
113 * @param escrowAnchor the escrow anchor needed to restore the key 113 * @param anchor the escrow anchor needed to restore the key
114 * @param egoName the name of the ego to restore
115 * @param cb the function called upon completion 114 * @param cb the function called upon completion
116 * @param op_id unique ID of the respective ESCROW_Operation 115 * @param op_id unique ID of the respective ESCROW_Operation
117 * 116 *
@@ -119,8 +118,7 @@ verify_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h,
119 */ 118 */
120struct ESCROW_PluginOperationWrapper * 119struct ESCROW_PluginOperationWrapper *
121restore_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h, 120restore_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h,
122 struct GNUNET_ESCROW_Anchor *escrowAnchor, 121 struct GNUNET_ESCROW_Anchor *anchor,
123 const char *egoName,
124 GNUNET_SCHEDULER_TaskCallback cb, 122 GNUNET_SCHEDULER_TaskCallback cb,
125 uint32_t op_id) 123 uint32_t op_id)
126{ 124{
@@ -159,7 +157,8 @@ anastasis_get_status (struct GNUNET_ESCROW_Handle *h,
159 * 157 *
160 * @param anchorString the encoded escrow anchor string 158 * @param anchorString the encoded escrow anchor string
161 * 159 *
162 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct 160 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct,
161 * NULL if we failed to parse the string
163 */ 162 */
164struct GNUNET_ESCROW_Anchor * 163struct GNUNET_ESCROW_Anchor *
165anastasis_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, 164anastasis_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h,
@@ -167,13 +166,34 @@ anastasis_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h,
167{ 166{
168 struct GNUNET_ESCROW_Anchor *anchor; 167 struct GNUNET_ESCROW_Anchor *anchor;
169 uint32_t data_size; 168 uint32_t data_size;
170 169 char *anchorStringCopy, *ptr, *egoNameCopy;
171 data_size = strlen (anchorString) + 1; 170 char delimiter[] = ":";
172 171
172 anchorStringCopy = GNUNET_strdup (anchorString);
173
174 // split the string at the first occurrence of the delimiter
175 ptr = strtok (anchorStringCopy, delimiter);
176 egoNameCopy = GNUNET_strdup (ptr);
177 ptr = strtok (NULL, delimiter);
178
179 if (NULL == ptr)
180 {
181 // delimiter was not found
182 GNUNET_free (egoNameCopy);
183 GNUNET_free (anchorStringCopy);
184 return NULL;
185 }
186
187 data_size = strlen (ptr) + 1;
173 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + data_size); 188 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + data_size);
174 anchor->size = data_size; 189 anchor->size = data_size;
190 anchor->egoName = egoNameCopy;
191 anchor->method = GNUNET_ESCROW_KEY_ANASTASIS;
192
175 // TODO: deserialize? 193 // TODO: deserialize?
176 GNUNET_memcpy (&anchor[1], anchorString, data_size); 194 GNUNET_memcpy (&anchor[1], ptr, data_size);
195
196 GNUNET_free (anchorStringCopy);
177 197
178 return anchor; 198 return anchor;
179} 199}
@@ -191,8 +211,17 @@ char *
191anastasis_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h, 211anastasis_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
192 struct GNUNET_ESCROW_Anchor *escrowAnchor) 212 struct GNUNET_ESCROW_Anchor *escrowAnchor)
193{ 213{
194 // TODO: implement 214 char *anchorString;
195 return NULL; 215 size_t egoNameSize;
216
217 egoNameSize = strlen (escrowAnchor->egoName);
218
219 anchorString = GNUNET_malloc (egoNameSize + 1 + escrowAnchor->size);
220 GNUNET_memcpy (anchorString, escrowAnchor->egoName, egoNameSize);
221 anchorString[egoNameSize] = ':';
222 GNUNET_memcpy (anchorString + egoNameSize + 1, &escrowAnchor[1], escrowAnchor->size);
223
224 return anchorString;
196} 225}
197 226
198 227
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 */
41char *
42gns_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
1309static char *
1310get_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
1314static void 1321static void
1315restore_private_key (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, 1322restore_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 */
1579struct ESCROW_PluginOperationWrapper * 1592struct ESCROW_PluginOperationWrapper *
1580restore_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, 1593restore_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 */
1654struct GNUNET_ESCROW_Anchor * 1667struct GNUNET_ESCROW_Anchor *
1655gns_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, 1668gns_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}
diff --git a/src/escrow/plugin_escrow_plaintext.c b/src/escrow/plugin_escrow_plaintext.c
index 0dab8fd1e..eace829ea 100644
--- a/src/escrow/plugin_escrow_plaintext.c
+++ b/src/escrow/plugin_escrow_plaintext.c
@@ -182,6 +182,7 @@ start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
182 anchorDataSize = strlen (pkString) + 1; 182 anchorDataSize = strlen (pkString) + 1;
183 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize); 183 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize);
184 anchor->method = GNUNET_ESCROW_KEY_PLAINTEXT; 184 anchor->method = GNUNET_ESCROW_KEY_PLAINTEXT;
185 anchor->egoName = GNUNET_strdup (ego->name);
185 anchor->size = anchorDataSize; 186 anchor->size = anchorDataSize;
186 GNUNET_memcpy (&anchor[1], pkString, anchorDataSize); 187 GNUNET_memcpy (&anchor[1], pkString, anchorDataSize);
187 188
@@ -256,11 +257,17 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
256 p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); 257 p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap);
257 return plugin_op_wrap; 258 return plugin_op_wrap;
258 } 259 }
260 if (0 != strcmp (ego->name, escrowAnchor->egoName))
261 {
262 w->verificationResult = GNUNET_ESCROW_INVALID;
263 w->emsg = _ ("This anchor was not created when putting ego that in escrow!\n");
264 p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap);
265 return plugin_op_wrap;
266 }
259 pk = GNUNET_IDENTITY_ego_get_private_key (ego); 267 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
260 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); 268 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
261 verificationResult = strncmp (pkString, 269 verificationResult = strcmp (pkString,
262 (char *)&escrowAnchor[1], 270 (char *)&escrowAnchor[1]) == 0 ?
263 strlen (pkString)) == 0 ?
264 GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; 271 GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID;
265 272
266 w->verificationResult = verificationResult; 273 w->verificationResult = verificationResult;
@@ -357,8 +364,7 @@ handle_restore_error (void *cls)
357 * Restore the key from plaintext escrow 364 * Restore the key from plaintext escrow
358 * 365 *
359 * @param h the handle for the escrow component 366 * @param h the handle for the escrow component
360 * @param escrowAnchor the escrow anchor needed to restore the key 367 * @param anchor the escrow anchor needed to restore the key
361 * @param egoName the name of the ego to restore
362 * @param cb the function called upon completion 368 * @param cb the function called upon completion
363 * @param op_id unique ID of the respective ESCROW_Operation 369 * @param op_id unique ID of the respective ESCROW_Operation
364 * 370 *
@@ -366,8 +372,7 @@ handle_restore_error (void *cls)
366 */ 372 */
367struct ESCROW_PluginOperationWrapper * 373struct ESCROW_PluginOperationWrapper *
368restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, 374restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
369 struct GNUNET_ESCROW_Anchor *escrowAnchor, 375 struct GNUNET_ESCROW_Anchor *anchor,
370 const char *egoName,
371 ESCROW_Plugin_Continuation cb, 376 ESCROW_Plugin_Continuation cb,
372 uint32_t op_id) 377 uint32_t op_id)
373{ 378{
@@ -393,17 +398,17 @@ restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
393 w->op_id = op_id; 398 w->op_id = op_id;
394 p_op->ego_wrap = w; 399 p_op->ego_wrap = w;
395 400
396 if (NULL == escrowAnchor) 401 if (NULL == anchor)
397 { 402 {
398 w->ego = NULL; 403 w->ego = NULL;
399 w->emsg = _ ("ESCROW_get was called with escrowAnchor == NULL!\n"); 404 w->emsg = _ ("ESCROW_get was called with anchor == NULL!\n");
400 // schedule handle_restore_error, which calls the callback and cleans up 405 // schedule handle_restore_error, which calls the callback and cleans up
401 p_op->sched_task = GNUNET_SCHEDULER_add_now (&handle_restore_error, plugin_op_wrap); 406 p_op->sched_task = GNUNET_SCHEDULER_add_now (&handle_restore_error, plugin_op_wrap);
402 return plugin_op_wrap; 407 return plugin_op_wrap;
403 } 408 }
404 if (GNUNET_OK != 409 if (GNUNET_OK !=
405 GNUNET_CRYPTO_ecdsa_private_key_from_string ((char *)&escrowAnchor[1], 410 GNUNET_CRYPTO_ecdsa_private_key_from_string ((char *)&anchor[1],
406 strlen ((char *)&escrowAnchor[1]), 411 strlen ((char *)&anchor[1]),
407 &pk)) 412 &pk))
408 { 413 {
409 w->ego = NULL; 414 w->ego = NULL;
@@ -414,7 +419,7 @@ restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
414 } 419 }
415 420
416 p_op->id_op = GNUNET_IDENTITY_create (identity_handle, 421 p_op->id_op = GNUNET_IDENTITY_create (identity_handle,
417 egoName, 422 anchor->egoName,
418 &pk, 423 &pk,
419 &create_finished, 424 &create_finished,
420 p_op); 425 p_op);
@@ -445,7 +450,8 @@ plaintext_get_status (struct GNUNET_ESCROW_Handle *h,
445 * @param h the handle for the escrow component 450 * @param h the handle for the escrow component
446 * @param anchorString the encoded escrow anchor string 451 * @param anchorString the encoded escrow anchor string
447 * 452 *
448 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct 453 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct,
454 * NULL if we failed to parse the string
449 */ 455 */
450struct GNUNET_ESCROW_Anchor * 456struct GNUNET_ESCROW_Anchor *
451plaintext_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, 457plaintext_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h,
@@ -453,13 +459,34 @@ plaintext_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h,
453{ 459{
454 struct GNUNET_ESCROW_Anchor *anchor; 460 struct GNUNET_ESCROW_Anchor *anchor;
455 uint32_t data_size; 461 uint32_t data_size;
462 char *anchorStringCopy, *ptr, *egoNameCopy;
463 char delimiter[] = ":";
464
465 anchorStringCopy = GNUNET_strdup (anchorString);
456 466
457 data_size = strlen (anchorString) + 1; 467 // split the string at the first occurrence of the delimiter
468 ptr = strtok (anchorStringCopy, delimiter);
469 egoNameCopy = GNUNET_strdup (ptr);
470 ptr = strtok (NULL, delimiter);
458 471
472 if (NULL == ptr)
473 {
474 // delimiter was not found
475 GNUNET_free (egoNameCopy);
476 GNUNET_free (anchorStringCopy);
477 return NULL;
478 }
479
480 data_size = strlen (ptr) + 1;
459 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + data_size); 481 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + data_size);
460 anchor->size = data_size; 482 anchor->size = data_size;
483 anchor->egoName = egoNameCopy;
484 anchor->method = GNUNET_ESCROW_KEY_PLAINTEXT;
485
461 // TODO: deserialize? 486 // TODO: deserialize?
462 GNUNET_memcpy (&anchor[1], anchorString, data_size); 487 GNUNET_memcpy (&anchor[1], ptr, data_size);
488
489 GNUNET_free (anchorStringCopy);
463 490
464 return anchor; 491 return anchor;
465} 492}
@@ -478,9 +505,14 @@ plaintext_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
478 struct GNUNET_ESCROW_Anchor *escrowAnchor) 505 struct GNUNET_ESCROW_Anchor *escrowAnchor)
479{ 506{
480 char *anchorString; 507 char *anchorString;
508 size_t egoNameSize;
509
510 egoNameSize = strlen (escrowAnchor->egoName);
481 511
482 anchorString = GNUNET_malloc (escrowAnchor->size); 512 anchorString = GNUNET_malloc (egoNameSize + 1 + escrowAnchor->size);
483 GNUNET_memcpy (anchorString, &escrowAnchor[1], escrowAnchor->size); 513 GNUNET_memcpy (anchorString, escrowAnchor->egoName, egoNameSize);
514 anchorString[egoNameSize] = ':';
515 GNUNET_memcpy (anchorString + egoNameSize + 1, &escrowAnchor[1], escrowAnchor->size);
484 516
485 return anchorString; 517 return anchorString;
486} 518}
diff --git a/src/escrow/test_gns_escrow.sh b/src/escrow/test_gns_escrow.sh
index b29650718..5af2c806d 100755
--- a/src/escrow/test_gns_escrow.sh
+++ b/src/escrow/test_gns_escrow.sh
@@ -36,7 +36,7 @@ then
36 exit 1 36 exit 1
37fi 37fi
38gnunet-identity -D testego -c test_escrow.conf 38gnunet-identity -D testego -c test_escrow.conf
39gnunet-escrow -m gns -G testego -a $ANCHOR -c test_escrow.conf 39gnunet-escrow -m gns -G -a $ANCHOR -c test_escrow.conf
40if test $? != 0 40if test $? != 0
41then 41then
42 echo "GNS restore failed!" 42 echo "GNS restore failed!"
diff --git a/src/escrow/test_plaintext_escrow.sh b/src/escrow/test_plaintext_escrow.sh
index 8113110e2..6b66de8ba 100755
--- a/src/escrow/test_plaintext_escrow.sh
+++ b/src/escrow/test_plaintext_escrow.sh
@@ -35,7 +35,7 @@ then
35 exit 1 35 exit 1
36fi 36fi
37gnunet-identity -D testego -c test_escrow.conf 37gnunet-identity -D testego -c test_escrow.conf
38gnunet-escrow -m plaintext -G testego -a $ANCHOR -c test_escrow.conf 38gnunet-escrow -m plaintext -G -a $ANCHOR -c test_escrow.conf
39if test $? != 0 39if test $? != 0
40then 40then
41 echo "Plaintext restore failed!" 41 echo "Plaintext restore failed!"
diff --git a/src/include/gnunet_escrow_lib.h b/src/include/gnunet_escrow_lib.h
index 7d9d39dce..dddf5e030 100644
--- a/src/include/gnunet_escrow_lib.h
+++ b/src/include/gnunet_escrow_lib.h
@@ -75,6 +75,11 @@ struct GNUNET_ESCROW_Anchor
75 enum GNUNET_ESCROW_Key_Escrow_Method method; 75 enum GNUNET_ESCROW_Key_Escrow_Method method;
76 76
77 /** 77 /**
78 * The name of the ego that was put in escrow.
79 */
80 char *egoName;
81
82 /**
78 * The size of the anchor data. 83 * The size of the anchor data.
79 */ 84 */
80 uint32_t size; 85 uint32_t size;
@@ -305,8 +310,7 @@ GNUNET_ESCROW_put (
305 * Get the escrowed data back 310 * Get the escrowed data back
306 * 311 *
307 * @param h the handle for the escrow component 312 * @param h the handle for the escrow component
308 * @param escrowAnchor the escrow anchor returned by the GNUNET_ESCROW_put method 313 * @param anchor the escrow anchor returned by the GNUNET_ESCROW_put method
309 * @param egoName the name of the ego to get back
310 * @param method the escrow method to use 314 * @param method the escrow method to use
311 * @param cb function to call with the restored ego on completion 315 * @param cb function to call with the restored ego on completion
312 * @param cb_cls closure for @a cb 316 * @param cb_cls closure for @a cb
@@ -316,8 +320,7 @@ GNUNET_ESCROW_put (
316struct GNUNET_ESCROW_Operation * 320struct GNUNET_ESCROW_Operation *
317GNUNET_ESCROW_get ( 321GNUNET_ESCROW_get (
318 struct GNUNET_ESCROW_Handle *h, 322 struct GNUNET_ESCROW_Handle *h,
319 struct GNUNET_ESCROW_Anchor *escrowAnchor, 323 struct GNUNET_ESCROW_Anchor *anchor,
320 const char *egoName,
321 enum GNUNET_ESCROW_Key_Escrow_Method method, 324 enum GNUNET_ESCROW_Key_Escrow_Method method,
322 GNUNET_ESCROW_EgoContinuation cb, 325 GNUNET_ESCROW_EgoContinuation cb,
323 void *cb_cls); 326 void *cb_cls);
@@ -371,7 +374,8 @@ GNUNET_ESCROW_get_status (
371 * @param anchorString the encoded escrow anchor string 374 * @param anchorString the encoded escrow anchor string
372 * @param method the escrow method to use 375 * @param method the escrow method to use
373 * 376 *
374 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct 377 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct,
378 * NULL if we failed to parse the string
375 */ 379 */
376struct GNUNET_ESCROW_Anchor * 380struct GNUNET_ESCROW_Anchor *
377GNUNET_ESCROW_anchor_string_to_data ( 381GNUNET_ESCROW_anchor_string_to_data (
diff --git a/src/include/gnunet_escrow_plugin.h b/src/include/gnunet_escrow_plugin.h
index b54506970..b8b88ff3f 100644
--- a/src/include/gnunet_escrow_plugin.h
+++ b/src/include/gnunet_escrow_plugin.h
@@ -85,8 +85,7 @@ typedef struct ESCROW_PluginOperationWrapper *(*GNUNET_ESCROW_VerifyKeyEscrowFun
85 * Function called to restore a key from an escrow 85 * Function called to restore a key from an escrow
86 * 86 *
87 * @param h the handle for the escrow component 87 * @param h the handle for the escrow component
88 * @param escrowAnchor the escrow anchor needed to restore the key 88 * @param anchor the escrow anchor needed to restore the key
89 * @param egoName the name of the ego to restore
90 * @param cb the function called upon completion 89 * @param cb the function called upon completion
91 * @param op_id unique ID of the respective ESCROW_Operation 90 * @param op_id unique ID of the respective ESCROW_Operation
92 * 91 *
@@ -94,8 +93,7 @@ typedef struct ESCROW_PluginOperationWrapper *(*GNUNET_ESCROW_VerifyKeyEscrowFun
94 */ 93 */
95typedef struct ESCROW_PluginOperationWrapper *(*GNUNET_ESCROW_RestoreKeyFunction) ( 94typedef struct ESCROW_PluginOperationWrapper *(*GNUNET_ESCROW_RestoreKeyFunction) (
96 struct GNUNET_ESCROW_Handle *h, 95 struct GNUNET_ESCROW_Handle *h,
97 struct GNUNET_ESCROW_Anchor *escrowAnchor, 96 struct GNUNET_ESCROW_Anchor *anchor,
98 const char *egoName,
99 GNUNET_SCHEDULER_TaskCallback cb, 97 GNUNET_SCHEDULER_TaskCallback cb,
100 uint32_t op_id); 98 uint32_t op_id);
101 99
@@ -122,7 +120,8 @@ typedef struct GNUNET_ESCROW_Status *(*GNUNET_ESCROW_GetEscrowStatusFunction) (
122 * @param h the handle for the escrow component 120 * @param h the handle for the escrow component
123 * @param anchorString the encoded escrow anchor string 121 * @param anchorString the encoded escrow anchor string
124 * 122 *
125 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct 123 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct,
124 * NULL if we failed to parse the string
126 */ 125 */
127typedef struct GNUNET_ESCROW_Anchor *(*GNUNET_ESCROW_AnchorStringToDataFunction) ( 126typedef struct GNUNET_ESCROW_Anchor *(*GNUNET_ESCROW_AnchorStringToDataFunction) (
128 struct GNUNET_ESCROW_Handle *h, 127 struct GNUNET_ESCROW_Handle *h,