aboutsummaryrefslogtreecommitdiff
path: root/src/credential/gnunet-service-credential.c
diff options
context:
space:
mode:
authorAndreas Ebner <pansy007@googlemail.com>2019-07-24 16:29:32 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-10-07 12:15:32 +0200
commit40624873cbd2eaf3a94185995b14899ea6ab36bf (patch)
tree0bcc45fc8ba74c7b218ed2b32fc8b7482a42a37c /src/credential/gnunet-service-credential.c
parent5091edcec16455febee99afec20e0ffe6cc59c21 (diff)
downloadgnunet-40624873cbd2eaf3a94185995b14899ea6ab36bf.tar.gz
gnunet-40624873cbd2eaf3a94185995b14899ea6ab36bf.zip
Run clang format over some files, experimental implementation of forward algorithm
Diffstat (limited to 'src/credential/gnunet-service-credential.c')
-rw-r--r--src/credential/gnunet-service-credential.c206
1 files changed, 199 insertions, 7 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index a3c066444..d7f6e34d5 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -542,7 +542,185 @@ test_resolution (void *cls,
542 uint32_t rd_count, 542 uint32_t rd_count,
543 const struct GNUNET_GNSRECORD_Data *rd) 543 const struct GNUNET_GNSRECORD_Data *rd)
544{ 544{
545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Yo, im Test und so\n"); 545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:Got %d entries\n", rd_count);
546
547 struct VerifyRequestHandle *vrh;
548 struct DelegationSetQueueEntry *current_set;
549 struct DelegationSetQueueEntry *ds_entry;
550 struct DelegationQueueEntry *dq_entry;
551
552 current_set = cls;
553 // set handle to NULL (as el = NULL)
554 current_set->lookup_request = NULL;
555 vrh = current_set->handle;
556 vrh->pending_lookups--;
557 //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:current set %s\n", current_set->issuer_attribute);
558
559
560 // Loop record entries
561 for (uint32_t i = 0; i < rd_count; i++) {
562 if (GNUNET_GNSRECORD_TYPE_DELEGATE != rd[i].record_type)
563 continue;
564
565 // Start deserialize into Delegate
566 struct GNUNET_CREDENTIAL_Delegate *del;
567 del = GNUNET_CREDENTIAL_delegate_deserialize(rd[i].data, rd[i].data_size);
568
569 // TODO parse subject and issuer attributes which are required for algo solving
570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:iss %s %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->issuer_key), del->issuer_attribute);
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:sub %s %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->subject_key), del->subject_attribute);
572
573 // Start: Create DQ Entry
574 dq_entry = GNUNET_new (struct DelegationQueueEntry);
575 // AND delegations are not possible, only 1 solution
576 dq_entry->required_solutions = 1;
577 dq_entry->parent_set = current_set;
578
579 // Insert it into the current set
580 GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head,
581 current_set->queue_entries_tail,
582 dq_entry);
583
584 // Start: Create DS Entry
585 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
586
587 // (1) A.a <- A.b.c
588 // (2) A.b <- D.d
589 // (3) D.d <- E
590 // (4) E.c <- F.c
591 // (5) F.c <- G
592 // Possibilities:
593 // 1. complete match: trailer = 0, validate
594 // 2. partial match: replace
595 // 3. new solution: replace, add trailer
596
597 //GNUNET_assert(NULL != current_set->attr_trailer);
598 // TODO only during test
599 if (NULL == current_set->attr_trailer) {
600 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: trailer null\n");
601 // for (5) F.c <- G, remember .c when going upwards
602 ds_entry->attr_trailer = GNUNET_strdup(del->issuer_attribute);
603 } else {
604 if (0 == del->subject_attribute_len){
605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: new solution\n");
606 // new solution
607 // create new trailer del->issuer_attribute, ds_entry->attr_trailer
608 GNUNET_asprintf (&ds_entry->attr_trailer,
609 "%s.%s",
610 del->issuer_attribute,
611 current_set->attr_trailer);
612 } else if(0 == strcmp(del->subject_attribute, current_set->attr_trailer)){
613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: complete match\n");
614 // complete match
615 // new trailer == issuer attribute (e.g. (5) to (4))
616 // TODO memleak, free trailer before
617 ds_entry->attr_trailer = GNUNET_strdup(del->issuer_attribute);
618 } else {
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: partial match\n");
620 // partial match
621
622 // TODO problem when checking with contains: attr = disco or attr = disc both say success
623 // ==> therefore: split and check the single attributes
624 // replace/remove partial match trailer and add the new one
625
626 char *saveptr1, *saveptr2;
627 char *trail_token;
628 char *sub_token;
629 char *tmp_trail = GNUNET_strdup (current_set->attr_trailer);
630 char *tmp_subattr = GNUNET_strdup (del->subject_attribute);
631
632 // tok both, parent->attr_trailer and del->sub_attr to see how far they match,
633 // take rest of parent trailer (only when del->sub_attr token is null), and
634 // create new/actual trailer with del->iss_attr
635 trail_token = strtok_r (tmp_trail, ".", &saveptr1);
636 sub_token = strtok_r (tmp_subattr, ".", &saveptr2);
637 while (NULL != trail_token && NULL != sub_token)
638 {
639 if(0 == strcmp(trail_token,sub_token))
640 {
641 // good, matches, remove
642 } else {
643 // not relevant for solving the chain, end function here
644 // TODO how to end this correctly? just return?
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:throwing %s %s\n", trail_token, sub_token);
646
647 // TODO break zum nächsten for
648 //return;
649 }
650
651 trail_token = strtok_r (NULL, ".", &saveptr1);
652 sub_token = strtok_r (NULL, ".", &saveptr2);
653 }
654 if(NULL == trail_token)
655 {
656 //TODO error, can't happen
657 }
658 // do not have to check sub_token == NULL, if both would be NULL
659 // at the same time, the complete match part above should have triggered already
660
661 // otherwise, above while only ends when sub_token == NULL
662 GNUNET_asprintf (&ds_entry->attr_trailer,
663 "%s",
664 trail_token);
665 trail_token = strtok_r (NULL, ".", &saveptr1);
666 while(NULL != trail_token)
667 {
668 GNUNET_asprintf (&ds_entry->attr_trailer,
669 "%s.%s",
670 current_set->attr_trailer,
671 trail_token);
672 trail_token = strtok_r (NULL, ".", &saveptr1);
673
674 }
675 GNUNET_asprintf (&ds_entry->attr_trailer,
676 "%s.%s",
677 del->issuer_attribute,
678 ds_entry->attr_trailer);
679
680 }
681 }
682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: new tailer %s\n", ds_entry->attr_trailer);
683
684 // Start: Credential Chain Entry
685 // issuer key is subject key, who needs to be contacted to resolve this (forward, therefore subject)
686 // TODO: new ds_entry struct with subject_key (or one for both with contact_key or sth)
687 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
688 GNUNET_memcpy (ds_entry->issuer_key,
689 &del->subject_key,
690 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
691
692 ds_entry->delegation_chain_entry = GNUNET_new (struct DelegationChainEntry);
693 ds_entry->delegation_chain_entry->subject_key = del->subject_key;
694 if (0 < del->subject_attribute_len)
695 ds_entry->delegation_chain_entry->subject_attribute = GNUNET_strdup (del->subject_attribute);
696 ds_entry->delegation_chain_entry->issuer_key = del->issuer_key;
697 ds_entry->delegation_chain_entry->issuer_attribute = GNUNET_strdup (del->issuer_attribute);
698
699 // current delegation as parent
700 ds_entry->parent_queue_entry = dq_entry;
701
702 // TODO verify if end is reached:
703 // what is required? Only issuer key/attr and attr_trailer new == 0
704
705 // TODO until good verify check: fixed number of lookups
706 //vrh->pending_lookups++;
707 ds_entry->handle = vrh;
708
709 const struct GNUNET_CRYPTO_EcdsaPublicKey *kkey = &del->issuer_key;
710 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "-----------FW: Starting AGAIN %s\n",GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->issuer_key));
711 if (0 == vrh->pending_lookups) {
712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
713 return;
714 }
715 GNUNET_GNS_lookup (gns,
716 GNUNET_GNS_EMPTY_LABEL_AT,
717 kkey, // subject_key,
718 GNUNET_GNSRECORD_TYPE_DELEGATE,
719 GNUNET_GNS_LO_DEFAULT,
720 &test_resolution,
721 ds_entry);
722
723 }
546} 724}
547 725
548static void 726static void
@@ -732,22 +910,24 @@ backward_resolution (void *cls,
732 910
733 vrh->pending_lookups++; 911 vrh->pending_lookups++;
734 ds_entry->handle = vrh; 912 ds_entry->handle = vrh;
735 ds_entry->lookup_request 913 /*ds_entry->lookup_request
736 = GNUNET_GNS_lookup (gns, 914 = GNUNET_GNS_lookup (gns,
737 lookup_attribute, 915 lookup_attribute,
738 ds_entry->issuer_key, // issuer_key, 916 ds_entry->issuer_key, // issuer_key,
739 GNUNET_GNSRECORD_TYPE_ATTRIBUTE, 917 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
740 GNUNET_GNS_LO_DEFAULT, 918 GNUNET_GNS_LO_DEFAULT,
741 &backward_resolution, 919 &backward_resolution,
742 ds_entry); 920 ds_entry);*/
743 /*GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting\n"); 921 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(ds_entry->issuer_key));
744 GNUNET_GNS_lookup (gns, 922 vrh->pending_lookups = 5;
923 ds_entry->lookup_request
924 = GNUNET_GNS_lookup (gns,
745 GNUNET_GNS_EMPTY_LABEL_AT, 925 GNUNET_GNS_EMPTY_LABEL_AT,
746 ds_entry->issuer_key, // subject_key, 926 ds_entry->issuer_key, // issuer_key,
747 GNUNET_GNSRECORD_TYPE_DELEGATE, 927 GNUNET_GNSRECORD_TYPE_DELEGATE,
748 GNUNET_GNS_LO_DEFAULT, 928 GNUNET_GNS_LO_DEFAULT,
749 &test_resolution, 929 &test_resolution,
750 ds_entry);*/ 930 ds_entry);
751 GNUNET_free (lookup_attribute); 931 GNUNET_free (lookup_attribute);
752 } 932 }
753 } 933 }
@@ -825,6 +1005,18 @@ delegation_chain_resolution_start (void *cls)
825 GNUNET_GNS_LO_DEFAULT, 1005 GNUNET_GNS_LO_DEFAULT,
826 &backward_resolution, 1006 &backward_resolution,
827 ds_entry); 1007 ds_entry);
1008 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(&vrh->issuer_key));
1009
1010 // TODO we start with example (5) F.c <- G
1011 // => attr_trailer = c
1012 //ds_entry->attr_trailer = "c";
1013 /*ds_entry->lookup_request = GNUNET_GNS_lookup (gns,
1014 GNUNET_GNS_EMPTY_LABEL_AT,
1015 &vrh->issuer_key, // subject_key,
1016 GNUNET_GNSRECORD_TYPE_DELEGATE,
1017 GNUNET_GNS_LO_DEFAULT,
1018 &test_resolution,
1019 ds_entry);*/
828} 1020}
829 1021
830static int 1022static int