aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/gnunet-reclaim.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reclaim/gnunet-reclaim.c')
-rw-r--r--src/reclaim/gnunet-reclaim.c221
1 files changed, 114 insertions, 107 deletions
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c
index 6bef5b6fe..ab281a645 100644
--- a/src/reclaim/gnunet-reclaim.c
+++ b/src/reclaim/gnunet-reclaim.c
@@ -43,29 +43,34 @@ static int ret;
43static int list; 43static int list;
44 44
45/** 45/**
46 * List attestations flag 46 * List credentials flag
47 */ 47 */
48static int list_attestations; 48static int list_credentials;
49 49
50/** 50/**
51 * Attestation ID string 51 * Credential ID string
52 */ 52 */
53static char *attestation_id; 53static char *credential_id;
54 54
55/** 55/**
56 * Attestation ID 56 * Credential ID
57 */ 57 */
58static struct GNUNET_RECLAIM_Identifier attestation; 58static struct GNUNET_RECLAIM_Identifier credential;
59 59
60/** 60/**
61 * Attestation name 61 * Credential name
62 */ 62 */
63static char *attestation_name; 63static char *credential_name;
64 64
65/** 65/**
66 * Attestation exists 66 * Credential type
67 */ 67 */
68static int attestation_exists; 68static char *credential_type;
69
70/**
71 * Credential exists
72 */
73static int credential_exists;
69 74
70/** 75/**
71 * Relying party 76 * Relying party
@@ -133,9 +138,9 @@ static struct GNUNET_RECLAIM_Operation *reclaim_op;
133static struct GNUNET_RECLAIM_AttributeIterator *attr_iterator; 138static struct GNUNET_RECLAIM_AttributeIterator *attr_iterator;
134 139
135/** 140/**
136 * Attestation iterator 141 * Credential iterator
137 */ 142 */
138static struct GNUNET_RECLAIM_AttestationIterator *attest_iterator; 143static struct GNUNET_RECLAIM_CredentialIterator *cred_iterator;
139 144
140 145
141/** 146/**
@@ -143,10 +148,6 @@ static struct GNUNET_RECLAIM_AttestationIterator *attest_iterator;
143 */ 148 */
144static struct GNUNET_RECLAIM_TicketIterator *ticket_iterator; 149static struct GNUNET_RECLAIM_TicketIterator *ticket_iterator;
145 150
146/**
147 * Master ABE key
148 */
149static struct GNUNET_CRYPTO_AbeMasterKey *abe_key;
150 151
151/** 152/**
152 * ego private key 153 * ego private key
@@ -208,25 +209,27 @@ do_cleanup (void *cls)
208 GNUNET_RECLAIM_cancel (reclaim_op); 209 GNUNET_RECLAIM_cancel (reclaim_op);
209 if (NULL != attr_iterator) 210 if (NULL != attr_iterator)
210 GNUNET_RECLAIM_get_attributes_stop (attr_iterator); 211 GNUNET_RECLAIM_get_attributes_stop (attr_iterator);
211 if (NULL != attest_iterator) 212 if (NULL != cred_iterator)
212 GNUNET_RECLAIM_get_attestations_stop (attest_iterator); 213 GNUNET_RECLAIM_get_credentials_stop (cred_iterator);
213 if (NULL != ticket_iterator) 214 if (NULL != ticket_iterator)
214 GNUNET_RECLAIM_ticket_iteration_stop (ticket_iterator); 215 GNUNET_RECLAIM_ticket_iteration_stop (ticket_iterator);
215 if (NULL != reclaim_handle) 216 if (NULL != reclaim_handle)
216 GNUNET_RECLAIM_disconnect (reclaim_handle); 217 GNUNET_RECLAIM_disconnect (reclaim_handle);
217 if (NULL != identity_handle) 218 if (NULL != identity_handle)
218 GNUNET_IDENTITY_disconnect (identity_handle); 219 GNUNET_IDENTITY_disconnect (identity_handle);
219 if (NULL != abe_key)
220 GNUNET_free (abe_key);
221 if (NULL != attr_list) 220 if (NULL != attr_list)
222 GNUNET_free (attr_list); 221 GNUNET_free (attr_list);
223 if (NULL != attr_to_delete) 222 if (NULL != attr_to_delete)
224 GNUNET_free (attr_to_delete); 223 GNUNET_free (attr_to_delete);
224 if (NULL == credential_type)
225 GNUNET_free (credential_type);
225} 226}
226 227
227 228
228static void 229static void
229ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) 230ticket_issue_cb (void *cls,
231 const struct GNUNET_RECLAIM_Ticket *ticket,
232 const struct GNUNET_RECLAIM_PresentationList *presentations)
230{ 233{
231 char *ticket_str; 234 char *ticket_str;
232 235
@@ -260,7 +263,7 @@ static void
260process_attrs (void *cls, 263process_attrs (void *cls,
261 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 264 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
262 const struct GNUNET_RECLAIM_Attribute *attr, 265 const struct GNUNET_RECLAIM_Attribute *attr,
263 const struct GNUNET_RECLAIM_Attestation *attest) 266 const struct GNUNET_RECLAIM_Presentation *presentation)
264{ 267{
265 char *value_str; 268 char *value_str;
266 char *id; 269 char *id;
@@ -280,7 +283,7 @@ process_attrs (void *cls,
280 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type); 283 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type);
281 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id)); 284 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id));
282 value_str = NULL; 285 value_str = NULL;
283 if (NULL == attest) 286 if (NULL == presentation)
284 { 287 {
285 value_str = GNUNET_RECLAIM_attribute_value_to_string (attr->type, 288 value_str = GNUNET_RECLAIM_attribute_value_to_string (attr->type,
286 attr->data, 289 attr->data,
@@ -290,7 +293,7 @@ process_attrs (void *cls,
290 { 293 {
291 struct GNUNET_RECLAIM_AttributeListEntry *ale; 294 struct GNUNET_RECLAIM_AttributeListEntry *ale;
292 struct GNUNET_RECLAIM_AttributeList *al 295 struct GNUNET_RECLAIM_AttributeList *al
293 = GNUNET_RECLAIM_attestation_get_attributes (attest); 296 = GNUNET_RECLAIM_presentation_get_attributes (presentation);
294 297
295 for (ale = al->list_head; NULL != ale; ale = ale->next) 298 for (ale = al->list_head; NULL != ale; ale = ale->next)
296 { 299 {
@@ -298,10 +301,8 @@ process_attrs (void *cls,
298 continue; 301 continue;
299 value_str 302 value_str
300 = GNUNET_RECLAIM_attribute_value_to_string (ale->attribute->type, 303 = GNUNET_RECLAIM_attribute_value_to_string (ale->attribute->type,
301 ale->attribute-> 304 ale->attribute->data,
302 data, 305 ale->attribute->data_size);
303 ale->attribute->
304 data_size);
305 break; 306 break;
306 } 307 }
307 } 308 }
@@ -312,7 +313,7 @@ process_attrs (void *cls,
312 attr_type, 313 attr_type,
313 attr->flag, 314 attr->flag,
314 id, 315 id,
315 (NULL == attest) ? "" : "(ATTESTED)"); 316 (NULL == presentation) ? "" : "(ATTESTED)");
316 GNUNET_free (value_str); 317 GNUNET_free (value_str);
317 GNUNET_free (id); 318 GNUNET_free (id);
318} 319}
@@ -362,7 +363,7 @@ static void
362iter_error (void *cls) 363iter_error (void *cls)
363{ 364{
364 attr_iterator = NULL; 365 attr_iterator = NULL;
365 attest_iterator = NULL; 366 cred_iterator = NULL;
366 fprintf (stderr, "Failed\n"); 367 fprintf (stderr, "Failed\n");
367 368
368 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 369 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
@@ -457,6 +458,7 @@ iter_finished (void *cls)
457 if (NULL == attr_to_delete) 458 if (NULL == attr_to_delete)
458 { 459 {
459 fprintf (stdout, "No such attribute ``%s''\n", attr_delete); 460 fprintf (stdout, "No such attribute ``%s''\n", attr_delete);
461 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
460 return; 462 return;
461 } 463 }
462 reclaim_op = GNUNET_RECLAIM_attribute_delete (reclaim_handle, 464 reclaim_op = GNUNET_RECLAIM_attribute_delete (reclaim_handle,
@@ -489,9 +491,9 @@ iter_finished (void *cls)
489 claim = 491 claim =
490 GNUNET_RECLAIM_attribute_new (attr_name, NULL, type, data, data_size); 492 GNUNET_RECLAIM_attribute_new (attr_name, NULL, type, data, data_size);
491 } 493 }
492 if (NULL != attestation_id) 494 if (NULL != credential_id)
493 { 495 {
494 claim->attestation = attestation; 496 claim->credential = credential;
495 } 497 }
496 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle, 498 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle,
497 pkey, 499 pkey,
@@ -524,7 +526,7 @@ iter_cb (void *cls,
524 if (0 == strcasecmp (attr_name, attr->name)) 526 if (0 == strcasecmp (attr_name, attr->name))
525 { 527 {
526 claim = GNUNET_RECLAIM_attribute_new (attr->name, 528 claim = GNUNET_RECLAIM_attribute_new (attr->name,
527 &attr->attestation, 529 &attr->credential,
528 attr->type, 530 attr->type,
529 attr->data, 531 attr->data,
530 attr->data_size); 532 attr->data_size);
@@ -543,7 +545,7 @@ iter_cb (void *cls,
543 } 545 }
544 le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); 546 le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
545 le->attribute = GNUNET_RECLAIM_attribute_new (attr->name, 547 le->attribute = GNUNET_RECLAIM_attribute_new (attr->name,
546 &attr->attestation, 548 &attr->credential,
547 attr->type, 549 attr->type,
548 attr->data, 550 attr->data,
549 attr->data_size); 551 attr->data_size);
@@ -562,7 +564,7 @@ iter_cb (void *cls,
562 if (0 == strcasecmp (attr_delete, label)) 564 if (0 == strcasecmp (attr_delete, label))
563 { 565 {
564 attr_to_delete = GNUNET_RECLAIM_attribute_new (attr->name, 566 attr_to_delete = GNUNET_RECLAIM_attribute_new (attr->name,
565 &attr->attestation, 567 &attr->credential,
566 attr->type, 568 attr->type,
567 attr->data, 569 attr->data,
568 attr->data_size); 570 attr->data_size);
@@ -577,7 +579,7 @@ iter_cb (void *cls,
577 attr->data_size); 579 attr->data_size);
578 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type); 580 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type);
579 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id)); 581 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id));
580 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attr->attestation)) 582 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attr->credential))
581 { 583 {
582 fprintf (stdout, 584 fprintf (stdout,
583 "%s: ``%s'' (%s); ID: %s\n", 585 "%s: ``%s'' (%s); ID: %s\n",
@@ -588,17 +590,17 @@ iter_cb (void *cls,
588 } 590 }
589 else 591 else
590 { 592 {
591 char *attest_id = 593 char *cred_id =
592 GNUNET_STRINGS_data_to_string_alloc (&attr->attestation, 594 GNUNET_STRINGS_data_to_string_alloc (&attr->credential,
593 sizeof(attr->attestation)); 595 sizeof(attr->credential));
594 fprintf (stdout, 596 fprintf (stdout,
595 "%s: <``%s'' in attestation %s> (%s); ID: %s\n", 597 "%s: ``%s'' in credential presentation `%s' (%s); ID: %s\n",
596 attr->name, 598 attr->name,
597 attr_str, 599 attr_str,
598 attest_id, 600 cred_id,
599 attr_type, 601 attr_type,
600 id); 602 id);
601 GNUNET_free (attest_id); 603 GNUNET_free (cred_id);
602 604
603 } 605 }
604 GNUNET_free (id); 606 GNUNET_free (id);
@@ -608,29 +610,31 @@ iter_cb (void *cls,
608 610
609 611
610static void 612static void
611attest_iter_finished (void *cls) 613cred_iter_finished (void *cls)
612{ 614{
613 attest_iterator = NULL; 615 cred_iterator = NULL;
614 616
615 // Add new attestation 617 // Add new credential
616 if ((NULL != attestation_name) && 618 if ((NULL != credential_name) &&
617 (NULL != attr_value)) 619 (NULL != attr_value))
618 { 620 {
619 struct GNUNET_RECLAIM_Attestation *attestation = 621 enum GNUNET_RECLAIM_CredentialType ctype =
620 GNUNET_RECLAIM_attestation_new (attestation_name, 622 GNUNET_RECLAIM_credential_typename_to_number (credential_type);
621 GNUNET_RECLAIM_ATTESTATION_TYPE_JWT, // FIXME hardcoded 623 struct GNUNET_RECLAIM_Credential *credential =
622 attr_value, 624 GNUNET_RECLAIM_credential_new (credential_name,
623 strlen (attr_value)); 625 ctype,
624 reclaim_op = GNUNET_RECLAIM_attestation_store (reclaim_handle, 626 attr_value,
625 pkey, 627 strlen (attr_value));
626 attestation, 628 reclaim_op = GNUNET_RECLAIM_credential_store (reclaim_handle,
627 &exp_interval, 629 pkey,
628 store_cont, 630 credential,
629 NULL); 631 &exp_interval,
632 store_cont,
633 NULL);
630 return; 634 return;
631 635
632 } 636 }
633 if (list_attestations) 637 if (list_credentials)
634 { 638 {
635 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 639 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
636 return; 640 return;
@@ -648,34 +652,34 @@ attest_iter_finished (void *cls)
648 652
649 653
650static void 654static void
651attest_iter_cb (void *cls, 655cred_iter_cb (void *cls,
652 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 656 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
653 const struct GNUNET_RECLAIM_Attestation *attest) 657 const struct GNUNET_RECLAIM_Credential *cred)
654{ 658{
655 char *attest_str; 659 char *cred_str;
656 char *attr_str; 660 char *attr_str;
657 char *id; 661 char *id;
658 const char *attest_type; 662 const char *cred_type;
659 struct GNUNET_RECLAIM_AttributeListEntry *ale; 663 struct GNUNET_RECLAIM_AttributeListEntry *ale;
660 664
661 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (&attestation, 665 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (&credential,
662 &attest->id)) 666 &cred->id))
663 attestation_exists = GNUNET_YES; 667 credential_exists = GNUNET_YES;
664 if (list_attestations) 668 if (list_credentials)
665 { 669 {
666 attest_str = GNUNET_RECLAIM_attestation_value_to_string (attest->type, 670 cred_str = GNUNET_RECLAIM_credential_value_to_string (cred->type,
667 attest->data, 671 cred->data,
668 attest->data_size); 672 cred->data_size);
669 attest_type = GNUNET_RECLAIM_attestation_number_to_typename (attest->type); 673 cred_type = GNUNET_RECLAIM_credential_number_to_typename (cred->type);
670 id = GNUNET_STRINGS_data_to_string_alloc (&attest->id, sizeof(attest->id)); 674 id = GNUNET_STRINGS_data_to_string_alloc (&cred->id, sizeof(cred->id));
671 fprintf (stdout, 675 fprintf (stdout,
672 "%s: ``%s'' (%s); ID: %s\n", 676 "%s: ``%s'' (%s); ID: %s\n",
673 attest->name, 677 cred->name,
674 attest_str, 678 cred_str,
675 attest_type, 679 cred_type,
676 id); 680 id);
677 struct GNUNET_RECLAIM_AttributeList *attrs = 681 struct GNUNET_RECLAIM_AttributeList *attrs =
678 GNUNET_RECLAIM_attestation_get_attributes (attest); 682 GNUNET_RECLAIM_credential_get_attributes (cred);
679 if (NULL != attrs) 683 if (NULL != attrs)
680 { 684 {
681 fprintf (stdout, 685 fprintf (stdout,
@@ -684,11 +688,8 @@ attest_iter_cb (void *cls,
684 { 688 {
685 attr_str = GNUNET_RECLAIM_attribute_value_to_string ( 689 attr_str = GNUNET_RECLAIM_attribute_value_to_string (
686 ale->attribute->type, 690 ale->attribute->type,
687 ale->attribute-> 691 ale->attribute->data,
688 data, 692 ale->attribute->data_size);
689 ale->attribute->
690 data_size);
691
692 fprintf (stdout, 693 fprintf (stdout,
693 "\t %s: %s\n", ale->attribute->name, attr_str); 694 "\t %s: %s\n", ale->attribute->name, attr_str);
694 GNUNET_free (attr_str); 695 GNUNET_free (attr_str);
@@ -697,7 +698,7 @@ attest_iter_cb (void *cls,
697 } 698 }
698 GNUNET_free (id); 699 GNUNET_free (id);
699 } 700 }
700 GNUNET_RECLAIM_get_attestations_next (attest_iterator); 701 GNUNET_RECLAIM_get_credentials_next (cred_iterator);
701} 702}
702 703
703 704
@@ -710,12 +711,14 @@ start_process ()
710 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 711 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
711 return; 712 return;
712 } 713 }
713 attestation = GNUNET_RECLAIM_ID_ZERO; 714 if (NULL == credential_type)
714 if (NULL != attestation_id) 715 credential_type = GNUNET_strdup ("JWT");
715 GNUNET_STRINGS_string_to_data (attestation_id, 716 credential = GNUNET_RECLAIM_ID_ZERO;
716 strlen (attestation_id), 717 if (NULL != credential_id)
717 &attestation, sizeof(attestation)); 718 GNUNET_STRINGS_string_to_data (credential_id,
718 attestation_exists = GNUNET_NO; 719 strlen (credential_id),
720 &credential, sizeof(credential));
721 credential_exists = GNUNET_NO;
719 if (list_tickets) 722 if (list_tickets)
720 { 723 {
721 ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle, 724 ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle,
@@ -750,15 +753,14 @@ start_process ()
750 753
751 attr_list = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 754 attr_list = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
752 claim = NULL; 755 claim = NULL;
753 attest_iterator = GNUNET_RECLAIM_get_attestations_start (reclaim_handle, 756 cred_iterator = GNUNET_RECLAIM_get_credentials_start (reclaim_handle,
754 pkey, 757 pkey,
755 &iter_error, 758 &iter_error,
756 NULL, 759 NULL,
757 &attest_iter_cb, 760 &cred_iter_cb,
758 NULL, 761 NULL,
759 & 762 &cred_iter_finished,
760 attest_iter_finished, 763 NULL);
761 NULL);
762 764
763} 765}
764 766
@@ -856,20 +858,20 @@ main (int argc, char *const argv[])
856 gettext_noop ("List attributes for EGO"), 858 gettext_noop ("List attributes for EGO"),
857 &list), 859 &list),
858 GNUNET_GETOPT_option_flag ('A', 860 GNUNET_GETOPT_option_flag ('A',
859 "attestations", 861 "credentials",
860 gettext_noop ("List attestations for EGO"), 862 gettext_noop ("List credentials for EGO"),
861 &list_attestations), 863 &list_credentials),
862 GNUNET_GETOPT_option_string ('I', 864 GNUNET_GETOPT_option_string ('I',
863 "Attestation ID", 865 "Credential ID",
864 "ATTESTATION_ID", 866 "CREDENTIAL_ID",
865 gettext_noop ( 867 gettext_noop (
866 "Attestation to use for attribute"), 868 "Credential to use for attribute"),
867 &attestation_id), 869 &credential_id),
868 GNUNET_GETOPT_option_string ('N', 870 GNUNET_GETOPT_option_string ('N',
869 "attestation-name", 871 "credential-name",
870 "NAME", 872 "NAME",
871 gettext_noop ("Attestation name"), 873 gettext_noop ("Credential name"),
872 &attestation_name), 874 &credential_name),
873 GNUNET_GETOPT_option_string ('i', 875 GNUNET_GETOPT_option_string ('i',
874 "issue", 876 "issue",
875 "A1,A2,...", 877 "A1,A2,...",
@@ -891,6 +893,11 @@ main (int argc, char *const argv[])
891 "TYPE", 893 "TYPE",
892 gettext_noop ("Type of attribute"), 894 gettext_noop ("Type of attribute"),
893 &type_str), 895 &type_str),
896 GNUNET_GETOPT_option_string ('u',
897 "credential-type",
898 "TYPE",
899 gettext_noop ("Type of credential"),
900 &credential_type),
894 GNUNET_GETOPT_option_flag ('T', 901 GNUNET_GETOPT_option_flag ('T',
895 "tickets", 902 "tickets",
896 gettext_noop ("List tickets of ego"), 903 gettext_noop ("List tickets of ego"),