aboutsummaryrefslogtreecommitdiff
path: root/src/escrow/plugin_escrow_gns.c
diff options
context:
space:
mode:
authorjospaeth <spaethj@in.tum.de>2020-08-09 10:27:25 +0200
committerjospaeth <spaethj@in.tum.de>2020-08-09 10:27:25 +0200
commitb2ebdaca4d0d3a4f1fac2f2f83cdedf4123a43b8 (patch)
tree222b0754649e843a746c2163cb6323f263287c1f /src/escrow/plugin_escrow_gns.c
parenta2280bff1c996cfe70326602c0204f8637c2c20b (diff)
downloadgnunet-b2ebdaca4d0d3a4f1fac2f2f83cdedf4123a43b8.tar.gz
gnunet-b2ebdaca4d0d3a4f1fac2f2f83cdedf4123a43b8.zip
GNS escrow
check for existing escrow IDs some cleanup
Diffstat (limited to 'src/escrow/plugin_escrow_gns.c')
-rw-r--r--src/escrow/plugin_escrow_gns.c105
1 files changed, 87 insertions, 18 deletions
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c
index 8c2ac0de4..8859275c6 100644
--- a/src/escrow/plugin_escrow_gns.c
+++ b/src/escrow/plugin_escrow_gns.c
@@ -196,6 +196,7 @@ cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap)
196 GNUNET_CONTAINER_DLL_remove (p_op->id_ops_head, 196 GNUNET_CONTAINER_DLL_remove (p_op->id_ops_head,
197 p_op->id_ops_tail, 197 p_op->id_ops_tail,
198 curr_id_op); 198 curr_id_op);
199 GNUNET_IDENTITY_cancel (curr_id_op->id_op);
199 GNUNET_free (curr_id_op->id_op); 200 GNUNET_free (curr_id_op->id_op);
200 GNUNET_free (curr_id_op); 201 GNUNET_free (curr_id_op);
201 } 202 }
@@ -269,12 +270,15 @@ distribute_keyshares (struct ESCROW_GnsPluginOperation *p_op,
269 270
270 271
271void 272void
272escrow_ids_finished (struct ESCROW_GnsPluginOperation *p_op) 273escrow_ids_finished (struct ESCROW_PluginOperationWrapper *plugin_op_wrap)
273{ 274{
275 struct ESCROW_GnsPluginOperation *p_op;
274 sss_Keyshare *keyshares; 276 sss_Keyshare *keyshares;
275 struct GNUNET_ESCROW_Anchor *anchor; 277 struct GNUNET_ESCROW_Anchor *anchor;
276 int anchorDataSize; 278 int anchorDataSize;
277 279
280 p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op;
281
278 /* split the private key (SSS) */ 282 /* split the private key (SSS) */
279 keyshares = split_private_key (p_op); 283 keyshares = split_private_key (p_op);
280 if (NULL == keyshares) 284 if (NULL == keyshares)
@@ -295,6 +299,7 @@ escrow_ids_finished (struct ESCROW_GnsPluginOperation *p_op)
295 299
296 /* call the continuation */ 300 /* call the continuation */
297 p_op->cont (p_op->anchor_wrap); 301 p_op->cont (p_op->anchor_wrap);
302 cleanup_plugin_operation (plugin_op_wrap);
298} 303}
299 304
300 305
@@ -303,10 +308,13 @@ escrow_id_created (void *cls,
303 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, 308 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
304 const char *emsg) 309 const char *emsg)
305{ 310{
306 struct ESCROW_GnsPluginOperation *p_op = cls; 311 struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls;
312 struct ESCROW_GnsPluginOperation *p_op;
307 struct IdentityOperationEntry *curr_id_op; 313 struct IdentityOperationEntry *curr_id_op;
308 struct PkEntry *pk_entry; 314 struct PkEntry *pk_entry;
309 315
316 p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op;
317
310 if (NULL == pk) 318 if (NULL == pk)
311 { 319 {
312 if (NULL != emsg) 320 if (NULL != emsg)
@@ -317,6 +325,8 @@ escrow_id_created (void *cls,
317 fprintf (stderr, "Failed to create ego!"); 325 fprintf (stderr, "Failed to create ego!");
318 p_op->anchor_wrap->escrowAnchor = NULL; 326 p_op->anchor_wrap->escrowAnchor = NULL;
319 p_op->cont (p_op->anchor_wrap); 327 p_op->cont (p_op->anchor_wrap);
328 // this also cancels all running identity operations
329 cleanup_plugin_operation (plugin_op_wrap);
320 return; 330 return;
321 } 331 }
322 332
@@ -342,7 +352,7 @@ escrow_id_created (void *cls,
342 p_op->escrow_id_counter++; 352 p_op->escrow_id_counter++;
343 if (p_op->escrow_id_counter == p_op->shares) 353 if (p_op->escrow_id_counter == p_op->shares)
344 { 354 {
345 escrow_ids_finished (p_op); 355 escrow_ids_finished (plugin_op_wrap);
346 } 356 }
347} 357}
348 358
@@ -392,30 +402,88 @@ get_escrow_id_name (const char *name,
392} 402}
393 403
394 404
405static int
406escrow_id_exists (const char *name,
407 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
408{
409 struct EgoEntry *curr;
410
411 for (curr = ph.ego_head; NULL != curr; curr = curr->next)
412 {
413 if (0 == strcmp (name, curr->identifier))
414 {
415 if (curr->ego->pk.d == pk->d) // TODO: correct equality check?
416 return GNUNET_YES;
417 else // the escrow id's name exists for an ego, but the pk is wrong
418 return GNUNET_SYSERR;
419 }
420 }
421
422 return GNUNET_NO;
423}
424
425
426static struct GNUNET_CRYPTO_EcdsaPrivateKey *
427derive_private_key (const char *name,
428 void *password,
429 uint8_t i)
430{
431 // TODO: derive key
432 return NULL;
433}
434
435
395static void 436static void
396create_escrow_identities (struct ESCROW_GnsPluginOperation *p_op, 437create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap,
397 const char *name) 438 const char *name)
398{ 439{
440 struct ESCROW_GnsPluginOperation *p_op;
399 struct GNUNET_CRYPTO_EcdsaPrivateKey *curr_pk; 441 struct GNUNET_CRYPTO_EcdsaPrivateKey *curr_pk;
400 char *curr_name; 442 char *curr_name;
401 struct IdentityOperationEntry *curr_id_op; 443 struct IdentityOperationEntry *curr_id_op;
444 struct PkEntry *curr_pk_entry;
445 int exists_ret;
446
447 p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op;
402 448
403 for (uint8_t i = 0; i < p_op->shares; i++) 449 for (uint8_t i = 0; i < p_op->shares; i++)
404 { 450 {
405 curr_pk = NULL; // TODO: derive key 451 curr_pk = derive_private_key (name, NULL, i); // TODO: password
406 curr_name = get_escrow_id_name (name, i); 452 curr_name = get_escrow_id_name (name, i);
407 453
408 /* store the identity operation in our list */ 454 // check if the escrow identity already exists
409 curr_id_op = GNUNET_new (struct IdentityOperationEntry); 455 exists_ret = escrow_id_exists (curr_name, curr_pk);
410 curr_id_op->pk = curr_pk; 456 if (GNUNET_SYSERR == exists_ret)
411 curr_id_op->id_op = GNUNET_IDENTITY_create (identity_handle, 457 {
412 curr_name, 458 p_op->anchor_wrap->escrowAnchor = NULL;
413 curr_pk, 459 p_op->cont (p_op->anchor_wrap);
414 &escrow_id_created, 460 // this also cancels all running identity operations
415 p_op); 461 cleanup_plugin_operation (plugin_op_wrap);
416 GNUNET_CONTAINER_DLL_insert (p_op->id_ops_head, 462 return;
417 p_op->id_ops_tail, 463 }
418 curr_id_op); 464 else if (GNUNET_YES == exists_ret)
465 {
466 // the escrow id already exists, so insert the pk into our list
467 curr_pk_entry = GNUNET_new (struct PkEntry);
468 curr_pk_entry->pk = curr_pk;
469 GNUNET_CONTAINER_DLL_insert (p_op->escrow_pks_head,
470 p_op->escrow_pks_tail,
471 curr_pk_entry);
472 }
473 else // GNUNET_NO
474 {
475 /* store the identity operation in our list */
476 curr_id_op = GNUNET_new (struct IdentityOperationEntry);
477 curr_id_op->pk = curr_pk;
478 curr_id_op->id_op = GNUNET_IDENTITY_create (identity_handle,
479 curr_name,
480 curr_pk,
481 &escrow_id_created,
482 plugin_op_wrap);
483 GNUNET_CONTAINER_DLL_insert (p_op->id_ops_head,
484 p_op->id_ops_tail,
485 curr_id_op);
486 }
419 } 487 }
420} 488}
421 489
@@ -490,7 +558,8 @@ start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
490 p_op->share_threshold = (uint8_t)share_threshold; 558 p_op->share_threshold = (uint8_t)share_threshold;
491 559
492 /* create the escrow identities */ 560 /* create the escrow identities */
493 create_escrow_identities (p_op, ego->name); 561 // TODO: check for existing escrow identities
562 create_escrow_identities (plugin_op_wrap, ego->name);
494 563
495 /* operation continues in escrow_ids_finished 564 /* operation continues in escrow_ids_finished
496 after all escrow identities are created */ 565 after all escrow identities are created */