aboutsummaryrefslogtreecommitdiff
path: root/src/credential/gnunet-service-credential.c
diff options
context:
space:
mode:
authorAndreas Ebner <pansy007@googlemail.com>2019-06-25 15:21:12 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-10-07 12:15:06 +0200
commitd2634b1f96dfd55ae4daef294bb6c05d687354c8 (patch)
tree85250438ba58e5c33c30003bde8e4a6bccf13ca8 /src/credential/gnunet-service-credential.c
parent921b03e4cee5653083e61de42ced85a7278647b2 (diff)
downloadgnunet-d2634b1f96dfd55ae4daef294bb6c05d687354c8.tar.gz
gnunet-d2634b1f96dfd55ae4daef294bb6c05d687354c8.zip
Handle all credential storage via credential service, prepared for subject side storage
- new commandline parameters - new gns record type: DELEGATE for subject side storage - credential connection to namestore - store all credentials via credential service (replacing namestore) - stable, but experimental implementation, atm just using existing methods, next step: introduce own methods and replace/rename existing variables
Diffstat (limited to 'src/credential/gnunet-service-credential.c')
-rw-r--r--src/credential/gnunet-service-credential.c231
1 files changed, 105 insertions, 126 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index f4a96014f..a3c066444 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19*/
20/** 20/**
21 * @file credential/gnunet-service-credential.c 21 * @file credential/gnunet-service-credential.c
22 * @brief GNUnet Credential Service (main service) 22 * @brief GNUnet Credential Service (main service)
@@ -225,6 +225,7 @@ struct DelegationSetQueueEntry
225 */ 225 */
226struct VerifyRequestHandle 226struct VerifyRequestHandle
227{ 227{
228
228 /** 229 /**
229 * We keep these in a DLL. 230 * We keep these in a DLL.
230 */ 231 */
@@ -358,14 +359,12 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
358 return; 359 return;
359 360
360 for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry; 361 for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry;
361 dq_entry = ds_entry->queue_entries_head) 362 dq_entry = ds_entry->queue_entries_head) {
362 {
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, 364 ds_entry->queue_entries_tail,
365 dq_entry); 365 dq_entry);
366 for (child = dq_entry->set_entries_head; NULL != child; 366 for (child = dq_entry->set_entries_head; NULL != child;
367 child = dq_entry->set_entries_head) 367 child = dq_entry->set_entries_head) {
368 {
369 GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head, 368 GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head,
370 dq_entry->set_entries_tail, 369 dq_entry->set_entries_tail,
371 child); 370 child);
@@ -378,13 +377,11 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
378 GNUNET_free_non_null (ds_entry->issuer_attribute); 377 GNUNET_free_non_null (ds_entry->issuer_attribute);
379 GNUNET_free_non_null (ds_entry->unresolved_attribute_delegation); 378 GNUNET_free_non_null (ds_entry->unresolved_attribute_delegation);
380 GNUNET_free_non_null (ds_entry->attr_trailer); 379 GNUNET_free_non_null (ds_entry->attr_trailer);
381 if (NULL != ds_entry->lookup_request) 380 if (NULL != ds_entry->lookup_request) {
382 {
383 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request); 381 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request);
384 ds_entry->lookup_request = NULL; 382 ds_entry->lookup_request = NULL;
385 } 383 }
386 if (NULL != ds_entry->delegation_chain_entry) 384 if (NULL != ds_entry->delegation_chain_entry) {
387 {
388 GNUNET_free_non_null (ds_entry->delegation_chain_entry->subject_attribute); 385 GNUNET_free_non_null (ds_entry->delegation_chain_entry->subject_attribute);
389 GNUNET_free_non_null (ds_entry->delegation_chain_entry->issuer_attribute); 386 GNUNET_free_non_null (ds_entry->delegation_chain_entry->issuer_attribute);
390 GNUNET_free (ds_entry->delegation_chain_entry); 387 GNUNET_free (ds_entry->delegation_chain_entry);
@@ -396,18 +393,15 @@ static void
396cleanup_handle (struct VerifyRequestHandle *vrh) 393cleanup_handle (struct VerifyRequestHandle *vrh)
397{ 394{
398 struct CredentialRecordEntry *cr_entry; 395 struct CredentialRecordEntry *cr_entry;
399
400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n"); 396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n");
401 if (NULL != vrh->lookup_request) 397 if (NULL != vrh->lookup_request) {
402 {
403 GNUNET_GNS_lookup_cancel (vrh->lookup_request); 398 GNUNET_GNS_lookup_cancel (vrh->lookup_request);
404 vrh->lookup_request = NULL; 399 vrh->lookup_request = NULL;
405 } 400 }
406 cleanup_delegation_set (vrh->root_set); 401 cleanup_delegation_set (vrh->root_set);
407 GNUNET_free_non_null (vrh->issuer_attribute); 402 GNUNET_free_non_null (vrh->issuer_attribute);
408 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;
409 cr_entry = vrh->cred_chain_head) 404 cr_entry = vrh->cred_chain_head) {
410 {
411 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, 405 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head,
412 vrh->cred_chain_tail, 406 vrh->cred_chain_tail,
413 cr_entry); 407 cr_entry);
@@ -424,25 +418,21 @@ shutdown_task (void *cls)
424 418
425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n"); 419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n");
426 420
427 while (NULL != (vrh = vrh_head)) 421 while (NULL != (vrh = vrh_head)) {
428 {
429 // CREDENTIAL_resolver_lookup_cancel (clh->lookup); 422 // CREDENTIAL_resolver_lookup_cancel (clh->lookup);
430 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); 423 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
431 cleanup_handle (vrh); 424 cleanup_handle (vrh);
432 } 425 }
433 426
434 if (NULL != gns) 427 if (NULL != gns) {
435 {
436 GNUNET_GNS_disconnect (gns); 428 GNUNET_GNS_disconnect (gns);
437 gns = NULL; 429 gns = NULL;
438 } 430 }
439 if (NULL != namestore) 431 if (NULL != namestore) {
440 {
441 GNUNET_NAMESTORE_disconnect (namestore); 432 GNUNET_NAMESTORE_disconnect (namestore);
442 namestore = NULL; 433 namestore = NULL;
443 } 434 }
444 if (NULL != statistics) 435 if (NULL != statistics) {
445 {
446 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); 436 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
447 statistics = NULL; 437 statistics = NULL;
448 } 438 }
@@ -463,16 +453,14 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
463 453
464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response\n"); 454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response\n");
465 dce = vrh->delegation_chain_head; 455 dce = vrh->delegation_chain_head;
466 for (uint32_t i = 0; i < vrh->delegation_chain_size; i++) 456 for (uint32_t i = 0; i < vrh->delegation_chain_size; i++) {
467 {
468 dd[i].issuer_key = dce->issuer_key; 457 dd[i].issuer_key = dce->issuer_key;
469 dd[i].subject_key = dce->subject_key; 458 dd[i].subject_key = dce->subject_key;
470 dd[i].issuer_attribute = dce->issuer_attribute; 459 dd[i].issuer_attribute = dce->issuer_attribute;
471 dd[i].issuer_attribute_len = strlen (dce->issuer_attribute) + 1; 460 dd[i].issuer_attribute_len = strlen (dce->issuer_attribute) + 1;
472 dd[i].subject_attribute_len = 0; 461 dd[i].subject_attribute_len = 0;
473 dd[i].subject_attribute = NULL; 462 dd[i].subject_attribute = NULL;
474 if (NULL != dce->subject_attribute) 463 if (NULL != dce->subject_attribute) {
475 {
476 dd[i].subject_attribute = dce->subject_attribute; 464 dd[i].subject_attribute = dce->subject_attribute;
477 dd[i].subject_attribute_len = strlen (dce->subject_attribute) + 1; 465 dd[i].subject_attribute_len = strlen (dce->subject_attribute) + 1;
478 } 466 }
@@ -482,10 +470,8 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
482 /** 470 /**
483 * Remove all credentials not needed 471 * Remove all credentials not needed
484 */ 472 */
485 for (cd = vrh->cred_chain_head; NULL != cd;) 473 for (cd = vrh->cred_chain_head; NULL != cd;) {
486 { 474 if (cd->refcount > 0) {
487 if (cd->refcount > 0)
488 {
489 cd = cd->next; 475 cd = cd->next;
490 continue; 476 continue;
491 } 477 }
@@ -504,8 +490,7 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
504 * Append at the end of rmsg 490 * Append at the end of rmsg
505 */ 491 */
506 cd = vrh->cred_chain_head; 492 cd = vrh->cred_chain_head;
507 for (uint32_t i = 0; i < vrh->cred_chain_size; i++) 493 for (uint32_t i = 0; i < vrh->cred_chain_size; i++) {
508 {
509 cred[i].issuer_key = cd->credential->issuer_key; 494 cred[i].issuer_key = cd->credential->issuer_key;
510 cred[i].subject_key = cd->credential->subject_key; 495 cred[i].subject_key = cd->credential->subject_key;
511 cred[i].issuer_attribute_len 496 cred[i].issuer_attribute_len
@@ -540,7 +525,7 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
540 vrh->cred_chain_size, 525 vrh->cred_chain_size,
541 cred, 526 cred,
542 size, 527 size,
543 (char *) &rmsg[1])); 528 (char *)&rmsg[1]));
544 529
545 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env); 530 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env);
546 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); 531 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
@@ -552,6 +537,13 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
552 GNUNET_NO); 537 GNUNET_NO);
553} 538}
554 539
540static void
541test_resolution (void *cls,
542 uint32_t rd_count,
543 const struct GNUNET_GNSRECORD_Data *rd)
544{
545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Yo, im Test und so\n");
546}
555 547
556static void 548static void
557backward_resolution (void *cls, 549backward_resolution (void *cls,
@@ -568,16 +560,17 @@ backward_resolution (void *cls,
568 char *expanded_attr; 560 char *expanded_attr;
569 char *lookup_attribute; 561 char *lookup_attribute;
570 562
571
572 current_set = cls; 563 current_set = cls;
573 current_set->lookup_request = NULL; 564 current_set->lookup_request = NULL;
574 vrh = current_set->handle; 565 vrh = current_set->handle;
575 vrh->pending_lookups--; 566 vrh->pending_lookups--;
576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %d attrs\n", rd_count); 567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %d attrs\n", rd_count);
577 568
569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "# Issuer Att %s\n", current_set->issuer_attribute);
570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "# Lookup Att %s\n", current_set->lookup_attribute);
571
578 // Each OR 572 // Each OR
579 for (uint32_t i = 0; i < rd_count; i++) 573 for (uint32_t i = 0; i < rd_count; i++) {
580 {
581 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) 574 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
582 continue; 575 continue;
583 576
@@ -591,31 +584,29 @@ backward_resolution (void *cls,
591 if (GNUNET_OK 584 if (GNUNET_OK
592 != GNUNET_CREDENTIAL_delegation_set_deserialize ( 585 != GNUNET_CREDENTIAL_delegation_set_deserialize (
593 GNUNET_ntohll (sets->data_size), 586 GNUNET_ntohll (sets->data_size),
594 (const char *) &sets[1], 587 (const char *)&sets[1],
595 ntohl (sets->set_count), 588 ntohl (sets->set_count),
596 set)) 589 set)) {
597 {
598 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n"); 590 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n");
599 continue; 591 continue;
600 } 592 }
601 dq_entry = GNUNET_new (struct DelegationQueueEntry); 593 dq_entry = GNUNET_new (struct DelegationQueueEntry);
602 dq_entry->required_solutions = ntohl (sets->set_count); 594 dq_entry->required_solutions = ntohl (sets->set_count);
603 dq_entry->parent_set = current_set; 595 dq_entry->parent_set = current_set;
596
597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "# New OR entry into queue\n");
598
604 GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head, 599 GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head,
605 current_set->queue_entries_tail, 600 current_set->queue_entries_tail,
606 dq_entry); 601 dq_entry);
607 // Each AND 602 // Each AND
608 for (uint32_t j = 0; j < ntohl (sets->set_count); j++) 603 for (uint32_t j = 0; j < ntohl (sets->set_count); j++) {
609 {
610 ds_entry = GNUNET_new (struct DelegationSetQueueEntry); 604 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
611 if (NULL != current_set->attr_trailer) 605 if (NULL != current_set->attr_trailer) {
612 { 606 if (0 == set[j].subject_attribute_len) {
613 if (0 == set[j].subject_attribute_len)
614 {
615 GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer); 607 GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer);
616 } 608
617 else 609 } else {
618 {
619 GNUNET_asprintf (&expanded_attr, 610 GNUNET_asprintf (&expanded_attr,
620 "%s.%s", 611 "%s.%s",
621 set[j].subject_attribute, 612 set[j].subject_attribute,
@@ -623,11 +614,8 @@ backward_resolution (void *cls,
623 } 614 }
624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr); 615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr);
625 ds_entry->unresolved_attribute_delegation = expanded_attr; 616 ds_entry->unresolved_attribute_delegation = expanded_attr;
626 } 617 } else {
627 else 618 if (0 != set[j].subject_attribute_len) {
628 {
629 if (0 != set[j].subject_attribute_len)
630 {
631 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
632 "Not Expanding %s\n", 620 "Not Expanding %s\n",
633 set[j].subject_attribute); 621 set[j].subject_attribute);
@@ -643,7 +631,7 @@ backward_resolution (void *cls,
643 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 631 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
644 GNUNET_memcpy (ds_entry->issuer_key, 632 GNUNET_memcpy (ds_entry->issuer_key,
645 &set[j].subject_key, 633 &set[j].subject_key,
646 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); 634 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
647 if (0 < set[j].subject_attribute_len) 635 if (0 < set[j].subject_attribute_len)
648 ds_entry->delegation_chain_entry->subject_attribute 636 ds_entry->delegation_chain_entry->subject_attribute
649 = GNUNET_strdup (set[j].subject_attribute); 637 = GNUNET_strdup (set[j].subject_attribute);
@@ -651,7 +639,12 @@ backward_resolution (void *cls,
651 ds_entry->delegation_chain_entry->issuer_attribute 639 ds_entry->delegation_chain_entry->issuer_attribute
652 = GNUNET_strdup (current_set->lookup_attribute); 640 = GNUNET_strdup (current_set->lookup_attribute);
653 641
654 ds_entry->parent_queue_entry = dq_entry; // current_delegation; 642 ds_entry->parent_queue_entry = dq_entry; // current_delegation;
643
644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "# New AND DS entry into DQ queue\n");
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "# DS entry Issuer ATT %s\n", ds_entry->delegation_chain_entry->issuer_attribute);
646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "# DS entry Subject ATT %s\n", ds_entry->delegation_chain_entry->subject_attribute);
647
655 GNUNET_CONTAINER_DLL_insert (dq_entry->set_entries_head, 648 GNUNET_CONTAINER_DLL_insert (dq_entry->set_entries_head,
656 dq_entry->set_entries_tail, 649 dq_entry->set_entries_tail,
657 ds_entry); 650 ds_entry);
@@ -661,11 +654,12 @@ backward_resolution (void *cls,
661 * Check if this delegation already matches one of our credentials 654 * Check if this delegation already matches one of our credentials
662 */ 655 */
663 for (cred_pointer = vrh->cred_chain_head; cred_pointer != NULL; 656 for (cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
664 cred_pointer = cred_pointer->next) 657 cred_pointer = cred_pointer->next) {
665 { 658 // If key and attribute match credential continue and backtrack
666 if (0 659 if (0
667 != GNUNET_memcmp (&set->subject_key, 660 != memcmp (&set->subject_key,
668 &cred_pointer->credential->issuer_key)) 661 &cred_pointer->credential->issuer_key,
662 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
669 continue; 663 continue;
670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
671 "Checking if %s matches %s\n", 665 "Checking if %s matches %s\n",
@@ -681,11 +675,10 @@ backward_resolution (void *cls,
681 cred_pointer->refcount++; 675 cred_pointer->refcount++;
682 // Backtrack 676 // Backtrack
683 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry; 677 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
684 tmp_set = tmp_set->parent_queue_entry->parent_set) 678 tmp_set = tmp_set->parent_queue_entry->parent_set) {
685 { 679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "# %s\n", tmp_set->unresolved_attribute_delegation);
686 tmp_set->parent_queue_entry->required_solutions--; 680 tmp_set->parent_queue_entry->required_solutions--;
687 if (NULL != tmp_set->delegation_chain_entry) 681 if (NULL != tmp_set->delegation_chain_entry) {
688 {
689 vrh->delegation_chain_size++; 682 vrh->delegation_chain_size++;
690 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head, 683 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head,
691 vrh->delegation_chain_tail, 684 vrh->delegation_chain_tail,
@@ -695,8 +688,7 @@ backward_resolution (void *cls,
695 break; 688 break;
696 } 689 }
697 690
698 if (NULL == tmp_set->parent_queue_entry) 691 if (NULL == tmp_set->parent_queue_entry) {
699 {
700 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "All solutions found\n"); 692 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "All solutions found\n");
701 // Found match 693 // Found match
702 send_lookup_response (vrh); 694 send_lookup_response (vrh);
@@ -713,9 +705,9 @@ backward_resolution (void *cls,
713 issuer_attribute_name[strlen (ds_entry->unresolved_attribute_delegation) 705 issuer_attribute_name[strlen (ds_entry->unresolved_attribute_delegation)
714 + 1]; 706 + 1];
715 strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation); 707 strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation);
708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "# Issuer Att Name: %s\n", issuer_attribute_name);
716 char *next_attr = strtok (issuer_attribute_name, "."); 709 char *next_attr = strtok (issuer_attribute_name, ".");
717 if (NULL == next_attr) 710 if (NULL == next_attr) {
718 {
719 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 711 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
720 "Failed to parse next attribute\n"); 712 "Failed to parse next attribute\n");
721 continue; 713 continue;
@@ -723,12 +715,9 @@ backward_resolution (void *cls,
723 GNUNET_asprintf (&lookup_attribute, "%s", next_attr); 715 GNUNET_asprintf (&lookup_attribute, "%s", next_attr);
724 GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr); 716 GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr);
725 if (strlen (next_attr) 717 if (strlen (next_attr)
726 == strlen (ds_entry->unresolved_attribute_delegation)) 718 == strlen (ds_entry->unresolved_attribute_delegation)) {
727 {
728 ds_entry->attr_trailer = NULL; 719 ds_entry->attr_trailer = NULL;
729 } 720 } else {
730 else
731 {
732 next_attr += strlen (next_attr) + 1; 721 next_attr += strlen (next_attr) + 1;
733 ds_entry->attr_trailer = GNUNET_strdup (next_attr); 722 ds_entry->attr_trailer = GNUNET_strdup (next_attr);
734 } 723 }
@@ -746,17 +735,24 @@ backward_resolution (void *cls,
746 ds_entry->lookup_request 735 ds_entry->lookup_request
747 = GNUNET_GNS_lookup (gns, 736 = GNUNET_GNS_lookup (gns,
748 lookup_attribute, 737 lookup_attribute,
749 ds_entry->issuer_key, // issuer_key, 738 ds_entry->issuer_key, // issuer_key,
750 GNUNET_GNSRECORD_TYPE_ATTRIBUTE, 739 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
751 GNUNET_GNS_LO_DEFAULT, 740 GNUNET_GNS_LO_DEFAULT,
752 &backward_resolution, 741 &backward_resolution,
753 ds_entry); 742 ds_entry);
743 /*GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting\n");
744 GNUNET_GNS_lookup (gns,
745 GNUNET_GNS_EMPTY_LABEL_AT,
746 ds_entry->issuer_key, // subject_key,
747 GNUNET_GNSRECORD_TYPE_DELEGATE,
748 GNUNET_GNS_LO_DEFAULT,
749 &test_resolution,
750 ds_entry);*/
754 GNUNET_free (lookup_attribute); 751 GNUNET_free (lookup_attribute);
755 } 752 }
756 } 753 }
757 754
758 if (0 == vrh->pending_lookups) 755 if (0 == vrh->pending_lookups) {
759 {
760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n"); 756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
761 send_lookup_response (vrh); 757 send_lookup_response (vrh);
762 return; 758 return;
@@ -775,22 +771,20 @@ delegation_chain_resolution_start (void *cls)
775 struct VerifyRequestHandle *vrh = cls; 771 struct VerifyRequestHandle *vrh = cls;
776 struct DelegationSetQueueEntry *ds_entry; 772 struct DelegationSetQueueEntry *ds_entry;
777 struct CredentialRecordEntry *cr_entry; 773 struct CredentialRecordEntry *cr_entry;
778
779 vrh->lookup_request = NULL; 774 vrh->lookup_request = NULL;
780 775
781 if (0 == vrh->cred_chain_size) 776 if (0 == vrh->cred_chain_size) {
782 {
783 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No credentials found\n"); 777 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No credentials found\n");
784 send_lookup_response (vrh); 778 send_lookup_response (vrh);
785 return; 779 return;
786 } 780 }
787 781
788 for (cr_entry = vrh->cred_chain_head; cr_entry != NULL; 782 for (cr_entry = vrh->cred_chain_head; cr_entry != NULL;
789 cr_entry = cr_entry->next) 783 cr_entry = cr_entry->next) {
790 {
791 if (0 784 if (0
792 != GNUNET_memcmp (&cr_entry->credential->issuer_key, 785 != memcmp (&cr_entry->credential->issuer_key,
793 &vrh->issuer_key)) 786 &vrh->issuer_key,
787 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
794 continue; 788 continue;
795 if (0 789 if (0
796 != strcmp (cr_entry->credential->issuer_attribute, 790 != strcmp (cr_entry->credential->issuer_attribute,
@@ -815,13 +809,15 @@ delegation_chain_resolution_start (void *cls)
815 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 809 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
816 GNUNET_memcpy (ds_entry->issuer_key, 810 GNUNET_memcpy (ds_entry->issuer_key,
817 &vrh->issuer_key, 811 &vrh->issuer_key,
818 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); 812 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
819 ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute); 813 ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute);
820 ds_entry->handle = vrh; 814 ds_entry->handle = vrh;
821 ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute); 815 ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute);
822 vrh->root_set = ds_entry; 816 vrh->root_set = ds_entry;
823 vrh->pending_lookups = 1; 817 vrh->pending_lookups = 1;
824 // Start with backward resolution 818 // Start with backward resolution
819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "# Start Backward Resolution\n");
820
825 ds_entry->lookup_request = GNUNET_GNS_lookup (gns, 821 ds_entry->lookup_request = GNUNET_GNS_lookup (gns,
826 issuer_attribute_name, 822 issuer_attribute_name,
827 &vrh->issuer_key, // issuer_key, 823 &vrh->issuer_key, // issuer_key,
@@ -838,20 +834,17 @@ check_verify (void *cls, const struct VerifyMessage *v_msg)
838 const char *attr; 834 const char *attr;
839 835
840 msg_size = ntohs (v_msg->header.size); 836 msg_size = ntohs (v_msg->header.size);
841 if (msg_size < sizeof(struct VerifyMessage)) 837 if (msg_size < sizeof (struct VerifyMessage)) {
842 {
843 GNUNET_break (0); 838 GNUNET_break (0);
844 return GNUNET_SYSERR; 839 return GNUNET_SYSERR;
845 } 840 }
846 if (ntohs (v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) 841 if (ntohs (v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) {
847 {
848 GNUNET_break (0); 842 GNUNET_break (0);
849 return GNUNET_SYSERR; 843 return GNUNET_SYSERR;
850 } 844 }
851 attr = (const char *) &v_msg[1]; 845 attr = (const char *)&v_msg[1];
852 846
853 if (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH) 847 if (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH) {
854 {
855 GNUNET_break (0); 848 GNUNET_break (0);
856 return GNUNET_SYSERR; 849 return GNUNET_SYSERR;
857 } 850 }
@@ -873,7 +866,7 @@ handle_verify (void *cls, const struct VerifyMessage *v_msg)
873 const char *utf_in; 866 const char *utf_in;
874 867
875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n"); 868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n");
876 utf_in = (const char *) &v_msg[1]; 869 utf_in = (const char *)&v_msg[1];
877 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); 870 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
878 GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len)); 871 GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len));
879 issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0'; 872 issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0';
@@ -885,8 +878,7 @@ handle_verify (void *cls, const struct VerifyMessage *v_msg)
885 vrh->subject_key = v_msg->subject_key; 878 vrh->subject_key = v_msg->subject_key;
886 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); 879 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
887 GNUNET_SERVICE_client_continue (vrh->client); 880 GNUNET_SERVICE_client_continue (vrh->client);
888 if (0 == strlen (issuer_attribute)) 881 if (0 == strlen (issuer_attribute)) {
889 {
890 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n"); 882 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
891 send_lookup_response (vrh); 883 send_lookup_response (vrh);
892 return; 884 return;
@@ -897,40 +889,37 @@ handle_verify (void *cls, const struct VerifyMessage *v_msg)
897 */ 889 */
898 credentials_count = ntohl (v_msg->c_count); 890 credentials_count = ntohl (v_msg->c_count);
899 credential_data_size = ntohs (v_msg->header.size) 891 credential_data_size = ntohs (v_msg->header.size)
900 - sizeof(struct VerifyMessage) 892 - sizeof (struct VerifyMessage)
901 - ntohs (v_msg->issuer_attribute_len) - 1; 893 - ntohs (v_msg->issuer_attribute_len) - 1;
902 struct GNUNET_CREDENTIAL_Credential credentials[credentials_count]; 894 struct GNUNET_CREDENTIAL_Credential credentials[credentials_count];
903 memset (credentials, 895 memset (credentials,
904 0, 896 0,
905 sizeof(struct GNUNET_CREDENTIAL_Credential) * credentials_count); 897 sizeof (struct GNUNET_CREDENTIAL_Credential) * credentials_count);
906 credential_data = (char *) &v_msg[1] + ntohs (v_msg->issuer_attribute_len) 898 credential_data = (char *)&v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1;
907 + 1;
908 if (GNUNET_OK 899 if (GNUNET_OK
909 != GNUNET_CREDENTIAL_credentials_deserialize (credential_data_size, 900 != GNUNET_CREDENTIAL_credentials_deserialize (credential_data_size,
910 credential_data, 901 credential_data,
911 credentials_count, 902 credentials_count,
912 credentials)) 903 credentials)) {
913 {
914 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize credentials!\n"); 904 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize credentials!\n");
915 send_lookup_response (vrh); 905 send_lookup_response (vrh);
916 return; 906 return;
917 } 907 }
918 908
919 for (uint32_t i = 0; i < credentials_count; i++) 909 for (uint32_t i = 0; i < credentials_count; i++) {
920 {
921 cr_entry = GNUNET_new (struct CredentialRecordEntry); 910 cr_entry = GNUNET_new (struct CredentialRecordEntry);
922 cr_entry->credential 911 cr_entry->credential
923 = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) 912 = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential)
924 + credentials[i].issuer_attribute_len + 1); 913 + credentials[i].issuer_attribute_len + 1);
925 GNUNET_memcpy (cr_entry->credential, 914 GNUNET_memcpy (cr_entry->credential,
926 &credentials[i], 915 &credentials[i],
927 sizeof(struct GNUNET_CREDENTIAL_Credential)); 916 sizeof (struct GNUNET_CREDENTIAL_Credential));
928 GNUNET_memcpy (&cr_entry->credential[1], 917 GNUNET_memcpy (&cr_entry->credential[1],
929 credentials[i].issuer_attribute, 918 credentials[i].issuer_attribute,
930 credentials[i].issuer_attribute_len); 919 credentials[i].issuer_attribute_len);
931 cr_entry->credential->issuer_attribute_len 920 cr_entry->credential->issuer_attribute_len
932 = credentials[i].issuer_attribute_len; 921 = credentials[i].issuer_attribute_len;
933 cr_entry->credential->issuer_attribute = (char *) &cr_entry->credential[1]; 922 cr_entry->credential->issuer_attribute = (char *)&cr_entry->credential[1];
934 GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head, 923 GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head,
935 vrh->cred_chain_tail, 924 vrh->cred_chain_tail,
936 cr_entry); 925 cr_entry);
@@ -944,7 +933,6 @@ static void
944handle_cred_collection_error_cb (void *cls) 933handle_cred_collection_error_cb (void *cls)
945{ 934{
946 struct VerifyRequestHandle *vrh = cls; 935 struct VerifyRequestHandle *vrh = cls;
947
948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 936 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
949 "Got disconnected from namestore database.\n"); 937 "Got disconnected from namestore database.\n");
950 vrh->cred_collection_iter = NULL; 938 vrh->cred_collection_iter = NULL;
@@ -955,7 +943,6 @@ static void
955collect_next (void *cls) 943collect_next (void *cls)
956{ 944{
957 struct VerifyRequestHandle *vrh = cls; 945 struct VerifyRequestHandle *vrh = cls;
958
959 vrh->collect_next_task = NULL; 946 vrh->collect_next_task = NULL;
960 GNUNET_assert (NULL != vrh->cred_collection_iter); 947 GNUNET_assert (NULL != vrh->cred_collection_iter);
961 GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter, 1); 948 GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter, 1);
@@ -975,15 +962,13 @@ handle_cred_collection_cb (void *cls,
975 int cred_record_count; 962 int cred_record_count;
976 963
977 cred_record_count = 0; 964 cred_record_count = 0;
978 for (uint32_t i = 0; i < rd_count; i++) 965 for (uint32_t i = 0; i < rd_count; i++) {
979 {
980 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type) 966 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type)
981 continue; 967 continue;
982 cred_record_count++; 968 cred_record_count++;
983 crd 969 crd
984 = GNUNET_CREDENTIAL_credential_deserialize (rd[i].data, rd[i].data_size); 970 = GNUNET_CREDENTIAL_credential_deserialize (rd[i].data, rd[i].data_size);
985 if (NULL == crd) 971 if (NULL == crd) {
986 {
987 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n"); 972 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n");
988 continue; 973 continue;
989 } 974 }
@@ -1001,7 +986,6 @@ static void
1001handle_cred_collection_finished_cb (void *cls) 986handle_cred_collection_finished_cb (void *cls)
1002{ 987{
1003 struct VerifyRequestHandle *vrh = cls; 988 struct VerifyRequestHandle *vrh = cls;
1004
1005 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting credentials.\n"); 989 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting credentials.\n");
1006 vrh->cred_collection_iter = NULL; 990 vrh->cred_collection_iter = NULL;
1007 delegation_chain_resolution_start (vrh); 991 delegation_chain_resolution_start (vrh);
@@ -1019,7 +1003,7 @@ handle_collect (void *cls, const struct CollectMessage *c_msg)
1019 1003
1020 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n"); 1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n");
1021 1005
1022 utf_in = (const char *) &c_msg[1]; 1006 utf_in = (const char *)&c_msg[1];
1023 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); 1007 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
1024 1008
1025 GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len)); 1009 GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len));
@@ -1032,8 +1016,7 @@ handle_collect (void *cls, const struct CollectMessage *c_msg)
1032 GNUNET_CRYPTO_ecdsa_key_get_public (&c_msg->subject_key, &vrh->subject_key); 1016 GNUNET_CRYPTO_ecdsa_key_get_public (&c_msg->subject_key, &vrh->subject_key);
1033 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); 1017 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
1034 1018
1035 if (0 == strlen (issuer_attribute)) 1019 if (0 == strlen (issuer_attribute)) {
1036 {
1037 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n"); 1020 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
1038 send_lookup_response (vrh); 1021 send_lookup_response (vrh);
1039 return; 1022 return;
@@ -1062,21 +1045,18 @@ check_collect (void *cls, const struct CollectMessage *c_msg)
1062 const char *attr; 1045 const char *attr;
1063 1046
1064 msg_size = ntohs (c_msg->header.size); 1047 msg_size = ntohs (c_msg->header.size);
1065 if (msg_size < sizeof(struct CollectMessage)) 1048 if (msg_size < sizeof (struct CollectMessage)) {
1066 {
1067 GNUNET_break (0); 1049 GNUNET_break (0);
1068 return GNUNET_SYSERR; 1050 return GNUNET_SYSERR;
1069 } 1051 }
1070 if (ntohs (c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) 1052 if (ntohs (c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) {
1071 {
1072 GNUNET_break (0); 1053 GNUNET_break (0);
1073 return GNUNET_SYSERR; 1054 return GNUNET_SYSERR;
1074 } 1055 }
1075 attr = (const char *) &c_msg[1]; 1056 attr = (const char *)&c_msg[1];
1076 1057
1077 if (('\0' != attr[msg_size - sizeof(struct CollectMessage) - 1]) 1058 if (('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1])
1078 || (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)) 1059 || (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)) {
1079 {
1080 GNUNET_break (0); 1060 GNUNET_break (0);
1081 return GNUNET_SYSERR; 1061 return GNUNET_SYSERR;
1082 } 1062 }
@@ -1112,14 +1092,13 @@ run (void *cls,
1112 const struct GNUNET_CONFIGURATION_Handle *c, 1092 const struct GNUNET_CONFIGURATION_Handle *c,
1113 struct GNUNET_SERVICE_Handle *handle) 1093 struct GNUNET_SERVICE_Handle *handle)
1114{ 1094{
1095
1115 gns = GNUNET_GNS_connect (c); 1096 gns = GNUNET_GNS_connect (c);
1116 if (NULL == gns) 1097 if (NULL == gns) {
1117 {
1118 fprintf (stderr, _ ("Failed to connect to GNS\n")); 1098 fprintf (stderr, _ ("Failed to connect to GNS\n"));
1119 } 1099 }
1120 namestore = GNUNET_NAMESTORE_connect (c); 1100 namestore = GNUNET_NAMESTORE_connect (c);
1121 if (NULL == namestore) 1101 if (NULL == namestore) {
1122 {
1123 fprintf (stderr, _ ("Failed to connect to namestore\n")); 1102 fprintf (stderr, _ ("Failed to connect to namestore\n"));
1124 } 1103 }
1125 1104