diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-16 16:32:08 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-16 16:32:08 +0200 |
commit | 9b84e344cac92456d0d6574b3bf662c2fba4e559 (patch) | |
tree | 71d8f446dba5af630020f943d51701aad39c5d11 /src/credential | |
parent | b929e294b336d2627919f423d3cafd938ed75d8c (diff) | |
download | gnunet-9b84e344cac92456d0d6574b3bf662c2fba4e559.tar.gz gnunet-9b84e344cac92456d0d6574b3bf662c2fba4e559.zip |
fix memleaks
Diffstat (limited to 'src/credential')
-rw-r--r-- | src/credential/gnunet-service-credential.c | 256 | ||||
-rw-r--r-- | src/credential/test_credential_lookup.conf | 2 |
2 files changed, 163 insertions, 95 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c index 4a3002fa1..b0475d0f2 100644 --- a/src/credential/gnunet-service-credential.c +++ b/src/credential/gnunet-service-credential.c | |||
@@ -361,11 +361,13 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry) | |||
361 | for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry; | 361 | for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry; |
362 | dq_entry = ds_entry->queue_entries_head) { | 362 | dq_entry = ds_entry->queue_entries_head) { |
363 | GNUNET_CONTAINER_DLL_remove (ds_entry->queue_entries_head, | 363 | GNUNET_CONTAINER_DLL_remove (ds_entry->queue_entries_head, |
364 | ds_entry->queue_entries_tail, dq_entry); | 364 | ds_entry->queue_entries_tail, |
365 | dq_entry); | ||
365 | for (child = dq_entry->set_entries_head; NULL != child; | 366 | for (child = dq_entry->set_entries_head; NULL != child; |
366 | child = dq_entry->set_entries_head) { | 367 | child = dq_entry->set_entries_head) { |
367 | GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head, | 368 | GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head, |
368 | dq_entry->set_entries_tail, child); | 369 | dq_entry->set_entries_tail, |
370 | child); | ||
369 | cleanup_delegation_set (child); | 371 | cleanup_delegation_set (child); |
370 | } | 372 | } |
371 | GNUNET_free (dq_entry); | 373 | GNUNET_free (dq_entry); |
@@ -400,7 +402,8 @@ cleanup_handle (struct VerifyRequestHandle *vrh) | |||
400 | GNUNET_free_non_null (vrh->issuer_attribute); | 402 | GNUNET_free_non_null (vrh->issuer_attribute); |
401 | for (cr_entry = vrh->cred_chain_head; NULL != vrh->cred_chain_head; | 403 | for (cr_entry = vrh->cred_chain_head; NULL != vrh->cred_chain_head; |
402 | cr_entry = vrh->cred_chain_head) { | 404 | cr_entry = vrh->cred_chain_head) { |
403 | GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, vrh->cred_chain_tail, | 405 | GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, |
406 | vrh->cred_chain_tail, | ||
404 | cr_entry); | 407 | cr_entry); |
405 | GNUNET_free_non_null (cr_entry->credential); | 408 | GNUNET_free_non_null (cr_entry->credential); |
406 | GNUNET_free (cr_entry); | 409 | GNUNET_free (cr_entry); |
@@ -474,7 +477,8 @@ send_lookup_response (struct VerifyRequestHandle *vrh) | |||
474 | } | 477 | } |
475 | tmp = cd; | 478 | tmp = cd; |
476 | cd = cd->next; | 479 | cd = cd->next; |
477 | GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, vrh->cred_chain_tail, | 480 | GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, |
481 | vrh->cred_chain_tail, | ||
478 | tmp); | 482 | tmp); |
479 | GNUNET_free (tmp->credential); | 483 | GNUNET_free (tmp->credential); |
480 | GNUNET_free (tmp); | 484 | GNUNET_free (tmp); |
@@ -489,16 +493,20 @@ send_lookup_response (struct VerifyRequestHandle *vrh) | |||
489 | for (uint32_t i = 0; i < vrh->cred_chain_size; i++) { | 493 | for (uint32_t i = 0; i < vrh->cred_chain_size; i++) { |
490 | cred[i].issuer_key = cd->credential->issuer_key; | 494 | cred[i].issuer_key = cd->credential->issuer_key; |
491 | cred[i].subject_key = cd->credential->subject_key; | 495 | cred[i].subject_key = cd->credential->subject_key; |
492 | cred[i].issuer_attribute_len = | 496 | cred[i].issuer_attribute_len |
493 | strlen (cd->credential->issuer_attribute) + 1; | 497 | = strlen (cd->credential->issuer_attribute) + 1; |
494 | cred[i].issuer_attribute = cd->credential->issuer_attribute; | 498 | cred[i].issuer_attribute = cd->credential->issuer_attribute; |
495 | cred[i].expiration = cd->credential->expiration; | 499 | cred[i].expiration = cd->credential->expiration; |
496 | cred[i].signature = cd->credential->signature; | 500 | cred[i].signature = cd->credential->signature; |
497 | cd = cd->next; | 501 | cd = cd->next; |
498 | } | 502 | } |
499 | size = GNUNET_CREDENTIAL_delegation_chain_get_size ( | 503 | size |
500 | vrh->delegation_chain_size, dd, vrh->cred_chain_size, cred); | 504 | = GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->delegation_chain_size, |
501 | env = GNUNET_MQ_msg_extra (rmsg, size, | 505 | dd, |
506 | vrh->cred_chain_size, | ||
507 | cred); | ||
508 | env = GNUNET_MQ_msg_extra (rmsg, | ||
509 | size, | ||
502 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); | 510 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); |
503 | // Assign id so that client can find associated request | 511 | // Assign id so that client can find associated request |
504 | rmsg->id = vrh->request_id; | 512 | rmsg->id = vrh->request_id; |
@@ -510,21 +518,29 @@ send_lookup_response (struct VerifyRequestHandle *vrh) | |||
510 | else | 518 | else |
511 | rmsg->cred_found = htonl (GNUNET_NO); | 519 | rmsg->cred_found = htonl (GNUNET_NO); |
512 | 520 | ||
513 | GNUNET_assert (-1 != GNUNET_CREDENTIAL_delegation_chain_serialize ( | 521 | GNUNET_assert ( |
514 | vrh->delegation_chain_size, dd, vrh->cred_chain_size, | 522 | -1 |
515 | cred, size, (char *)&rmsg[1])); | 523 | != GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size, |
524 | dd, | ||
525 | vrh->cred_chain_size, | ||
526 | cred, | ||
527 | size, | ||
528 | (char *)&rmsg[1])); | ||
516 | 529 | ||
517 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env); | 530 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env); |
518 | GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); | 531 | GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); |
519 | cleanup_handle (vrh); | 532 | cleanup_handle (vrh); |
520 | 533 | ||
521 | GNUNET_STATISTICS_update (statistics, "Completed verifications", 1, | 534 | GNUNET_STATISTICS_update (statistics, |
535 | "Completed verifications", | ||
536 | 1, | ||
522 | GNUNET_NO); | 537 | GNUNET_NO); |
523 | } | 538 | } |
524 | 539 | ||
525 | 540 | ||
526 | static void | 541 | static void |
527 | backward_resolution (void *cls, uint32_t rd_count, | 542 | backward_resolution (void *cls, |
543 | uint32_t rd_count, | ||
528 | const struct GNUNET_GNSRECORD_Data *rd) | 544 | const struct GNUNET_GNSRECORD_Data *rd) |
529 | { | 545 | { |
530 | 546 | ||
@@ -553,14 +569,16 @@ backward_resolution (void *cls, uint32_t rd_count, | |||
553 | sets = rd[i].data; | 569 | sets = rd[i].data; |
554 | struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets->set_count)]; | 570 | struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets->set_count)]; |
555 | GNUNET_log ( | 571 | GNUNET_log ( |
556 | GNUNET_ERROR_TYPE_DEBUG, | 572 | GNUNET_ERROR_TYPE_DEBUG, |
557 | "Found new attribute delegation with %d sets. Creating new Job...\n", | 573 | "Found new attribute delegation with %d sets. Creating new Job...\n", |
558 | ntohl (sets->set_count)); | 574 | ntohl (sets->set_count)); |
559 | 575 | ||
560 | if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize ( | 576 | if (GNUNET_OK |
561 | GNUNET_ntohll (sets->data_size), | 577 | != GNUNET_CREDENTIAL_delegation_set_deserialize ( |
562 | (const char *)&sets[1], ntohl (sets->set_count), | 578 | GNUNET_ntohll (sets->data_size), |
563 | set)) { | 579 | (const char *)&sets[1], |
580 | ntohl (sets->set_count), | ||
581 | set)) { | ||
564 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n"); | 582 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n"); |
565 | continue; | 583 | continue; |
566 | } | 584 | } |
@@ -568,7 +586,8 @@ backward_resolution (void *cls, uint32_t rd_count, | |||
568 | dq_entry->required_solutions = ntohl (sets->set_count); | 586 | dq_entry->required_solutions = ntohl (sets->set_count); |
569 | dq_entry->parent_set = current_set; | 587 | dq_entry->parent_set = current_set; |
570 | GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head, | 588 | GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head, |
571 | current_set->queue_entries_tail, dq_entry); | 589 | current_set->queue_entries_tail, |
590 | dq_entry); | ||
572 | // Each AND | 591 | // Each AND |
573 | for (uint32_t j = 0; j < ntohl (sets->set_count); j++) { | 592 | for (uint32_t j = 0; j < ntohl (sets->set_count); j++) { |
574 | ds_entry = GNUNET_new (struct DelegationSetQueueEntry); | 593 | ds_entry = GNUNET_new (struct DelegationSetQueueEntry); |
@@ -577,37 +596,42 @@ backward_resolution (void *cls, uint32_t rd_count, | |||
577 | GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer); | 596 | GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer); |
578 | 597 | ||
579 | } else { | 598 | } else { |
580 | GNUNET_asprintf (&expanded_attr, "%s.%s", set[j].subject_attribute, | 599 | GNUNET_asprintf (&expanded_attr, |
600 | "%s.%s", | ||
601 | set[j].subject_attribute, | ||
581 | current_set->attr_trailer); | 602 | current_set->attr_trailer); |
582 | } | 603 | } |
583 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr); | 604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr); |
584 | ds_entry->unresolved_attribute_delegation = expanded_attr; | 605 | ds_entry->unresolved_attribute_delegation = expanded_attr; |
585 | } else { | 606 | } else { |
586 | if (0 != set[j].subject_attribute_len) { | 607 | if (0 != set[j].subject_attribute_len) { |
587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not Expanding %s\n", | 608 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
609 | "Not Expanding %s\n", | ||
588 | set[j].subject_attribute); | 610 | set[j].subject_attribute); |
589 | ds_entry->unresolved_attribute_delegation = | 611 | ds_entry->unresolved_attribute_delegation |
590 | GNUNET_strdup (set[j].subject_attribute); | 612 | = GNUNET_strdup (set[j].subject_attribute); |
591 | } | 613 | } |
592 | } | 614 | } |
593 | 615 | ||
594 | // Add a credential chain entry | 616 | // Add a credential chain entry |
595 | ds_entry->delegation_chain_entry = | 617 | ds_entry->delegation_chain_entry |
596 | GNUNET_new (struct DelegationChainEntry); | 618 | = GNUNET_new (struct DelegationChainEntry); |
597 | ds_entry->delegation_chain_entry->subject_key = set[j].subject_key; | 619 | ds_entry->delegation_chain_entry->subject_key = set[j].subject_key; |
598 | ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); | 620 | ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); |
599 | GNUNET_memcpy (ds_entry->issuer_key, &set[j].subject_key, | 621 | GNUNET_memcpy (ds_entry->issuer_key, |
622 | &set[j].subject_key, | ||
600 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 623 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); |
601 | if (0 < set[j].subject_attribute_len) | 624 | if (0 < set[j].subject_attribute_len) |
602 | ds_entry->delegation_chain_entry->subject_attribute = | 625 | ds_entry->delegation_chain_entry->subject_attribute |
603 | GNUNET_strdup (set[j].subject_attribute); | 626 | = GNUNET_strdup (set[j].subject_attribute); |
604 | ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key; | 627 | ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key; |
605 | ds_entry->delegation_chain_entry->issuer_attribute = | 628 | ds_entry->delegation_chain_entry->issuer_attribute |
606 | GNUNET_strdup (current_set->lookup_attribute); | 629 | = GNUNET_strdup (current_set->lookup_attribute); |
607 | 630 | ||
608 | ds_entry->parent_queue_entry = dq_entry; // current_delegation; | 631 | ds_entry->parent_queue_entry = dq_entry; // current_delegation; |
609 | GNUNET_CONTAINER_DLL_insert (dq_entry->set_entries_head, | 632 | GNUNET_CONTAINER_DLL_insert (dq_entry->set_entries_head, |
610 | dq_entry->set_entries_tail, ds_entry); | 633 | dq_entry->set_entries_tail, |
634 | ds_entry); | ||
611 | 635 | ||
612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n"); | 636 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n"); |
613 | /** | 637 | /** |
@@ -615,16 +639,19 @@ backward_resolution (void *cls, uint32_t rd_count, | |||
615 | */ | 639 | */ |
616 | for (cred_pointer = vrh->cred_chain_head; cred_pointer != NULL; | 640 | for (cred_pointer = vrh->cred_chain_head; cred_pointer != NULL; |
617 | cred_pointer = cred_pointer->next) { | 641 | cred_pointer = cred_pointer->next) { |
618 | if (0 != memcmp (&set->subject_key, | 642 | if (0 |
619 | &cred_pointer->credential->issuer_key, | 643 | != memcmp (&set->subject_key, |
620 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 644 | &cred_pointer->credential->issuer_key, |
645 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
621 | continue; | 646 | continue; |
622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking if %s matches %s\n", | 647 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
648 | "Checking if %s matches %s\n", | ||
623 | ds_entry->unresolved_attribute_delegation, | 649 | ds_entry->unresolved_attribute_delegation, |
624 | cred_pointer->credential->issuer_attribute); | 650 | cred_pointer->credential->issuer_attribute); |
625 | 651 | ||
626 | if (0 != strcmp (ds_entry->unresolved_attribute_delegation, | 652 | if (0 |
627 | cred_pointer->credential->issuer_attribute)) | 653 | != strcmp (ds_entry->unresolved_attribute_delegation, |
654 | cred_pointer->credential->issuer_attribute)) | ||
628 | continue; | 655 | continue; |
629 | 656 | ||
630 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n"); | 657 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n"); |
@@ -656,8 +683,9 @@ backward_resolution (void *cls, uint32_t rd_count, | |||
656 | "Building new lookup request from %s\n", | 683 | "Building new lookup request from %s\n", |
657 | ds_entry->unresolved_attribute_delegation); | 684 | ds_entry->unresolved_attribute_delegation); |
658 | // Continue with backward resolution | 685 | // Continue with backward resolution |
659 | char issuer_attribute_name | 686 | char |
660 | [strlen (ds_entry->unresolved_attribute_delegation) + 1]; | 687 | issuer_attribute_name[strlen (ds_entry->unresolved_attribute_delegation) |
688 | + 1]; | ||
661 | strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation); | 689 | strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation); |
662 | char *next_attr = strtok (issuer_attribute_name, "."); | 690 | char *next_attr = strtok (issuer_attribute_name, "."); |
663 | if (NULL == next_attr) { | 691 | if (NULL == next_attr) { |
@@ -667,27 +695,32 @@ backward_resolution (void *cls, uint32_t rd_count, | |||
667 | } | 695 | } |
668 | GNUNET_asprintf (&lookup_attribute, "%s", next_attr); | 696 | GNUNET_asprintf (&lookup_attribute, "%s", next_attr); |
669 | GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr); | 697 | GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr); |
670 | if (strlen (next_attr) == | 698 | if (strlen (next_attr) |
671 | strlen (ds_entry->unresolved_attribute_delegation)) { | 699 | == strlen (ds_entry->unresolved_attribute_delegation)) { |
672 | ds_entry->attr_trailer = NULL; | 700 | ds_entry->attr_trailer = NULL; |
673 | } else { | 701 | } else { |
674 | next_attr += strlen (next_attr) + 1; | 702 | next_attr += strlen (next_attr) + 1; |
675 | ds_entry->attr_trailer = GNUNET_strdup (next_attr); | 703 | ds_entry->attr_trailer = GNUNET_strdup (next_attr); |
676 | } | 704 | } |
677 | 705 | ||
678 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Looking up %s\n", | 706 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
707 | "Looking up %s\n", | ||
679 | ds_entry->lookup_attribute); | 708 | ds_entry->lookup_attribute); |
680 | if (NULL != ds_entry->attr_trailer) | 709 | if (NULL != ds_entry->attr_trailer) |
681 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s still to go...\n", | 710 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
711 | "%s still to go...\n", | ||
682 | ds_entry->attr_trailer); | 712 | ds_entry->attr_trailer); |
683 | 713 | ||
684 | vrh->pending_lookups++; | 714 | vrh->pending_lookups++; |
685 | ds_entry->handle = vrh; | 715 | ds_entry->handle = vrh; |
686 | ds_entry->lookup_request = GNUNET_GNS_lookup ( | 716 | ds_entry->lookup_request |
687 | gns, lookup_attribute, | 717 | = GNUNET_GNS_lookup (gns, |
688 | ds_entry->issuer_key, // issuer_key, | 718 | lookup_attribute, |
689 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_GNS_LO_DEFAULT, | 719 | ds_entry->issuer_key, // issuer_key, |
690 | &backward_resolution, ds_entry); | 720 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, |
721 | GNUNET_GNS_LO_DEFAULT, | ||
722 | &backward_resolution, | ||
723 | ds_entry); | ||
691 | GNUNET_free (lookup_attribute); | 724 | GNUNET_free (lookup_attribute); |
692 | } | 725 | } |
693 | } | 726 | } |
@@ -721,11 +754,14 @@ delegation_chain_resolution_start (void *cls) | |||
721 | 754 | ||
722 | for (cr_entry = vrh->cred_chain_head; cr_entry != NULL; | 755 | for (cr_entry = vrh->cred_chain_head; cr_entry != NULL; |
723 | cr_entry = cr_entry->next) { | 756 | cr_entry = cr_entry->next) { |
724 | if (0 != memcmp (&cr_entry->credential->issuer_key, &vrh->issuer_key, | 757 | if (0 |
725 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 758 | != memcmp (&cr_entry->credential->issuer_key, |
759 | &vrh->issuer_key, | ||
760 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
726 | continue; | 761 | continue; |
727 | if (0 != | 762 | if (0 |
728 | strcmp (cr_entry->credential->issuer_attribute, vrh->issuer_attribute)) | 763 | != strcmp (cr_entry->credential->issuer_attribute, |
764 | vrh->issuer_attribute)) | ||
729 | continue; | 765 | continue; |
730 | cr_entry->refcount++; | 766 | cr_entry->refcount++; |
731 | // Found match prematurely | 767 | // Found match prematurely |
@@ -739,11 +775,13 @@ delegation_chain_resolution_start (void *cls) | |||
739 | */ | 775 | */ |
740 | char issuer_attribute_name[strlen (vrh->issuer_attribute) + 1]; | 776 | char issuer_attribute_name[strlen (vrh->issuer_attribute) + 1]; |
741 | strcpy (issuer_attribute_name, vrh->issuer_attribute); | 777 | strcpy (issuer_attribute_name, vrh->issuer_attribute); |
742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up %s\n", | 778 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
779 | "Looking up %s\n", | ||
743 | issuer_attribute_name); | 780 | issuer_attribute_name); |
744 | ds_entry = GNUNET_new (struct DelegationSetQueueEntry); | 781 | ds_entry = GNUNET_new (struct DelegationSetQueueEntry); |
745 | ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); | 782 | ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); |
746 | GNUNET_memcpy (ds_entry->issuer_key, &vrh->issuer_key, | 783 | GNUNET_memcpy (ds_entry->issuer_key, |
784 | &vrh->issuer_key, | ||
747 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 785 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); |
748 | ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute); | 786 | ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute); |
749 | ds_entry->handle = vrh; | 787 | ds_entry->handle = vrh; |
@@ -751,11 +789,13 @@ delegation_chain_resolution_start (void *cls) | |||
751 | vrh->root_set = ds_entry; | 789 | vrh->root_set = ds_entry; |
752 | vrh->pending_lookups = 1; | 790 | vrh->pending_lookups = 1; |
753 | // Start with backward resolution | 791 | // Start with backward resolution |
754 | ds_entry->lookup_request = | 792 | ds_entry->lookup_request = GNUNET_GNS_lookup (gns, |
755 | GNUNET_GNS_lookup (gns, issuer_attribute_name, | 793 | issuer_attribute_name, |
756 | &vrh->issuer_key, // issuer_key, | 794 | &vrh->issuer_key, // issuer_key, |
757 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_GNS_LO_DEFAULT, | 795 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, |
758 | &backward_resolution, ds_entry); | 796 | GNUNET_GNS_LO_DEFAULT, |
797 | &backward_resolution, | ||
798 | ds_entry); | ||
759 | } | 799 | } |
760 | 800 | ||
761 | static int | 801 | static int |
@@ -819,14 +859,19 @@ handle_verify (void *cls, const struct VerifyMessage *v_msg) | |||
819 | * TODO: cleanup! | 859 | * TODO: cleanup! |
820 | */ | 860 | */ |
821 | credentials_count = ntohl (v_msg->c_count); | 861 | credentials_count = ntohl (v_msg->c_count); |
822 | credential_data_size = ntohs (v_msg->header.size) - | 862 | credential_data_size = ntohs (v_msg->header.size) |
823 | sizeof (struct VerifyMessage) - | 863 | - sizeof (struct VerifyMessage) |
824 | ntohs (v_msg->issuer_attribute_len) - 1; | 864 | - ntohs (v_msg->issuer_attribute_len) - 1; |
825 | struct GNUNET_CREDENTIAL_Credential credentials[credentials_count]; | 865 | struct GNUNET_CREDENTIAL_Credential credentials[credentials_count]; |
866 | memset (credentials, | ||
867 | 0, | ||
868 | sizeof (struct GNUNET_CREDENTIAL_Credential) * credentials_count); | ||
826 | credential_data = (char *)&v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1; | 869 | credential_data = (char *)&v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1; |
827 | if (GNUNET_OK != GNUNET_CREDENTIAL_credentials_deserialize ( | 870 | if (GNUNET_OK |
828 | credential_data_size, credential_data, credentials_count, | 871 | != GNUNET_CREDENTIAL_credentials_deserialize (credential_data_size, |
829 | credentials)) { | 872 | credential_data, |
873 | credentials_count, | ||
874 | credentials)) { | ||
830 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize credentials!\n"); | 875 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize credentials!\n"); |
831 | send_lookup_response (vrh); | 876 | send_lookup_response (vrh); |
832 | return; | 877 | return; |
@@ -834,16 +879,21 @@ handle_verify (void *cls, const struct VerifyMessage *v_msg) | |||
834 | 879 | ||
835 | for (uint32_t i = 0; i < credentials_count; i++) { | 880 | for (uint32_t i = 0; i < credentials_count; i++) { |
836 | cr_entry = GNUNET_new (struct CredentialRecordEntry); | 881 | cr_entry = GNUNET_new (struct CredentialRecordEntry); |
837 | cr_entry->credential = | 882 | cr_entry->credential |
838 | GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + | 883 | = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) |
839 | credentials[i].issuer_attribute_len); | 884 | + credentials[i].issuer_attribute_len + 1); |
840 | GNUNET_memcpy (cr_entry->credential, &credentials[i], | 885 | GNUNET_memcpy (cr_entry->credential, |
886 | &credentials[i], | ||
841 | sizeof (struct GNUNET_CREDENTIAL_Credential)); | 887 | sizeof (struct GNUNET_CREDENTIAL_Credential)); |
842 | GNUNET_memcpy (&cr_entry->credential[1], credentials[i].issuer_attribute, | 888 | GNUNET_memcpy (&cr_entry->credential[1], |
889 | credentials[i].issuer_attribute, | ||
843 | credentials[i].issuer_attribute_len); | 890 | credentials[i].issuer_attribute_len); |
891 | cr_entry->credential->issuer_attribute_len | ||
892 | = credentials[i].issuer_attribute_len; | ||
844 | cr_entry->credential->issuer_attribute = (char *)&cr_entry->credential[1]; | 893 | cr_entry->credential->issuer_attribute = (char *)&cr_entry->credential[1]; |
845 | GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head, | 894 | GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head, |
846 | vrh->cred_chain_tail, cr_entry); | 895 | vrh->cred_chain_tail, |
896 | cr_entry); | ||
847 | vrh->cred_chain_size++; | 897 | vrh->cred_chain_size++; |
848 | } | 898 | } |
849 | 899 | ||
@@ -873,7 +923,8 @@ collect_next (void *cls) | |||
873 | static void | 923 | static void |
874 | handle_cred_collection_cb (void *cls, | 924 | handle_cred_collection_cb (void *cls, |
875 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 925 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, |
876 | const char *label, unsigned int rd_count, | 926 | const char *label, |
927 | unsigned int rd_count, | ||
877 | const struct GNUNET_GNSRECORD_Data *rd) | 928 | const struct GNUNET_GNSRECORD_Data *rd) |
878 | { | 929 | { |
879 | struct VerifyRequestHandle *vrh = cls; | 930 | struct VerifyRequestHandle *vrh = cls; |
@@ -886,8 +937,8 @@ handle_cred_collection_cb (void *cls, | |||
886 | if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type) | 937 | if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type) |
887 | continue; | 938 | continue; |
888 | cred_record_count++; | 939 | cred_record_count++; |
889 | crd = | 940 | crd |
890 | GNUNET_CREDENTIAL_credential_deserialize (rd[i].data, rd[i].data_size); | 941 | = GNUNET_CREDENTIAL_credential_deserialize (rd[i].data, rd[i].data_size); |
891 | if (NULL == crd) { | 942 | if (NULL == crd) { |
892 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n"); | 943 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n"); |
893 | continue; | 944 | continue; |
@@ -895,7 +946,8 @@ handle_cred_collection_cb (void *cls, | |||
895 | cr_entry = GNUNET_new (struct CredentialRecordEntry); | 946 | cr_entry = GNUNET_new (struct CredentialRecordEntry); |
896 | cr_entry->credential = crd; | 947 | cr_entry->credential = crd; |
897 | GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head, | 948 | GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head, |
898 | vrh->cred_chain_tail, cr_entry); | 949 | vrh->cred_chain_tail, |
950 | cr_entry); | ||
899 | vrh->cred_chain_size++; | 951 | vrh->cred_chain_size++; |
900 | } | 952 | } |
901 | vrh->collect_next_task = GNUNET_SCHEDULER_add_now (&collect_next, vrh); | 953 | vrh->collect_next_task = GNUNET_SCHEDULER_add_now (&collect_next, vrh); |
@@ -945,9 +997,14 @@ handle_collect (void *cls, const struct CollectMessage *c_msg) | |||
945 | * First, get attribute from subject | 997 | * First, get attribute from subject |
946 | */ | 998 | */ |
947 | vrh->cred_collection_iter = GNUNET_NAMESTORE_zone_iteration_start ( | 999 | vrh->cred_collection_iter = GNUNET_NAMESTORE_zone_iteration_start ( |
948 | namestore, &c_msg->subject_key, &handle_cred_collection_error_cb, vrh, | 1000 | namestore, |
949 | &handle_cred_collection_cb, vrh, &handle_cred_collection_finished_cb, | 1001 | &c_msg->subject_key, |
950 | vrh); | 1002 | &handle_cred_collection_error_cb, |
1003 | vrh, | ||
1004 | &handle_cred_collection_cb, | ||
1005 | vrh, | ||
1006 | &handle_cred_collection_finished_cb, | ||
1007 | vrh); | ||
951 | GNUNET_SERVICE_client_continue (vrh->client); | 1008 | GNUNET_SERVICE_client_continue (vrh->client); |
952 | } | 1009 | } |
953 | 1010 | ||
@@ -969,8 +1026,8 @@ check_collect (void *cls, const struct CollectMessage *c_msg) | |||
969 | } | 1026 | } |
970 | attr = (const char *)&c_msg[1]; | 1027 | attr = (const char *)&c_msg[1]; |
971 | 1028 | ||
972 | if (('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) || | 1029 | if (('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) |
973 | (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)) { | 1030 | || (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)) { |
974 | GNUNET_break (0); | 1031 | GNUNET_break (0); |
975 | return GNUNET_SYSERR; | 1032 | return GNUNET_SYSERR; |
976 | } | 1033 | } |
@@ -978,14 +1035,16 @@ check_collect (void *cls, const struct CollectMessage *c_msg) | |||
978 | } | 1035 | } |
979 | 1036 | ||
980 | static void | 1037 | static void |
981 | client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, | 1038 | client_disconnect_cb (void *cls, |
1039 | struct GNUNET_SERVICE_Client *client, | ||
982 | void *app_ctx) | 1040 | void *app_ctx) |
983 | { | 1041 | { |
984 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); | 1042 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); |
985 | } | 1043 | } |
986 | 1044 | ||
987 | static void * | 1045 | static void * |
988 | client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, | 1046 | client_connect_cb (void *cls, |
1047 | struct GNUNET_SERVICE_Client *client, | ||
989 | struct GNUNET_MQ_Handle *mq) | 1048 | struct GNUNET_MQ_Handle *mq) |
990 | { | 1049 | { |
991 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); | 1050 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); |
@@ -1000,7 +1059,8 @@ client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, | |||
1000 | * @param handle service handle | 1059 | * @param handle service handle |
1001 | */ | 1060 | */ |
1002 | static void | 1061 | static void |
1003 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, | 1062 | run (void *cls, |
1063 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
1004 | struct GNUNET_SERVICE_Handle *handle) | 1064 | struct GNUNET_SERVICE_Handle *handle) |
1005 | { | 1065 | { |
1006 | 1066 | ||
@@ -1022,12 +1082,20 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, | |||
1022 | * Define "main" method using service macro | 1082 | * Define "main" method using service macro |
1023 | */ | 1083 | */ |
1024 | GNUNET_SERVICE_MAIN ( | 1084 | GNUNET_SERVICE_MAIN ( |
1025 | "credential", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, | 1085 | "credential", |
1026 | &client_disconnect_cb, NULL, | 1086 | GNUNET_SERVICE_OPTION_NONE, |
1027 | GNUNET_MQ_hd_var_size (verify, GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY, | 1087 | &run, |
1028 | struct VerifyMessage, NULL), | 1088 | &client_connect_cb, |
1029 | GNUNET_MQ_hd_var_size (collect, GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT, | 1089 | &client_disconnect_cb, |
1030 | struct CollectMessage, NULL), | 1090 | NULL, |
1031 | GNUNET_MQ_handler_end ()); | 1091 | GNUNET_MQ_hd_var_size (verify, |
1092 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY, | ||
1093 | struct VerifyMessage, | ||
1094 | NULL), | ||
1095 | GNUNET_MQ_hd_var_size (collect, | ||
1096 | GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT, | ||
1097 | struct CollectMessage, | ||
1098 | NULL), | ||
1099 | GNUNET_MQ_handler_end ()); | ||
1032 | 1100 | ||
1033 | /* end of gnunet-service-credential.c */ | 1101 | /* end of gnunet-service-credential.c */ |
diff --git a/src/credential/test_credential_lookup.conf b/src/credential/test_credential_lookup.conf index cebe71b04..9cd16605d 100644 --- a/src/credential/test_credential_lookup.conf +++ b/src/credential/test_credential_lookup.conf | |||
@@ -11,7 +11,7 @@ PLUGINS = | |||
11 | 11 | ||
12 | [credential] | 12 | [credential] |
13 | START_ON_DEMAND = YES | 13 | START_ON_DEMAND = YES |
14 | #PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=$GNUNET_TMP/credlog | 14 | #PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=/tmp/credlog |
15 | 15 | ||
16 | [rest] | 16 | [rest] |
17 | PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=$GNUNET_TMP/restlog | 17 | PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=$GNUNET_TMP/restlog |