aboutsummaryrefslogtreecommitdiff
path: root/src/escrow
diff options
context:
space:
mode:
authorjospaeth <spaethj@in.tum.de>2020-07-19 14:05:32 +0200
committerjospaeth <spaethj@in.tum.de>2020-07-19 14:05:32 +0200
commit3a4b9fedc88c8c30e25a32336c512c387e00436e (patch)
tree7d610109b04d9b0bc7dfcc348a6d17e38c56d5e6 /src/escrow
parent15ad508b20fbca46d8b9a8682a723b34098545bf (diff)
downloadgnunet-3a4b9fedc88c8c30e25a32336c512c387e00436e.tar.gz
gnunet-3a4b9fedc88c8c30e25a32336c512c387e00436e.zip
fix plaintext escrow
Diffstat (limited to 'src/escrow')
-rw-r--r--src/escrow/escrow_plugin_helper.c11
-rw-r--r--src/escrow/gnunet-escrow.c26
-rw-r--r--src/escrow/plugin_escrow_anastasis.c2
-rw-r--r--src/escrow/plugin_escrow_gns.c2
-rw-r--r--src/escrow/plugin_escrow_plaintext.c42
5 files changed, 54 insertions, 29 deletions
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,
79 { 79 {
80 ph->state = ESCROW_PLUGIN_STATE_POST_INIT; 80 ph->state = ESCROW_PLUGIN_STATE_POST_INIT;
81 /* call IdentityInitContinuation */ 81 /* call IdentityInitContinuation */
82 ph->cont (); 82 ph->id_init_cont ();
83 return; 83 return;
84 } 84 }
85 GNUNET_assert (NULL != ego); 85 GNUNET_assert (NULL != ego);
@@ -107,6 +107,11 @@ ESCROW_list_ego (void *cls,
107 /* Rename */ 107 /* Rename */
108 GNUNET_free (ego_entry->identifier); 108 GNUNET_free (ego_entry->identifier);
109 ego_entry->identifier = GNUNET_strdup (identifier); 109 ego_entry->identifier = GNUNET_strdup (identifier);
110 /* TODO: this handles an edge case when the user restores an ego
111 that already exists. In that case, @param ego is the same for the
112 new as for the existing ego and this method thinks it is a rename. */
113 if (NULL != ph->ego_create_cont)
114 ph->ego_create_cont (ego);
110 break; 115 break;
111 } 116 }
112 } 117 }
@@ -121,6 +126,10 @@ ESCROW_list_ego (void *cls,
121 GNUNET_CONTAINER_DLL_insert_tail (ph->ego_head, 126 GNUNET_CONTAINER_DLL_insert_tail (ph->ego_head,
122 ph->ego_tail, 127 ph->ego_tail,
123 ego_entry); 128 ego_entry);
129 /* new ego is added to the list, call ego_create_cont if this was
130 because of an ESCROW_get operation, i.e. ego_create_cont != NULL */
131 if (NULL != ph->ego_create_cont)
132 ph->ego_create_cont (ego);
124 } 133 }
125 } 134 }
126 else 135 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;
117static void 117static void
118do_cleanup (void *cls) 118do_cleanup (void *cls)
119{ 119{
120 GNUNET_ESCROW_fini (escrow_handle); 120 cleanup_task = NULL;
121 if (NULL != escrow_handle)
122 GNUNET_ESCROW_fini (escrow_handle);
123 if (NULL != identity_handle)
124 GNUNET_IDENTITY_disconnect (identity_handle);
121 if (NULL != put_ego) 125 if (NULL != put_ego)
122 { 126 {
123 GNUNET_free (put_ego); 127 GNUNET_free (put_ego);
@@ -135,7 +139,7 @@ do_cleanup (void *cls)
135 } 139 }
136 if (NULL != ego) 140 if (NULL != ego)
137 { 141 {
138 GNUNET_free (ego); 142 //GNUNET_free (ego); // TODO: free correctly!
139 ego = NULL; 143 ego = NULL;
140 } 144 }
141 method = 0; 145 method = 0;
@@ -153,7 +157,8 @@ put_cb (void *cls,
153 method); 157 method);
154 158
155 fprintf (stdout, "Escrow finished! Please keep the following anchor \ 159 fprintf (stdout, "Escrow finished! Please keep the following anchor \
156 in order to restore the key later!\n%s\n", anchorString); 160in order to restore the key later!\n%s\n", anchorString);
161 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
157} 162}
158 163
159 164
@@ -175,6 +180,7 @@ verify_cb (void *cls,
175 default: 180 default:
176 fprintf (stderr, "invalid verificationResult!\n"); 181 fprintf (stderr, "invalid verificationResult!\n");
177 } 182 }
183 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
178} 184}
179 185
180 186
@@ -188,7 +194,8 @@ get_cb (void *cls,
188 fprintf (stderr, _ ("escrow failed!")); 194 fprintf (stderr, _ ("escrow failed!"));
189 return; 195 return;
190 } 196 }
191 fprintf (stdout, "Ego %s could successfully be restored!", ego->name); 197 fprintf (stdout, "Ego %s could successfully be restored!\n", ego->name);
198 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
192} 199}
193 200
194 201
@@ -342,10 +349,13 @@ run (void *cls,
342 349
343 escrow_handle = GNUNET_ESCROW_init (c); 350 escrow_handle = GNUNET_ESCROW_init (c);
344 351
345 /* parse anchor_string according to method */ 352 if (NULL != anchor_string)
346 anchor = GNUNET_ESCROW_anchor_string_to_data (escrow_handle, 353 {
347 anchor_string, 354 /* parse anchor_string according to method */
348 method); 355 anchor = GNUNET_ESCROW_anchor_string_to_data (escrow_handle,
356 anchor_string,
357 method);
358 }
349 359
350 /* connect to identity service in order to get the egos */ 360 /* connect to identity service in order to get the egos */
351 identity_handle = GNUNET_IDENTITY_connect (c, &ego_cb, ego_name); 361 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)
178 api->restore_key = &restore_anastasis_key_escrow; 178 api->restore_key = &restore_anastasis_key_escrow;
179 api->anchor_string_to_data = &anastasis_anchor_string_to_data; 179 api->anchor_string_to_data = &anastasis_anchor_string_to_data;
180 180
181 ph.cont = &anastasis_cont_init; 181 ph.id_init_cont = &anastasis_cont_init;
182 182
183 identity_handle = GNUNET_IDENTITY_connect (cfg, 183 identity_handle = GNUNET_IDENTITY_connect (cfg,
184 &ESCROW_list_ego, 184 &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)
208 api->restore_key = &restore_gns_key_escrow; 208 api->restore_key = &restore_gns_key_escrow;
209 api->anchor_string_to_data = &gns_anchor_string_to_data; 209 api->anchor_string_to_data = &gns_anchor_string_to_data;
210 210
211 ph.cont = &gns_cont_init; 211 ph.id_init_cont = &gns_cont_init;
212 212
213 identity_handle = GNUNET_IDENTITY_connect (cfg, 213 identity_handle = GNUNET_IDENTITY_connect (cfg,
214 &ESCROW_list_ego, 214 &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,
122} 122}
123 123
124 124
125void
126ego_created (const struct GNUNET_IDENTITY_Ego *ego)
127{
128 ph.ego_create_cont = NULL;
129 ph.curr_op->cb_get (ph.curr_op->cb_cls, ego);
130 ph.curr_op = NULL;
131}
132
133
125/** 134/**
126 * Creation operation finished. 135 * Creation operation finished.
136 * This method only handles errors that may have occured. On success,
137 * the callback is executed by the ESCROW_list_ego function, as the
138 * new ego is in our ego list only after ESCROW_list_ego has added it.
127 * 139 *
128 * @param cls pointer to operation handle 140 * @param cls pointer to operation handle
129 * @param pk private key of the ego, or NULL on error 141 * @param pk private key of the ego, or NULL on error
@@ -135,29 +147,23 @@ create_finished (void *cls,
135 const char *emsg) 147 const char *emsg)
136{ 148{
137 struct GNUNET_ESCROW_Operation *op = cls; 149 struct GNUNET_ESCROW_Operation *op = cls;
138 struct EgoEntry *ego_list;
139 150
140 if (NULL == pk) 151 if (NULL == pk)
141 { 152 {
142 fprintf (stderr, _ ("Failed to create ego: %s\n"), emsg); 153 if (NULL != emsg)
154 fprintf (stderr,
155 "Identity create operation returned with error: %s\n",
156 emsg);
157 else
158 fprintf (stderr, "Failed to create ego!");
159 op->cb_get (op->cb_cls, NULL);
143 return; 160 return;
144 } 161 }
145 162
146 /* find the ego in our ego list */ 163 /* no error occured, op->cb_get will be called from ESCROW_list_ego after
147 ego_list = ph.ego_head; 164 adding the new ego to our list */
148 while (NULL != ego_list) 165 ph.ego_create_cont = &ego_created;
149 { 166 ph.curr_op = op;
150 if (&ego_list->ego->pk == pk)
151 {
152 /* ego found */
153 op->cb_get (op->cb_cls, ego_list->ego);
154 return;
155 }
156 ego_list = ego_list->next;
157 }
158
159 /* ego not found (should not happen!) */
160 op->cb_get (op->cb_cls, NULL);
161} 167}
162 168
163 169
@@ -278,7 +284,7 @@ libgnunet_plugin_escrow_plaintext_init (void *cls)
278 api->anchor_string_to_data = &plaintext_anchor_string_to_data; 284 api->anchor_string_to_data = &plaintext_anchor_string_to_data;
279 api->anchor_data_to_string = &plaintext_anchor_data_to_string; 285 api->anchor_data_to_string = &plaintext_anchor_data_to_string;
280 286
281 ph.cont = &plaintext_cont_init; 287 ph.id_init_cont = &plaintext_cont_init;
282 288
283 identity_handle = GNUNET_IDENTITY_connect (cfg, 289 identity_handle = GNUNET_IDENTITY_connect (cfg,
284 &ESCROW_list_ego, 290 &ESCROW_list_ego,