diff options
author | jospaeth <spaethj@in.tum.de> | 2020-08-03 11:58:50 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-08-03 11:58:50 +0200 |
commit | 1c09fd9efa3ce06b980b8e493644a7d271c52747 (patch) | |
tree | b1c1dfaa305d0a9e8b8b6a1145df80e1538854db /src/escrow/plugin_escrow_plaintext.c | |
parent | 7694804564e41a04e9d6e0909a59ee7ec3b7e627 (diff) | |
download | gnunet-1c09fd9efa3ce06b980b8e493644a7d271c52747.tar.gz gnunet-1c09fd9efa3ce06b980b8e493644a7d271c52747.zip |
major restructuring of the escrow component
refine the several layers (CLI, API, plugins) and enable async execution
Diffstat (limited to 'src/escrow/plugin_escrow_plaintext.c')
-rw-r--r-- | src/escrow/plugin_escrow_plaintext.c | 220 |
1 files changed, 186 insertions, 34 deletions
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 | ||
37 | struct 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 | */ |
44 | struct EscrowPluginHandle ph; | 79 | struct 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 | */ |
54 | void | 91 | struct ESCROW_PluginOperationWrapper * |
55 | start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | 92 | start_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 | |||
89 | renew_plaintext_key_escrow (struct GNUNET_ESCROW_Operation *op, | 146 | renew_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 | */ |
104 | void | 163 | struct ESCROW_PluginOperationWrapper * |
105 | verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | 164 | verify_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 | ||
129 | void | 208 | void |
130 | ego_created (const struct GNUNET_IDENTITY_Ego *ego) | 209 | ego_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 | */ |
182 | void | 289 | struct ESCROW_PluginOperationWrapper * |
183 | restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | 290 | restore_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 | */ |
268 | void | 399 | void |
269 | cancel_plaintext_ () | 400 | cancel_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); |