diff options
author | jospaeth <spaethj@in.tum.de> | 2020-08-29 22:28:23 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-08-29 22:28:23 +0200 |
commit | abd526c01164422a086374a1a96ca9ee5e781b01 (patch) | |
tree | 757b6f4431a1278b6d356138a6cd4a75dc87c58a /src/escrow/plugin_escrow_plaintext.c | |
parent | 5f7d255ae5221c447367c4ac7a157ddcd27bcd57 (diff) | |
download | gnunet-abd526c01164422a086374a1a96ca9ee5e781b01.tar.gz gnunet-abd526c01164422a086374a1a96ca9ee5e781b01.zip |
add egoName to the escrow anchor,
no need to pass it to the API in case of a GET operation
Diffstat (limited to 'src/escrow/plugin_escrow_plaintext.c')
-rw-r--r-- | src/escrow/plugin_escrow_plaintext.c | 66 |
1 files changed, 49 insertions, 17 deletions
diff --git a/src/escrow/plugin_escrow_plaintext.c b/src/escrow/plugin_escrow_plaintext.c index 0dab8fd1e..eace829ea 100644 --- a/src/escrow/plugin_escrow_plaintext.c +++ b/src/escrow/plugin_escrow_plaintext.c | |||
@@ -182,6 +182,7 @@ start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
182 | anchorDataSize = strlen (pkString) + 1; | 182 | anchorDataSize = strlen (pkString) + 1; |
183 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize); | 183 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize); |
184 | anchor->method = GNUNET_ESCROW_KEY_PLAINTEXT; | 184 | anchor->method = GNUNET_ESCROW_KEY_PLAINTEXT; |
185 | anchor->egoName = GNUNET_strdup (ego->name); | ||
185 | anchor->size = anchorDataSize; | 186 | anchor->size = anchorDataSize; |
186 | GNUNET_memcpy (&anchor[1], pkString, anchorDataSize); | 187 | GNUNET_memcpy (&anchor[1], pkString, anchorDataSize); |
187 | 188 | ||
@@ -256,11 +257,17 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
256 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); | 257 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); |
257 | return plugin_op_wrap; | 258 | return plugin_op_wrap; |
258 | } | 259 | } |
260 | if (0 != strcmp (ego->name, escrowAnchor->egoName)) | ||
261 | { | ||
262 | w->verificationResult = GNUNET_ESCROW_INVALID; | ||
263 | w->emsg = _ ("This anchor was not created when putting ego that in escrow!\n"); | ||
264 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); | ||
265 | return plugin_op_wrap; | ||
266 | } | ||
259 | pk = GNUNET_IDENTITY_ego_get_private_key (ego); | 267 | pk = GNUNET_IDENTITY_ego_get_private_key (ego); |
260 | pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); | 268 | pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); |
261 | verificationResult = strncmp (pkString, | 269 | verificationResult = strcmp (pkString, |
262 | (char *)&escrowAnchor[1], | 270 | (char *)&escrowAnchor[1]) == 0 ? |
263 | strlen (pkString)) == 0 ? | ||
264 | GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; | 271 | GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; |
265 | 272 | ||
266 | w->verificationResult = verificationResult; | 273 | w->verificationResult = verificationResult; |
@@ -357,8 +364,7 @@ handle_restore_error (void *cls) | |||
357 | * Restore the key from plaintext escrow | 364 | * Restore the key from plaintext escrow |
358 | * | 365 | * |
359 | * @param h the handle for the escrow component | 366 | * @param h the handle for the escrow component |
360 | * @param escrowAnchor the escrow anchor needed to restore the key | 367 | * @param anchor the escrow anchor needed to restore the key |
361 | * @param egoName the name of the ego to restore | ||
362 | * @param cb the function called upon completion | 368 | * @param cb the function called upon completion |
363 | * @param op_id unique ID of the respective ESCROW_Operation | 369 | * @param op_id unique ID of the respective ESCROW_Operation |
364 | * | 370 | * |
@@ -366,8 +372,7 @@ handle_restore_error (void *cls) | |||
366 | */ | 372 | */ |
367 | struct ESCROW_PluginOperationWrapper * | 373 | struct ESCROW_PluginOperationWrapper * |
368 | restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | 374 | restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, |
369 | struct GNUNET_ESCROW_Anchor *escrowAnchor, | 375 | struct GNUNET_ESCROW_Anchor *anchor, |
370 | const char *egoName, | ||
371 | ESCROW_Plugin_Continuation cb, | 376 | ESCROW_Plugin_Continuation cb, |
372 | uint32_t op_id) | 377 | uint32_t op_id) |
373 | { | 378 | { |
@@ -393,17 +398,17 @@ restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
393 | w->op_id = op_id; | 398 | w->op_id = op_id; |
394 | p_op->ego_wrap = w; | 399 | p_op->ego_wrap = w; |
395 | 400 | ||
396 | if (NULL == escrowAnchor) | 401 | if (NULL == anchor) |
397 | { | 402 | { |
398 | w->ego = NULL; | 403 | w->ego = NULL; |
399 | w->emsg = _ ("ESCROW_get was called with escrowAnchor == NULL!\n"); | 404 | w->emsg = _ ("ESCROW_get was called with anchor == NULL!\n"); |
400 | // schedule handle_restore_error, which calls the callback and cleans up | 405 | // schedule handle_restore_error, which calls the callback and cleans up |
401 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&handle_restore_error, plugin_op_wrap); | 406 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&handle_restore_error, plugin_op_wrap); |
402 | return plugin_op_wrap; | 407 | return plugin_op_wrap; |
403 | } | 408 | } |
404 | if (GNUNET_OK != | 409 | if (GNUNET_OK != |
405 | GNUNET_CRYPTO_ecdsa_private_key_from_string ((char *)&escrowAnchor[1], | 410 | GNUNET_CRYPTO_ecdsa_private_key_from_string ((char *)&anchor[1], |
406 | strlen ((char *)&escrowAnchor[1]), | 411 | strlen ((char *)&anchor[1]), |
407 | &pk)) | 412 | &pk)) |
408 | { | 413 | { |
409 | w->ego = NULL; | 414 | w->ego = NULL; |
@@ -414,7 +419,7 @@ restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
414 | } | 419 | } |
415 | 420 | ||
416 | p_op->id_op = GNUNET_IDENTITY_create (identity_handle, | 421 | p_op->id_op = GNUNET_IDENTITY_create (identity_handle, |
417 | egoName, | 422 | anchor->egoName, |
418 | &pk, | 423 | &pk, |
419 | &create_finished, | 424 | &create_finished, |
420 | p_op); | 425 | p_op); |
@@ -445,7 +450,8 @@ plaintext_get_status (struct GNUNET_ESCROW_Handle *h, | |||
445 | * @param h the handle for the escrow component | 450 | * @param h the handle for the escrow component |
446 | * @param anchorString the encoded escrow anchor string | 451 | * @param anchorString the encoded escrow anchor string |
447 | * | 452 | * |
448 | * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct | 453 | * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct, |
454 | * NULL if we failed to parse the string | ||
449 | */ | 455 | */ |
450 | struct GNUNET_ESCROW_Anchor * | 456 | struct GNUNET_ESCROW_Anchor * |
451 | plaintext_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, | 457 | plaintext_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, |
@@ -453,13 +459,34 @@ plaintext_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, | |||
453 | { | 459 | { |
454 | struct GNUNET_ESCROW_Anchor *anchor; | 460 | struct GNUNET_ESCROW_Anchor *anchor; |
455 | uint32_t data_size; | 461 | uint32_t data_size; |
462 | char *anchorStringCopy, *ptr, *egoNameCopy; | ||
463 | char delimiter[] = ":"; | ||
464 | |||
465 | anchorStringCopy = GNUNET_strdup (anchorString); | ||
456 | 466 | ||
457 | data_size = strlen (anchorString) + 1; | 467 | // split the string at the first occurrence of the delimiter |
468 | ptr = strtok (anchorStringCopy, delimiter); | ||
469 | egoNameCopy = GNUNET_strdup (ptr); | ||
470 | ptr = strtok (NULL, delimiter); | ||
458 | 471 | ||
472 | if (NULL == ptr) | ||
473 | { | ||
474 | // delimiter was not found | ||
475 | GNUNET_free (egoNameCopy); | ||
476 | GNUNET_free (anchorStringCopy); | ||
477 | return NULL; | ||
478 | } | ||
479 | |||
480 | data_size = strlen (ptr) + 1; | ||
459 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + data_size); | 481 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + data_size); |
460 | anchor->size = data_size; | 482 | anchor->size = data_size; |
483 | anchor->egoName = egoNameCopy; | ||
484 | anchor->method = GNUNET_ESCROW_KEY_PLAINTEXT; | ||
485 | |||
461 | // TODO: deserialize? | 486 | // TODO: deserialize? |
462 | GNUNET_memcpy (&anchor[1], anchorString, data_size); | 487 | GNUNET_memcpy (&anchor[1], ptr, data_size); |
488 | |||
489 | GNUNET_free (anchorStringCopy); | ||
463 | 490 | ||
464 | return anchor; | 491 | return anchor; |
465 | } | 492 | } |
@@ -478,9 +505,14 @@ plaintext_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h, | |||
478 | struct GNUNET_ESCROW_Anchor *escrowAnchor) | 505 | struct GNUNET_ESCROW_Anchor *escrowAnchor) |
479 | { | 506 | { |
480 | char *anchorString; | 507 | char *anchorString; |
508 | size_t egoNameSize; | ||
509 | |||
510 | egoNameSize = strlen (escrowAnchor->egoName); | ||
481 | 511 | ||
482 | anchorString = GNUNET_malloc (escrowAnchor->size); | 512 | anchorString = GNUNET_malloc (egoNameSize + 1 + escrowAnchor->size); |
483 | GNUNET_memcpy (anchorString, &escrowAnchor[1], escrowAnchor->size); | 513 | GNUNET_memcpy (anchorString, escrowAnchor->egoName, egoNameSize); |
514 | anchorString[egoNameSize] = ':'; | ||
515 | GNUNET_memcpy (anchorString + egoNameSize + 1, &escrowAnchor[1], escrowAnchor->size); | ||
484 | 516 | ||
485 | return anchorString; | 517 | return anchorString; |
486 | } | 518 | } |