aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjospaeth <spaethj@in.tum.de>2020-08-03 11:58:50 +0200
committerjospaeth <spaethj@in.tum.de>2020-08-03 11:58:50 +0200
commit1c09fd9efa3ce06b980b8e493644a7d271c52747 (patch)
treeb1c1dfaa305d0a9e8b8b6a1145df80e1538854db
parent7694804564e41a04e9d6e0909a59ee7ec3b7e627 (diff)
downloadgnunet-1c09fd9efa3ce06b980b8e493644a7d271c52747.tar.gz
gnunet-1c09fd9efa3ce06b980b8e493644a7d271c52747.zip
major restructuring of the escrow component
refine the several layers (CLI, API, plugins) and enable async execution
-rw-r--r--src/escrow/escrow.h116
-rw-r--r--src/escrow/escrow_api.c96
-rw-r--r--src/escrow/escrow_plugin_helper.c4
-rw-r--r--src/escrow/escrow_plugin_helper.h2
-rw-r--r--src/escrow/gnunet-escrow.c30
-rw-r--r--src/escrow/plugin_escrow_anastasis.c63
-rw-r--r--src/escrow/plugin_escrow_gns.c67
-rw-r--r--src/escrow/plugin_escrow_plaintext.c220
-rw-r--r--src/include/gnunet_escrow_lib.h32
-rw-r--r--src/include/gnunet_escrow_plugin.h121
10 files changed, 565 insertions, 186 deletions
diff --git a/src/escrow/escrow.h b/src/escrow/escrow.h
index 7be456bec..f6b9a6320 100644
--- a/src/escrow/escrow.h
+++ b/src/escrow/escrow.h
@@ -28,6 +28,122 @@
28#ifndef ESCROW_H 28#ifndef ESCROW_H
29#define ESCROW_H 29#define ESCROW_H
30 30
31#include "gnunet_escrow_lib.h"
32
33
34/**
35 * State while collecting all egos
36 */
37#define ESCROW_PLUGIN_STATE_INIT 0
38
39/**
40 * Done collecting egos
41 */
42#define ESCROW_PLUGIN_STATE_POST_INIT 1
43
44
45/**
46 * The ego list
47 */
48struct EgoEntry
49{
50 /**
51 * DLL
52 */
53 struct EgoEntry *next;
54
55 /**
56 * DLL
57 */
58 struct EgoEntry *prev;
59
60 /**
61 * Ego Identifier
62 */
63 char *identifier;
64
65 /**
66 * Public key string
67 */
68 char *keystring;
69
70 /**
71 * The Ego
72 */
73 struct GNUNET_IDENTITY_Ego *ego;
74};
75
76/**
77 * Handle for a plugin instance
78 */
79struct ESCROW_PluginHandle
80{
81 /**
82 * The identity init continuation.
83 */
84 GNUNET_ESCROW_IdentityInitContinuation id_init_cont;
85
86 /**
87 * The ego create continuation.
88 */
89 GNUNET_ESCROW_EgoCreateContinuation ego_create_cont;
90
91 /**
92 * The current restore callback.
93 */
94 GNUNET_ESCROW_EgoContinuation curr_restore_cb;
95
96 /**
97 * The handle to the escrow component.
98 */
99 struct GNUNET_ESCROW_Handle *escrow_handle;
100
101 /**
102 * The state of the plugin (in the initialization phase).
103 */
104 int state;
105
106 /**
107 * The head of the ego list.
108 */
109 struct EgoEntry *ego_head;
110
111 /**
112 * The tail of the ego list
113 */
114 struct EgoEntry *ego_tail;
115
116 /**
117 * The head of the plugin operation list
118 */
119 struct ESCROW_PluginOperationWrapper *plugin_op_head;
120
121 /**
122 * The tail of the plugin operation list
123 */
124 struct ESCROW_PluginOperationWrapper *plugin_op_tail;
125};
126
127/**
128 * Wrapper for an escrow plugin operation
129 */
130struct ESCROW_PluginOperationWrapper
131{
132 /**
133 * Plugin operations are kept in a DLL.
134 */
135 struct ESCROW_PluginOperationWrapper *prev;
136
137 /**
138 * Plugin operations are kept in a DLL.
139 */
140 struct ESCROW_PluginOperationWrapper *next;
141
142 /**
143 * The actual plugin operation
144 */
145 void *plugin_op;
146};
31 147
32 148
33#endif 149#endif
diff --git a/src/escrow/escrow_api.c b/src/escrow/escrow_api.c
index 579707af2..20cae2f5c 100644
--- a/src/escrow/escrow_api.c
+++ b/src/escrow/escrow_api.c
@@ -128,6 +128,8 @@ GNUNET_ESCROW_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
128 128
129 h = GNUNET_new (struct GNUNET_ESCROW_Handle); 129 h = GNUNET_new (struct GNUNET_ESCROW_Handle);
130 h->cfg = cfg; 130 h->cfg = cfg;
131 h->op_head = NULL;
132 h->op_tail = NULL;
131 return h; 133 return h;
132} 134}
133 135
@@ -174,22 +176,26 @@ GNUNET_ESCROW_fini (struct GNUNET_ESCROW_Handle *h)
174 176
175 177
176void 178void
177handle_start_escrow_result (void *cls, 179handle_start_escrow_result (void *cls)
178 struct GNUNET_ESCROW_Anchor *escrowAnchor)
179{ 180{
180 struct GNUNET_ESCROW_Handle *h = cls; 181 struct GNUNET_ESCROW_Plugin_AnchorContinuationWrapper *w = cls;
181 struct GNUNET_ESCROW_Operation *op; 182 struct GNUNET_ESCROW_Operation *op;
182 183
183 op = h->op_head; 184 for (op = w->h->op_head; NULL != op; op = op->next)
185 if (1) // TODO: find condition (e.g. unique ID)
186 break;
187
184 if (NULL == op) 188 if (NULL == op)
185 { 189 {
186 GNUNET_break (0); 190 GNUNET_break (0);
191 GNUNET_free (w);
187 return; 192 return;
188 } 193 }
189 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); 194 GNUNET_CONTAINER_DLL_remove (w->h->op_head, w->h->op_tail, op);
190 if (NULL != op->cb_get) 195 if (NULL != op->cb_put)
191 op->cb_put (op->cb_cls, escrowAnchor); 196 op->cb_put (w->escrowAnchor);
192 GNUNET_free (op); 197 GNUNET_free (op);
198 GNUNET_free (w);
193} 199}
194 200
195 201
@@ -216,12 +222,13 @@ GNUNET_ESCROW_put (struct GNUNET_ESCROW_Handle *h,
216 222
217 op = GNUNET_new (struct GNUNET_ESCROW_Operation); 223 op = GNUNET_new (struct GNUNET_ESCROW_Operation);
218 op->h = h; 224 op->h = h;
225 op->method = method;
219 op->cb_put = cb; 226 op->cb_put = cb;
220 op->cb_cls = cb_cls; 227 op->cb_cls = cb_cls;
221 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 228 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
222 229
223 api = init_plugin (h, method); 230 api = init_plugin (h, method);
224 api->start_key_escrow (h, ego, &handle_start_escrow_result); 231 op->plugin_op_wrap = api->start_key_escrow (h, ego, &handle_start_escrow_result);
225 232
226 return op; 233 return op;
227} 234}
@@ -250,6 +257,7 @@ GNUNET_ESCROW_renew (struct GNUNET_ESCROW_Handle *h,
250 257
251 op = GNUNET_new (struct GNUNET_ESCROW_Operation); 258 op = GNUNET_new (struct GNUNET_ESCROW_Operation);
252 op->h = h; 259 op->h = h;
260 op->method = method;
253 op->cb_renew = cb; 261 op->cb_renew = cb;
254 op->cb_cls = cb_cls; 262 op->cb_cls = cb_cls;
255 263
@@ -261,22 +269,26 @@ GNUNET_ESCROW_renew (struct GNUNET_ESCROW_Handle *h,
261 269
262 270
263static void 271static void
264handle_restore_key_result (void *cls, 272handle_restore_key_result (void *cls)
265 const struct GNUNET_IDENTITY_Ego *ego)
266{ 273{
267 struct GNUNET_ESCROW_Handle *h = cls; 274 struct GNUNET_ESCROW_Plugin_EgoContinuationWrapper *w = cls;
268 struct GNUNET_ESCROW_Operation *op; 275 struct GNUNET_ESCROW_Operation *op;
269 276
270 op = h->op_head; 277 for (op = w->h->op_head; NULL != op; op = op->next)
278 if (1) // TODO: find condition (e.g. unique ID)
279 break;
280
271 if (NULL == op) 281 if (NULL == op)
272 { 282 {
273 GNUNET_break (0); 283 GNUNET_break (0);
284 GNUNET_free (w);
274 return; 285 return;
275 } 286 }
276 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); 287 GNUNET_CONTAINER_DLL_remove (w->h->op_head, w->h->op_tail, op);
277 if (NULL != op->cb_get) 288 if (NULL != op->cb_get)
278 op->cb_get (op->cb_cls, ego); 289 op->cb_get (w->ego);
279 GNUNET_free (op); 290 GNUNET_free (op);
291 GNUNET_free (w);
280} 292}
281 293
282 294
@@ -305,34 +317,41 @@ GNUNET_ESCROW_get (struct GNUNET_ESCROW_Handle *h,
305 317
306 op = GNUNET_new (struct GNUNET_ESCROW_Operation); 318 op = GNUNET_new (struct GNUNET_ESCROW_Operation);
307 op->h = h; 319 op->h = h;
320 op->method = method;
308 op->cb_get = cb; 321 op->cb_get = cb;
309 op->cb_cls = cb_cls; 322 op->cb_cls = cb_cls;
310 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 323 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
311 324
312 api = init_plugin (h, method); 325 api = init_plugin (h, method);
313 api->restore_key (h, escrowAnchor, egoName, &handle_restore_key_result); 326 op->plugin_op_wrap = api->restore_key (h, escrowAnchor, egoName, &handle_restore_key_result);
314 327
315 return op; 328 return op;
316} 329}
317 330
318 331
319void 332void
320handle_verify_escrow_result (void *cls, 333handle_verify_escrow_result (void *cls)
321 int verificationResult)
322{ 334{
323 struct GNUNET_ESCROW_Handle *h = cls; 335 struct GNUNET_ESCROW_Plugin_VerifyContinuationWrapper *w = cls;
324 struct GNUNET_ESCROW_Operation *op; 336 struct GNUNET_ESCROW_Operation *op;
325 337
326 op = h->op_head; 338 for (op = w->h->op_head; NULL != op; op = op->next)
339 if (1) // TODO: find condition (e.g. unique ID)
340 break;
341
327 if (NULL == op) 342 if (NULL == op)
328 { 343 {
329 GNUNET_break (0); 344 GNUNET_break (0);
345 GNUNET_free (w);
330 return; 346 return;
331 } 347 }
332 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); 348 GNUNET_CONTAINER_DLL_remove (w->h->op_head, w->h->op_tail, op);
333 if (NULL != op->cb_get) 349 if (NULL != op->cb_verify)
334 op->cb_verify (op->cb_cls, verificationResult); 350 op->cb_verify (w->verificationResult);
351 GNUNET_free (op->plugin_op_wrap->plugin_op);
352 GNUNET_free (op->plugin_op_wrap);
335 GNUNET_free (op); 353 GNUNET_free (op);
354 GNUNET_free (w);
336} 355}
337 356
338 357
@@ -361,12 +380,13 @@ GNUNET_ESCROW_verify (struct GNUNET_ESCROW_Handle *h,
361 380
362 op = GNUNET_new (struct GNUNET_ESCROW_Operation); 381 op = GNUNET_new (struct GNUNET_ESCROW_Operation);
363 op->h = h; 382 op->h = h;
383 op->method = method;
364 op->cb_verify = cb; 384 op->cb_verify = cb;
365 op->cb_cls = cb_cls; 385 op->cb_cls = cb_cls;
366 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 386 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
367 387
368 api = init_plugin (h, method); 388 api = init_plugin (h, method);
369 api->verify_key_escrow (h, ego, escrowAnchor, &handle_verify_escrow_result); 389 op->plugin_op_wrap = api->verify_key_escrow (h, ego, escrowAnchor, &handle_verify_escrow_result);
370 390
371 return op; 391 return op;
372} 392}
@@ -420,21 +440,31 @@ GNUNET_ESCROW_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
420 * be executed; this merely cancels the continuation. 440 * be executed; this merely cancels the continuation.
421 * 441 *
422 * @param op operation to cancel 442 * @param op operation to cancel
423 * @param method the escrow method to use
424 */ 443 */
425void 444void
426GNUNET_ESCROW_cancel (struct GNUNET_ESCROW_Operation *op, 445GNUNET_ESCROW_cancel (struct GNUNET_ESCROW_Operation *op)
427 enum GNUNET_ESCROW_Key_Escrow_Method method)
428{ 446{
429 const struct GNUNET_ESCROW_KeyPluginFunctions *api; 447 const struct GNUNET_ESCROW_KeyPluginFunctions *api;
448 struct GNUNET_ESCROW_Handle *h = op->h;
449 struct GNUNET_ESCROW_Operation *curr;
430 450
431 api = init_plugin (op->h, method); 451 // check if op is in our DLL
432 // TODO: api->cancel (...); 452 for (curr = h->op_head; NULL != curr; curr = curr->next)
433 453 {
434 op->cb_put = NULL; 454 if (curr == op)
435 op->cb_renew = NULL; 455 {
436 op->cb_verify = NULL; 456 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
437 op->cb_get = NULL; 457 api = init_plugin (op->h, op->method);
458 api->cancel_plugin_operation (op->plugin_op_wrap);
459 // TODO: check which callback is not NULL?
460 op->cb_put = NULL;
461 op->cb_renew = NULL;
462 op->cb_verify = NULL;
463 op->cb_get = NULL;
464 GNUNET_free (op);
465 return;
466 }
467 }
438} 468}
439 469
440 470
diff --git a/src/escrow/escrow_plugin_helper.c b/src/escrow/escrow_plugin_helper.c
index afbbd409a..07cb5e139 100644
--- a/src/escrow/escrow_plugin_helper.c
+++ b/src/escrow/escrow_plugin_helper.c
@@ -71,7 +71,7 @@ ESCROW_list_ego (void *cls,
71 void **ctx, 71 void **ctx,
72 const char *identifier) 72 const char *identifier)
73{ 73{
74 struct EscrowPluginHandle *ph = cls; 74 struct ESCROW_PluginHandle *ph = cls;
75 struct EgoEntry *ego_entry; 75 struct EgoEntry *ego_entry;
76 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 76 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
77 77
@@ -161,7 +161,7 @@ ESCROW_list_ego (void *cls,
161 * @param ph handle for the plugin 161 * @param ph handle for the plugin
162 */ 162 */
163void 163void
164ESCROW_cleanup_ego_list (struct EscrowPluginHandle *ph) 164ESCROW_cleanup_ego_list (struct ESCROW_PluginHandle *ph)
165{ 165{
166 struct EgoEntry *ego_entry; 166 struct EgoEntry *ego_entry;
167 167
diff --git a/src/escrow/escrow_plugin_helper.h b/src/escrow/escrow_plugin_helper.h
index 96910ad6a..d0409bc38 100644
--- a/src/escrow/escrow_plugin_helper.h
+++ b/src/escrow/escrow_plugin_helper.h
@@ -78,4 +78,4 @@ ESCROW_list_ego (void *cls,
78 * @param ph handle for the plugin 78 * @param ph handle for the plugin
79 */ 79 */
80void 80void
81ESCROW_cleanup_ego_list (struct EscrowPluginHandle *ph); 81ESCROW_cleanup_ego_list (struct ESCROW_PluginHandle *ph);
diff --git a/src/escrow/gnunet-escrow.c b/src/escrow/gnunet-escrow.c
index 929ff169d..7918423ba 100644
--- a/src/escrow/gnunet-escrow.c
+++ b/src/escrow/gnunet-escrow.c
@@ -68,7 +68,7 @@ static char *get_ego;
68/** 68/**
69 * The ego 69 * The ego
70 */ 70 */
71struct GNUNET_IDENTITY_Ego *ego; 71const struct GNUNET_IDENTITY_Ego *ego;
72 72
73/** 73/**
74 * Anchor string 74 * Anchor string
@@ -124,7 +124,7 @@ do_cleanup (void *cls)
124 GNUNET_IDENTITY_disconnect (identity_handle); 124 GNUNET_IDENTITY_disconnect (identity_handle);
125 if (NULL != escrow_op) 125 if (NULL != escrow_op)
126 { 126 {
127 GNUNET_ESCROW_cancel (escrow_op, method); 127 GNUNET_ESCROW_cancel (escrow_op);
128 GNUNET_free (escrow_op); 128 GNUNET_free (escrow_op);
129 escrow_op = NULL; 129 escrow_op = NULL;
130 } 130 }
@@ -145,16 +145,16 @@ do_cleanup (void *cls)
145 } 145 }
146 if (NULL != ego) 146 if (NULL != ego)
147 { 147 {
148 //GNUNET_free (ego); // TODO: free correctly! 148 /* does not have to be freed, as this is done when
149 cleaning up the ego list in the plugin */
149 ego = NULL; 150 ego = NULL;
150 } 151 }
151 method = 0; 152 method = -1;
152} 153}
153 154
154 155
155static void 156static void
156put_cb (void *cls, 157put_cb (struct GNUNET_ESCROW_Anchor *escrowAnchor)
157 struct GNUNET_ESCROW_Anchor *escrowAnchor)
158{ 158{
159 char *anchorString; 159 char *anchorString;
160 160
@@ -171,8 +171,7 @@ in order to restore the key later!\n%s\n", anchorString);
171 171
172 172
173static void 173static void
174verify_cb (void *cls, 174verify_cb (int verificationResult)
175 int verificationResult)
176{ 175{
177 escrow_op = NULL; 176 escrow_op = NULL;
178 177
@@ -195,8 +194,7 @@ verify_cb (void *cls,
195 194
196 195
197static void 196static void
198get_cb (void *cls, 197get_cb (const struct GNUNET_IDENTITY_Ego *ego)
199 const struct GNUNET_IDENTITY_Ego *ego)
200{ 198{
201 escrow_op = NULL; 199 escrow_op = NULL;
202 200
@@ -330,11 +328,23 @@ run (void *cls,
330 return; 328 return;
331 } 329 }
332 /* verify */ 330 /* verify */
331 if (NULL == anchor_string)
332 {
333 ret = 1;
334 fprintf (stderr, _ ("-a is needed for -V!\n"));
335 return;
336 }
333 ego_name = verify_ego; 337 ego_name = verify_ego;
334 } 338 }
335 else if (NULL != get_ego) 339 else if (NULL != get_ego)
336 { 340 {
337 /* get */ 341 /* get */
342 if (NULL == anchor_string)
343 {
344 ret = 1;
345 fprintf (stderr, _ ("-a is needed for -G!\n"));
346 return;
347 }
338 ego_name = get_ego; 348 ego_name = get_ego;
339 } 349 }
340 else 350 else
diff --git a/src/escrow/plugin_escrow_anastasis.c b/src/escrow/plugin_escrow_anastasis.c
index 0c657de4d..3f70a4aaf 100644
--- a/src/escrow/plugin_escrow_anastasis.c
+++ b/src/escrow/plugin_escrow_anastasis.c
@@ -39,7 +39,7 @@ static struct GNUNET_IDENTITY_Handle *identity_handle;
39/** 39/**
40 * Handle for the plugin instance 40 * Handle for the plugin instance
41 */ 41 */
42struct EscrowPluginHandle ph; 42struct ESCROW_PluginHandle ph;
43 43
44 44
45/** 45/**
@@ -48,14 +48,23 @@ struct EscrowPluginHandle ph;
48 * @param h the handle for the escrow component 48 * @param h the handle for the escrow component
49 * @param ego the identity ego containing the private key 49 * @param ego the identity ego containing the private key
50 * @param cb the function called upon completion 50 * @param cb the function called upon completion
51 *
52 * @return plugin operation wrapper
51 */ 53 */
52void 54struct ESCROW_PluginOperationWrapper *
53start_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h, 55start_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h,
54 const struct GNUNET_IDENTITY_Ego *ego, 56 const struct GNUNET_IDENTITY_Ego *ego,
55 GNUNET_ESCROW_AnchorContinuation cb) 57 GNUNET_SCHEDULER_TaskCallback cb)
56{ 58{
59 struct GNUNET_ESCROW_Plugin_AnchorContinuationWrapper *w;
60
61 w = GNUNET_new (struct GNUNET_ESCROW_Plugin_AnchorContinuationWrapper);
62 w->h = h;
63
57 // TODO: implement 64 // TODO: implement
58 cb (h, NULL); 65 w->escrowAnchor = NULL;
66 GNUNET_SCHEDULER_add_now (cb, w);
67 return NULL;
59} 68}
60 69
61 70
@@ -70,7 +79,7 @@ renew_anastasis_key_escrow (struct GNUNET_ESCROW_Operation *op,
70 struct GNUNET_ESCROW_Anchor *escrowAnchor) 79 struct GNUNET_ESCROW_Anchor *escrowAnchor)
71{ 80{
72 // TODO: implement 81 // TODO: implement
73 op->cb_renew (op->cb_cls, NULL); 82 op->cb_renew (NULL);
74} 83}
75 84
76 85
@@ -81,15 +90,24 @@ renew_anastasis_key_escrow (struct GNUNET_ESCROW_Operation *op,
81 * @param ego the identity ego containing the private key 90 * @param ego the identity ego containing the private key
82 * @param escrowAnchor the escrow anchor needed to restore the key 91 * @param escrowAnchor the escrow anchor needed to restore the key
83 * @param cb the function called upon completion 92 * @param cb the function called upon completion
93 *
94 * @return plugin operation wrapper
84 */ 95 */
85void 96struct ESCROW_PluginOperationWrapper *
86verify_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h, 97verify_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h,
87 const struct GNUNET_IDENTITY_Ego *ego, 98 const struct GNUNET_IDENTITY_Ego *ego,
88 struct GNUNET_ESCROW_Anchor *escrowAnchor, 99 struct GNUNET_ESCROW_Anchor *escrowAnchor,
89 GNUNET_ESCROW_VerifyContinuation cb) 100 GNUNET_SCHEDULER_TaskCallback cb)
90{ 101{
102 struct GNUNET_ESCROW_Plugin_VerifyContinuationWrapper *w;
103
104 w = GNUNET_new (struct GNUNET_ESCROW_Plugin_VerifyContinuationWrapper);
105 w->h = h;
106
91 // TODO: implement 107 // TODO: implement
92 cb (h, GNUNET_ESCROW_INVALID); 108 w->verificationResult = GNUNET_ESCROW_INVALID;
109 GNUNET_SCHEDULER_add_now (cb, w);
110 return NULL;
93} 111}
94 112
95 113
@@ -100,15 +118,24 @@ verify_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h,
100 * @param escrowAnchor the escrow anchor needed to restore the key 118 * @param escrowAnchor the escrow anchor needed to restore the key
101 * @param egoName the name of the ego to restore 119 * @param egoName the name of the ego to restore
102 * @param cb the function called upon completion 120 * @param cb the function called upon completion
121 *
122 * @return plugin operation wrapper
103 */ 123 */
104void 124struct ESCROW_PluginOperationWrapper *
105restore_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h, 125restore_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h,
106 struct GNUNET_ESCROW_Anchor *escrowAnchor, 126 struct GNUNET_ESCROW_Anchor *escrowAnchor,
107 char *egoName, 127 char *egoName,
108 GNUNET_ESCROW_EgoContinuation cb) 128 GNUNET_SCHEDULER_TaskCallback cb)
109{ 129{
130 struct GNUNET_ESCROW_Plugin_EgoContinuationWrapper *w;
131
132 w = GNUNET_new (struct GNUNET_ESCROW_Plugin_EgoContinuationWrapper);
133 w->h = h;
134
110 // TODO: implement 135 // TODO: implement
111 cb (h, NULL); 136 w->ego = NULL;
137 GNUNET_SCHEDULER_add_now (cb, w);
138 return NULL;
112} 139}
113 140
114 141
@@ -155,6 +182,19 @@ anastasis_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
155 182
156 183
157/** 184/**
185 * Cancel an Anastasis plugin operation.
186 *
187 * @param plugin_op_wrap the plugin operation wrapper containing the operation
188 */
189void
190cancel_anastasis_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap)
191{
192 // TODO: implement
193 return;
194}
195
196
197/**
158 * IdentityInitContinuation for the Anastasis plugin 198 * IdentityInitContinuation for the Anastasis plugin
159 */ 199 */
160void 200void
@@ -183,6 +223,7 @@ libgnunet_plugin_escrow_anastasis_init (void *cls)
183 api->verify_key_escrow = &verify_anastasis_key_escrow; 223 api->verify_key_escrow = &verify_anastasis_key_escrow;
184 api->restore_key = &restore_anastasis_key_escrow; 224 api->restore_key = &restore_anastasis_key_escrow;
185 api->anchor_string_to_data = &anastasis_anchor_string_to_data; 225 api->anchor_string_to_data = &anastasis_anchor_string_to_data;
226 api->cancel_plugin_operation = &cancel_anastasis_operation;
186 227
187 ph.id_init_cont = &anastasis_cont_init; 228 ph.id_init_cont = &anastasis_cont_init;
188 229
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c
index f77ef30d6..278ceff5b 100644
--- a/src/escrow/plugin_escrow_gns.c
+++ b/src/escrow/plugin_escrow_gns.c
@@ -44,7 +44,7 @@ static struct GNUNET_IDENTITY_Handle *identity_handle;
44/** 44/**
45 * Handle for the plugin instance 45 * Handle for the plugin instance
46 */ 46 */
47struct EscrowPluginHandle ph; 47struct ESCROW_PluginHandle ph;
48 48
49 49
50/** 50/**
@@ -53,21 +53,28 @@ struct EscrowPluginHandle ph;
53 * @param h the handle for the escrow component 53 * @param h the handle for the escrow component
54 * @param ego the identity ego containing the private key 54 * @param ego the identity ego containing the private key
55 * @param cb the function called upon completion 55 * @param cb the function called upon completion
56 *
57 * @return plugin operation wrapper
56 */ 58 */
57void 59struct ESCROW_PluginOperationWrapper *
58start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, 60start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
59 const struct GNUNET_IDENTITY_Ego *ego, 61 const struct GNUNET_IDENTITY_Ego *ego,
60 GNUNET_ESCROW_AnchorContinuation cb) 62 GNUNET_SCHEDULER_TaskCallback cb)
61{ 63{
62 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 64 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
63 sss_Keyshare keyshares; 65 sss_Keyshare keyshares;
64 struct GNUNET_ESCROW_Anchor *anchor; 66 struct GNUNET_ESCROW_Anchor *anchor;
65 int anchorDataSize; 67 int anchorDataSize;
68 struct GNUNET_ESCROW_Plugin_AnchorContinuationWrapper *w;
69
70 w = GNUNET_new (struct GNUNET_ESCROW_Plugin_AnchorContinuationWrapper);
71 w->h = h;
66 72
67 if (NULL == ego) 73 if (NULL == ego)
68 { 74 {
69 cb (h, NULL); 75 w->escrowAnchor = NULL;
70 return; 76 GNUNET_SCHEDULER_add_now (cb, w);
77 return NULL; // TODO!
71 } 78 }
72 pk = GNUNET_IDENTITY_ego_get_private_key (ego); 79 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
73 80
@@ -85,7 +92,9 @@ start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
85 // TODO: implement 92 // TODO: implement
86 anchorDataSize = 0; // TODO! 93 anchorDataSize = 0; // TODO!
87 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize); 94 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize);
88 cb (h, anchor); 95 w->escrowAnchor = anchor;
96 GNUNET_SCHEDULER_add_now (cb, w);
97 return NULL; // TODO!
89} 98}
90 99
91 100
@@ -100,7 +109,7 @@ renew_gns_key_escrow (struct GNUNET_ESCROW_Operation *op,
100 struct GNUNET_ESCROW_Anchor *escrowAnchor) 109 struct GNUNET_ESCROW_Anchor *escrowAnchor)
101{ 110{
102 // TODO: implement 111 // TODO: implement
103 op->cb_renew (op->cb_cls, NULL); 112 op->cb_renew (NULL);
104} 113}
105 114
106 115
@@ -111,15 +120,24 @@ renew_gns_key_escrow (struct GNUNET_ESCROW_Operation *op,
111 * @param ego the identity ego containing the private key 120 * @param ego the identity ego containing the private key
112 * @param escrowAnchor the escrow anchor needed to restore the key 121 * @param escrowAnchor the escrow anchor needed to restore the key
113 * @param cb the function called upon completion 122 * @param cb the function called upon completion
123 *
124 * @return plugin operation wrapper
114 */ 125 */
115void 126struct ESCROW_PluginOperationWrapper *
116verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, 127verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
117 const struct GNUNET_IDENTITY_Ego *ego, 128 const struct GNUNET_IDENTITY_Ego *ego,
118 struct GNUNET_ESCROW_Anchor *escrowAnchor, 129 struct GNUNET_ESCROW_Anchor *escrowAnchor,
119 GNUNET_ESCROW_VerifyContinuation cb) 130 GNUNET_SCHEDULER_TaskCallback cb)
120{ 131{
132 struct GNUNET_ESCROW_Plugin_VerifyContinuationWrapper *w;
133
134 w = GNUNET_new (struct GNUNET_ESCROW_Plugin_VerifyContinuationWrapper);
135 w->h = h;
136
121 // TODO: implement 137 // TODO: implement
122 cb (h, GNUNET_ESCROW_INVALID); 138 w->verificationResult = GNUNET_ESCROW_INVALID;
139 GNUNET_SCHEDULER_add_now (cb, w);
140 return NULL;
123} 141}
124 142
125 143
@@ -130,15 +148,24 @@ verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
130 * @param escrowAnchor the escrow anchor needed to restore the key 148 * @param escrowAnchor the escrow anchor needed to restore the key
131 * @param egoName the name of the ego to restore 149 * @param egoName the name of the ego to restore
132 * @param cb the function called upon completion 150 * @param cb the function called upon completion
151 *
152 * @return plugin operation wrapper
133 */ 153 */
134void 154struct ESCROW_PluginOperationWrapper *
135restore_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, 155restore_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
136 struct GNUNET_ESCROW_Anchor *escrowAnchor, 156 struct GNUNET_ESCROW_Anchor *escrowAnchor,
137 char *egoName, 157 char *egoName,
138 GNUNET_ESCROW_EgoContinuation cb) 158 GNUNET_SCHEDULER_TaskCallback cb)
139{ 159{
160 struct GNUNET_ESCROW_Plugin_EgoContinuationWrapper *w;
161
162 w = GNUNET_new (struct GNUNET_ESCROW_Plugin_EgoContinuationWrapper);
163 w->h = h;
164
140 // TODO: implement 165 // TODO: implement
141 cb (h, NULL); 166 w->ego = NULL;
167 GNUNET_SCHEDULER_add_now (cb, w);
168 return NULL;
142} 169}
143 170
144 171
@@ -185,6 +212,19 @@ gns_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
185 212
186 213
187/** 214/**
215 * Cancel a GNS plugin operation.
216 *
217 * @param plugin_op_wrap the plugin operation wrapper containing the operation
218 */
219void
220cancel_gns_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap)
221{
222 // TODO: implement
223 return;
224}
225
226
227/**
188 * IdentityInitContinuation for the GNS plugin 228 * IdentityInitContinuation for the GNS plugin
189 */ 229 */
190void 230void
@@ -213,6 +253,7 @@ libgnunet_plugin_escrow_gns_init (void *cls)
213 api->verify_key_escrow = &verify_gns_key_escrow; 253 api->verify_key_escrow = &verify_gns_key_escrow;
214 api->restore_key = &restore_gns_key_escrow; 254 api->restore_key = &restore_gns_key_escrow;
215 api->anchor_string_to_data = &gns_anchor_string_to_data; 255 api->anchor_string_to_data = &gns_anchor_string_to_data;
256 api->cancel_plugin_operation = &cancel_gns_operation;
216 257
217 ph.id_init_cont = &gns_cont_init; 258 ph.id_init_cont = &gns_cont_init;
218 259
diff --git a/src/escrow/plugin_escrow_plaintext.c b/src/escrow/plugin_escrow_plaintext.c
index 63ffe7720..b260f6190 100644
--- a/src/escrow/plugin_escrow_plaintext.c
+++ b/src/escrow/plugin_escrow_plaintext.c
@@ -30,9 +30,44 @@
30#include "escrow_plugin_helper.h" 30#include "escrow_plugin_helper.h"
31#include "gnunet_identity_service.h" 31#include "gnunet_identity_service.h"
32#include "../identity/identity.h" 32#include "../identity/identity.h"
33#include "escrow.h"
33#include <inttypes.h> 34#include <inttypes.h>
34 35
35 36
37struct ESCROW_PlaintextPluginOperation
38{
39 /**
40 * Handle for the escrow component
41 */
42 struct GNUNET_ESCROW_Handle *h;
43
44 /**
45 * Continuation for a plugin operation (e.g. used for restore, as this
46 * callback has to be called from the IDENTITY service after finishing)
47 */
48 GNUNET_SCHEDULER_TaskCallback cont;
49
50 /**
51 * Scheduler task the SCHEDULE operation returns (needed for cancellation)
52 */
53 struct GNUNET_SCHEDULER_Task *sched_task;
54
55 /**
56 * Identity operation
57 */
58 struct GNUNET_IDENTITY_Operation *id_op;
59
60 /**
61 * Private key of the created ego
62 */
63 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
64
65 /**
66 * Ego continuation wrapper
67 */
68 struct GNUNET_ESCROW_Plugin_EgoContinuationWrapper *ego_cont_wrap;
69};
70
36/** 71/**
37 * Identity handle 72 * Identity handle
38 */ 73 */
@@ -41,7 +76,7 @@ static struct GNUNET_IDENTITY_Handle *identity_handle;
41/** 76/**
42 * Handle for the plugin instance 77 * Handle for the plugin instance
43 */ 78 */
44struct EscrowPluginHandle ph; 79struct ESCROW_PluginHandle ph;
45 80
46 81
47/** 82/**
@@ -50,21 +85,40 @@ struct EscrowPluginHandle ph;
50 * @param h the handle for the escrow component 85 * @param h the handle for the escrow component
51 * @param ego the identity ego containing the private key 86 * @param ego the identity ego containing the private key
52 * @param cb the function called upon completion 87 * @param cb the function called upon completion
88 *
89 * @return plugin operation wrapper
53 */ 90 */
54void 91struct ESCROW_PluginOperationWrapper *
55start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, 92start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
56 const struct GNUNET_IDENTITY_Ego *ego, 93 const struct GNUNET_IDENTITY_Ego *ego,
57 GNUNET_ESCROW_AnchorContinuation cb) 94 GNUNET_SCHEDULER_TaskCallback cb)
58{ 95{
59 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 96 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
60 struct GNUNET_ESCROW_Anchor *anchor; 97 struct GNUNET_ESCROW_Anchor *anchor;
61 char *pkString; 98 char *pkString;
62 uint32_t anchorDataSize; 99 uint32_t anchorDataSize;
100 struct ESCROW_PluginOperationWrapper *plugin_op_wrap;
101 struct ESCROW_PlaintextPluginOperation *p_op;
102 struct GNUNET_ESCROW_Plugin_AnchorContinuationWrapper *w;
103
104 // create a new plaintext plugin operation (in a wrapper) and insert it into the DLL
105 plugin_op_wrap = GNUNET_new (struct ESCROW_PluginOperationWrapper);
106 plugin_op_wrap->plugin_op = GNUNET_new (struct ESCROW_PlaintextPluginOperation);
107 GNUNET_CONTAINER_DLL_insert_tail (ph.plugin_op_head,
108 ph.plugin_op_tail,
109 plugin_op_wrap);
110
111 p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op;
112 p_op->h = h;
113
114 w = GNUNET_new (struct GNUNET_ESCROW_Plugin_AnchorContinuationWrapper);
115 w->h = h;
63 116
64 if (NULL == ego) 117 if (NULL == ego)
65 { 118 {
66 cb (h, NULL); 119 w->escrowAnchor = NULL;
67 return; 120 p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w);
121 return plugin_op_wrap;
68 } 122 }
69 pk = GNUNET_IDENTITY_ego_get_private_key (ego); 123 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
70 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); 124 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
@@ -75,7 +129,10 @@ start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
75 anchor->size = anchorDataSize; 129 anchor->size = anchorDataSize;
76 GNUNET_memcpy (&anchor[1], pkString, anchorDataSize); 130 GNUNET_memcpy (&anchor[1], pkString, anchorDataSize);
77 131
78 cb (h, anchor); 132 w->escrowAnchor = anchor;
133
134 p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w);
135 return plugin_op_wrap;
79} 136}
80 137
81 138
@@ -89,7 +146,7 @@ void
89renew_plaintext_key_escrow (struct GNUNET_ESCROW_Operation *op, 146renew_plaintext_key_escrow (struct GNUNET_ESCROW_Operation *op,
90 struct GNUNET_ESCROW_Anchor *escrowAnchor) 147 struct GNUNET_ESCROW_Anchor *escrowAnchor)
91{ 148{
92 op->cb_renew (op->cb_cls, escrowAnchor); 149 op->cb_renew (escrowAnchor);
93} 150}
94 151
95 152
@@ -100,21 +157,40 @@ renew_plaintext_key_escrow (struct GNUNET_ESCROW_Operation *op,
100 * @param ego the identity ego containing the private key 157 * @param ego the identity ego containing the private key
101 * @param escrowAnchor the escrow anchor needed to restore the key 158 * @param escrowAnchor the escrow anchor needed to restore the key
102 * @param cb the function called upon completion 159 * @param cb the function called upon completion
160 *
161 * @return plugin operation wrapper
103 */ 162 */
104void 163struct ESCROW_PluginOperationWrapper *
105verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, 164verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
106 const struct GNUNET_IDENTITY_Ego *ego, 165 const struct GNUNET_IDENTITY_Ego *ego,
107 struct GNUNET_ESCROW_Anchor *escrowAnchor, 166 struct GNUNET_ESCROW_Anchor *escrowAnchor,
108 GNUNET_ESCROW_VerifyContinuation cb) 167 GNUNET_SCHEDULER_TaskCallback cb)
109{ 168{
110 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 169 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
111 char *pkString; 170 char *pkString;
112 int verificationResult; 171 int verificationResult;
172 struct ESCROW_PluginOperationWrapper *plugin_op_wrap;
173 struct ESCROW_PlaintextPluginOperation *p_op;
174 struct GNUNET_ESCROW_Plugin_VerifyContinuationWrapper *w;
175
176 // create a new plaintext plugin operation (in a wrapper) and insert it into the DLL
177 plugin_op_wrap = GNUNET_new (struct ESCROW_PluginOperationWrapper);
178 plugin_op_wrap->plugin_op = GNUNET_new (struct ESCROW_PlaintextPluginOperation);
179 GNUNET_CONTAINER_DLL_insert_tail (ph.plugin_op_head,
180 ph.plugin_op_tail,
181 plugin_op_wrap);
182
183 p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op;
184 p_op->h = h;
185
186 w = GNUNET_new (struct GNUNET_ESCROW_Plugin_VerifyContinuationWrapper);
187 w->h = h;
113 188
114 if (NULL == ego) 189 if (NULL == ego)
115 { 190 {
116 cb (h, GNUNET_ESCROW_INVALID); 191 w->verificationResult = GNUNET_ESCROW_INVALID;
117 return; 192 p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w);
193 return plugin_op_wrap;
118 } 194 }
119 pk = GNUNET_IDENTITY_ego_get_private_key (ego); 195 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
120 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); 196 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
@@ -122,16 +198,45 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
122 (char *)&escrowAnchor[1], 198 (char *)&escrowAnchor[1],
123 strlen (pkString)) == 0 ? 199 strlen (pkString)) == 0 ?
124 GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; 200 GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID;
125 cb (h, verificationResult); 201
202 w->verificationResult = verificationResult;
203 p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w);
204 return plugin_op_wrap;
126} 205}
127 206
128 207
129void 208void
130ego_created (const struct GNUNET_IDENTITY_Ego *ego) 209ego_created (const struct GNUNET_IDENTITY_Ego *ego)
131{ 210{
132 ph.ego_create_cont = NULL; 211 struct ESCROW_PluginOperationWrapper *curr;
133 ph.curr_restore_cb (ph.escrow_handle, ego); 212 struct ESCROW_PlaintextPluginOperation *curr_p_op;
134 ph.curr_restore_cb = NULL; 213 char *ego_pk_string, *curr_pk_string;
214
215 ego_pk_string = GNUNET_CRYPTO_ecdsa_private_key_to_string (&ego->pk);
216
217 for (curr = ph.plugin_op_head; NULL != curr; curr = curr->next)
218 {
219 curr_p_op = (struct ESCROW_PlaintextPluginOperation *)curr->plugin_op;
220 curr_pk_string = GNUNET_CRYPTO_ecdsa_private_key_to_string (curr_p_op->pk);
221 // compare the strings of the private keys
222 if (0 == strcmp (ego_pk_string, curr_pk_string))
223 {
224 // the ego was created due to a restore operation that is not yet finished
225 GNUNET_free (curr_pk_string);
226 GNUNET_CONTAINER_DLL_remove (ph.plugin_op_head,
227 ph.plugin_op_tail,
228 curr);
229 curr_p_op->ego_cont_wrap->ego = ego;
230 curr_p_op->sched_task = GNUNET_SCHEDULER_add_now (curr_p_op->cont,
231 curr_p_op->ego_cont_wrap);
232 GNUNET_free (curr_p_op);
233 GNUNET_free (curr);
234 GNUNET_free (ego_pk_string);
235 return;
236 }
237 GNUNET_free (curr_pk_string);
238 }
239 GNUNET_free (ego_pk_string);
135} 240}
136 241
137 242
@@ -150,7 +255,7 @@ create_finished (void *cls,
150 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, 255 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
151 const char *emsg) 256 const char *emsg)
152{ 257{
153 GNUNET_ESCROW_EgoContinuation cb = cls; 258 struct ESCROW_PlaintextPluginOperation *p_op = cls;
154 259
155 if (NULL == pk) 260 if (NULL == pk)
156 { 261 {
@@ -160,14 +265,14 @@ create_finished (void *cls,
160 emsg); 265 emsg);
161 else 266 else
162 fprintf (stderr, "Failed to create ego!"); 267 fprintf (stderr, "Failed to create ego!");
163 cb (ph.escrow_handle, NULL); 268 p_op->ego_cont_wrap->ego = NULL;
269 p_op->sched_task = GNUNET_SCHEDULER_add_now (p_op->cont, p_op->ego_cont_wrap);
164 return; 270 return;
165 } 271 }
166 272
167 /* no error occurred, op->cb_get will be called from ESCROW_list_ego after 273 /* no error occurred, p_op->restore_cont will be called in ego_created, which
168 adding the new ego to our list */ 274 is called from ESCROW_list_ego after adding the new ego to our list */
169 ph.ego_create_cont = &ego_created; 275 p_op->pk = pk;
170 ph.curr_restore_cb = cb;
171} 276}
172 277
173 278
@@ -178,40 +283,64 @@ create_finished (void *cls,
178 * @param escrowAnchor the escrow anchor needed to restore the key 283 * @param escrowAnchor the escrow anchor needed to restore the key
179 * @param egoName the name of the ego to restore 284 * @param egoName the name of the ego to restore
180 * @param cb the function called upon completion 285 * @param cb the function called upon completion
286 *
287 * @return plugin operation wrapper
181 */ 288 */
182void 289struct ESCROW_PluginOperationWrapper *
183restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, 290restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
184 struct GNUNET_ESCROW_Anchor *escrowAnchor, 291 struct GNUNET_ESCROW_Anchor *escrowAnchor,
185 char *egoName, 292 char *egoName,
186 GNUNET_ESCROW_EgoContinuation cb) 293 GNUNET_SCHEDULER_TaskCallback cb)
187{ 294{
188 struct GNUNET_CRYPTO_EcdsaPrivateKey pk; 295 struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
189 struct GNUNET_IDENTITY_Operation *id_op; 296 struct GNUNET_IDENTITY_Operation *id_op;
297 struct ESCROW_PluginOperationWrapper *plugin_op_wrap;
298 struct ESCROW_PlaintextPluginOperation *p_op;
299 struct GNUNET_ESCROW_Plugin_EgoContinuationWrapper *w;
300
301 // create a new plaintext plugin operation (in a wrapper) and insert it into the DLL
302 plugin_op_wrap = GNUNET_new (struct ESCROW_PluginOperationWrapper);
303 plugin_op_wrap->plugin_op = GNUNET_new (struct ESCROW_PlaintextPluginOperation);
304 GNUNET_CONTAINER_DLL_insert_tail (ph.plugin_op_head,
305 ph.plugin_op_tail,
306 plugin_op_wrap);
307
308 p_op = (struct ESCROW_PlaintextPluginOperation *)plugin_op_wrap->plugin_op;
309 p_op->h = h;
310 // set cont here (has to be scheduled from the IDENTITY service when it finished)
311 p_op->cont = cb;
312
313 w = GNUNET_new (struct GNUNET_ESCROW_Plugin_EgoContinuationWrapper);
314 w->h = h;
190 315
191 // TODO: is this the right place for that? 316 p_op->ego_cont_wrap = w;
192 ph.escrow_handle = h;
193 317
194 if (NULL == escrowAnchor) 318 if (NULL == escrowAnchor)
195 { 319 {
196 cb (h, NULL); 320 // TODO: correct error handling?
197 return; 321 w->ego = NULL;
322 p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w);
323 return plugin_op_wrap;
198 } 324 }
199 if (GNUNET_OK != 325 if (GNUNET_OK !=
200 GNUNET_CRYPTO_ecdsa_private_key_from_string ((char *)&escrowAnchor[1], 326 GNUNET_CRYPTO_ecdsa_private_key_from_string ((char *)&escrowAnchor[1],
201 strlen ((char *)&escrowAnchor[1]), 327 strlen ((char *)&escrowAnchor[1]),
202 &pk)) 328 &pk))
203 { 329 {
204 cb (h, NULL); 330 w->ego = NULL;
205 return; 331 p_op->sched_task = GNUNET_SCHEDULER_add_now (cb, w);
332 return plugin_op_wrap;
206 } 333 }
207 334
208 id_op = GNUNET_IDENTITY_create (identity_handle, 335 id_op = GNUNET_IDENTITY_create (identity_handle,
209 egoName, 336 egoName,
210 &pk, 337 &pk,
211 &create_finished, 338 &create_finished,
212 cb); 339 p_op);
213 340
214 // TODO: return id_op? 341 p_op->id_op = id_op;
342
343 return plugin_op_wrap;
215} 344}
216 345
217 346
@@ -263,12 +392,32 @@ plaintext_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
263 392
264 393
265/** 394/**
266 * Cancel ... TODO 395 * Cancel a plaintext plugin operation.
396 *
397 * @param plugin_op_wrap the plugin operation wrapper containing the operation
267 */ 398 */
268void 399void
269cancel_plaintext_ () 400cancel_plaintext_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap)
270{ 401{
271 return; 402 struct ESCROW_PluginOperationWrapper *curr;
403 struct ESCROW_PlaintextPluginOperation *plugin_op;
404
405 for (curr = ph.plugin_op_head; NULL != curr; curr = curr->next)
406 {
407 if (curr == plugin_op_wrap)
408 {
409 GNUNET_CONTAINER_DLL_remove (ph.plugin_op_head,
410 ph.plugin_op_tail,
411 curr);
412 plugin_op = (struct ESCROW_PlaintextPluginOperation *)curr->plugin_op;
413 GNUNET_IDENTITY_cancel (plugin_op->id_op);
414 if (NULL != plugin_op->sched_task)
415 GNUNET_SCHEDULER_cancel (plugin_op->sched_task);
416 GNUNET_free (plugin_op);
417 GNUNET_free (curr);
418 return;
419 }
420 }
272} 421}
273 422
274 423
@@ -302,9 +451,12 @@ libgnunet_plugin_escrow_plaintext_init (void *cls)
302 api->restore_key = &restore_plaintext_key_escrow; 451 api->restore_key = &restore_plaintext_key_escrow;
303 api->anchor_string_to_data = &plaintext_anchor_string_to_data; 452 api->anchor_string_to_data = &plaintext_anchor_string_to_data;
304 api->anchor_data_to_string = &plaintext_anchor_data_to_string; 453 api->anchor_data_to_string = &plaintext_anchor_data_to_string;
454 api->cancel_plugin_operation = &cancel_plaintext_operation;
305 455
306 ph.id_init_cont = &plaintext_cont_init; 456 ph.id_init_cont = &plaintext_cont_init;
307 457
458 // set ego_create_cont here so it is called every time an ego is created
459 ph.ego_create_cont = &ego_created;
308 identity_handle = GNUNET_IDENTITY_connect (cfg, 460 identity_handle = GNUNET_IDENTITY_connect (cfg,
309 &ESCROW_list_ego, 461 &ESCROW_list_ego,
310 &ph); 462 &ph);
diff --git a/src/include/gnunet_escrow_lib.h b/src/include/gnunet_escrow_lib.h
index 388f5a3e1..aea081319 100644
--- a/src/include/gnunet_escrow_lib.h
+++ b/src/include/gnunet_escrow_lib.h
@@ -97,7 +97,6 @@ typedef void (*GNUNET_ESCROW_EgoCreateContinuation) (
97 * @param escrowAnchor the escrow anchor needed to get the data back 97 * @param escrowAnchor the escrow anchor needed to get the data back
98 */ 98 */
99typedef void (*GNUNET_ESCROW_AnchorContinuation) ( 99typedef void (*GNUNET_ESCROW_AnchorContinuation) (
100 void *cls,
101 struct GNUNET_ESCROW_Anchor *escrowAnchor); 100 struct GNUNET_ESCROW_Anchor *escrowAnchor);
102 101
103/** 102/**
@@ -107,7 +106,6 @@ typedef void (*GNUNET_ESCROW_AnchorContinuation) (
107 * @param ego a new identity ego restored from the escrow 106 * @param ego a new identity ego restored from the escrow
108 */ 107 */
109typedef void (*GNUNET_ESCROW_EgoContinuation) ( 108typedef void (*GNUNET_ESCROW_EgoContinuation) (
110 void *cls,
111 const struct GNUNET_IDENTITY_Ego *ego); 109 const struct GNUNET_IDENTITY_Ego *ego);
112 110
113/** 111/**
@@ -120,7 +118,6 @@ typedef void (*GNUNET_ESCROW_EgoContinuation) (
120 * GNUNET_ESCROW_INVALID otherwise 118 * GNUNET_ESCROW_INVALID otherwise
121 */ 119 */
122typedef void (*GNUNET_ESCROW_VerifyContinuation) ( 120typedef void (*GNUNET_ESCROW_VerifyContinuation) (
123 void *cls,
124 int verificationResult); 121 int verificationResult);
125 122
126 123
@@ -167,6 +164,31 @@ struct GNUNET_ESCROW_Operation
167 struct GNUNET_ESCROW_Operation *prev; 164 struct GNUNET_ESCROW_Operation *prev;
168 165
169 /** 166 /**
167 * The used escrow method.
168 */
169 enum GNUNET_ESCROW_Key_Escrow_Method method;
170
171 /**
172 * The respective plugin operation
173 */
174 struct ESCROW_PluginOperationWrapper *plugin_op_wrap;
175
176 /**
177 * The escrow anchor.
178 */
179 struct GNUNET_ESCROW_Anchor *escrow_anchor;
180
181 /**
182 * The ego.
183 */
184 struct GNUNET_IDENTITY_Ego *ego;
185
186 /**
187 * The verification result.
188 */
189 enum GNUNET_ESCROW_Verification_Result verification_result;
190
191 /**
170 * Continuation for a PUT operation. 192 * Continuation for a PUT operation.
171 */ 193 */
172 GNUNET_ESCROW_AnchorContinuation cb_put; 194 GNUNET_ESCROW_AnchorContinuation cb_put;
@@ -336,11 +358,9 @@ GNUNET_ESCROW_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
336 * be executed; this merely cancels the continuation. 358 * be executed; this merely cancels the continuation.
337 * 359 *
338 * @param op operation to cancel 360 * @param op operation to cancel
339 * @param method the escrow method to use
340 */ 361 */
341void 362void
342GNUNET_ESCROW_cancel (struct GNUNET_ESCROW_Operation *op, 363GNUNET_ESCROW_cancel (struct GNUNET_ESCROW_Operation *op);
343 enum GNUNET_ESCROW_Key_Escrow_Method method);
344 364
345 365
346#if 0 /* keep Emacsens' auto-indent happy */ 366#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/include/gnunet_escrow_plugin.h b/src/include/gnunet_escrow_plugin.h
index d3bb33745..b0a5f5652 100644
--- a/src/include/gnunet_escrow_plugin.h
+++ b/src/include/gnunet_escrow_plugin.h
@@ -33,6 +33,8 @@
33#include "gnunet_util_lib.h" 33#include "gnunet_util_lib.h"
34#include "gnunet_escrow_lib.h" 34#include "gnunet_escrow_lib.h"
35#include "gnunet_identity_service.h" 35#include "gnunet_identity_service.h"
36#include "../escrow/escrow.h"
37#include "gnunet_scheduler_lib.h"
36 38
37#ifdef __cplusplus 39#ifdef __cplusplus
38extern "C" { 40extern "C" {
@@ -41,88 +43,41 @@ extern "C" {
41#endif 43#endif
42#endif 44#endif
43 45
44/**
45 * State while collecting all egos
46 */
47#define ESCROW_PLUGIN_STATE_INIT 0
48 46
49/** 47/**
50 * Done collecting egos 48 * Wrapper for the Plugin_AnchorContinuation.
49 *
50 * As this type of function is called from the scheduler, which only takes
51 * one argument as closure, this struct is used to pass more arguments.
51 */ 52 */
52#define ESCROW_PLUGIN_STATE_POST_INIT 1 53struct GNUNET_ESCROW_Plugin_AnchorContinuationWrapper
53 54{
55 struct GNUNET_ESCROW_Handle *h;
56 struct GNUNET_ESCROW_Anchor *escrowAnchor;
57};
54 58
55/** 59/**
56 * The ego list 60 * Wrapper for the Plugin_EgoContinuation.
61 *
62 * As this type of function is called from the scheduler, which only takes
63 * one argument as closure, this struct is used to pass more arguments.
57 */ 64 */
58struct EgoEntry 65struct GNUNET_ESCROW_Plugin_EgoContinuationWrapper
59{ 66{
60 /** 67 struct GNUNET_ESCROW_Handle *h;
61 * DLL 68 const struct GNUNET_IDENTITY_Ego *ego;
62 */
63 struct EgoEntry *next;
64
65 /**
66 * DLL
67 */
68 struct EgoEntry *prev;
69
70 /**
71 * Ego Identifier
72 */
73 char *identifier;
74
75 /**
76 * Public key string
77 */
78 char *keystring;
79
80 /**
81 * The Ego
82 */
83 struct GNUNET_IDENTITY_Ego *ego;
84}; 69};
85 70
86
87/** 71/**
88 * Handle for a plugin instance 72 * Wrapper for the Plugin_VerifyContinuation.
73 *
74 * As this type of function is called from the scheduler, which only takes
75 * one argument as closure, this struct is used to pass more arguments.
89 */ 76 */
90struct EscrowPluginHandle 77struct GNUNET_ESCROW_Plugin_VerifyContinuationWrapper
91{ 78{
92 /** 79 struct GNUNET_ESCROW_Handle *h;
93 * The identity init continuation. 80 int verificationResult;
94 */
95 GNUNET_ESCROW_IdentityInitContinuation id_init_cont;
96
97 /**
98 * The ego create continuation.
99 */
100 GNUNET_ESCROW_EgoCreateContinuation ego_create_cont;
101
102 /**
103 * The current restore callback.
104 */
105 GNUNET_ESCROW_EgoContinuation curr_restore_cb;
106
107 /**
108 * The handle to the escrow component.
109 */
110 struct GNUNET_ESCROW_Handle *escrow_handle;
111
112 /**
113 * The state of the plugin (in the initialization phase).
114 */
115 int state;
116
117 /**
118 * The head of the ego list.
119 */
120 struct EgoEntry *ego_head;
121
122 /**
123 * The tail of the ego list
124 */
125 struct EgoEntry *ego_tail;
126}; 81};
127 82
128 83
@@ -133,10 +88,10 @@ struct EscrowPluginHandle
133 * @param ego the identity ego containing the private key 88 * @param ego the identity ego containing the private key
134 * @param cb the function called upon completion 89 * @param cb the function called upon completion
135 */ 90 */
136typedef void (*GNUNET_ESCROW_StartKeyEscrowFunction) ( 91typedef struct ESCROW_PluginOperationWrapper *(*GNUNET_ESCROW_StartKeyEscrowFunction) (
137 struct GNUNET_ESCROW_Handle *h, 92 struct GNUNET_ESCROW_Handle *h,
138 const struct GNUNET_IDENTITY_Ego *ego, 93 const struct GNUNET_IDENTITY_Ego *ego,
139 GNUNET_ESCROW_AnchorContinuation cb); 94 GNUNET_SCHEDULER_TaskCallback cb);
140 95
141/** 96/**
142 * Function called to renew the escrow of the key 97 * Function called to renew the escrow of the key
@@ -156,11 +111,11 @@ typedef void (*GNUNET_ESCROW_RenewKeyEscrowFunction) (
156 * @param escrowAnchor the escrow anchor needed to restore the key 111 * @param escrowAnchor the escrow anchor needed to restore the key
157 * @param cb the function called upon completion 112 * @param cb the function called upon completion
158 */ 113 */
159typedef void (*GNUNET_ESCROW_VerifyKeyEscrowFunction) ( 114typedef struct ESCROW_PluginOperationWrapper *(*GNUNET_ESCROW_VerifyKeyEscrowFunction) (
160 struct GNUNET_ESCROW_Handle *h, 115 struct GNUNET_ESCROW_Handle *h,
161 const struct GNUNET_IDENTITY_Ego *ego, 116 const struct GNUNET_IDENTITY_Ego *ego,
162 struct GNUNET_ESCROW_Anchor *escrowAnchor, 117 struct GNUNET_ESCROW_Anchor *escrowAnchor,
163 GNUNET_ESCROW_VerifyContinuation cb); 118 GNUNET_SCHEDULER_TaskCallback cb);
164 119
165/** 120/**
166 * Function called to restore a key from an escrow 121 * Function called to restore a key from an escrow
@@ -170,11 +125,11 @@ typedef void (*GNUNET_ESCROW_VerifyKeyEscrowFunction) (
170 * @param egoName the name of the ego to restore 125 * @param egoName the name of the ego to restore
171 * @param cb the function called upon completion 126 * @param cb the function called upon completion
172 */ 127 */
173typedef void (*GNUNET_ESCROW_RestoreKeyFunction) ( 128typedef struct ESCROW_PluginOperationWrapper *(*GNUNET_ESCROW_RestoreKeyFunction) (
174 struct GNUNET_ESCROW_Handle *h, 129 struct GNUNET_ESCROW_Handle *h,
175 struct GNUNET_ESCROW_Anchor *escrowAnchor, 130 struct GNUNET_ESCROW_Anchor *escrowAnchor,
176 char *egoName, 131 char *egoName,
177 GNUNET_ESCROW_EgoContinuation cb); 132 GNUNET_SCHEDULER_TaskCallback cb);
178 133
179 134
180/** 135/**
@@ -205,6 +160,15 @@ typedef char *(*GNUNET_ESCROW_AnchorDataToStringFunction) (
205 160
206 161
207/** 162/**
163 * Function called to cancel a plugin operation
164 *
165 * @param plugin_op_wrap plugin operation wrapper containing the plugin operation
166 */
167typedef void (*GNUNET_ESCROW_CancelPluginOperationFunction) (
168 struct ESCROW_PluginOperationWrapper *plugin_op_wrap);
169
170
171/**
208 * Each plugin is required to return a pointer to a struct of this 172 * Each plugin is required to return a pointer to a struct of this
209 * type as the return value from its entry point. 173 * type as the return value from its entry point.
210 */ 174 */
@@ -244,6 +208,11 @@ struct GNUNET_ESCROW_KeyPluginFunctions
244 * Serialize anchor data to string 208 * Serialize anchor data to string
245 */ 209 */
246 GNUNET_ESCROW_AnchorDataToStringFunction anchor_data_to_string; 210 GNUNET_ESCROW_AnchorDataToStringFunction anchor_data_to_string;
211
212 /**
213 * Cancel plugin operation
214 */
215 GNUNET_ESCROW_CancelPluginOperationFunction cancel_plugin_operation;
247}; 216};
248 217
249 218