GNUnet 0.22.2
gnunet-service-abd.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011-2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19*/
25#include "platform.h"
26
27#include "gnunet_util_lib.h"
28
29#include "abd.h"
30#include "abd_serialization.h"
31#include "gnunet_abd_service.h"
32#include "gnunet_protocols.h"
34#include <gnunet_gns_service.h>
38
39
40#define GNUNET_ABD_MAX_LENGTH 255
41
43
45
46
48{
53
58
63
68
73
78};
79
84{
89
94
98 uint32_t refcount;
99
104};
105
111{
116
121
126
131};
132
138{
143
148
153
158
163
168
173
178
183
188
193
198
203
208
213};
214
215
220{
229
234
239
244
249
254
259
264
269
274
279
284
289
294
299
303 uint32_t request_id;
304
309
314
319};
320
321
325static struct VerifyRequestHandle *vrh_head = NULL;
326
330static struct VerifyRequestHandle *vrh_tail = NULL;
331
336
340static struct GNUNET_GNS_Handle *gns;
341
346
347static void
348print_deleset (struct DelegationSetQueueEntry *dsentry, const char *text)
349{
351 "%s %s.%s <- %s.%s\n",
352 text,
359}
360
361
362static void
364{
365 GNUNET_free (ds_entry->issuer_key);
366 GNUNET_free (ds_entry->issuer_attribute);
367 GNUNET_free (ds_entry->attr_trailer);
368 // those fields are only set/used in bw search
369 if (ds_entry->from_bw)
370 {
371 GNUNET_free (ds_entry->lookup_attribute);
373 }
374 if (NULL != ds_entry->lookup_request)
375 {
377 ds_entry->lookup_request = NULL;
378 }
379 if (NULL != ds_entry->delegation_chain_entry)
380 {
385 }
386 // Free DQ entries
387 for (struct DelegationQueueEntry *dq_entry = ds_entry->queue_entries_head;
388 NULL != ds_entry->queue_entries_head;
389 dq_entry = ds_entry->queue_entries_head)
390 {
392 ds_entry->queue_entries_tail,
393 dq_entry);
394 GNUNET_free (dq_entry);
395 }
396 GNUNET_free (ds_entry);
397}
398
399
400static void
402{
403 struct DelegateRecordEntry *del_entry;
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n");
405
406 if (NULL != vrh->dsq_head)
407 {
408 for (struct DelegationSetQueueEntry *ds_entry = vrh->dsq_head; NULL !=
409 vrh->dsq_head;
410 ds_entry = vrh->dsq_head)
411 {
412 GNUNET_CONTAINER_DLL_remove (vrh->dsq_head, vrh->dsq_tail, ds_entry);
413 cleanup_dsq_entry (ds_entry);
414 }
415 }
416 if (NULL != vrh->del_chain_head)
417 {
418 for (del_entry = vrh->del_chain_head; NULL != vrh->del_chain_head;
419 del_entry = vrh->del_chain_head)
420 {
422 vrh->del_chain_tail,
423 del_entry);
424 GNUNET_free (del_entry->delegate);
425 GNUNET_free (del_entry);
426 }
427 }
429 GNUNET_free (vrh);
430}
431
432
433static void
434shutdown_task (void *cls)
435{
436 struct VerifyRequestHandle *vrh;
437
438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n");
439
440 while (NULL != (vrh = vrh_head))
441 {
442 // ABD_resolver_lookup_cancel (clh->lookup);
444 cleanup_handle (vrh);
445 }
446
447 if (NULL != gns)
448 {
450 gns = NULL;
451 }
452 if (NULL != namestore)
453 {
455 namestore = NULL;
456 }
457 if (NULL != statistics)
458 {
460 statistics = NULL;
461 }
462}
463
464
465static void
467 DelegationChainEntry *ch_entry, bool is_bw)
468{
470 struct GNUNET_MQ_Envelope *env;
471 struct GNUNET_ABD_Delegation *dd;
472 size_t size;
473
474 // Don't report immediate results during collect
475 if (vrh->is_collect)
476 return;
477
478 dd = GNUNET_new (struct GNUNET_ABD_Delegation);
479 dd->issuer_key = ch_entry->issuer_key;
480 dd->subject_key = ch_entry->subject_key;
481 dd->issuer_attribute = ch_entry->issuer_attribute;
482 dd->issuer_attribute_len = strlen (ch_entry->issuer_attribute) + 1;
483 dd->subject_attribute_len = 0;
484 dd->subject_attribute = NULL;
485 if (NULL != ch_entry->subject_attribute)
486 {
487 dd->subject_attribute = ch_entry->subject_attribute;
488 dd->subject_attribute_len = strlen (ch_entry->subject_attribute) + 1;
489 }
490
491
493 dd,
494 0,
495 NULL);
496
497 env = GNUNET_MQ_msg_extra (rmsg,
498 size,
500 // Assign id so that client can find associated request
501 rmsg->id = vrh->request_id;
502 rmsg->is_bw = htons (is_bw);
503 rmsg->size = htonl (size);
504
507 dd,
508 0,
509 NULL,
510 size,
511 (char *) &rmsg[1]));
513
514 GNUNET_free (dd);
515}
516
517
518static void
520{
521 struct GNUNET_MQ_Envelope *env;
522 struct DelegationChainResultMessage *rmsg;
523 struct DelegationChainEntry *dce;
524 struct GNUNET_ABD_Delegation dd[vrh->delegation_chain_size];
525 struct GNUNET_ABD_Delegate dele[vrh->del_chain_size];
526 struct DelegateRecordEntry *del;
527 struct DelegateRecordEntry *tmp;
528 size_t size;
529
530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response\n");
531 dce = vrh->delegation_chain_head;
532 for (uint32_t i = 0; i < vrh->delegation_chain_size; i++)
533 {
534 dd[i].issuer_key = dce->issuer_key;
535 dd[i].subject_key = dce->subject_key;
537 dd[i].issuer_attribute_len = strlen (dce->issuer_attribute) + 1;
538 dd[i].subject_attribute_len = 0;
539 dd[i].subject_attribute = NULL;
540 if (NULL != dce->subject_attribute)
541 {
543 dd[i].subject_attribute_len = strlen (dce->subject_attribute) + 1;
544 }
545 dce = dce->next;
546 }
547
548 // Remove all not needed credentials
549 for (del = vrh->del_chain_head; NULL != del;)
550 {
551 if (del->refcount > 0)
552 {
553 del = del->next;
554 continue;
555 }
556 tmp = del;
557 del = del->next;
559 GNUNET_free (tmp->delegate);
560 GNUNET_free (tmp);
561 vrh->del_chain_size--;
562 }
563
564 // Get serialized record data
565 // Append at the end of rmsg
566 del = vrh->del_chain_head;
567 for (uint32_t i = 0; i < vrh->del_chain_size; i++)
568 {
569 dele[i].issuer_key = del->delegate->issuer_key;
570 dele[i].subject_key = del->delegate->subject_key;
571 dele[i].issuer_attribute_len = strlen (del->delegate->issuer_attribute) + 1;
572 dele[i].issuer_attribute = del->delegate->issuer_attribute;
573 dele[i].subject_attribute_len = del->delegate->subject_attribute_len;
574 dele[i].subject_attribute = del->delegate->subject_attribute;
575 dele[i].expiration = del->delegate->expiration;
576 dele[i].signature = del->delegate->signature;
577 del = del->next;
578 }
579 size =
581 dd,
582 vrh->del_chain_size,
583 dele);
584 env = GNUNET_MQ_msg_extra (rmsg,
585 size,
587 // Assign id so that client can find associated request
588 rmsg->id = vrh->request_id;
589 rmsg->d_count = htonl (vrh->delegation_chain_size);
590 rmsg->c_count = htonl (vrh->del_chain_size);
591
592 if (0 < vrh->del_chain_size)
593 rmsg->del_found = htonl (GNUNET_YES);
594 else
595 rmsg->del_found = htonl (GNUNET_NO);
596
598 -1 !=
600 dd,
601 vrh->del_chain_size,
602 dele,
603 size,
604 (char *) &rmsg[1]));
605
608 cleanup_handle (vrh);
610 "Completed verifications",
611 1,
612 GNUNET_NO);
613}
614
615
616static char *
617partial_match (char *tmp_trail,
618 char *tmp_subattr,
619 char *parent_trail,
620 char *issuer_attribute)
621{
622 char *saveptr1, *saveptr2;
623 char *trail_token;
624 char *sub_token;
625 char *attr_trailer;
626
627 // tok both, parent->attr_trailer and del->sub_attr to see how far they match,
628 // take rest of parent trailer (only when del->sub_attr token is null), and
629 // create new/actual trailer with del->iss_attr
630 trail_token = strtok_r (tmp_trail, ".", &saveptr1);
631 sub_token = strtok_r (tmp_subattr, ".", &saveptr2);
632 while (NULL != trail_token && NULL != sub_token)
633 {
634 if (0 == strcmp (trail_token, sub_token))
635 {
636 // good, matches, remove
637 }
638 else
639 {
640 // not relevant for solving the chain, end for iteration here
641 return NULL;
642 }
643
644 trail_token = strtok_r (NULL, ".", &saveptr1);
645 sub_token = strtok_r (NULL, ".", &saveptr2);
646 }
647 // skip this entry and go to next for if:
648 // 1. at some point the attr of the trailer and the subject dont match
649 // 2. the trailer is NULL, but the subject has more attributes
650 // Reason: This will lead to "startzone.attribute" but we're looking for a solution
651 // for "<- startzone"
652 if (NULL == trail_token)
653 {
654 return NULL;
655 }
656
657 // do not have to check sub_token == NULL, if both would be NULL
658 // at the same time, the complete match part above should have triggered already
659
660 // otherwise, above while only ends when sub_token == NULL
661 GNUNET_asprintf (&attr_trailer, "%s", trail_token);
662 trail_token = strtok_r (NULL, ".", &saveptr1);
663 while (NULL != trail_token)
664 {
665 GNUNET_asprintf (&attr_trailer, "%s.%s", parent_trail, trail_token);
666 trail_token = strtok_r (NULL, ".", &saveptr1);
667 }
668 GNUNET_asprintf (&attr_trailer, "%s.%s", issuer_attribute, attr_trailer);
669 return attr_trailer;
670}
671
672
673static int
675 struct DelegationSetQueueEntry *match_entry,
676 struct VerifyRequestHandle *vrh)
677{
678 struct DelegationSetQueueEntry *old_fw_parent;
679 struct DelegationSetQueueEntry *fw_entry = actual_entry;
680 struct DelegationSetQueueEntry *last_entry = match_entry;
681 // parent fixing, combine backward and forward chain parts
682 while (NULL != fw_entry->parent_queue_entry)
683 {
684 old_fw_parent = fw_entry->parent_queue_entry->parent_set;
685 // set parent
686 fw_entry->parent_queue_entry->parent_set = last_entry;
687
688 last_entry = fw_entry;
689 fw_entry = old_fw_parent;
690 }
691 // set last entry of chain as actual_entry
692 // actual_entry = last_entry;
693 // set refcount, loop all delegations
694 for (struct DelegateRecordEntry *del_entry = vrh->del_chain_head;
695 del_entry != NULL;
696 del_entry = del_entry->next)
697 {
698 if (0 != memcmp (&last_entry->delegation_chain_entry->subject_key,
699 &del_entry->delegate->issuer_key,
700 sizeof (struct GNUNET_CRYPTO_PublicKey)))
701 continue;
702 if (0 != strcmp (last_entry->delegation_chain_entry->subject_attribute,
703 del_entry->delegate->issuer_attribute))
704 continue;
705
706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found delegate.\n");
707 // increase refcount of the start delegation
708 del_entry->refcount++;
709 }
710 // backtrack
711 for (struct DelegationSetQueueEntry *tmp_set = last_entry;
712 NULL != tmp_set->parent_queue_entry;
713 tmp_set = tmp_set->parent_queue_entry->parent_set)
714 {
715 tmp_set->parent_queue_entry->required_solutions--;
716
717 // add new found entry to vrh
721 tmp_set->delegation_chain_entry);
722
723 // if one node on the path still needs solutions, this current
724 // patch cannot fulfill the conditions and therefore stops here
725 // however, it is in the vrh and can be used by the other paths
726 // related to this path/collection/verification
727 if (0 < tmp_set->parent_queue_entry->required_solutions)
728 {
730 "Chain requires more solutions, waiting...\n");
731 return GNUNET_NO;
732 }
733 }
734 return GNUNET_YES;
735}
736
737
738static void
740 uint32_t rd_count,
741 const struct GNUNET_GNSRECORD_Data *rd)
742{
743 struct VerifyRequestHandle *vrh;
744 struct DelegationSetQueueEntry *current_set;
745 struct DelegationSetQueueEntry *ds_entry;
746 struct DelegationQueueEntry *dq_entry;
747 struct GNUNET_ABD_Delegate *del;
748
749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %d entries.\n", rd_count);
750
751 current_set = cls;
752 // set handle to NULL (as el = NULL)
753 current_set->lookup_request = NULL;
754 vrh = current_set->handle;
755 vrh->pending_lookups--;
756
757 // Loop record entries
758 for (uint32_t i = 0; i < rd_count; i++)
759 {
760 if (GNUNET_GNSRECORD_TYPE_DELEGATE != rd[i].record_type)
761 continue;
762
763 // Start deserialize into Delegate
765
766 if (NULL == del)
767 continue;
768
769 // Start: Create DQ Entry
770 dq_entry = GNUNET_new (struct DelegationQueueEntry);
771 // AND delegations are not possible, only 1 solution
772 dq_entry->required_solutions = 1;
773 dq_entry->parent_set = current_set;
774
775 // Insert it into the current set
777 current_set->queue_entries_tail,
778 dq_entry);
779
780 // Start: Create DS Entry
781 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
782 GNUNET_CONTAINER_DLL_insert (vrh->dsq_head, vrh->dsq_tail, ds_entry);
783 ds_entry->from_bw = false;
784
785 // (1) A.a <- A.b.c
786 // (2) A.b <- D.d
787 // (3) D.d <- E
788 // (4) E.c <- F.c
789 // (5) F.c <- G
790 // Possibilities:
791 // 1. complete match: trailer = 0, validate
792 // 2. partial match: replace
793 // 3. new solution: replace, add trailer
794
795 // At resolution chain start trailer of parent is NULL
796 if (NULL == current_set->attr_trailer)
797 {
798 // for (5) F.c <- G, remember .c when going upwards
799 ds_entry->attr_trailer = GNUNET_strdup (del->issuer_attribute);
800 }
801 else
802 {
803 if (0 == del->subject_attribute_len)
804 {
805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: New solution\n");
806 // new solution
807 // create new trailer del->issuer_attribute, ds_entry->attr_trailer
808 GNUNET_asprintf (&ds_entry->attr_trailer,
809 "%s.%s",
810 del->issuer_attribute,
811 current_set->attr_trailer);
812 }
813 else if (0 == strcmp (del->subject_attribute, current_set->attr_trailer))
814 {
815 // complete match
816 // new trailer == issuer attribute (e.g. (5) to (4))
817 ds_entry->attr_trailer = GNUNET_strdup (del->issuer_attribute);
818 }
819 else
820 {
821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: Partial match\n");
822 // partial match
823 {
824 char *trail = partial_match (GNUNET_strdup (current_set->attr_trailer)
825 ,
826 GNUNET_strdup (del->subject_attribute),
827 current_set->attr_trailer,
828 GNUNET_strdup (del->issuer_attribute));
829
830 // if null: skip this record entry (reasons: mismatch or overmatch, both not relevant)
831 if (NULL == trail)
832 {
834 "Entry not relevant, discarding: %s.%s <- %s.%s\n",
836 &del->issuer_key),
837 del->issuer_attribute,
839 &del->subject_key),
840 del->subject_attribute);
842 continue;
843 }
844 else
845 {
846 ds_entry->attr_trailer = trail;
847 }
848 }
849 }
850 }
851
852
853 // Start: Credential Chain Entry
854 // issuer key is subject key, who needs to be contacted to resolve this (forward, therefore subject)
855 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_PublicKey);
856 GNUNET_memcpy (ds_entry->issuer_key,
857 &del->subject_key,
858 sizeof (struct GNUNET_CRYPTO_PublicKey));
859
861 ds_entry->delegation_chain_entry->subject_key = del->subject_key;
862 if (0 < del->subject_attribute_len)
864 GNUNET_strdup (del->subject_attribute);
865 ds_entry->delegation_chain_entry->issuer_key = del->issuer_key;
867 GNUNET_strdup (del->issuer_attribute);
868
869 // Found new entry, repoting intermediate result
871
872 // current delegation as parent
873 ds_entry->parent_queue_entry = dq_entry;
874
875 // Check for solution
876 // if: issuer key we looking for
877 if (0 == memcmp (&del->issuer_key,
878 &vrh->issuer_key,
879 sizeof (struct GNUNET_CRYPTO_PublicKey)))
880 {
881 // if: issuer attr we looking for
882 if (0 == strcmp (del->issuer_attribute, vrh->issuer_attribute))
883 {
884 // if: complete match, meaning new trailer == issuer attr
885 if (0 == strcmp (vrh->issuer_attribute, ds_entry->attr_trailer))
886 {
887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found: Solution\n");
888
889 // Add found solution into delegation_chain
890 {
891 struct DelegationSetQueueEntry *tmp_set;
892 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
893 tmp_set = tmp_set->parent_queue_entry->parent_set)
894 {
895 if (NULL != tmp_set->delegation_chain_entry)
896 {
900 tmp_set->delegation_chain_entry);
901 }
902 }
903 }
904
905 // Increase refcount for this delegate
906 for (struct DelegateRecordEntry *del_entry = vrh->del_chain_head;
907 del_entry != NULL;
908 del_entry = del_entry->next)
909 {
910 if (0 == memcmp (&del_entry->delegate->issuer_key,
912 sizeof (struct GNUNET_CRYPTO_PublicKey)))
913 {
914 if (0 == strcmp (del_entry->delegate->issuer_attribute,
916 {
917 del_entry->refcount++;
918 }
919 }
920 }
921
924 return;
925 }
926 }
927 }
928
929 // Check for bidirectional crossmatch
930 for (struct DelegationSetQueueEntry *del_entry = vrh->dsq_head;
931 del_entry != NULL;
932 del_entry = del_entry->next)
933 {
934 // only check entries not by backward algorithm
935 if (del_entry->from_bw)
936 {
937 // key of list entry matches actual key
938 if (0 == memcmp (&del_entry->delegation_chain_entry->subject_key,
940 sizeof (struct GNUNET_CRYPTO_PublicKey)))
941 {
942 // compare entry subject attributes to this trailer (iss attr + old trailer)
943 if (0 == strcmp (del_entry->unresolved_attribute_delegation,
944 ds_entry->attr_trailer))
945 {
946 print_deleset (del_entry, "Forward:");
948 "Forward: Found match with above!\n");
949
951 // one node on the path still needs solutions: return
952 if (GNUNET_NO ==
953 handle_bidirectional_match (ds_entry, del_entry, vrh))
954 return;
955
957 return;
958 }
959 }
960 }
961 }
962
963 // Starting a new GNS lookup
964 vrh->pending_lookups++;
965 ds_entry->handle = vrh;
966
968 "Starting to look up trailer %s in zone %s\n",
969 ds_entry->attr_trailer,
971
972 ds_entry->lookup_request =
975 &del->issuer_key,
979 ds_entry);
981 }
982
983 if (0 == vrh->pending_lookups)
984 {
985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
987 return;
988 }
989}
990
991
992static void
994 uint32_t rd_count,
995 const struct GNUNET_GNSRECORD_Data *rd)
996{
997 struct VerifyRequestHandle *vrh;
998 const struct GNUNET_ABD_DelegationRecord *sets;
999 struct DelegateRecordEntry *del_pointer;
1000 struct DelegationSetQueueEntry *current_set;
1001 struct DelegationSetQueueEntry *ds_entry;
1002 struct DelegationSetQueueEntry *tmp_set;
1003 struct DelegationQueueEntry *dq_entry;
1004 char *expanded_attr;
1005 char *lookup_attribute;
1006
1007 current_set = cls;
1008 current_set->lookup_request = NULL;
1009 vrh = current_set->handle;
1010 vrh->pending_lookups--;
1011
1012 // Each OR
1013 for (uint32_t i = 0; i < rd_count; i++)
1014 {
1015 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
1016 continue;
1017
1018 sets = rd[i].data;
1019 struct GNUNET_ABD_DelegationSet set[ntohl (sets->set_count)];
1021 "Found new attribute delegation with %d sets. Creating new Job...\n",
1022 ntohl (sets->set_count));
1023
1024 if (GNUNET_OK !=
1026 sets->data_size),
1027 (const char *) &sets[1],
1028 ntohl (sets->set_count),
1029 set))
1030 {
1031 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n");
1032 continue;
1033 }
1034 dq_entry = GNUNET_new (struct DelegationQueueEntry);
1035 dq_entry->required_solutions = ntohl (sets->set_count);
1036 dq_entry->parent_set = current_set;
1037
1039 current_set->queue_entries_tail,
1040 dq_entry);
1041 // Each AND
1042 for (uint32_t j = 0; j < ntohl (sets->set_count); j++)
1043 {
1044 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
1045 GNUNET_CONTAINER_DLL_insert (vrh->dsq_head, vrh->dsq_tail, ds_entry);
1046 ds_entry->from_bw = true;
1047
1048 if (NULL != current_set->attr_trailer)
1049 {
1050 if (0 == set[j].subject_attribute_len)
1051 {
1052 GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer);
1053 }
1054 else
1055 {
1056 GNUNET_asprintf (&expanded_attr,
1057 "%s.%s",
1058 set[j].subject_attribute,
1059 current_set->attr_trailer);
1060 }
1061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr);
1062 ds_entry->unresolved_attribute_delegation = expanded_attr;
1063 }
1064 else
1065 {
1066 if (0 != set[j].subject_attribute_len)
1067 {
1069 "Not Expanding %s\n",
1070 set[j].subject_attribute);
1073 }
1074 }
1075
1076 // Add a credential chain entry
1077 ds_entry->delegation_chain_entry =
1080 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_PublicKey);
1081 GNUNET_memcpy (ds_entry->issuer_key,
1082 &set[j].subject_key,
1083 sizeof (struct GNUNET_CRYPTO_PublicKey));
1084 if (0 < set[j].subject_attribute_len)
1087 ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key;
1089 GNUNET_strdup (current_set->lookup_attribute);
1090
1091 // Found new entry, repoting intermediate result
1093
1094 ds_entry->parent_queue_entry = dq_entry; // current_delegation;
1095
1099 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n");
1100
1101 for (del_pointer = vrh->del_chain_head; del_pointer != NULL;
1102 del_pointer = del_pointer->next)
1103 {
1104 // If key and attribute match credential: continue and backtrack
1105 if (0 != memcmp (&set[j].subject_key,
1106 &del_pointer->delegate->issuer_key,
1107 sizeof (struct GNUNET_CRYPTO_PublicKey)))
1108 continue;
1110 "Checking if %s matches %s\n",
1112 del_pointer->delegate->issuer_attribute);
1113
1114 if (0 != strcmp (ds_entry->unresolved_attribute_delegation,
1115 del_pointer->delegate->issuer_attribute))
1116 continue;
1117
1118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n");
1119 // increase refcount of the start delegation
1120 del_pointer->refcount++;
1121
1122 // Backtrack
1123 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
1124 tmp_set = tmp_set->parent_queue_entry->parent_set)
1125 {
1127 if (NULL != tmp_set->delegation_chain_entry)
1128 {
1129 vrh->delegation_chain_size++;
1132 tmp_set->delegation_chain_entry);
1133 }
1134 if (0 < tmp_set->parent_queue_entry->required_solutions)
1135 break;
1136 }
1137
1138 // if the break above is not called the condition of the for is met
1139 if (NULL == tmp_set->parent_queue_entry)
1140 {
1141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All solutions found\n");
1142 // Found match
1144 return;
1145 }
1146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not all solutions found yet.\n");
1147 continue;
1148 }
1149
1151 "Building new lookup request from %s\n",
1153 // Continue with next/new backward resolution
1154 char issuer_attribute_name[strlen (
1156 + 1];
1157 strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation);
1158 char *next_attr = strtok (issuer_attribute_name, ".");
1159 if (NULL == next_attr)
1160 {
1162 "Failed to parse next attribute\n");
1163 continue;
1164 }
1165 GNUNET_asprintf (&lookup_attribute, "%s", next_attr);
1166 GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr);
1167 if (strlen (next_attr) ==
1168 strlen (ds_entry->unresolved_attribute_delegation))
1169 {
1170 ds_entry->attr_trailer = NULL;
1171 }
1172 else
1173 {
1174 next_attr += strlen (next_attr) + 1;
1175 ds_entry->attr_trailer = GNUNET_strdup (next_attr);
1176 }
1177
1178 // Check for bidirectional crossmatch
1179 for (struct DelegationSetQueueEntry *del_entry = vrh->dsq_head;
1180 del_entry != NULL;
1181 del_entry = del_entry->next)
1182 {
1183 // only check entries added by forward algorithm
1184 if (! del_entry->from_bw)
1185 {
1186 // key of list entry matches actual key
1187 if (0 == memcmp (&del_entry->delegation_chain_entry->issuer_key,
1189 sizeof (struct GNUNET_CRYPTO_PublicKey)))
1190 {
1191 // compare entry subject attributes to this trailer (iss attr + old trailer)
1192 if (0 == strcmp (del_entry->attr_trailer,
1194 {
1195 print_deleset (del_entry, "Backward:");
1197 "Backward: Found match with above!\n");
1198
1199 // if one node on the path still needs solutions: return
1200 if (GNUNET_NO ==
1201 handle_bidirectional_match (del_entry, ds_entry, vrh))
1202 break;
1203
1204 // Send lookup response
1206 return;
1207 }
1208 }
1209 }
1210 }
1211
1212 // Starting a new GNS lookup
1214 "Looking up %s\n",
1215 ds_entry->lookup_attribute);
1216 if (NULL != ds_entry->attr_trailer)
1218 "%s still to go...\n",
1219 ds_entry->attr_trailer);
1220
1221 vrh->pending_lookups++;
1222 ds_entry->handle = vrh;
1223 ds_entry->lookup_request =
1225 lookup_attribute,
1226 ds_entry->issuer_key, // issuer_key,
1230 ds_entry);
1231
1232 GNUNET_free (lookup_attribute);
1233 }
1234 }
1235
1236 if (0 == vrh->pending_lookups)
1237 {
1238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
1240 return;
1241 }
1242}
1243
1244
1250static int
1252{
1253
1254 struct VerifyRequestHandle *vrh = cls;
1255 struct DelegationSetQueueEntry *ds_entry;
1256 struct DelegateRecordEntry *del_entry;
1257
1258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Start Backward Resolution...\n");
1259 if (0 == vrh->del_chain_size)
1260 {
1261 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No delegates found\n");
1263 return 1;
1264 }
1265
1266 // Pre-check with vrh->dele_chain_.. if match issuer_key
1267 // Backward: check every cred entry if match issuer key
1268 // otherwise: start at issuer and go down till match
1269 // A.a <- ...
1270 // X.x <- C
1271 // Y.y <- C
1272 // if not X.x or Y.y == A.a start at A
1273 for (del_entry = vrh->del_chain_head; del_entry != NULL;
1274 del_entry = del_entry->next)
1275 {
1276 if (0 != memcmp (&del_entry->delegate->issuer_key,
1277 &vrh->issuer_key,
1278 sizeof (struct GNUNET_CRYPTO_PublicKey)))
1279 continue;
1280 if (0 !=
1281 strcmp (del_entry->delegate->issuer_attribute, vrh->issuer_attribute))
1282 continue;
1283 del_entry->refcount++;
1284 // Found match prematurely
1286 return 1;
1287 }
1288
1289
1290 // Check for attributes from the issuer and follow the chain
1291 // till you get the required subject's attributes
1292 char issuer_attribute_name[strlen (vrh->issuer_attribute) + 1];
1293 strcpy (issuer_attribute_name, vrh->issuer_attribute);
1295 "Looking up %s\n",
1296 issuer_attribute_name);
1297 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
1298 GNUNET_CONTAINER_DLL_insert (vrh->dsq_head, vrh->dsq_tail, ds_entry);
1299 ds_entry->from_bw = true;
1300 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_PublicKey);
1301 GNUNET_memcpy (ds_entry->issuer_key,
1302 &vrh->issuer_key,
1303 sizeof (struct GNUNET_CRYPTO_PublicKey));
1305
1310
1311 ds_entry->handle = vrh;
1313 ds_entry->unresolved_attribute_delegation = NULL;
1314 vrh->pending_lookups = 1;
1315
1316 // Start with backward resolution
1317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start Backward Resolution\n");
1318
1320 issuer_attribute_name,
1321 &vrh->issuer_key, // issuer_key,
1325 ds_entry);
1326 return 0;
1327}
1328
1329
1330static int
1332{
1333
1334 struct VerifyRequestHandle *vrh = cls;
1335 struct DelegationSetQueueEntry *ds_entry;
1336 struct DelegateRecordEntry *del_entry;
1337
1338 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Start Forward Resolution...\n");
1339 // set to 0 and increase on each lookup: for fw multiple lookups (may be) started
1340 vrh->pending_lookups = 0;
1341
1342 if (0 == vrh->del_chain_size)
1343 {
1344 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No delegations found\n");
1346 return 1;
1347 }
1348
1349 // Pre-check with vrh->dele_chain_.. if match issuer_key
1350 // otherwise FW: start multiple lookups for each vrh->dele_chain
1351 // A.a <- ...
1352 // X.x <- C
1353 // Y.y <- C
1354 // if not X.x or Y.y == A.a start at X and at Y
1355 for (del_entry = vrh->del_chain_head; del_entry != NULL;
1356 del_entry = del_entry->next)
1357 {
1358 if (0 != memcmp (&del_entry->delegate->issuer_key,
1359 &vrh->issuer_key,
1360 sizeof (struct GNUNET_CRYPTO_PublicKey)))
1361 continue;
1362 if (0 !=
1363 strcmp (del_entry->delegate->issuer_attribute, vrh->issuer_attribute))
1364 continue;
1365 del_entry->refcount++;
1366 // Found match prematurely
1368 return 1;
1369 }
1370
1371 // None match, therefore start for every delegation found a lookup chain
1372 // Return and end collect process on first chain iss <-> sub found
1373
1374 // ds_entry created belongs to the first lookup, vrh still has the
1375 // issuer+attr we look for
1376 for (del_entry = vrh->del_chain_head; del_entry != NULL;
1377 del_entry = del_entry->next)
1378 {
1379
1381 "Looking for %s.%s\n",
1383 &del_entry->delegate->issuer_key),
1384 del_entry->delegate->issuer_attribute);
1385
1386 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
1387 GNUNET_CONTAINER_DLL_insert (vrh->dsq_head, vrh->dsq_tail, ds_entry);
1388 ds_entry->from_bw = false;
1389 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_PublicKey);
1390 GNUNET_memcpy (ds_entry->issuer_key,
1391 &del_entry->delegate->subject_key,
1392 sizeof (struct GNUNET_CRYPTO_PublicKey));
1393
1396 del_entry->delegate->subject_key;
1397 ds_entry->delegation_chain_entry->subject_attribute = NULL;
1399 del_entry->delegate->issuer_key;
1402
1403 ds_entry->attr_trailer =
1405 ds_entry->handle = vrh;
1406
1407 vrh->pending_lookups++;
1408 // Start with forward resolution
1409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start Forward Resolution\n");
1410
1411 ds_entry->lookup_request =
1414 &del_entry->delegate->issuer_key, // issuer_key,
1418 ds_entry);
1419 }
1420 return 0;
1421}
1422
1423
1424static int
1425check_verify (void *cls, const struct VerifyMessage *v_msg)
1426{
1427 size_t msg_size;
1428 const char *attr;
1429
1430 msg_size = ntohs (v_msg->header.size);
1431 if (msg_size < sizeof (struct VerifyMessage))
1432 {
1433 GNUNET_break (0);
1434 return GNUNET_SYSERR;
1435 }
1436 if (ntohs (v_msg->issuer_attribute_len) > GNUNET_ABD_MAX_LENGTH)
1437 {
1438 GNUNET_break (0);
1439 return GNUNET_SYSERR;
1440 }
1441 attr = (const char *) &v_msg[1];
1442
1443 if (strlen (attr) > GNUNET_ABD_MAX_LENGTH)
1444 {
1445 GNUNET_break (0);
1446 return GNUNET_SYSERR;
1447 }
1448 return GNUNET_OK;
1449}
1450
1451
1452static void
1453handle_verify (void *cls, const struct VerifyMessage *v_msg)
1454{
1455 struct VerifyRequestHandle *vrh;
1456 struct GNUNET_SERVICE_Client *client = cls;
1457 struct DelegateRecordEntry *del_entry;
1458 uint32_t delegate_count;
1459 uint32_t delegate_data_size;
1460 char attr[GNUNET_ABD_MAX_LENGTH + 1];
1461 char issuer_attribute[GNUNET_ABD_MAX_LENGTH + 1];
1462 char *attrptr = attr;
1463 char *delegate_data;
1464 const char *utf_in;
1465
1466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n");
1467 utf_in = (const char *) &v_msg[1];
1468 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
1469 GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len));
1470 issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0';
1471 vrh = GNUNET_new (struct VerifyRequestHandle);
1472 vrh->is_collect = false;
1474 vrh->client = client;
1475 vrh->request_id = v_msg->id;
1476 vrh->issuer_key = v_msg->issuer_key;
1477 vrh->subject_key = v_msg->subject_key;
1478 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
1479 vrh->resolution_algo = ntohs (v_msg->resolution_algo);
1480
1481 vrh->del_chain_head = NULL;
1482 vrh->del_chain_tail = NULL;
1483 vrh->dsq_head = NULL;
1484 vrh->dsq_tail = NULL;
1485 vrh->del_chain_head = NULL;
1486 vrh->del_chain_tail = NULL;
1487
1489 if (0 == strlen (issuer_attribute))
1490 {
1491 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
1493 return;
1494 }
1495
1496 // Parse delegates from verifaction message
1497 delegate_count = ntohl (v_msg->d_count);
1498 delegate_data_size = ntohs (v_msg->header.size)
1499 - sizeof (struct VerifyMessage)
1500 - ntohs (v_msg->issuer_attribute_len) - 1;
1501 struct GNUNET_ABD_Delegate delegates[delegate_count];
1502 memset (delegates,
1503 0,
1504 sizeof (struct GNUNET_ABD_Delegate) * delegate_count);
1505 delegate_data = (char *) &v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1;
1506 if (GNUNET_OK != GNUNET_ABD_delegates_deserialize (delegate_data_size,
1507 delegate_data,
1508 delegate_count,
1509 delegates))
1510 {
1511 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize delegates!\n");
1513 return;
1514 }
1515
1516 // Prepare vrh delegation chain for later validation
1517 for (uint32_t i = 0; i < delegate_count; i++)
1518 {
1519 del_entry = GNUNET_new (struct DelegateRecordEntry);
1520 del_entry->delegate =
1521 GNUNET_malloc (sizeof (struct GNUNET_ABD_Delegate)
1522 + delegates[i].issuer_attribute_len + 1);
1523 GNUNET_memcpy (del_entry->delegate,
1524 &delegates[i],
1525 sizeof (struct GNUNET_ABD_Delegate));
1526 GNUNET_memcpy (&del_entry->delegate[1],
1527 delegates[i].issuer_attribute,
1528 delegates[i].issuer_attribute_len);
1529 del_entry->delegate->issuer_attribute_len =
1530 delegates[i].issuer_attribute_len;
1531 del_entry->delegate->issuer_attribute = (char *) &del_entry->delegate[1];
1533 vrh->del_chain_tail,
1534 del_entry);
1535 vrh->del_chain_size++;
1536 }
1537
1538 // Switch resolution algo
1541 {
1543 return;
1545 }
1547 {
1549 }
1551 {
1553 }
1554}
1555
1556
1557static void
1559{
1560 struct VerifyRequestHandle *vrh = cls;
1562 "Got disconnected from namestore database.\n");
1563 vrh->dele_qe = NULL;
1565}
1566
1567
1568static void
1570{
1571 struct VerifyRequestHandle *vrh = cls;
1572 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting delegates.\n");
1573
1574 // if both are set: bidirectional search, meaning start both chain resolutions
1577 {
1578 // if premature match found don't start bw resolution
1580 return;
1582 }
1584 {
1586 }
1588 {
1590 }
1591}
1592
1593
1594static void
1596 const struct GNUNET_CRYPTO_PrivateKey *key,
1597 const char *label,
1598 unsigned int rd_count,
1599 const struct GNUNET_GNSRECORD_Data *rd)
1600{
1601 struct VerifyRequestHandle *vrh = cls;
1602 struct DelegateRecordEntry *del_entry;
1603 vrh->dele_qe = NULL;
1604
1605 for (uint32_t i = 0; i < rd_count; i++)
1606 {
1607 if (GNUNET_GNSRECORD_TYPE_DELEGATE != rd[i].record_type)
1608 continue;
1609 // only add the entries that are explicitly marked as private
1610 // and therefore symbolize the end of a chain
1611 if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
1612 continue;
1613 del_entry = GNUNET_new (struct DelegateRecordEntry);
1614 del_entry->delegate = GNUNET_ABD_delegate_deserialize (rd[i].data, rd[i].
1615 data_size);
1616 if (NULL == del_entry->delegate)
1617 {
1618 GNUNET_free (del_entry);
1619 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid delegate found\n");
1620 continue;
1621 }
1623 vrh->del_chain_tail,
1624 del_entry);
1625 vrh->del_chain_size++;
1626 }
1627
1629}
1630
1631
1632static void
1633handle_collect (void *cls, const struct CollectMessage *c_msg)
1634{
1635 char attr[GNUNET_ABD_MAX_LENGTH + 1];
1636 char issuer_attribute[GNUNET_ABD_MAX_LENGTH + 1];
1637 struct VerifyRequestHandle *vrh;
1638 struct GNUNET_SERVICE_Client *client = cls;
1639 char *attrptr = attr;
1640 const char *utf_in;
1641
1642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n");
1643
1644 utf_in = (const char *) &c_msg[1];
1645 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
1646
1647 GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len));
1648 issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0';
1649 vrh = GNUNET_new (struct VerifyRequestHandle);
1650 vrh->is_collect = true;
1652 vrh->client = client;
1653 vrh->request_id = c_msg->id;
1654 vrh->issuer_key = c_msg->issuer_key;
1656 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
1657 vrh->resolution_algo = ntohs (c_msg->resolution_algo);
1658
1659 vrh->del_chain_head = NULL;
1660 vrh->del_chain_tail = NULL;
1661 vrh->dsq_head = NULL;
1662 vrh->dsq_tail = NULL;
1663 vrh->del_chain_head = NULL;
1664 vrh->del_chain_tail = NULL;
1665
1666 if (0 == strlen (issuer_attribute))
1667 {
1668 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
1670 return;
1671 }
1672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting delegates for subject\n");
1673
1674 // Get all delegates from subject
1675 vrh->dele_qe =
1677 &c_msg->subject_key,
1680 vrh,
1682 vrh);
1684}
1685
1686
1687static int
1688check_collect (void *cls, const struct CollectMessage *c_msg)
1689{
1690 size_t msg_size;
1691 const char *attr;
1692
1693 msg_size = ntohs (c_msg->header.size);
1694 if (msg_size < sizeof (struct CollectMessage))
1695 {
1696 GNUNET_break (0);
1697 return GNUNET_SYSERR;
1698 }
1699 if (ntohs (c_msg->issuer_attribute_len) > GNUNET_ABD_MAX_LENGTH)
1700 {
1701 GNUNET_break (0);
1702 return GNUNET_SYSERR;
1703 }
1704 attr = (const char *) &c_msg[1];
1705
1706 if (('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) ||
1707 (strlen (attr) > GNUNET_ABD_MAX_LENGTH))
1708 {
1709 GNUNET_break (0);
1710 return GNUNET_SYSERR;
1711 }
1712 return GNUNET_OK;
1713}
1714
1715
1716static void
1718 struct GNUNET_SERVICE_Client *client,
1719 void *app_ctx)
1720{
1721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
1722}
1723
1724
1725static void *
1727 struct GNUNET_SERVICE_Client *client,
1728 struct GNUNET_MQ_Handle *mq)
1729{
1730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
1731 return client;
1732}
1733
1734
1742static void
1743run (void *cls,
1744 const struct GNUNET_CONFIGURATION_Handle *c,
1746{
1747
1748 gns = GNUNET_GNS_connect (c);
1749 if (NULL == gns)
1750 {
1751 fprintf (stderr, _ ("Failed to connect to GNS\n"));
1752 }
1754 if (NULL == namestore)
1755 {
1756 fprintf (stderr, _ ("Failed to connect to namestore\n"));
1757 }
1758
1761}
1762
1763
1769 "abd",
1771 &run,
1774 NULL,
1777 struct VerifyMessage,
1778 NULL),
1781 struct CollectMessage,
1782 NULL),
1784
1785/* end of gnunet-service-abd.c */
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
IPC messages between ABD API and ABD service.
struct GNUNET_ABD_Delegate * GNUNET_ABD_delegate_deserialize(const char *data, size_t data_size)
int GNUNET_ABD_delegates_deserialize(size_t len, const char *src, unsigned int c_count, struct GNUNET_ABD_Delegate *cd)
Deserialize the given destination.
int GNUNET_ABD_delegation_set_deserialize(size_t len, const char *src, unsigned int d_count, struct GNUNET_ABD_DelegationSet *dsr)
Deserialize the given destination.
ssize_t GNUNET_ABD_delegation_chain_serialize(unsigned int d_count, const struct GNUNET_ABD_Delegation *dd, unsigned int c_count, const struct GNUNET_ABD_Delegate *cd, size_t dest_size, char *dest)
Serizalize the given delegation chain entries and abd.
size_t GNUNET_ABD_delegation_chain_get_size(unsigned int d_count, const struct GNUNET_ABD_Delegation *dd, unsigned int c_count, const struct GNUNET_ABD_Delegate *cd)
Calculate how many bytes we will need to serialize the given delegation chain and abd.
API to serialize and deserialize delegation chains and abds.
#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE
For ABD reverse lookups.
#define GNUNET_GNSRECORD_TYPE_DELEGATE
For ABD policies.
static int collect
Collect mode.
Definition: gnunet-abd.c:133
static int verify
Verify mode.
Definition: gnunet-abd.c:128
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static int del
Desired action is to remove a record.
static size_t data_size
Number of bytes in data.
static void handle_collect(void *cls, const struct CollectMessage *c_msg)
static struct GNUNET_GNS_Handle * gns
Handle to GNS service.
static struct VerifyRequestHandle * vrh_tail
Tail of the DLL.
static void forward_resolution(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
static int delegation_chain_bw_resolution_start(void *cls)
Result from GNS lookup.
static void cleanup_handle(struct VerifyRequestHandle *vrh)
static int check_verify(void *cls, const struct VerifyMessage *v_msg)
static struct VerifyRequestHandle * vrh_head
Head of the DLL.
GNUNET_SERVICE_MAIN(GNUNET_OS_project_data_gnunet(), "abd", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(verify, GNUNET_MESSAGE_TYPE_ABD_VERIFY, struct VerifyMessage, NULL), GNUNET_MQ_hd_var_size(collect, GNUNET_MESSAGE_TYPE_ABD_COLLECT, struct CollectMessage, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
static void handle_delegate_collection_error_cb(void *cls)
static void shutdown_task(void *cls)
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
static int handle_bidirectional_match(struct DelegationSetQueueEntry *actual_entry, struct DelegationSetQueueEntry *match_entry, struct VerifyRequestHandle *vrh)
static int delegation_chain_fw_resolution_start(void *cls)
static void cleanup_dsq_entry(struct DelegationSetQueueEntry *ds_entry)
static struct GNUNET_NAMESTORE_Handle * namestore
Handle to namestore service.
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *handle)
Process Credential requests.
static void delegate_collection_finished(void *cls)
static char * partial_match(char *tmp_trail, char *tmp_subattr, char *parent_trail, char *issuer_attribute)
static void send_intermediate_response(struct VerifyRequestHandle *vrh, struct DelegationChainEntry *ch_entry, bool is_bw)
static void print_deleset(struct DelegationSetQueueEntry *dsentry, const char *text)
static void backward_resolution(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
static void handle_verify(void *cls, const struct VerifyMessage *v_msg)
static int check_collect(void *cls, const struct CollectMessage *c_msg)
static void send_lookup_response(struct VerifyRequestHandle *vrh)
#define GNUNET_ABD_MAX_LENGTH
static void handle_delegate_collection_cb(void *cls, const struct GNUNET_CRYPTO_PrivateKey *key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
API to the Credential service.
API to the GNS service.
API that can be used to manipulate GNS record data.
Identity service; implements identity management for GNUnet.
API that can be used to store naming information on a GNUnet node;.
Constants for network protocols.
API to create, modify and access statistics.
GNUNET_ABD_AlgoDirectionFlags
@ GNUNET_ABD_FLAG_BACKWARD
@ GNUNET_ABD_FLAG_FORWARD
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
Definition: gns_api.c:289
struct GNUNET_GNS_LookupRequest * GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle, const char *name, const struct GNUNET_CRYPTO_PublicKey *zone, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS.
Definition: gns_api.c:421
void * GNUNET_GNS_lookup_cancel(struct GNUNET_GNS_LookupRequest *lr)
Cancel pending lookup request.
Definition: gns_api.c:313
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
Definition: gns_api.c:267
@ GNUNET_GNS_LO_DEFAULT
Defaults, look in cache, then in DHT.
#define GNUNET_GNS_EMPTY_LABEL_AT
String we use to indicate an empty label (top-level entry in the zone).
@ GNUNET_GNSRECORD_RF_PRIVATE
This is a private record of this peer and it should thus not be published.
#define GNUNET_log(kind,...)
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
Definition: crypto_pkey.c:379
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: crypto_pkey.c:430
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:61
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#define GNUNET_MESSAGE_TYPE_ABD_VERIFY_RESULT
#define GNUNET_MESSAGE_TYPE_ABD_INTERMEDIATE_RESULT
#define GNUNET_MESSAGE_TYPE_ABD_COLLECT
#define GNUNET_MESSAGE_TYPE_ABD_VERIFY
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1339
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2500
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2389
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:459
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
Message from client to Credential service to collect credentials.
Definition: abd.h:36
struct GNUNET_CRYPTO_PublicKey issuer_key
Trust anchor.
Definition: abd.h:50
uint16_t resolution_algo
Direction of the resolution algo.
Definition: abd.h:60
uint16_t issuer_attribute_len
Length of the issuer attribute.
Definition: abd.h:55
struct GNUNET_CRYPTO_PrivateKey subject_key
Subject public key.
Definition: abd.h:45
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_ABD_VERIFY.
Definition: abd.h:40
uint32_t id
Unique identifier for this request (for key collisions).
Definition: abd.h:65
uint32_t refcount
Number of references in delegation chains.
struct DelegateRecordEntry * prev
DLL.
struct GNUNET_ABD_Delegate * delegate
Payload.
struct DelegateRecordEntry * next
DLL.
struct DelegationChainEntry * prev
DLL.
char * subject_attribute
The delegated attribute.
struct GNUNET_CRYPTO_PublicKey issuer_key
The issuer.
struct DelegationChainEntry * next
DLL.
struct GNUNET_CRYPTO_PublicKey subject_key
The subject.
char * issuer_attribute
The issued attribute.
Message from ABD service to client: new results.
Definition: abd.h:152
uint32_t id
Unique identifier for this request (for key collisions).
Definition: abd.h:161
Message from ABD service to client: new results.
Definition: abd.h:119
uint32_t del_found
Indicates if credential has been found at all.
Definition: abd.h:133
uint32_t d_count
The number of delegations in the response.
Definition: abd.h:138
uint32_t id
Unique identifier for this request (for key collisions).
Definition: abd.h:128
uint32_t c_count
The number of credentials in the response.
Definition: abd.h:143
DLL used for delegations Used for OR delegations.
struct DelegationQueueEntry * next
DLL.
struct DelegationQueueEntry * prev
DLL.
uint32_t required_solutions
Required solutions.
struct DelegationSetQueueEntry * parent_set
Parent set.
DLL for delegation sets Used for AND delegation set.
char * lookup_attribute
The current attribute to look up.
struct DelegationQueueEntry * parent_queue_entry
Parent QueueEntry.
char * attr_trailer
Trailing attribute context.
struct DelegationSetQueueEntry * prev
DLL.
char * issuer_attribute
Issuer attribute delegated to.
struct DelegationChainEntry * delegation_chain_entry
The delegation chain entry.
struct VerifyRequestHandle * handle
Verify handle.
struct DelegationQueueEntry * parent
Parent attribute delegation.
char * unresolved_attribute_delegation
Still to resolve delegation as string.
struct DelegationQueueEntry * queue_entries_head
Queue entries of this set.
struct GNUNET_CRYPTO_PublicKey * issuer_key
Issuer key.
struct DelegationSetQueueEntry * next
DLL.
struct DelegationQueueEntry * queue_entries_tail
Queue entries of this set.
bool from_bw
True if added by backward resolution.
struct GNUNET_GNS_LookupRequest * lookup_request
GNS handle.
const char * subject_attribute
The subject attribute.
const char * issuer_attribute
The issuer attribute.
uint32_t issuer_attribute_len
Length of the issuer attribute.
uint32_t subject_attribute_len
Length of the subject attribute.
struct GNUNET_CRYPTO_Signature signature
Signature of this credential.
struct GNUNET_CRYPTO_PublicKey issuer_key
The issuer of the credential.
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
struct GNUNET_CRYPTO_PublicKey subject_key
Public key of the subject this credential was issued to.
The attribute delegation record.
The attribute delegation record.
const char * subject_attribute
The subject attribute.
struct GNUNET_CRYPTO_PublicKey subject_key
Public key of the subject this attribute was delegated to.
uint32_t issuer_attribute_len
Length of the attribute.
uint32_t subject_attribute_len
Length of the attribute.
struct GNUNET_CRYPTO_PublicKey subject_key
Public key of the subject this attribute was delegated to.
const char * issuer_attribute
The attribute.
const char * subject_attribute
The attribute.
struct GNUNET_CRYPTO_PublicKey issuer_key
The issuer of the delegation.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
const void * data
Binary value stored in the DNS record.
Connection to the GNS service.
Definition: gns_api.h:36
Handle to a lookup request.
Definition: gns_api.c:48
Handle to a message queue.
Definition: mq.c:87
Connection to the NAMESTORE service.
An QueueEntry used to store information for a pending NAMESTORE record operation.
Definition: namestore_api.c:49
Handle to a client that is connected to a service.
Definition: service.c:249
Handle to a service.
Definition: service.c:116
Handle for the service.
Message from client to Credential service to verify attributes.
Definition: abd.h:75
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_ABD_VERIFY.
Definition: abd.h:79
uint16_t resolution_algo
Direction of the resolution algo.
Definition: abd.h:104
struct GNUNET_CRYPTO_PublicKey subject_key
Subject public key.
Definition: abd.h:84
uint32_t id
Unique identifier for this request (for key collisions).
Definition: abd.h:109
uint32_t d_count
Number of delegates.
Definition: abd.h:94
uint16_t issuer_attribute_len
Length of the issuer attribute.
Definition: abd.h:99
struct GNUNET_CRYPTO_PublicKey issuer_key
Trust anchor.
Definition: abd.h:89
Handle to a lookup operation from api.
struct VerifyRequestHandle * prev
We keep these in a DLL.
struct GNUNET_NAMESTORE_QueueEntry * dele_qe
Delegate iterator for lookup.
struct GNUNET_SERVICE_Client * client
Handle to the requesting client.
struct GNUNET_CRYPTO_PublicKey subject_key
Subject public key.
uint32_t request_id
request id
struct DelegationQueueEntry * current_delegation
Current Delegation Pointer.
struct VerifyRequestHandle * next
We keep these in a DLL.
enum GNUNET_ABD_AlgoDirectionFlags resolution_algo
Direction of the resolution algo.
uint32_t del_chain_size
Delegate DLL size.
uint64_t pending_lookups
Pending lookups.
struct DelegationSetQueueEntry * dsq_head
List for bidirectional matching.
uint32_t delegation_chain_size
Size of delegation tree.
struct DelegationSetQueueEntry * dsq_tail
List for bidirectional matching.
struct GNUNET_CRYPTO_PublicKey issuer_key
Issuer public key.
struct DelegationChainEntry * delegation_chain_tail
Children of this attribute.
struct DelegateRecordEntry * del_chain_head
Delegate DLL.
bool is_collect
True if created by a collect request.
struct DelegateRecordEntry * del_chain_tail
Delegate DLL.
char * issuer_attribute
Issuer attribute.
struct DelegationChainEntry * delegation_chain_head
Children of this attribute.