aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-12 14:31:06 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-14 10:01:23 +0200
commita12b8c2c4cbf952c8c305cde193bb25c13a0912b (patch)
tree0c7f27a870ce6fc8789e1b9672156758b1c1c2e6
parent947b84dcdee19d6a4b1fcad10618a2b4f505b3b9 (diff)
downloadgnunet-a12b8c2c4cbf952c8c305cde193bb25c13a0912b.tar.gz
gnunet-a12b8c2c4cbf952c8c305cde193bb25c13a0912b.zip
RECLAIM: refactoring; cleanup
-rw-r--r--src/include/gnunet_gnsrecord_lib.h7
-rw-r--r--src/reclaim-attribute/reclaim_attribute.c2
-rw-r--r--src/reclaim/Makefile.am4
-rw-r--r--src/reclaim/gnunet-service-reclaim.c369
-rw-r--r--src/reclaim/gnunet-service-reclaim_tickets.c455
-rw-r--r--src/reclaim/gnunet-service-reclaim_tickets.h63
-rw-r--r--src/reclaim/plugin_gnsrecord_reclaim.c3
-rw-r--r--src/reclaim/reclaim_api.c2
8 files changed, 676 insertions, 229 deletions
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h
index c76e87d12..27228c0bc 100644
--- a/src/include/gnunet_gnsrecord_lib.h
+++ b/src/include/gnunet_gnsrecord_lib.h
@@ -99,7 +99,12 @@ extern "C"
99#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR 65544 99#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR 65544
100 100
101/** 101/**
102 * 65544-65547 deprecated 102 * Record type for local ticket references
103 */
104#define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF 65545
105
106/**
107 * 65546 reserved
103 */ 108 */
104 109
105/** 110/**
diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c
index 3d260f15b..86f0f8f67 100644
--- a/src/reclaim-attribute/reclaim_attribute.c
+++ b/src/reclaim-attribute/reclaim_attribute.c
@@ -349,6 +349,8 @@ GNUNET_RECLAIM_ATTRIBUTE_list_dup (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimLi
349 le->claim->type, 349 le->claim->type,
350 le->claim->data, 350 le->claim->data,
351 le->claim->data_size); 351 le->claim->data_size);
352 result_le->claim->version = le->claim->version;
353 result_le->claim->id = le->claim->id;
352 GNUNET_CONTAINER_DLL_insert (result->list_head, 354 GNUNET_CONTAINER_DLL_insert (result->list_head,
353 result->list_tail, 355 result->list_tail,
354 result_le); 356 result_le);
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index 210759fce..7e8686734 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -108,14 +108,14 @@ libgnunet_plugin_reclaim_sqlite_la_LDFLAGS = \
108 108
109 109
110gnunet_service_reclaim_SOURCES = \ 110gnunet_service_reclaim_SOURCES = \
111 gnunet-service-reclaim.c 111 gnunet-service-reclaim.c \
112 gnunet-service-reclaim_tickets.c
112gnunet_service_reclaim_LDADD = \ 113gnunet_service_reclaim_LDADD = \
113 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 114 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
114 $(top_builddir)/src/util/libgnunetutil.la \ 115 $(top_builddir)/src/util/libgnunetutil.la \
115 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 116 $(top_builddir)/src/namestore/libgnunetnamestore.la \
116 $(top_builddir)/src/identity/libgnunetidentity.la \ 117 $(top_builddir)/src/identity/libgnunetidentity.la \
117 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 118 $(top_builddir)/src/statistics/libgnunetstatistics.la \
118 $(top_builddir)/src/credential/libgnunetcredential.la \
119 $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \ 119 $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \
120 libgnunetreclaim.la \ 120 libgnunetreclaim.la \
121 $(top_builddir)/src/gns/libgnunetgns.la \ 121 $(top_builddir)/src/gns/libgnunetgns.la \
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index f3a6e2073..b963b0a9b 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -30,12 +30,12 @@
30#include "gnunet_identity_service.h" 30#include "gnunet_identity_service.h"
31#include "gnunet_gnsrecord_lib.h" 31#include "gnunet_gnsrecord_lib.h"
32#include "gnunet_namestore_service.h" 32#include "gnunet_namestore_service.h"
33#include "gnunet_credential_service.h"
34#include "gnunet_statistics_service.h" 33#include "gnunet_statistics_service.h"
35#include "gnunet_gns_service.h" 34#include "gnunet_gns_service.h"
36#include "gnunet_reclaim_plugin.h" 35#include "gnunet_reclaim_plugin.h"
37#include "gnunet_reclaim_attribute_lib.h" 36#include "gnunet_reclaim_attribute_lib.h"
38#include "gnunet_signatures.h" 37#include "gnunet_signatures.h"
38#include "gnunet-service-reclaim_tickets.h"
39#include "reclaim.h" 39#include "reclaim.h"
40 40
41/** 41/**
@@ -89,21 +89,6 @@ static struct GNUNET_NAMESTORE_Handle *nsh;
89static struct GNUNET_GNS_Handle *gns_handle; 89static struct GNUNET_GNS_Handle *gns_handle;
90 90
91/** 91/**
92 * Credential handle
93 */
94static struct GNUNET_CREDENTIAL_Handle *credential_handle;
95
96/**
97 * Namestore qe
98 */
99static struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
100
101/**
102 * Namestore iterator
103 */
104static struct GNUNET_NAMESTORE_ZoneIterator *ns_it;
105
106/**
107 * Timeout task 92 * Timeout task
108 */ 93 */
109static struct GNUNET_SCHEDULER_Task *timeout_task; 94static struct GNUNET_SCHEDULER_Task *timeout_task;
@@ -268,12 +253,12 @@ struct IdpClient
268 /** 253 /**
269 * Head of DLL of ticket issue ops 254 * Head of DLL of ticket issue ops
270 */ 255 */
271 struct TicketIssueHandle *issue_op_head; 256 struct TicketIssueOperation *issue_op_head;
272 257
273 /** 258 /**
274 * Tail of DLL of ticket issue ops 259 * Tail of DLL of ticket issue ops
275 */ 260 */
276 struct TicketIssueHandle *issue_op_tail; 261 struct TicketIssueOperation *issue_op_tail;
277 262
278 /** 263 /**
279 * Head of DLL of ticket consume ops 264 * Head of DLL of ticket consume ops
@@ -543,19 +528,19 @@ struct TicketRevocationHandle
543 528
544 529
545/** 530/**
546 * Ticket issue request handle 531 * Ticket issue operation handle
547 */ 532 */
548struct TicketIssueHandle 533struct TicketIssueOperation
549{ 534{
550 /** 535 /**
551 * DLL 536 * DLL
552 */ 537 */
553 struct TicketIssueHandle *prev; 538 struct TicketIssueOperation *prev;
554 539
555 /** 540 /**
556 * DLL 541 * DLL
557 */ 542 */
558 struct TicketIssueHandle *next; 543 struct TicketIssueOperation *next;
559 544
560 /** 545 /**
561 * Client connection 546 * Client connection
@@ -563,26 +548,6 @@ struct TicketIssueHandle
563 struct IdpClient *client; 548 struct IdpClient *client;
564 549
565 /** 550 /**
566 * Attributes to issue
567 */
568 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
569
570 /**
571 * Issuer Key
572 */
573 struct GNUNET_CRYPTO_EcdsaPrivateKey identity;
574
575 /**
576 * Ticket to issue
577 */
578 struct GNUNET_RECLAIM_Ticket ticket;
579
580 /**
581 * QueueEntry
582 */
583 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
584
585 /**
586 * request id 551 * request id
587 */ 552 */
588 uint32_t r_id; 553 uint32_t r_id;
@@ -644,12 +609,6 @@ cleanup()
644 GNUNET_IDENTITY_disconnect (identity_handle); 609 GNUNET_IDENTITY_disconnect (identity_handle);
645 if (NULL != gns_handle) 610 if (NULL != gns_handle)
646 GNUNET_GNS_disconnect (gns_handle); 611 GNUNET_GNS_disconnect (gns_handle);
647 if (NULL != credential_handle)
648 GNUNET_CREDENTIAL_disconnect (credential_handle);
649 if (NULL != ns_it)
650 GNUNET_NAMESTORE_zone_iteration_stop (ns_it);
651 if (NULL != ns_qe)
652 GNUNET_NAMESTORE_cancel (ns_qe);
653 if (NULL != nsh) 612 if (NULL != nsh)
654 GNUNET_NAMESTORE_disconnect (nsh); 613 GNUNET_NAMESTORE_disconnect (nsh);
655} 614}
@@ -691,83 +650,136 @@ create_sym_key_from_ecdh (const struct GNUNET_HashCode *new_key_hash,
691 return GNUNET_OK; 650 return GNUNET_OK;
692} 651}
693 652
694/**
695 * Cleanup ticket consume handle
696 * @param handle the handle to clean up
697 */
698static void
699cleanup_ticket_issue_handle (struct TicketIssueHandle *handle)
700{
701 if (NULL != handle->attrs)
702 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (handle->attrs);
703 if (NULL != handle->ns_qe)
704 GNUNET_NAMESTORE_cancel (handle->ns_qe);
705 GNUNET_free (handle);
706}
707
708 653
709static void 654static void
710send_ticket_result (struct IdpClient *client, 655send_ticket_result (const struct IdpClient *client,
711 uint32_t r_id, 656 uint32_t r_id,
712 const struct GNUNET_RECLAIM_Ticket *ticket, 657 const struct GNUNET_RECLAIM_Ticket *ticket,
713 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) 658 uint32_t success)
714{ 659{
715 struct TicketResultMessage *irm; 660 struct TicketResultMessage *irm;
716 struct GNUNET_MQ_Envelope *env; 661 struct GNUNET_MQ_Envelope *env;
717 struct GNUNET_RECLAIM_Ticket *ticket_buf; 662 struct GNUNET_RECLAIM_Ticket *ticket_buf;
718 663
719 /* store ticket in DB */ 664 if (NULL != ticket)
720 if (GNUNET_OK != TKT_database->store_ticket (TKT_database->cls,
721 ticket,
722 attrs))
723 { 665 {
724 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 666 env = GNUNET_MQ_msg_extra (irm,
725 "Unable to store ticket after issue\n"); 667 sizeof (struct GNUNET_RECLAIM_Ticket),
726 GNUNET_break (0); 668 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
669 ticket_buf = (struct GNUNET_RECLAIM_Ticket *)&irm[1];
670 *ticket_buf = *ticket;
671 } else {
672 env = GNUNET_MQ_msg (irm,
673 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
727 } 674 }
728 675 //TODO add success member
729 env = GNUNET_MQ_msg_extra (irm,
730 sizeof (struct GNUNET_RECLAIM_Ticket),
731 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
732 ticket_buf = (struct GNUNET_RECLAIM_Ticket *)&irm[1];
733 *ticket_buf = *ticket;
734 irm->id = htonl (r_id); 676 irm->id = htonl (r_id);
735 GNUNET_MQ_send (client->mq, 677 GNUNET_MQ_send (client->mq,
736 env); 678 env);
737} 679}
738 680
681
739static void 682static void
740store_ticket_issue_cont (void *cls, 683issue_ticket_result_cb (void *cls,
741 int32_t success, 684 struct GNUNET_RECLAIM_Ticket *ticket,
742 const char *emsg) 685 uint32_t success,
686 const char* emsg)
743{ 687{
744 struct TicketIssueHandle *handle = cls; 688 struct TicketIssueOperation *tio = cls;
745 689 if (GNUNET_OK != success)
746 handle->ns_qe = NULL;
747 GNUNET_CONTAINER_DLL_remove (handle->client->issue_op_head,
748 handle->client->issue_op_tail,
749 handle);
750 if (GNUNET_SYSERR == success)
751 { 690 {
752 cleanup_ticket_issue_handle (handle); 691 send_ticket_result (tio->client,
753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", 692 tio->r_id,
754 "Unknown Error\n"); 693 NULL,
755 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 694 GNUNET_SYSERR);
695 GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head,
696 tio->client->issue_op_tail,
697 tio);
698 GNUNET_free (tio);
699 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
700 "Error issuing ticket: %s\n",
701 emsg);
756 return; 702 return;
757 } 703 }
758 send_ticket_result (handle->client, 704 send_ticket_result (tio->client,
759 handle->r_id, 705 tio->r_id,
760 &handle->ticket, 706 ticket,
761 handle->attrs); 707 GNUNET_SYSERR);
762 cleanup_ticket_issue_handle (handle); 708 GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head,
709 tio->client->issue_op_tail,
710 tio);
711 GNUNET_free (tio);
712}
713
714static int
715check_issue_ticket_message (void *cls,
716 const struct IssueTicketMessage *im)
717{
718 uint16_t size;
719
720 size = ntohs (im->header.size);
721 if (size <= sizeof (struct IssueTicketMessage))
722 {
723 GNUNET_break (0);
724 return GNUNET_SYSERR;
725 }
726 return GNUNET_OK;
763} 727}
764 728
729static void
730handle_issue_ticket_message (void *cls,
731 const struct IssueTicketMessage *im)
732{
733 struct TicketIssueOperation *tio;
734 struct IdpClient *idp = cls;
735 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
736 size_t attrs_len;
737
738 tio = GNUNET_new (struct TicketIssueOperation);
739 attrs_len = ntohs (im->attr_len);
740 attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char*)&im[1], attrs_len);
741 tio->r_id = ntohl (im->id);
742 tio->client = idp;
743 GNUNET_CONTAINER_DLL_insert (idp->issue_op_head,
744 idp->issue_op_tail,
745 tio);
746 RECLAIM_TICKETS_issue_ticket (&im->identity,
747 attrs,
748 &im->rp,
749 &issue_ticket_result_cb,
750 tio);
751 GNUNET_SERVICE_client_continue (idp->client);
752 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs);
753}
754
755/**********************************************************
756 * Revocation
757 **********************************************************/
758
759/**
760 * Cleanup revoke handle
761 *
762 * @param rh the ticket revocation handle
763 */
764static void
765cleanup_revoke_ticket_handle (struct TicketRevocationHandle *rh)
766{
767 if (NULL != rh->attrs)
768 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (rh->attrs);
769 if (NULL != rh->rvk_attrs)
770 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (rh->rvk_attrs);
771 if (NULL != rh->ns_qe)
772 GNUNET_NAMESTORE_cancel (rh->ns_qe);
773 if (NULL != rh->ns_it)
774 GNUNET_NAMESTORE_zone_iteration_stop (rh->ns_it);
775 GNUNET_free (rh);
776}
765 777
766static int 778static int
767serialize_authz_record (const struct GNUNET_RECLAIM_Ticket *ticket, 779serialize_authz_record (const struct GNUNET_RECLAIM_Ticket *ticket,
768 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, 780 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
769 struct GNUNET_CRYPTO_EcdhePrivateKey **ecdh_privkey, 781 struct GNUNET_CRYPTO_EcdhePrivateKey **ecdh_privkey,
770 char **result) 782 char **result)
771{ 783{
772 struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey; 784 struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey;
773 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; 785 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
@@ -833,111 +845,6 @@ serialize_authz_record (const struct GNUNET_RECLAIM_Ticket *ticket,
833} 845}
834 846
835 847
836
837static void
838issue_ticket (struct TicketIssueHandle *ih)
839{
840 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey;
841 struct GNUNET_GNSRECORD_Data code_record[1];
842 char *authz_record_data;
843 size_t authz_record_len;
844 char *label;
845
846 //TODO rename function
847 authz_record_len = serialize_authz_record (&ih->ticket,
848 ih->attrs,
849 &ecdhe_privkey,
850 &authz_record_data);
851 code_record[0].data = authz_record_data;
852 code_record[0].data_size = authz_record_len;
853 code_record[0].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us;
854 code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ;
855 code_record[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
856
857 label = GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd,
858 sizeof (uint64_t));
859 //Publish record
860 ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
861 &ih->identity,
862 label,
863 1,
864 code_record,
865 &store_ticket_issue_cont,
866 ih);
867 GNUNET_free (ecdhe_privkey);
868 GNUNET_free (label);
869 GNUNET_free (authz_record_data);
870}
871
872
873static int
874check_issue_ticket_message(void *cls,
875 const struct IssueTicketMessage *im)
876{
877 uint16_t size;
878
879 size = ntohs (im->header.size);
880 if (size <= sizeof (struct IssueTicketMessage))
881 {
882 GNUNET_break (0);
883 return GNUNET_SYSERR;
884 }
885 return GNUNET_OK;
886}
887
888
889static void
890handle_issue_ticket_message (void *cls,
891 const struct IssueTicketMessage *im)
892{
893 struct TicketIssueHandle *ih;
894 struct IdpClient *idp = cls;
895 size_t attrs_len;
896
897 ih = GNUNET_new (struct TicketIssueHandle);
898 attrs_len = ntohs (im->attr_len);
899 ih->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char*)&im[1], attrs_len);
900 ih->r_id = ntohl (im->id);
901 ih->client = idp;
902 ih->identity = im->identity;
903 GNUNET_CRYPTO_ecdsa_key_get_public (&ih->identity,
904 &ih->ticket.identity);
905 ih->ticket.audience = im->rp;
906 ih->ticket.rnd =
907 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
908 UINT64_MAX);
909 GNUNET_CONTAINER_DLL_insert (idp->issue_op_head,
910 idp->issue_op_tail,
911 ih);
912 issue_ticket (ih);
913 GNUNET_SERVICE_client_continue (idp->client);
914
915}
916
917/**********************************************************
918 * Revocation
919 **********************************************************/
920
921/**
922 * Cleanup revoke handle
923 *
924 * @param rh the ticket revocation handle
925 */
926static void
927cleanup_revoke_ticket_handle (struct TicketRevocationHandle *rh)
928{
929 if (NULL != rh->attrs)
930 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (rh->attrs);
931 if (NULL != rh->rvk_attrs)
932 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (rh->rvk_attrs);
933 if (NULL != rh->ns_qe)
934 GNUNET_NAMESTORE_cancel (rh->ns_qe);
935 if (NULL != rh->ns_it)
936 GNUNET_NAMESTORE_zone_iteration_stop (rh->ns_it);
937 GNUNET_free (rh);
938}
939
940
941/** 848/**
942 * Send revocation result 849 * Send revocation result
943 * 850 *
@@ -1086,8 +993,6 @@ ticket_reissue_proc (void *cls,
1086 993
1087 rh->offset++; 994 rh->offset++;
1088 GNUNET_SCHEDULER_add_now (&reissue_next, rh); 995 GNUNET_SCHEDULER_add_now (&reissue_next, rh);
1089
1090
1091 return; 996 return;
1092 } 997 }
1093 998
@@ -1186,6 +1091,7 @@ check_attr_cb (void *cls,
1186{ 1091{
1187 struct TicketRevocationHandle *rh = cls; 1092 struct TicketRevocationHandle *rh = cls;
1188 struct TicketAttributeUpdateEntry *tue; 1093 struct TicketAttributeUpdateEntry *tue;
1094 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
1189 struct GNUNET_GNSRECORD_Data rd[1]; 1095 struct GNUNET_GNSRECORD_Data rd[1];
1190 char* buf; 1096 char* buf;
1191 size_t buf_size; 1097 size_t buf_size;
@@ -1193,6 +1099,16 @@ check_attr_cb (void *cls,
1193 1099
1194 rh->ns_qe = NULL; 1100 rh->ns_qe = NULL;
1195 if (1 != rd_count) { 1101 if (1 != rd_count) {
1102 le = rh->attrs->list_head;
1103 GNUNET_CONTAINER_DLL_remove (rh->attrs->list_head,
1104 rh->attrs->list_tail,
1105 le);
1106 GNUNET_assert (NULL != rh->rvk_attrs);
1107 GNUNET_CONTAINER_DLL_insert (rh->rvk_attrs->list_head,
1108 rh->rvk_attrs->list_tail,
1109 le);
1110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1111 "Re-encrypting next attribute\n");
1196 GNUNET_SCHEDULER_add_now (&reenc_next_attribute, 1112 GNUNET_SCHEDULER_add_now (&reenc_next_attribute,
1197 rh); 1113 rh);
1198 return; 1114 return;
@@ -1213,7 +1129,7 @@ check_attr_cb (void *cls,
1213 rh->attrs->list_head->claim->id = tue->new_id; 1129 rh->attrs->list_head->claim->id = tue->new_id;
1214 new_label = GNUNET_STRINGS_data_to_string_alloc (&tue->new_id, 1130 new_label = GNUNET_STRINGS_data_to_string_alloc (&tue->new_id,
1215 sizeof (uint64_t)); 1131 sizeof (uint64_t));
1216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1217 "New attr id %s\n", new_label); 1133 "New attr id %s\n", new_label);
1218 rd[0].data_size = buf_size; 1134 rd[0].data_size = buf_size;
1219 rd[0].data = buf; 1135 rd[0].data = buf;
@@ -1247,6 +1163,7 @@ reenc_next_attribute (void *cls)
1247 /* First check if attribute still exists */ 1163 /* First check if attribute still exists */
1248 label = GNUNET_STRINGS_data_to_string_alloc (&rh->attrs->list_head->claim->id, 1164 label = GNUNET_STRINGS_data_to_string_alloc (&rh->attrs->list_head->claim->id,
1249 sizeof (uint64_t)); 1165 sizeof (uint64_t));
1166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ID: %lu\n", rh->attrs->list_head->claim->id);
1250 rh->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, 1167 rh->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh,
1251 &rh->identity, 1168 &rh->identity,
1252 label, 1169 label,
@@ -1308,7 +1225,7 @@ process_attributes_to_update (void *cls,
1308 struct TicketRevocationHandle *rh = cls; 1225 struct TicketRevocationHandle *rh = cls;
1309 1226
1310 rh->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (attrs); 1227 rh->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (attrs);
1311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1228 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1312 "Revocation Phase I: Collecting attributes\n"); 1229 "Revocation Phase I: Collecting attributes\n");
1313 /* Reencrypt all attributes with new key */ 1230 /* Reencrypt all attributes with new key */
1314 if (NULL == rh->attrs->list_head) 1231 if (NULL == rh->attrs->list_head)
@@ -1318,7 +1235,7 @@ process_attributes_to_update (void *cls,
1318 cleanup_revoke_ticket_handle (rh); 1235 cleanup_revoke_ticket_handle (rh);
1319 return; 1236 return;
1320 } else { 1237 } else {
1321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1238 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1322 "Revocation Phase II: Re-encrypting attributes\n"); 1239 "Revocation Phase II: Re-encrypting attributes\n");
1323 reenc_next_attribute (rh); 1240 reenc_next_attribute (rh);
1324 } 1241 }
@@ -1463,16 +1380,16 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count,
1463 /* Else we are done */ 1380 /* Else we are done */
1464 1381
1465 /** Store ticket in DB 1382 /** Store ticket in DB
1466 * TODO: Store in GNS 1383 * TODO: Store in GNS?
1467 */ 1384 */
1468 if (GNUNET_OK != TKT_database->store_ticket (TKT_database->cls, 1385 /**if (GNUNET_OK != TKT_database->store_ticket (TKT_database->cls,
1469 &handle->ticket, 1386 &handle->ticket,
1470 handle->attrs)) 1387 handle->attrs))
1471 { 1388 {
1472 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1389 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1473 "Unable to store ticket after consume\n"); 1390 "Unable to store ticket after consume\n");
1474 GNUNET_break (0); 1391 GNUNET_break (0);
1475 } 1392 }*/
1476 1393
1477 GNUNET_SCHEDULER_cancel (handle->kill_task); 1394 GNUNET_SCHEDULER_cancel (handle->kill_task);
1478 attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (handle->attrs); 1395 attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (handle->attrs);
@@ -1775,7 +1692,7 @@ handle_attribute_store_message (void *cls,
1775 1692
1776 ash = GNUNET_new (struct AttributeStoreHandle); 1693 ash = GNUNET_new (struct AttributeStoreHandle);
1777 ash->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char*)&sam[1], 1694 ash->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char*)&sam[1],
1778 data_len); 1695 data_len);
1779 1696
1780 ash->r_id = ntohl (sam->id); 1697 ash->r_id = ntohl (sam->id);
1781 ash->identity = sam->identity; 1698 ash->identity = sam->identity;
@@ -2028,7 +1945,7 @@ ticket_iterate_proc (void *cls,
2028 send_ticket_result (proc->ti->client, 1945 send_ticket_result (proc->ti->client,
2029 proc->ti->r_id, 1946 proc->ti->r_id,
2030 ticket, 1947 ticket,
2031 attrs); 1948 GNUNET_OK);
2032 1949
2033} 1950}
2034 1951
@@ -2180,6 +2097,13 @@ run (void *cls,
2180 2097
2181 stats = GNUNET_STATISTICS_create ("reclaim", cfg); 2098 stats = GNUNET_STATISTICS_create ("reclaim", cfg);
2182 2099
2100 if (GNUNET_OK != RECLAIM_TICKETS_init (cfg))
2101 {
2102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2103 "Unable to initialized TICKETS subsystem.\n");
2104 GNUNET_SCHEDULER_shutdown ();
2105 return;
2106 }
2183 //Connect to identity and namestore services 2107 //Connect to identity and namestore services
2184 nsh = GNUNET_NAMESTORE_connect (cfg); 2108 nsh = GNUNET_NAMESTORE_connect (cfg);
2185 if (NULL == nsh) 2109 if (NULL == nsh)
@@ -2192,11 +2116,6 @@ run (void *cls,
2192 { 2116 {
2193 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to gns"); 2117 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to gns");
2194 } 2118 }
2195 credential_handle = GNUNET_CREDENTIAL_connect (cfg);
2196 if (NULL == credential_handle)
2197 {
2198 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to credential");
2199 }
2200 identity_handle = GNUNET_IDENTITY_connect (cfg, 2119 identity_handle = GNUNET_IDENTITY_connect (cfg,
2201 NULL, 2120 NULL,
2202 NULL); 2121 NULL);
@@ -2256,7 +2175,7 @@ client_disconnect_cb (void *cls,
2256 struct AttributeIterator *ai; 2175 struct AttributeIterator *ai;
2257 struct TicketIteration *ti; 2176 struct TicketIteration *ti;
2258 struct TicketRevocationHandle *rh; 2177 struct TicketRevocationHandle *rh;
2259 struct TicketIssueHandle *iss; 2178 struct TicketIssueOperation *iss;
2260 struct ConsumeTicketHandle *ct; 2179 struct ConsumeTicketHandle *ct;
2261 struct AttributeStoreHandle *as; 2180 struct AttributeStoreHandle *as;
2262 2181
@@ -2271,7 +2190,7 @@ client_disconnect_cb (void *cls,
2271 GNUNET_CONTAINER_DLL_remove (idp->issue_op_head, 2190 GNUNET_CONTAINER_DLL_remove (idp->issue_op_head,
2272 idp->issue_op_tail, 2191 idp->issue_op_tail,
2273 iss); 2192 iss);
2274 cleanup_ticket_issue_handle (iss); 2193 GNUNET_free (iss);
2275 } 2194 }
2276 while (NULL != (ct = idp->consume_op_head)) 2195 while (NULL != (ct = idp->consume_op_head))
2277 { 2196 {
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c
new file mode 100644
index 000000000..f93e934ee
--- /dev/null
+++ b/src/reclaim/gnunet-service-reclaim_tickets.c
@@ -0,0 +1,455 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 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 */
20
21/**
22 * @author Martin Schanzenbach
23 * @file src/reclaim/gnunet-service-reclaim_tickets.c
24 * @brief reclaim tickets
25 *
26 */
27#include "gnunet-service-reclaim_tickets.h"
28
29/**
30 * A reference to a ticket stored in GNS
31 */
32struct TicketReference
33{
34 /**
35 * DLL
36 */
37 struct TicketReference *next;
38
39 /**
40 * DLL
41 */
42 struct TicketReference *prev;
43
44 /**
45 * Attributes
46 */
47 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
48
49 /**
50 * Tickets
51 */
52 struct GNUNET_RECLAIM_Ticket ticket;
53};
54
55
56/**
57 * Ticket issue request handle
58 */
59struct TicketIssueHandle
60{
61 /**
62 * Attributes to issue
63 */
64 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
65
66 /**
67 * Issuer Key
68 */
69 struct GNUNET_CRYPTO_EcdsaPrivateKey identity;
70
71 /**
72 * Ticket to issue
73 */
74 struct GNUNET_RECLAIM_Ticket ticket;
75
76 /**
77 * QueueEntry
78 */
79 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
80
81 /**
82 * Ticket reference list
83 */
84 struct TicketReference *ticket_refs_head;
85
86 /**
87 * Ticket reference list
88 */
89 struct TicketReference *ticket_refs_tail;
90
91 /**
92 * Number of references
93 */
94 uint32_t ticket_ref_num;
95
96 /**
97 * Callback
98 */
99 RECLAIM_TICKETS_TicketResult cb;
100
101 /**
102 * Callback cls
103 */
104 void *cb_cls;
105
106};
107
108static struct GNUNET_NAMESTORE_Handle *nsh;
109
110/**
111 * Cleanup ticket consume handle
112 * @param handle the handle to clean up
113 */
114static void
115cleanup_issue_handle (struct TicketIssueHandle *handle)
116{
117 struct TicketReference *tr;
118 struct TicketReference *tr_tmp;
119 if (NULL != handle->attrs)
120 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (handle->attrs);
121 if (NULL != handle->ns_qe)
122 GNUNET_NAMESTORE_cancel (handle->ns_qe);
123 for (tr = handle->ticket_refs_head; NULL != tr;)
124 {
125 if (NULL != tr->attrs)
126 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (tr->attrs);
127 tr_tmp = tr;
128 tr = tr->next;
129 GNUNET_free (tr_tmp);
130 }
131 GNUNET_free (handle);
132}
133
134
135
136static void
137store_ticket_refs_cont (void *cls,
138 int32_t success,
139 const char *emsg)
140{
141 struct TicketIssueHandle *handle = cls;
142 handle->ns_qe = NULL;
143 if (GNUNET_OK != success)
144 {
145 handle->cb (handle->cb_cls,
146 NULL,
147 GNUNET_SYSERR,
148 "Error storing updated ticket refs in GNS");
149 cleanup_issue_handle (handle);
150 return;
151 }
152 handle->cb (handle->cb_cls,
153 &handle->ticket,
154 GNUNET_OK,
155 NULL);
156 cleanup_issue_handle (handle);
157}
158
159
160
161static void
162update_ticket_refs (void* cls)
163{
164 struct TicketIssueHandle *handle = cls;
165 struct GNUNET_GNSRECORD_Data refs_rd[handle->ticket_ref_num];
166 struct TicketReference *tr;
167 char* buf;
168 size_t buf_size;
169
170 tr = handle->ticket_refs_head;
171 for (int i = 0; i < handle->ticket_ref_num; i++)
172 {
173 buf_size = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (tr->attrs);
174 buf_size += sizeof (struct GNUNET_RECLAIM_Ticket);
175 buf = GNUNET_malloc (buf_size);
176 memcpy (buf, &tr->ticket, sizeof (struct GNUNET_RECLAIM_Ticket));
177 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (tr->attrs,
178 buf + sizeof (struct GNUNET_RECLAIM_Ticket));
179 refs_rd[i].data = buf;
180 refs_rd[i].data_size = buf_size;
181 refs_rd[i].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us;
182 refs_rd[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF;
183 refs_rd[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION |
184 GNUNET_GNSRECORD_RF_PRIVATE;
185 tr = tr->next;
186 }
187
188 handle->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
189 &handle->identity,
190 GNUNET_GNS_EMPTY_LABEL_AT,
191 handle->ticket_ref_num,
192 refs_rd,
193 &store_ticket_refs_cont,
194 handle);
195 for (int i = 0; i < handle->ticket_ref_num; i++)
196 GNUNET_free ((char*)refs_rd[i].data);
197}
198
199
200
201static void
202ticket_lookup_cb (void *cls,
203 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
204 const char *label,
205 unsigned int rd_count,
206 const struct GNUNET_GNSRECORD_Data *rd)
207{
208 struct TicketIssueHandle *handle = cls;
209 struct TicketReference *tr;
210 const char* attr_data;
211 size_t attr_data_len;
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
213 "Received tickets from local namestore.\n");
214 handle->ns_qe = NULL;
215 for (int i = 0; i < rd_count; i++)
216 {
217 if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF != rd[i].record_type)
218 continue;
219 tr = GNUNET_new (struct TicketReference);
220 memcpy (&tr->ticket, rd[i].data,
221 sizeof (struct GNUNET_RECLAIM_Ticket));
222 if (0 != memcmp (&tr->ticket.identity,
223 &handle->ticket.identity,
224 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
225 {
226 //Not our ticket
227 GNUNET_free (tr);
228 continue;
229 }
230 attr_data = rd[i].data + sizeof (struct GNUNET_RECLAIM_Ticket);
231 attr_data_len = rd[i].data_size - sizeof (struct GNUNET_RECLAIM_Ticket);
232 tr->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attr_data,
233 attr_data_len);
234 GNUNET_CONTAINER_DLL_insert (handle->ticket_refs_head,
235 handle->ticket_refs_tail,
236 tr);
237 handle->ticket_ref_num++;
238 }
239 tr = GNUNET_new (struct TicketReference);
240 tr->ticket = handle->ticket;
241 tr->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (handle->attrs);
242 GNUNET_CONTAINER_DLL_insert (handle->ticket_refs_head,
243 handle->ticket_refs_tail,
244 tr);
245 handle->ticket_ref_num++;
246 GNUNET_SCHEDULER_add_now (&update_ticket_refs, handle);
247}
248
249static void
250ticket_lookup_error_cb (void *cls)
251{
252 struct TicketIssueHandle *handle = cls;
253 handle->ns_qe = NULL;
254 handle->cb (handle->cb_cls,
255 &handle->ticket,
256 GNUNET_SYSERR,
257 "Error checking for ticketsin GNS\n");
258 cleanup_issue_handle (handle);
259}
260
261static void
262store_ticket_issue_cont (void *cls,
263 int32_t success,
264 const char *emsg)
265{
266 struct TicketIssueHandle *handle = cls;
267
268 handle->ns_qe = NULL;
269 if (GNUNET_SYSERR == success)
270 {
271 handle->cb (handle->cb_cls,
272 &handle->ticket,
273 GNUNET_SYSERR,
274 "Error storing AuthZ ticket in GNS");
275 return;
276 }
277 /* First, local references to tickets */
278 handle->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh,
279 &handle->identity,
280 GNUNET_GNS_EMPTY_LABEL_AT,
281 &ticket_lookup_error_cb,
282 handle,
283 &ticket_lookup_cb,
284 handle);
285}
286
287static int
288create_sym_key_from_ecdh (const struct GNUNET_HashCode *new_key_hash,
289 struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
290 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
291{
292 struct GNUNET_CRYPTO_HashAsciiEncoded new_key_hash_str;
293
294 GNUNET_CRYPTO_hash_to_enc (new_key_hash,
295 &new_key_hash_str);
296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating symmetric rsa key from %s\n", (char*)&new_key_hash_str);
297 static const char ctx_key[] = "gnuid-aes-ctx-key";
298 GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey),
299 new_key_hash, sizeof (struct GNUNET_HashCode),
300 ctx_key, strlen (ctx_key),
301 NULL, 0);
302 static const char ctx_iv[] = "gnuid-aes-ctx-iv";
303 GNUNET_CRYPTO_kdf (iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector),
304 new_key_hash, sizeof (struct GNUNET_HashCode),
305 ctx_iv, strlen (ctx_iv),
306 NULL, 0);
307 return GNUNET_OK;
308}
309
310
311static int
312serialize_authz_record (const struct GNUNET_RECLAIM_Ticket *ticket,
313 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
314 struct GNUNET_CRYPTO_EcdhePrivateKey **ecdh_privkey,
315 char **result)
316{
317 struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey;
318 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
319 struct GNUNET_CRYPTO_SymmetricSessionKey skey;
320 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
321 struct GNUNET_HashCode new_key_hash;
322 ssize_t enc_size;
323 char *enc_keyinfo;
324 char *buf;
325 char *write_ptr;
326 char attrs_str_len;
327 char* label;
328
329 GNUNET_assert (NULL != attrs->list_head);
330 attrs_str_len = 0;
331 for (le = attrs->list_head; NULL != le; le = le->next) {
332 attrs_str_len += 15 + 1; //TODO propery calculate
333 }
334 buf = GNUNET_malloc (attrs_str_len);
335 write_ptr = buf;
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
337 "Writing attributes\n");
338 for (le = attrs->list_head; NULL != le; le = le->next) {
339 label = GNUNET_STRINGS_data_to_string_alloc (&le->claim->id,
340 sizeof (uint64_t));
341 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
342 "Adding attribute to record: %s\n", label);
343
344 GNUNET_memcpy (write_ptr,
345 label,
346 strlen (label));
347 write_ptr[strlen (label)] = ',';
348 write_ptr += strlen (label) + 1;
349 GNUNET_free (label);
350 }
351 write_ptr--;
352 write_ptr[0] = '\0'; //replace last , with a 0-terminator
353 // ECDH keypair E = eG
354 *ecdh_privkey = GNUNET_CRYPTO_ecdhe_key_create();
355 GNUNET_CRYPTO_ecdhe_key_get_public (*ecdh_privkey,
356 &ecdh_pubkey);
357 enc_keyinfo = GNUNET_malloc (attrs_str_len);
358 // Derived key K = H(eB)
359 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdh_ecdsa (*ecdh_privkey,
360 &ticket->audience,
361 &new_key_hash));
362 create_sym_key_from_ecdh (&new_key_hash, &skey, &iv);
363 enc_size = GNUNET_CRYPTO_symmetric_encrypt (buf,
364 attrs_str_len,
365 &skey, &iv,
366 enc_keyinfo);
367 *result = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)+
368 enc_size);
369 GNUNET_memcpy (*result,
370 &ecdh_pubkey,
371 sizeof (struct GNUNET_CRYPTO_EcdhePublicKey));
372 GNUNET_memcpy (*result + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey),
373 enc_keyinfo,
374 enc_size);
375 GNUNET_free (enc_keyinfo);
376 GNUNET_free (buf);
377 return sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)+enc_size;
378}
379
380
381
382static void
383issue_ticket (struct TicketIssueHandle *ih)
384{
385 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey;
386 struct GNUNET_GNSRECORD_Data code_record[1];
387 char *authz_record_data;
388 size_t authz_record_len;
389 char *label;
390
391 //TODO rename function
392 authz_record_len = serialize_authz_record (&ih->ticket,
393 ih->attrs,
394 &ecdhe_privkey,
395 &authz_record_data);
396 code_record[0].data = authz_record_data;
397 code_record[0].data_size = authz_record_len;
398 code_record[0].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us;
399 code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ;
400 code_record[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
401
402 label = GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd,
403 sizeof (uint64_t));
404 //Publish record
405 ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
406 &ih->identity,
407 label,
408 1,
409 code_record,
410 &store_ticket_issue_cont,
411 ih);
412 GNUNET_free (ecdhe_privkey);
413 GNUNET_free (label);
414 GNUNET_free (authz_record_data);
415}
416
417
418
419
420void
421RECLAIM_TICKETS_issue_ticket (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
422 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
423 const struct GNUNET_CRYPTO_EcdsaPublicKey *audience,
424 RECLAIM_TICKETS_TicketResult cb,
425 void* cb_cls)
426{
427 struct TicketIssueHandle *tih;
428 tih = GNUNET_new (struct TicketIssueHandle);
429 tih->cb = cb;
430 tih->cb_cls = cb_cls;
431 tih->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (attrs);
432 tih->identity = *identity;
433 GNUNET_CRYPTO_ecdsa_key_get_public (identity,
434 &tih->ticket.identity);
435 tih->ticket.rnd =
436 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
437 UINT64_MAX);
438 tih->ticket.audience = *audience;
439 issue_ticket (tih);
440}
441
442
443int
444RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c)
445{
446 //Connect to identity and namestore services
447 nsh = GNUNET_NAMESTORE_connect (c);
448 if (NULL == nsh)
449 {
450 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
451 "Error connecting to namestore\n");
452 return GNUNET_SYSERR;
453 }
454 return GNUNET_OK;
455}
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.h b/src/reclaim/gnunet-service-reclaim_tickets.h
new file mode 100644
index 000000000..7ad86dba5
--- /dev/null
+++ b/src/reclaim/gnunet-service-reclaim_tickets.h
@@ -0,0 +1,63 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 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 */
20#include "platform.h"
21#include "gnunet_util_lib.h"
22#include "gnunet_constants.h"
23#include "gnunet_protocols.h"
24#include "gnunet_gnsrecord_lib.h"
25#include "gnunet_gns_service.h"
26#include "gnunet_namestore_service.h"
27#include "gnunet_statistics_service.h"
28#include "gnunet_reclaim_plugin.h"
29#include "gnunet_reclaim_attribute_lib.h"
30#include "gnunet_signatures.h"
31#include "reclaim.h"
32
33/**
34 * Continuation called with ticket.
35 *
36 * @param cls closure
37 * @param ticket the ticket
38 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
39 * #GNUNET_OK on success
40 * @param emsg NULL on success, otherwise an error message
41 */
42typedef void
43(*RECLAIM_TICKETS_TicketResult) (void *cls,
44 struct GNUNET_RECLAIM_Ticket *ticket,
45 uint32_t success,
46 const char *emsg);
47
48
49/**
50 * @author Martin Schanzenbach
51 * @file src/reclaim/gnunet-service-reclaim_tickets.h
52 * @brief reclaim tickets
53 *
54 */
55void
56RECLAIM_TICKETS_issue_ticket (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
57 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
58 const struct GNUNET_CRYPTO_EcdsaPublicKey *audience,
59 RECLAIM_TICKETS_TicketResult cb,
60 void* cb_cls);
61
62int
63RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c);
diff --git a/src/reclaim/plugin_gnsrecord_reclaim.c b/src/reclaim/plugin_gnsrecord_reclaim.c
index d4d937f7e..2f075d8b9 100644
--- a/src/reclaim/plugin_gnsrecord_reclaim.c
+++ b/src/reclaim/plugin_gnsrecord_reclaim.c
@@ -52,6 +52,7 @@ value_to_string (void *cls,
52 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: 52 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT:
53 return GNUNET_strndup (data, data_size); 53 return GNUNET_strndup (data, data_size);
54 case GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ: 54 case GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ:
55 case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF:
55 case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: 56 case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER:
56 return GNUNET_STRINGS_data_to_string_alloc (data, data_size); 57 return GNUNET_STRINGS_data_to_string_alloc (data, data_size);
57 default: 58 default:
@@ -94,6 +95,7 @@ string_to_value (void *cls,
94 return GNUNET_OK; 95 return GNUNET_OK;
95 case GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ: 96 case GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ:
96 case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: 97 case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER:
98 case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF:
97 return GNUNET_STRINGS_string_to_data (s, 99 return GNUNET_STRINGS_string_to_data (s,
98 strlen (s), 100 strlen (s),
99 *data, 101 *data,
@@ -117,6 +119,7 @@ static struct {
117 { "RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER }, 119 { "RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER },
118 { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT }, 120 { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT },
119 { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT }, 121 { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT },
122 { "RECLAIM_TICKETREF", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF },
120 { NULL, UINT32_MAX } 123 { NULL, UINT32_MAX }
121}; 124};
122 125
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index cfa0cbbfb..c8fde121b 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17