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.c216
1 files changed, 110 insertions, 106 deletions
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c
index 6bef5b6fe..a59053f5f 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,20 +209,20 @@ 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
@@ -260,7 +261,7 @@ static void
260process_attrs (void *cls, 261process_attrs (void *cls,
261 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 262 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
262 const struct GNUNET_RECLAIM_Attribute *attr, 263 const struct GNUNET_RECLAIM_Attribute *attr,
263 const struct GNUNET_RECLAIM_Attestation *attest) 264 const struct GNUNET_RECLAIM_Presentation *presentation)
264{ 265{
265 char *value_str; 266 char *value_str;
266 char *id; 267 char *id;
@@ -280,7 +281,7 @@ process_attrs (void *cls,
280 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type); 281 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type);
281 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id)); 282 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id));
282 value_str = NULL; 283 value_str = NULL;
283 if (NULL == attest) 284 if (NULL == presentation)
284 { 285 {
285 value_str = GNUNET_RECLAIM_attribute_value_to_string (attr->type, 286 value_str = GNUNET_RECLAIM_attribute_value_to_string (attr->type,
286 attr->data, 287 attr->data,
@@ -290,7 +291,7 @@ process_attrs (void *cls,
290 { 291 {
291 struct GNUNET_RECLAIM_AttributeListEntry *ale; 292 struct GNUNET_RECLAIM_AttributeListEntry *ale;
292 struct GNUNET_RECLAIM_AttributeList *al 293 struct GNUNET_RECLAIM_AttributeList *al
293 = GNUNET_RECLAIM_attestation_get_attributes (attest); 294 = GNUNET_RECLAIM_presentation_get_attributes (presentation);
294 295
295 for (ale = al->list_head; NULL != ale; ale = ale->next) 296 for (ale = al->list_head; NULL != ale; ale = ale->next)
296 { 297 {
@@ -298,10 +299,8 @@ process_attrs (void *cls,
298 continue; 299 continue;
299 value_str 300 value_str
300 = GNUNET_RECLAIM_attribute_value_to_string (ale->attribute->type, 301 = GNUNET_RECLAIM_attribute_value_to_string (ale->attribute->type,
301 ale->attribute-> 302 ale->attribute->data,
302 data, 303 ale->attribute->data_size);
303 ale->attribute->
304 data_size);
305 break; 304 break;
306 } 305 }
307 } 306 }
@@ -312,7 +311,7 @@ process_attrs (void *cls,
312 attr_type, 311 attr_type,
313 attr->flag, 312 attr->flag,
314 id, 313 id,
315 (NULL == attest) ? "" : "(ATTESTED)"); 314 (NULL == presentation) ? "" : "(ATTESTED)");
316 GNUNET_free (value_str); 315 GNUNET_free (value_str);
317 GNUNET_free (id); 316 GNUNET_free (id);
318} 317}
@@ -362,7 +361,7 @@ static void
362iter_error (void *cls) 361iter_error (void *cls)
363{ 362{
364 attr_iterator = NULL; 363 attr_iterator = NULL;
365 attest_iterator = NULL; 364 cred_iterator = NULL;
366 fprintf (stderr, "Failed\n"); 365 fprintf (stderr, "Failed\n");
367 366
368 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 367 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
@@ -489,9 +488,9 @@ iter_finished (void *cls)
489 claim = 488 claim =
490 GNUNET_RECLAIM_attribute_new (attr_name, NULL, type, data, data_size); 489 GNUNET_RECLAIM_attribute_new (attr_name, NULL, type, data, data_size);
491 } 490 }
492 if (NULL != attestation_id) 491 if (NULL != credential_id)
493 { 492 {
494 claim->attestation = attestation; 493 claim->credential = credential;
495 } 494 }
496 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle, 495 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle,
497 pkey, 496 pkey,
@@ -524,7 +523,7 @@ iter_cb (void *cls,
524 if (0 == strcasecmp (attr_name, attr->name)) 523 if (0 == strcasecmp (attr_name, attr->name))
525 { 524 {
526 claim = GNUNET_RECLAIM_attribute_new (attr->name, 525 claim = GNUNET_RECLAIM_attribute_new (attr->name,
527 &attr->attestation, 526 &attr->credential,
528 attr->type, 527 attr->type,
529 attr->data, 528 attr->data,
530 attr->data_size); 529 attr->data_size);
@@ -543,7 +542,7 @@ iter_cb (void *cls,
543 } 542 }
544 le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); 543 le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
545 le->attribute = GNUNET_RECLAIM_attribute_new (attr->name, 544 le->attribute = GNUNET_RECLAIM_attribute_new (attr->name,
546 &attr->attestation, 545 &attr->credential,
547 attr->type, 546 attr->type,
548 attr->data, 547 attr->data,
549 attr->data_size); 548 attr->data_size);
@@ -562,7 +561,7 @@ iter_cb (void *cls,
562 if (0 == strcasecmp (attr_delete, label)) 561 if (0 == strcasecmp (attr_delete, label))
563 { 562 {
564 attr_to_delete = GNUNET_RECLAIM_attribute_new (attr->name, 563 attr_to_delete = GNUNET_RECLAIM_attribute_new (attr->name,
565 &attr->attestation, 564 &attr->credential,
566 attr->type, 565 attr->type,
567 attr->data, 566 attr->data,
568 attr->data_size); 567 attr->data_size);
@@ -577,7 +576,7 @@ iter_cb (void *cls,
577 attr->data_size); 576 attr->data_size);
578 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type); 577 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type);
579 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id)); 578 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id));
580 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attr->attestation)) 579 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attr->credential))
581 { 580 {
582 fprintf (stdout, 581 fprintf (stdout,
583 "%s: ``%s'' (%s); ID: %s\n", 582 "%s: ``%s'' (%s); ID: %s\n",
@@ -588,17 +587,17 @@ iter_cb (void *cls,
588 } 587 }
589 else 588 else
590 { 589 {
591 char *attest_id = 590 char *cred_id =
592 GNUNET_STRINGS_data_to_string_alloc (&attr->attestation, 591 GNUNET_STRINGS_data_to_string_alloc (&attr->credential,
593 sizeof(attr->attestation)); 592 sizeof(attr->credential));
594 fprintf (stdout, 593 fprintf (stdout,
595 "%s: <``%s'' in attestation %s> (%s); ID: %s\n", 594 "%s: ``%s'' in credential presentation `%s' (%s); ID: %s\n",
596 attr->name, 595 attr->name,
597 attr_str, 596 attr_str,
598 attest_id, 597 cred_id,
599 attr_type, 598 attr_type,
600 id); 599 id);
601 GNUNET_free (attest_id); 600 GNUNET_free (cred_id);
602 601
603 } 602 }
604 GNUNET_free (id); 603 GNUNET_free (id);
@@ -608,29 +607,31 @@ iter_cb (void *cls,
608 607
609 608
610static void 609static void
611attest_iter_finished (void *cls) 610cred_iter_finished (void *cls)
612{ 611{
613 attest_iterator = NULL; 612 cred_iterator = NULL;
614 613
615 // Add new attestation 614 // Add new credential
616 if ((NULL != attestation_name) && 615 if ((NULL != credential_name) &&
617 (NULL != attr_value)) 616 (NULL != attr_value))
618 { 617 {
619 struct GNUNET_RECLAIM_Attestation *attestation = 618 enum GNUNET_RECLAIM_CredentialType ctype =
620 GNUNET_RECLAIM_attestation_new (attestation_name, 619 GNUNET_RECLAIM_credential_typename_to_number (credential_type);
621 GNUNET_RECLAIM_ATTESTATION_TYPE_JWT, // FIXME hardcoded 620 struct GNUNET_RECLAIM_Credential *credential =
622 attr_value, 621 GNUNET_RECLAIM_credential_new (credential_name,
623 strlen (attr_value)); 622 ctype,
624 reclaim_op = GNUNET_RECLAIM_attestation_store (reclaim_handle, 623 attr_value,
625 pkey, 624 strlen (attr_value));
626 attestation, 625 reclaim_op = GNUNET_RECLAIM_credential_store (reclaim_handle,
627 &exp_interval, 626 pkey,
628 store_cont, 627 credential,
629 NULL); 628 &exp_interval,
629 store_cont,
630 NULL);
630 return; 631 return;
631 632
632 } 633 }
633 if (list_attestations) 634 if (list_credentials)
634 { 635 {
635 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 636 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
636 return; 637 return;
@@ -648,34 +649,34 @@ attest_iter_finished (void *cls)
648 649
649 650
650static void 651static void
651attest_iter_cb (void *cls, 652cred_iter_cb (void *cls,
652 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 653 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
653 const struct GNUNET_RECLAIM_Attestation *attest) 654 const struct GNUNET_RECLAIM_Credential *cred)
654{ 655{
655 char *attest_str; 656 char *cred_str;
656 char *attr_str; 657 char *attr_str;
657 char *id; 658 char *id;
658 const char *attest_type; 659 const char *cred_type;
659 struct GNUNET_RECLAIM_AttributeListEntry *ale; 660 struct GNUNET_RECLAIM_AttributeListEntry *ale;
660 661
661 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (&attestation, 662 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (&credential,
662 &attest->id)) 663 &cred->id))
663 attestation_exists = GNUNET_YES; 664 credential_exists = GNUNET_YES;
664 if (list_attestations) 665 if (list_credentials)
665 { 666 {
666 attest_str = GNUNET_RECLAIM_attestation_value_to_string (attest->type, 667 cred_str = GNUNET_RECLAIM_credential_value_to_string (cred->type,
667 attest->data, 668 cred->data,
668 attest->data_size); 669 cred->data_size);
669 attest_type = GNUNET_RECLAIM_attestation_number_to_typename (attest->type); 670 cred_type = GNUNET_RECLAIM_credential_number_to_typename (cred->type);
670 id = GNUNET_STRINGS_data_to_string_alloc (&attest->id, sizeof(attest->id)); 671 id = GNUNET_STRINGS_data_to_string_alloc (&cred->id, sizeof(cred->id));
671 fprintf (stdout, 672 fprintf (stdout,
672 "%s: ``%s'' (%s); ID: %s\n", 673 "%s: ``%s'' (%s); ID: %s\n",
673 attest->name, 674 cred->name,
674 attest_str, 675 cred_str,
675 attest_type, 676 cred_type,
676 id); 677 id);
677 struct GNUNET_RECLAIM_AttributeList *attrs = 678 struct GNUNET_RECLAIM_AttributeList *attrs =
678 GNUNET_RECLAIM_attestation_get_attributes (attest); 679 GNUNET_RECLAIM_credential_get_attributes (cred);
679 if (NULL != attrs) 680 if (NULL != attrs)
680 { 681 {
681 fprintf (stdout, 682 fprintf (stdout,
@@ -684,11 +685,8 @@ attest_iter_cb (void *cls,
684 { 685 {
685 attr_str = GNUNET_RECLAIM_attribute_value_to_string ( 686 attr_str = GNUNET_RECLAIM_attribute_value_to_string (
686 ale->attribute->type, 687 ale->attribute->type,
687 ale->attribute-> 688 ale->attribute->data,
688 data, 689 ale->attribute->data_size);
689 ale->attribute->
690 data_size);
691
692 fprintf (stdout, 690 fprintf (stdout,
693 "\t %s: %s\n", ale->attribute->name, attr_str); 691 "\t %s: %s\n", ale->attribute->name, attr_str);
694 GNUNET_free (attr_str); 692 GNUNET_free (attr_str);
@@ -697,7 +695,7 @@ attest_iter_cb (void *cls,
697 } 695 }
698 GNUNET_free (id); 696 GNUNET_free (id);
699 } 697 }
700 GNUNET_RECLAIM_get_attestations_next (attest_iterator); 698 GNUNET_RECLAIM_get_credentials_next (cred_iterator);
701} 699}
702 700
703 701
@@ -710,12 +708,14 @@ start_process ()
710 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 708 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
711 return; 709 return;
712 } 710 }
713 attestation = GNUNET_RECLAIM_ID_ZERO; 711 if (NULL == credential_type)
714 if (NULL != attestation_id) 712 credential_type = GNUNET_strdup ("JWT");
715 GNUNET_STRINGS_string_to_data (attestation_id, 713 credential = GNUNET_RECLAIM_ID_ZERO;
716 strlen (attestation_id), 714 if (NULL != credential_id)
717 &attestation, sizeof(attestation)); 715 GNUNET_STRINGS_string_to_data (credential_id,
718 attestation_exists = GNUNET_NO; 716 strlen (credential_id),
717 &credential, sizeof(credential));
718 credential_exists = GNUNET_NO;
719 if (list_tickets) 719 if (list_tickets)
720 { 720 {
721 ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle, 721 ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle,
@@ -750,15 +750,14 @@ start_process ()
750 750
751 attr_list = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 751 attr_list = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
752 claim = NULL; 752 claim = NULL;
753 attest_iterator = GNUNET_RECLAIM_get_attestations_start (reclaim_handle, 753 cred_iterator = GNUNET_RECLAIM_get_credentials_start (reclaim_handle,
754 pkey, 754 pkey,
755 &iter_error, 755 &iter_error,
756 NULL, 756 NULL,
757 &attest_iter_cb, 757 &cred_iter_cb,
758 NULL, 758 NULL,
759 & 759 &cred_iter_finished,
760 attest_iter_finished, 760 NULL);
761 NULL);
762 761
763} 762}
764 763
@@ -856,20 +855,20 @@ main (int argc, char *const argv[])
856 gettext_noop ("List attributes for EGO"), 855 gettext_noop ("List attributes for EGO"),
857 &list), 856 &list),
858 GNUNET_GETOPT_option_flag ('A', 857 GNUNET_GETOPT_option_flag ('A',
859 "attestations", 858 "credentials",
860 gettext_noop ("List attestations for EGO"), 859 gettext_noop ("List credentials for EGO"),
861 &list_attestations), 860 &list_credentials),
862 GNUNET_GETOPT_option_string ('I', 861 GNUNET_GETOPT_option_string ('I',
863 "Attestation ID", 862 "Credential ID",
864 "ATTESTATION_ID", 863 "CREDENTIAL_ID",
865 gettext_noop ( 864 gettext_noop (
866 "Attestation to use for attribute"), 865 "Credential to use for attribute"),
867 &attestation_id), 866 &credential_id),
868 GNUNET_GETOPT_option_string ('N', 867 GNUNET_GETOPT_option_string ('N',
869 "attestation-name", 868 "credential-name",
870 "NAME", 869 "NAME",
871 gettext_noop ("Attestation name"), 870 gettext_noop ("Credential name"),
872 &attestation_name), 871 &credential_name),
873 GNUNET_GETOPT_option_string ('i', 872 GNUNET_GETOPT_option_string ('i',
874 "issue", 873 "issue",
875 "A1,A2,...", 874 "A1,A2,...",
@@ -891,6 +890,11 @@ main (int argc, char *const argv[])
891 "TYPE", 890 "TYPE",
892 gettext_noop ("Type of attribute"), 891 gettext_noop ("Type of attribute"),
893 &type_str), 892 &type_str),
893 GNUNET_GETOPT_option_string ('u',
894 "credential-type",
895 "TYPE",
896 gettext_noop ("Type of credential"),
897 &credential_type),
894 GNUNET_GETOPT_option_flag ('T', 898 GNUNET_GETOPT_option_flag ('T',
895 "tickets", 899 "tickets",
896 gettext_noop ("List tickets of ego"), 900 gettext_noop ("List tickets of ego"),