From 3a4b9fedc88c8c30e25a32336c512c387e00436e Mon Sep 17 00:00:00 2001 From: jospaeth Date: Sun, 19 Jul 2020 14:05:32 +0200 Subject: fix plaintext escrow --- src/escrow/escrow_plugin_helper.c | 11 +++++++++- src/escrow/gnunet-escrow.c | 26 +++++++++++++++------- src/escrow/plugin_escrow_anastasis.c | 2 +- src/escrow/plugin_escrow_gns.c | 2 +- src/escrow/plugin_escrow_plaintext.c | 42 ++++++++++++++++++++---------------- 5 files changed, 54 insertions(+), 29 deletions(-) (limited to 'src/escrow') diff --git a/src/escrow/escrow_plugin_helper.c b/src/escrow/escrow_plugin_helper.c index 05c5be90b..afbbd409a 100644 --- a/src/escrow/escrow_plugin_helper.c +++ b/src/escrow/escrow_plugin_helper.c @@ -79,7 +79,7 @@ ESCROW_list_ego (void *cls, { ph->state = ESCROW_PLUGIN_STATE_POST_INIT; /* call IdentityInitContinuation */ - ph->cont (); + ph->id_init_cont (); return; } GNUNET_assert (NULL != ego); @@ -107,6 +107,11 @@ ESCROW_list_ego (void *cls, /* Rename */ GNUNET_free (ego_entry->identifier); ego_entry->identifier = GNUNET_strdup (identifier); + /* TODO: this handles an edge case when the user restores an ego + that already exists. In that case, @param ego is the same for the + new as for the existing ego and this method thinks it is a rename. */ + if (NULL != ph->ego_create_cont) + ph->ego_create_cont (ego); break; } } @@ -121,6 +126,10 @@ ESCROW_list_ego (void *cls, GNUNET_CONTAINER_DLL_insert_tail (ph->ego_head, ph->ego_tail, ego_entry); + /* new ego is added to the list, call ego_create_cont if this was + because of an ESCROW_get operation, i.e. ego_create_cont != NULL */ + if (NULL != ph->ego_create_cont) + ph->ego_create_cont (ego); } } else diff --git a/src/escrow/gnunet-escrow.c b/src/escrow/gnunet-escrow.c index 1651d96ed..32b139259 100644 --- a/src/escrow/gnunet-escrow.c +++ b/src/escrow/gnunet-escrow.c @@ -117,7 +117,11 @@ static struct GNUNET_SCHEDULER_Task *cleanup_task; static void do_cleanup (void *cls) { - GNUNET_ESCROW_fini (escrow_handle); + cleanup_task = NULL; + if (NULL != escrow_handle) + GNUNET_ESCROW_fini (escrow_handle); + if (NULL != identity_handle) + GNUNET_IDENTITY_disconnect (identity_handle); if (NULL != put_ego) { GNUNET_free (put_ego); @@ -135,7 +139,7 @@ do_cleanup (void *cls) } if (NULL != ego) { - GNUNET_free (ego); + //GNUNET_free (ego); // TODO: free correctly! ego = NULL; } method = 0; @@ -153,7 +157,8 @@ put_cb (void *cls, method); fprintf (stdout, "Escrow finished! Please keep the following anchor \ - in order to restore the key later!\n%s\n", anchorString); +in order to restore the key later!\n%s\n", anchorString); + cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } @@ -175,6 +180,7 @@ verify_cb (void *cls, default: fprintf (stderr, "invalid verificationResult!\n"); } + cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } @@ -188,7 +194,8 @@ get_cb (void *cls, fprintf (stderr, _ ("escrow failed!")); return; } - fprintf (stdout, "Ego %s could successfully be restored!", ego->name); + fprintf (stdout, "Ego %s could successfully be restored!\n", ego->name); + cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } @@ -342,10 +349,13 @@ run (void *cls, escrow_handle = GNUNET_ESCROW_init (c); - /* parse anchor_string according to method */ - anchor = GNUNET_ESCROW_anchor_string_to_data (escrow_handle, - anchor_string, - method); + if (NULL != anchor_string) + { + /* parse anchor_string according to method */ + anchor = GNUNET_ESCROW_anchor_string_to_data (escrow_handle, + anchor_string, + method); + } /* connect to identity service in order to get the egos */ identity_handle = GNUNET_IDENTITY_connect (c, &ego_cb, ego_name); diff --git a/src/escrow/plugin_escrow_anastasis.c b/src/escrow/plugin_escrow_anastasis.c index c4b4ce1ef..0b38463ca 100644 --- a/src/escrow/plugin_escrow_anastasis.c +++ b/src/escrow/plugin_escrow_anastasis.c @@ -178,7 +178,7 @@ libgnunet_plugin_escrow_anastasis_init (void *cls) api->restore_key = &restore_anastasis_key_escrow; api->anchor_string_to_data = &anastasis_anchor_string_to_data; - ph.cont = &anastasis_cont_init; + ph.id_init_cont = &anastasis_cont_init; identity_handle = GNUNET_IDENTITY_connect (cfg, &ESCROW_list_ego, diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c index f6b2822da..93d68f4d3 100644 --- a/src/escrow/plugin_escrow_gns.c +++ b/src/escrow/plugin_escrow_gns.c @@ -208,7 +208,7 @@ libgnunet_plugin_escrow_gns_init (void *cls) api->restore_key = &restore_gns_key_escrow; api->anchor_string_to_data = &gns_anchor_string_to_data; - ph.cont = &gns_cont_init; + ph.id_init_cont = &gns_cont_init; identity_handle = GNUNET_IDENTITY_connect (cfg, &ESCROW_list_ego, diff --git a/src/escrow/plugin_escrow_plaintext.c b/src/escrow/plugin_escrow_plaintext.c index c3680b625..d6f224330 100644 --- a/src/escrow/plugin_escrow_plaintext.c +++ b/src/escrow/plugin_escrow_plaintext.c @@ -122,8 +122,20 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Operation *op, } +void +ego_created (const struct GNUNET_IDENTITY_Ego *ego) +{ + ph.ego_create_cont = NULL; + ph.curr_op->cb_get (ph.curr_op->cb_cls, ego); + ph.curr_op = NULL; +} + + /** * Creation operation finished. + * This method only handles errors that may have occured. On success, + * the callback is executed by the ESCROW_list_ego function, as the + * new ego is in our ego list only after ESCROW_list_ego has added it. * * @param cls pointer to operation handle * @param pk private key of the ego, or NULL on error @@ -135,29 +147,23 @@ create_finished (void *cls, const char *emsg) { struct GNUNET_ESCROW_Operation *op = cls; - struct EgoEntry *ego_list; if (NULL == pk) { - fprintf (stderr, _ ("Failed to create ego: %s\n"), emsg); + if (NULL != emsg) + fprintf (stderr, + "Identity create operation returned with error: %s\n", + emsg); + else + fprintf (stderr, "Failed to create ego!"); + op->cb_get (op->cb_cls, NULL); return; } - /* find the ego in our ego list */ - ego_list = ph.ego_head; - while (NULL != ego_list) - { - if (&ego_list->ego->pk == pk) - { - /* ego found */ - op->cb_get (op->cb_cls, ego_list->ego); - return; - } - ego_list = ego_list->next; - } - - /* ego not found (should not happen!) */ - op->cb_get (op->cb_cls, NULL); + /* no error occured, op->cb_get will be called from ESCROW_list_ego after + adding the new ego to our list */ + ph.ego_create_cont = &ego_created; + ph.curr_op = op; } @@ -278,7 +284,7 @@ libgnunet_plugin_escrow_plaintext_init (void *cls) api->anchor_string_to_data = &plaintext_anchor_string_to_data; api->anchor_data_to_string = &plaintext_anchor_data_to_string; - ph.cont = &plaintext_cont_init; + ph.id_init_cont = &plaintext_cont_init; identity_handle = GNUNET_IDENTITY_connect (cfg, &ESCROW_list_ego, -- cgit v1.2.3