diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-02-04 21:53:47 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-02-09 20:38:10 +0100 |
commit | 73de82ef85076f0421af025887f0053e6c652b09 (patch) | |
tree | a8919806b613b1afda839869f1535acaad8bf932 | |
parent | ad342b7e0870185522c7dcb846e71029fcfda335 (diff) | |
download | gnunet-73de82ef85076f0421af025887f0053e6c652b09.tar.gz gnunet-73de82ef85076f0421af025887f0053e6c652b09.zip |
add attestation API to CLI
-rw-r--r-- | src/reclaim/gnunet-reclaim.c | 169 |
1 files changed, 150 insertions, 19 deletions
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index 93d9ee3df..35c1258f5 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.c | |||
@@ -43,6 +43,31 @@ static int ret; | |||
43 | static int list; | 43 | static int list; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * List attestations flag | ||
47 | */ | ||
48 | static int list_attestations; | ||
49 | |||
50 | /** | ||
51 | * Attestation ID string | ||
52 | */ | ||
53 | static char *attestation_id; | ||
54 | |||
55 | /** | ||
56 | * Attestation ID | ||
57 | */ | ||
58 | static struct GNUNET_RECLAIM_Identifier attestation; | ||
59 | |||
60 | /** | ||
61 | * Attestation name | ||
62 | */ | ||
63 | static char *attestation_name; | ||
64 | |||
65 | /** | ||
66 | * Attestation exists | ||
67 | */ | ||
68 | static int attestation_exists; | ||
69 | |||
70 | /** | ||
46 | * Relying party | 71 | * Relying party |
47 | */ | 72 | */ |
48 | static char *rp; | 73 | static char *rp; |
@@ -108,6 +133,12 @@ static struct GNUNET_RECLAIM_Operation *reclaim_op; | |||
108 | static struct GNUNET_RECLAIM_AttributeIterator *attr_iterator; | 133 | static struct GNUNET_RECLAIM_AttributeIterator *attr_iterator; |
109 | 134 | ||
110 | /** | 135 | /** |
136 | * Attestation iterator | ||
137 | */ | ||
138 | static struct GNUNET_RECLAIM_AttestationIterator *attest_iterator; | ||
139 | |||
140 | |||
141 | /** | ||
111 | * Ticket iterator | 142 | * Ticket iterator |
112 | */ | 143 | */ |
113 | static struct GNUNET_RECLAIM_TicketIterator *ticket_iterator; | 144 | static struct GNUNET_RECLAIM_TicketIterator *ticket_iterator; |
@@ -212,7 +243,7 @@ ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
212 | 243 | ||
213 | 244 | ||
214 | static void | 245 | static void |
215 | store_attr_cont (void *cls, int32_t success, const char *emsg) | 246 | store_cont (void *cls, int32_t success, const char *emsg) |
216 | { | 247 | { |
217 | reclaim_op = NULL; | 248 | reclaim_op = NULL; |
218 | if (GNUNET_SYSERR == success) | 249 | if (GNUNET_SYSERR == success) |
@@ -305,7 +336,9 @@ static void | |||
305 | iter_error (void *cls) | 336 | iter_error (void *cls) |
306 | { | 337 | { |
307 | attr_iterator = NULL; | 338 | attr_iterator = NULL; |
308 | fprintf (stderr, "Failed to iterate over attributes\n"); | 339 | attest_iterator = NULL; |
340 | fprintf (stderr, "Failed\n"); | ||
341 | |||
309 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 342 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
310 | } | 343 | } |
311 | 344 | ||
@@ -430,11 +463,16 @@ iter_finished (void *cls) | |||
430 | claim = | 463 | claim = |
431 | GNUNET_RECLAIM_attribute_new (attr_name, NULL, type, data, data_size); | 464 | GNUNET_RECLAIM_attribute_new (attr_name, NULL, type, data, data_size); |
432 | } | 465 | } |
466 | if (NULL != attestation_id) | ||
467 | { | ||
468 | claim->attestation = attestation; | ||
469 | } | ||
470 | else | ||
433 | reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle, | 471 | reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle, |
434 | pkey, | 472 | pkey, |
435 | claim, | 473 | claim, |
436 | &exp_interval, | 474 | &exp_interval, |
437 | &store_attr_cont, | 475 | &store_cont, |
438 | NULL); | 476 | NULL); |
439 | GNUNET_free (data); | 477 | GNUNET_free (data); |
440 | GNUNET_free (claim); | 478 | GNUNET_free (claim); |
@@ -528,6 +566,76 @@ iter_cb (void *cls, | |||
528 | 566 | ||
529 | 567 | ||
530 | static void | 568 | static void |
569 | attest_iter_finished (void *cls) | ||
570 | { | ||
571 | attest_iterator = NULL; | ||
572 | //Add new attestation | ||
573 | if ((NULL != attestation_name) && | ||
574 | (NULL != attr_value)) | ||
575 | { | ||
576 | struct GNUNET_RECLAIM_Attestation *attestation = | ||
577 | GNUNET_RECLAIM_attestation_new (attestation_name, | ||
578 | GNUNET_RECLAIM_ATTESTATION_TYPE_JWT, //FIXME hardcoded | ||
579 | attr_value, | ||
580 | strlen (attr_value)); | ||
581 | reclaim_op = GNUNET_RECLAIM_attestation_store (reclaim_handle, | ||
582 | pkey, | ||
583 | attestation, | ||
584 | &exp_interval, | ||
585 | store_cont, | ||
586 | NULL); | ||
587 | return; | ||
588 | |||
589 | } | ||
590 | if (! list_attestations) | ||
591 | { | ||
592 | attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle, | ||
593 | pkey, | ||
594 | &iter_error, | ||
595 | NULL, | ||
596 | &iter_cb, | ||
597 | NULL, | ||
598 | &iter_finished, | ||
599 | NULL); | ||
600 | |||
601 | } | ||
602 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | ||
603 | } | ||
604 | |||
605 | |||
606 | static void | ||
607 | attest_iter_cb (void *cls, | ||
608 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | ||
609 | const struct GNUNET_RECLAIM_Attestation *attest) | ||
610 | { | ||
611 | char *attest_str; | ||
612 | char *id; | ||
613 | const char *attest_type; | ||
614 | |||
615 | if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (&attestation, | ||
616 | &attest->id)) | ||
617 | attestation_exists = GNUNET_YES; | ||
618 | if (list_attestations) | ||
619 | { | ||
620 | attest_str = GNUNET_RECLAIM_attestation_value_to_string (attest->type, | ||
621 | attest->data, | ||
622 | attest->data_size); | ||
623 | attest_type = GNUNET_RECLAIM_attribute_number_to_typename (attest->type); | ||
624 | id = GNUNET_STRINGS_data_to_string_alloc (&attest->id, sizeof(attest->id)); | ||
625 | fprintf (stdout, | ||
626 | "Name: %s; Value: %s (%s); Flag %u; ID: %s\n", | ||
627 | attest->name, | ||
628 | attest_str, | ||
629 | attest_type, | ||
630 | attest->flag, | ||
631 | id); | ||
632 | GNUNET_free (id); | ||
633 | } | ||
634 | GNUNET_RECLAIM_get_attestations_next (attest_iterator); | ||
635 | } | ||
636 | |||
637 | |||
638 | static void | ||
531 | start_process () | 639 | start_process () |
532 | { | 640 | { |
533 | if (NULL == pkey) | 641 | if (NULL == pkey) |
@@ -536,7 +644,12 @@ start_process () | |||
536 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 644 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
537 | return; | 645 | return; |
538 | } | 646 | } |
539 | 647 | attestation = GNUNET_RECLAIM_ID_ZERO; | |
648 | if (NULL != attestation_id) | ||
649 | GNUNET_STRINGS_string_to_data (attestation_id, | ||
650 | strlen (attestation_id), | ||
651 | &attestation, sizeof(attestation)); | ||
652 | attestation_exists = GNUNET_NO; | ||
540 | if (list_tickets) | 653 | if (list_tickets) |
541 | { | 654 | { |
542 | ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle, | 655 | ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle, |
@@ -549,6 +662,19 @@ start_process () | |||
549 | NULL); | 662 | NULL); |
550 | return; | 663 | return; |
551 | } | 664 | } |
665 | if (list_attestations) | ||
666 | { | ||
667 | attest_iterator = GNUNET_RECLAIM_get_attestations_start (reclaim_handle, | ||
668 | pkey, | ||
669 | &iter_error, | ||
670 | NULL, | ||
671 | &attest_iter_cb, | ||
672 | NULL, | ||
673 | & | ||
674 | attest_iter_finished, | ||
675 | NULL); | ||
676 | return; | ||
677 | } | ||
552 | 678 | ||
553 | if ((NULL != rp) && | 679 | if ((NULL != rp) && |
554 | (GNUNET_OK != | 680 | (GNUNET_OK != |
@@ -571,14 +697,6 @@ start_process () | |||
571 | 697 | ||
572 | attr_list = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); | 698 | attr_list = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); |
573 | claim = NULL; | 699 | claim = NULL; |
574 | attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle, | ||
575 | pkey, | ||
576 | &iter_error, | ||
577 | NULL, | ||
578 | &iter_cb, | ||
579 | NULL, | ||
580 | &iter_finished, | ||
581 | NULL); | ||
582 | } | 700 | } |
583 | 701 | ||
584 | 702 | ||
@@ -674,13 +792,26 @@ main (int argc, char *const argv[]) | |||
674 | "dump", | 792 | "dump", |
675 | gettext_noop ("List attributes for EGO"), | 793 | gettext_noop ("List attributes for EGO"), |
676 | &list), | 794 | &list), |
677 | GNUNET_GETOPT_option_string ( | 795 | GNUNET_GETOPT_option_flag ('A', |
678 | 'i', | 796 | "attestations", |
679 | "issue", | 797 | gettext_noop ("List attestations for EGO"), |
680 | "A1,A2,...", | 798 | &list_attestations), |
681 | gettext_noop ( | 799 | GNUNET_GETOPT_option_string ('I', |
682 | "Issue a ticket for a set of attributes separated by comma"), | 800 | "Attestation ID", |
683 | &issue_attrs), | 801 | "ATTESTATION_ID", |
802 | gettext_noop ("Attestation to use for attribute"), | ||
803 | &attestation_id), | ||
804 | GNUNET_GETOPT_option_string ('N', | ||
805 | "attestation-name", | ||
806 | "NAME", | ||
807 | gettext_noop ("Attestation name"), | ||
808 | &attestation_name), | ||
809 | GNUNET_GETOPT_option_string ('i', | ||
810 | "issue", | ||
811 | "A1,A2,...", | ||
812 | gettext_noop ( | ||
813 | "Issue a ticket for a set of attributes separated by comma"), | ||
814 | &issue_attrs), | ||
684 | GNUNET_GETOPT_option_string ('C', | 815 | GNUNET_GETOPT_option_string ('C', |
685 | "consume", | 816 | "consume", |
686 | "TICKET", | 817 | "TICKET", |