aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-19 23:53:02 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-20 17:59:02 +0200
commita57d476abbe857365aff157f389cc1188b5dd090 (patch)
treee8f7163ef7e6f5426748fed8d2eaa5183038a5d6 /src
parente75869506cc08e08056168383bd4ab02e1f007de (diff)
downloadgnunet-a57d476abbe857365aff157f389cc1188b5dd090.tar.gz
gnunet-a57d476abbe857365aff157f389cc1188b5dd090.zip
reclaim: Attestations now called credentials. Credentials are presented to third parties as presentations.
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_gnsrecord_lib.h7
-rw-r--r--src/include/gnunet_reclaim_lib.h13
-rw-r--r--src/include/gnunet_reclaim_plugin.h10
-rw-r--r--src/include/gnunet_reclaim_service.h18
-rw-r--r--src/reclaim/gnunet-reclaim.c5
-rw-r--r--src/reclaim/gnunet-service-reclaim.c33
-rw-r--r--src/reclaim/gnunet-service-reclaim_tickets.c197
-rw-r--r--src/reclaim/gnunet-service-reclaim_tickets.h7
-rw-r--r--src/reclaim/json_reclaim.c12
-rw-r--r--src/reclaim/json_reclaim.h2
-rw-r--r--src/reclaim/oidc_helper.c22
-rw-r--r--src/reclaim/oidc_helper.h16
-rw-r--r--src/reclaim/plugin_gnsrecord_reclaim.c12
-rw-r--r--src/reclaim/plugin_reclaim_credential_jwt.c159
-rw-r--r--src/reclaim/plugin_rest_openid_connect.c68
-rw-r--r--src/reclaim/plugin_rest_reclaim.c6
-rw-r--r--src/reclaim/reclaim.h7
-rw-r--r--src/reclaim/reclaim_api.c58
-rw-r--r--src/reclaim/reclaim_credential.c501
-rw-r--r--src/reclaim/reclaim_credential.h35
20 files changed, 1010 insertions, 178 deletions
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h
index c976c89c5..960203fb1 100644
--- a/src/include/gnunet_gnsrecord_lib.h
+++ b/src/include/gnunet_gnsrecord_lib.h
@@ -143,12 +143,13 @@ extern "C" {
143/** 143/**
144 * Record type for an attribute attestation 144 * Record type for an attribute attestation
145 */ 145 */
146#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION 65554 146#define GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL 65554
147 147
148/** 148/**
149 * Record type for an attestation reference in a ticket 149 * Record type for a presentation of a credential (used
150 * in a ticket record set)
150 */ 151 */
151#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF 65555 152#define GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION 65555
152 153
153 154
154/** 155/**
diff --git a/src/include/gnunet_reclaim_lib.h b/src/include/gnunet_reclaim_lib.h
index f5c3d3864..bbf1c3ad3 100644
--- a/src/include/gnunet_reclaim_lib.h
+++ b/src/include/gnunet_reclaim_lib.h
@@ -780,6 +780,11 @@ GNUNET_RECLAIM_presentation_value_to_string (uint32_t type,
780 const void *data, 780 const void *data,
781 size_t data_size); 781 size_t data_size);
782 782
783struct GNUNET_RECLAIM_Presentation *
784GNUNET_RECLAIM_presentation_new (uint32_t type,
785 const void *data,
786 size_t data_size);
787
783/** 788/**
784 * Convert human-readable version of a 'claim' of a presentation to the binary 789 * Convert human-readable version of a 'claim' of a presentation to the binary
785 * representation 790 * representation
@@ -828,14 +833,16 @@ GNUNET_RECLAIM_presentation_get_expiration (const struct
828 * 833 *
829 * @param cred the credential to use 834 * @param cred the credential to use
830 * @param attrs the attributes to present from the credential 835 * @param attrs the attributes to present from the credential
831 * @return the credential presentation presenting the attributes according 836 * @param presentation the credential presentation presenting the attributes according
832 * to the presentation mechanism of the credential 837 * to the presentation mechanism of the credential
833 * or NULL on error. 838 * or NULL on error.
839 * @return GNUNET_OK on success.
834 */ 840 */
835struct GNUNET_RECLAIM_Presentation* 841int
836GNUNET_RECLAIM_credential_get_presentation ( 842GNUNET_RECLAIM_credential_get_presentation (
837 const struct GNUNET_RECLAIM_Credential *cred, 843 const struct GNUNET_RECLAIM_Credential *cred,
838 const struct GNUNET_RECLAIM_AttributeList *attrs); 844 const struct GNUNET_RECLAIM_AttributeList *attrs,
845 struct GNUNET_RECLAIM_Presentation **presentation);
839 846
840 847
841#if 0 /* keep Emacsens' auto-indent happy */ 848#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/include/gnunet_reclaim_plugin.h b/src/include/gnunet_reclaim_plugin.h
index af6c74e0b..2ba8fc8a0 100644
--- a/src/include/gnunet_reclaim_plugin.h
+++ b/src/include/gnunet_reclaim_plugin.h
@@ -301,6 +301,11 @@ typedef int (*GNUNET_RECLAIM_PresentationGetExpirationFunction) (
301 const struct GNUNET_RECLAIM_Presentation *cred, 301 const struct GNUNET_RECLAIM_Presentation *cred,
302 struct GNUNET_TIME_Absolute *expiration); 302 struct GNUNET_TIME_Absolute *expiration);
303 303
304typedef int (*GNUNET_RECLAIM_CredentialToPresentation) (
305 void *cls,
306 const struct GNUNET_RECLAIM_Credential *cred,
307 const struct GNUNET_RECLAIM_AttributeList *attrs,
308 struct GNUNET_RECLAIM_Presentation **presentation);
304 309
305/** 310/**
306 * Each plugin is required to return a pointer to a struct of this 311 * Each plugin is required to return a pointer to a struct of this
@@ -416,6 +421,11 @@ struct GNUNET_RECLAIM_CredentialPluginFunctions
416 */ 421 */
417 GNUNET_RECLAIM_PresentationGetExpirationFunction get_expiration_p; 422 GNUNET_RECLAIM_PresentationGetExpirationFunction get_expiration_p;
418 423
424 /**
425 * Get presentation
426 */
427 GNUNET_RECLAIM_CredentialToPresentation create_presentation;
428
419}; 429};
420 430
421 431
diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h
index 8387c79b0..368058f56 100644
--- a/src/include/gnunet_reclaim_service.h
+++ b/src/include/gnunet_reclaim_service.h
@@ -92,7 +92,21 @@ struct GNUNET_RECLAIM_Ticket
92 * @param ticket the ticket 92 * @param ticket the ticket
93 */ 93 */
94typedef void (*GNUNET_RECLAIM_TicketCallback) ( 94typedef void (*GNUNET_RECLAIM_TicketCallback) (
95 void *cls, const struct GNUNET_RECLAIM_Ticket *ticket); 95 void *cls,
96 const struct GNUNET_RECLAIM_Ticket *ticket);
97
98/**
99 * Method called when a token has been issued.
100 * On success returns a ticket that can be given to a relying party
101 * in order for it retrive identity attributes
102 *
103 * @param cls closure
104 * @param ticket the ticket
105 */
106typedef void (*GNUNET_RECLAIM_IssueTicketCallback) (
107 void *cls,
108 const struct GNUNET_RECLAIM_Ticket *ticket,
109 const struct GNUNET_RECLAIM_PresentationList *presentations);
96 110
97 111
98/** 112/**
@@ -369,7 +383,7 @@ GNUNET_RECLAIM_ticket_issue (
369 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, 383 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
370 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, 384 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
371 const struct GNUNET_RECLAIM_AttributeList *attrs, 385 const struct GNUNET_RECLAIM_AttributeList *attrs,
372 GNUNET_RECLAIM_TicketCallback cb, void *cb_cls); 386 GNUNET_RECLAIM_IssueTicketCallback cb, void *cb_cls);
373 387
374 388
375/** 389/**
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c
index a59053f5f..ab281a645 100644
--- a/src/reclaim/gnunet-reclaim.c
+++ b/src/reclaim/gnunet-reclaim.c
@@ -227,7 +227,9 @@ do_cleanup (void *cls)
227 227
228 228
229static void 229static void
230ticket_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)
231{ 233{
232 char *ticket_str; 234 char *ticket_str;
233 235
@@ -456,6 +458,7 @@ iter_finished (void *cls)
456 if (NULL == attr_to_delete) 458 if (NULL == attr_to_delete)
457 { 459 {
458 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);
459 return; 462 return;
460 } 463 }
461 reclaim_op = GNUNET_RECLAIM_attribute_delete (reclaim_handle, 464 reclaim_op = GNUNET_RECLAIM_attribute_delete (reclaim_handle,
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index 30a84b3e8..d2cdc62a2 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -646,19 +646,33 @@ static void
646send_ticket_result (const struct IdpClient *client, 646send_ticket_result (const struct IdpClient *client,
647 uint32_t r_id, 647 uint32_t r_id,
648 const struct GNUNET_RECLAIM_Ticket *ticket, 648 const struct GNUNET_RECLAIM_Ticket *ticket,
649 const struct GNUNET_RECLAIM_PresentationList *presentations,
649 uint32_t success) 650 uint32_t success)
650{ 651{
651 struct TicketResultMessage *irm; 652 struct TicketResultMessage *irm;
652 struct GNUNET_MQ_Envelope *env; 653 struct GNUNET_MQ_Envelope *env;
654 size_t pres_len = 0;
653 655
654 env = GNUNET_MQ_msg (irm, 656 if (NULL != presentations)
655 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); 657 {
658 pres_len =
659 GNUNET_RECLAIM_presentation_list_serialize_get_size (presentations);
660 }
661 env = GNUNET_MQ_msg_extra (irm,
662 pres_len,
663 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
656 if (NULL != ticket) 664 if (NULL != ticket)
657 { 665 {
658 irm->ticket = *ticket; 666 irm->ticket = *ticket;
659 } 667 }
660 // TODO add success member 668 // TODO add success member
661 irm->id = htonl (r_id); 669 irm->id = htonl (r_id);
670 irm->presentations_len = htons (pres_len);
671 if (NULL != presentations)
672 {
673 GNUNET_RECLAIM_presentation_list_serialize (presentations,
674 (char*) &irm[1]);
675 }
662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n"); 676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n");
663 GNUNET_MQ_send (client->mq, env); 677 GNUNET_MQ_send (client->mq, env);
664} 678}
@@ -669,12 +683,14 @@ send_ticket_result (const struct IdpClient *client,
669 * 683 *
670 * @param cls out ticket issue operation handle 684 * @param cls out ticket issue operation handle
671 * @param ticket the issued ticket 685 * @param ticket the issued ticket
686 * @param presentations newly created credential presentations (NULL on error)
672 * @param success issue success status (GNUNET_OK if successful) 687 * @param success issue success status (GNUNET_OK if successful)
673 * @param emsg error message (NULL of success is GNUNET_OK) 688 * @param emsg error message (NULL of success is GNUNET_OK)
674 */ 689 */
675static void 690static void
676issue_ticket_result_cb (void *cls, 691issue_ticket_result_cb (void *cls,
677 struct GNUNET_RECLAIM_Ticket *ticket, 692 struct GNUNET_RECLAIM_Ticket *ticket,
693 struct GNUNET_RECLAIM_PresentationList *presentations,
678 int32_t success, 694 int32_t success,
679 const char *emsg) 695 const char *emsg)
680{ 696{
@@ -682,7 +698,7 @@ issue_ticket_result_cb (void *cls,
682 698
683 if (GNUNET_OK != success) 699 if (GNUNET_OK != success)
684 { 700 {
685 send_ticket_result (tio->client, tio->r_id, NULL, GNUNET_SYSERR); 701 send_ticket_result (tio->client, tio->r_id, NULL, NULL, GNUNET_SYSERR);
686 GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head, 702 GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head,
687 tio->client->issue_op_tail, 703 tio->client->issue_op_tail,
688 tio); 704 tio);
@@ -690,7 +706,8 @@ issue_ticket_result_cb (void *cls,
690 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error issuing ticket: %s\n", emsg); 706 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error issuing ticket: %s\n", emsg);
691 return; 707 return;
692 } 708 }
693 send_ticket_result (tio->client, tio->r_id, ticket, GNUNET_SYSERR); 709 send_ticket_result (tio->client, tio->r_id,
710 ticket, presentations, GNUNET_SYSERR);
694 GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head, 711 GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head,
695 tio->client->issue_op_tail, 712 tio->client->issue_op_tail,
696 tio); 713 tio);
@@ -871,7 +888,7 @@ consume_result_cb (void *cls,
871 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT); 888 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT);
872 crm->id = htonl (cop->r_id); 889 crm->id = htonl (cop->r_id);
873 crm->attrs_len = htons (attrs_len); 890 crm->attrs_len = htons (attrs_len);
874 crm->pres_len = htons (pres_len); 891 crm->presentations_len = htons (pres_len);
875 crm->identity = *identity; 892 crm->identity = *identity;
876 crm->result = htonl (success); 893 crm->result = htonl (success);
877 data_tmp = (char *) &crm[1]; 894 data_tmp = (char *) &crm[1];
@@ -1152,7 +1169,7 @@ cred_add_cb (void *cls,
1152 1169
1153 buf_size = GNUNET_RECLAIM_credential_serialize_get_size (ash->credential); 1170 buf_size = GNUNET_RECLAIM_credential_serialize_get_size (ash->credential);
1154 buf = GNUNET_malloc (buf_size); 1171 buf = GNUNET_malloc (buf_size);
1155 GNUNET_RECLAIM_presentation_serialize (ash->credential, buf); 1172 GNUNET_RECLAIM_credential_serialize (ash->credential, buf);
1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1157 "Storing new credential under `%s'.\n", 1174 "Storing new credential under `%s'.\n",
1158 label); 1175 label);
@@ -1611,8 +1628,8 @@ cred_delete_cont (void *cls, int32_t success, const char *emsg)
1611 * @dam message to check 1628 * @dam message to check
1612 */ 1629 */
1613static int 1630static int
1614check_cred_delete_message (void *cls, 1631check_credential_delete_message (void *cls,
1615 const struct AttributeDeleteMessage *dam) 1632 const struct AttributeDeleteMessage *dam)
1616{ 1633{
1617 uint16_t size; 1634 uint16_t size;
1618 1635
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c
index 18b173aaa..4dd8100f9 100644
--- a/src/reclaim/gnunet-service-reclaim_tickets.c
+++ b/src/reclaim/gnunet-service-reclaim_tickets.c
@@ -114,9 +114,9 @@ struct RECLAIM_TICKETS_ConsumeHandle
114 struct GNUNET_RECLAIM_AttributeList *attrs; 114 struct GNUNET_RECLAIM_AttributeList *attrs;
115 115
116 /** 116 /**
117 * Credentials 117 * Presentations
118 */ 118 */
119 struct GNUNET_RECLAIM_CredentialList *credentials; 119 struct GNUNET_RECLAIM_PresentationList *presentations;
120 120
121 /** 121 /**
122 * Lookup time 122 * Lookup time
@@ -173,6 +173,11 @@ struct TicketIssueHandle
173 struct GNUNET_RECLAIM_AttributeList *attrs; 173 struct GNUNET_RECLAIM_AttributeList *attrs;
174 174
175 /** 175 /**
176 * Presentations to add
177 */
178 struct GNUNET_RECLAIM_PresentationList *presentations;
179
180 /**
176 * Issuer Key 181 * Issuer Key
177 */ 182 */
178 struct GNUNET_CRYPTO_EcdsaPrivateKey identity; 183 struct GNUNET_CRYPTO_EcdsaPrivateKey identity;
@@ -981,8 +986,8 @@ cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth)
981 986
982 if (NULL != cth->attrs) 987 if (NULL != cth->attrs)
983 GNUNET_RECLAIM_attribute_list_destroy (cth->attrs); 988 GNUNET_RECLAIM_attribute_list_destroy (cth->attrs);
984 if (NULL != cth->credentials) 989 if (NULL != cth->presentations)
985 GNUNET_RECLAIM_credential_list_destroy (cth->credentials); 990 GNUNET_RECLAIM_presentation_list_destroy (cth->presentations);
986 GNUNET_free (cth); 991 GNUNET_free (cth);
987} 992}
988 993
@@ -1040,7 +1045,7 @@ process_parallel_lookup_result (void *cls,
1040 return; // Wait for more 1045 return; // Wait for more
1041 /* Else we are done */ 1046 /* Else we are done */
1042 cth->cb (cth->cb_cls, &cth->ticket.identity, 1047 cth->cb (cth->cb_cls, &cth->ticket.identity,
1043 cth->attrs, cth->credentials, GNUNET_OK, NULL); 1048 cth->attrs, cth->presentations, GNUNET_OK, NULL);
1044 cleanup_cth (cth); 1049 cleanup_cth (cth);
1045} 1050}
1046 1051
@@ -1090,6 +1095,7 @@ lookup_authz_cb (void *cls,
1090 struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; 1095 struct RECLAIM_TICKETS_ConsumeHandle *cth = cls;
1091 struct ParallelLookup *parallel_lookup; 1096 struct ParallelLookup *parallel_lookup;
1092 char *lbl; 1097 char *lbl;
1098 struct GNUNET_RECLAIM_PresentationListEntry *ale;
1093 1099
1094 cth->lookup_request = NULL; 1100 cth->lookup_request = NULL;
1095 1101
@@ -1113,13 +1119,12 @@ lookup_authz_cb (void *cls,
1113 switch (rd[i].record_type) 1119 switch (rd[i].record_type)
1114 { 1120 {
1115 case GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION: 1121 case GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION:
1116 struct GNUNET_RECLAIM_CredentialListEntry *ale; 1122 ale = GNUNET_new (struct GNUNET_RECLAIM_PresentationListEntry);
1117 ale = GNUNET_new (struct GNUNET_RECLAIM_CredentialListEntry); 1123 ale->presentation =
1118 ale->credential = 1124 GNUNET_RECLAIM_presentation_deserialize (rd[i].data,
1119 GNUNET_RECLAIM_credential_deserialize (rd[i].data, 1125 rd[i].data_size);
1120 rd[i].data_size); 1126 GNUNET_CONTAINER_DLL_insert (cth->presentations->list_head,
1121 GNUNET_CONTAINER_DLL_insert (cth->credentials->list_head, 1127 cth->presentations->list_tail,
1122 cth->credentials->list_tail,
1123 ale); 1128 ale);
1124 break; 1129 break;
1125 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF: 1130 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF:
@@ -1162,7 +1167,7 @@ lookup_authz_cb (void *cls,
1162 * No references found, return empty attribute list 1167 * No references found, return empty attribute list
1163 */ 1168 */
1164 cth->cb (cth->cb_cls, &cth->ticket.identity, 1169 cth->cb (cth->cb_cls, &cth->ticket.identity,
1165 cth->attrs, cth->credentials, GNUNET_OK, NULL); 1170 cth->attrs, NULL, GNUNET_OK, NULL);
1166 cleanup_cth (cth); 1171 cleanup_cth (cth);
1167} 1172}
1168 1173
@@ -1192,7 +1197,7 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id,
1192 cth->identity = *id; 1197 cth->identity = *id;
1193 GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub); 1198 GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub);
1194 cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 1199 cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
1195 cth->credentials = GNUNET_new (struct GNUNET_RECLAIM_CredentialList); 1200 cth->presentations = GNUNET_new (struct GNUNET_RECLAIM_PresentationList);
1196 cth->ticket = *ticket; 1201 cth->ticket = *ticket;
1197 cth->cb = cb; 1202 cth->cb = cb;
1198 cth->cb_cls = cb_cls; 1203 cth->cb_cls = cb_cls;
@@ -1230,8 +1235,8 @@ RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth)
1230 1235
1231 1236
1232/******************************* 1237/*******************************
1233* Ticket issue 1238 * Ticket issue
1234*******************************/ 1239 *******************************/
1235 1240
1236/** 1241/**
1237 * Cleanup ticket consume handle 1242 * Cleanup ticket consume handle
@@ -1264,11 +1269,15 @@ store_ticket_issue_cont (void *cls, int32_t success, const char *emsg)
1264 { 1269 {
1265 handle->cb (handle->cb_cls, 1270 handle->cb (handle->cb_cls,
1266 &handle->ticket, 1271 &handle->ticket,
1272 NULL,
1267 GNUNET_SYSERR, 1273 GNUNET_SYSERR,
1268 "Error storing AuthZ ticket in GNS"); 1274 "Error storing AuthZ ticket in GNS");
1269 return; 1275 return;
1270 } 1276 }
1271 handle->cb (handle->cb_cls, &handle->ticket, GNUNET_OK, NULL); 1277 handle->cb (handle->cb_cls,
1278 &handle->ticket,
1279 handle->presentations,
1280 GNUNET_OK, NULL);
1272 cleanup_issue_handle (handle); 1281 cleanup_issue_handle (handle);
1273} 1282}
1274 1283
@@ -1284,15 +1293,17 @@ static void
1284issue_ticket (struct TicketIssueHandle *ih) 1293issue_ticket (struct TicketIssueHandle *ih)
1285{ 1294{
1286 struct GNUNET_RECLAIM_AttributeListEntry *le; 1295 struct GNUNET_RECLAIM_AttributeListEntry *le;
1296 struct GNUNET_RECLAIM_PresentationListEntry *ple;
1287 struct GNUNET_GNSRECORD_Data *attrs_record; 1297 struct GNUNET_GNSRECORD_Data *attrs_record;
1288 char *label; 1298 char *label;
1289 int i; 1299 int i;
1300 int j;
1290 int attrs_count = 0; 1301 int attrs_count = 0;
1291 1302
1292 for (le = ih->attrs->list_head; NULL != le; le = le->next) 1303 for (le = ih->attrs->list_head; NULL != le; le = le->next)
1293 attrs_count++; 1304 attrs_count++;
1294 1305
1295 // Worst case we have one credential per attribute 1306 // Worst case we have one presentation per attribute
1296 attrs_record = 1307 attrs_record =
1297 GNUNET_malloc (2 * attrs_count * sizeof(struct GNUNET_GNSRECORD_Data)); 1308 GNUNET_malloc (2 * attrs_count * sizeof(struct GNUNET_GNSRECORD_Data));
1298 i = 0; 1309 i = 0;
@@ -1309,31 +1320,65 @@ issue_ticket (struct TicketIssueHandle *ih)
1309 i++; 1320 i++;
1310 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->credential)) 1321 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->credential))
1311 { 1322 {
1312 struct GNUNET_RECLAIM_Presentation *pres; 1323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1313 int j; 1324 "Attribute is backed by credential. Adding...\n");
1325 struct GNUNET_RECLAIM_Presentation *pres = NULL;
1314 for (j = 0; j < i; j++) 1326 for (j = 0; j < i; j++)
1315 { 1327 {
1316 if (attrs_record[j].record_type 1328 if (attrs_record[j].record_type
1317 != GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION) 1329 != GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION)
1318 continue; 1330 continue;
1319 pres = attrs_record[j].data; 1331 pres = GNUNET_RECLAIM_presentation_deserialize (attrs_record[j].data,
1320 if (0 == memcmp (pres->credential_id, 1332 attrs_record[j].
1333 data_size);
1334 if (NULL == pres)
1335 {
1336 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1337 "Failed to deserialize presentation\n");
1338 continue;
1339 }
1340 if (0 == memcmp (&pres->credential_id,
1321 &le->attribute->credential, 1341 &le->attribute->credential,
1322 sizeof (le->attribute->credential))) 1342 sizeof (le->attribute->credential)))
1323 break; 1343 break;
1344 GNUNET_free (pres);
1345 pres = NULL;
1324 } 1346 }
1325 if (j < i) 1347 if (NULL != pres)
1348 {
1349 GNUNET_free (pres);
1326 continue; // Skip as we have already added this credential presentation. 1350 continue; // Skip as we have already added this credential presentation.
1327 /** 1351 }
1328 * FIXME: Create a new presentation from the credential. 1352 for (ple = ih->presentations->list_head; NULL != ple; ple = ple->next)
1329 */ 1353 {
1330 attrs_record[i].data = &le->attribute->credential; 1354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1331 attrs_record[i].data_size = sizeof(le->attribute->credential); 1355 "Checking presentation....\n");
1332 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; 1356
1333 attrs_record[i].record_type = 1357 if (0 != memcmp (&le->attribute->credential,
1334 GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION; 1358 &ple->presentation->credential_id,
1335 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 1359 sizeof (le->attribute->credential)))
1336 i++; 1360 {
1361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1362 "Presentation does not match credential ID.\n");
1363 continue;
1364 }
1365 char *pres_buf;
1366 size_t pres_size;
1367 pres_size =
1368 GNUNET_RECLAIM_presentation_serialize_get_size (ple->presentation);
1369 pres_buf = GNUNET_malloc (pres_size);
1370 GNUNET_RECLAIM_presentation_serialize (ple->presentation,
1371 pres_buf);
1372 attrs_record[i].data = pres_buf;
1373 attrs_record[i].data_size = pres_size;
1374 attrs_record[i].expiration_time =
1375 ticket_refresh_interval.rel_value_us;
1376 attrs_record[i].record_type =
1377 GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION;
1378 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1379 i++;
1380 break;
1381 }
1337 } 1382 }
1338 } 1383 }
1339 attrs_record[i].data = &ih->ticket; 1384 attrs_record[i].data = &ih->ticket;
@@ -1355,14 +1400,23 @@ issue_ticket (struct TicketIssueHandle *ih)
1355 attrs_record, 1400 attrs_record,
1356 &store_ticket_issue_cont, 1401 &store_ticket_issue_cont,
1357 ih); 1402 ih);
1403 for (j = 0; j > i; j++)
1404 {
1405 if (attrs_record[j].record_type
1406 != GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION)
1407 continue;
1408 // Yes, we are allowed to do this because we allocated it above
1409 char *ptr = (char*) attrs_record[j].data;
1410 GNUNET_free (ptr);
1411 }
1358 GNUNET_free (attrs_record); 1412 GNUNET_free (attrs_record);
1359 GNUNET_free (label); 1413 GNUNET_free (label);
1360} 1414}
1361 1415
1362 1416
1363/************************************************* 1417/*************************************************
1364* Ticket iteration (finding a specific ticket) 1418 * Ticket iteration (finding a specific ticket)
1365*************************************************/ 1419 *************************************************/
1366 1420
1367 1421
1368/** 1422/**
@@ -1378,6 +1432,7 @@ filter_tickets_error_cb (void *cls)
1378 tih->ns_it = NULL; 1432 tih->ns_it = NULL;
1379 tih->cb (tih->cb_cls, 1433 tih->cb (tih->cb_cls,
1380 &tih->ticket, 1434 &tih->ticket,
1435 NULL,
1381 GNUNET_SYSERR, 1436 GNUNET_SYSERR,
1382 "Error storing AuthZ ticket in GNS"); 1437 "Error storing AuthZ ticket in GNS");
1383 cleanup_issue_handle (tih); 1438 cleanup_issue_handle (tih);
@@ -1406,11 +1461,12 @@ filter_tickets_cb (void *cls,
1406 struct TicketIssueHandle *tih = cls; 1461 struct TicketIssueHandle *tih = cls;
1407 struct GNUNET_RECLAIM_Ticket *ticket = NULL; 1462 struct GNUNET_RECLAIM_Ticket *ticket = NULL;
1408 struct GNUNET_RECLAIM_Presentation *pres; 1463 struct GNUNET_RECLAIM_Presentation *pres;
1409 1464 struct GNUNET_RECLAIM_PresentationList *ticket_presentations;
1410 // figure out the number of requested attributes 1465 struct GNUNET_RECLAIM_Credential *cred;
1466 struct GNUNET_RECLAIM_PresentationListEntry *ple;
1411 struct GNUNET_RECLAIM_AttributeListEntry *le; 1467 struct GNUNET_RECLAIM_AttributeListEntry *le;
1412 unsigned int attr_cnt = 0; 1468 unsigned int attr_cnt = 0;
1413 unsigned int cred_cnt = 0; 1469 unsigned int pres_cnt = 0;
1414 1470
1415 for (le = tih->attrs->list_head; NULL != le; le = le->next) 1471 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1416 { 1472 {
@@ -1422,6 +1478,7 @@ filter_tickets_cb (void *cls,
1422 // ticket search 1478 // ticket search
1423 unsigned int found_attrs_cnt = 0; 1479 unsigned int found_attrs_cnt = 0;
1424 unsigned int found_pres_cnt = 0; 1480 unsigned int found_pres_cnt = 0;
1481 ticket_presentations = GNUNET_new (struct GNUNET_RECLAIM_PresentationList);
1425 1482
1426 for (int i = 0; i < rd_count; i++) 1483 for (int i = 0; i < rd_count; i++)
1427 { 1484 {
@@ -1450,15 +1507,65 @@ filter_tickets_cb (void *cls,
1450 found_attrs_cnt++; 1507 found_attrs_cnt++;
1451 } 1508 }
1452 } 1509 }
1510 if (GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL == rd[i].record_type)
1511 {
1512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1513 "Found credential...\n");
1514
1515 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1516 {
1517 cred = GNUNET_RECLAIM_credential_deserialize (rd[i].data,
1518 rd[i].data_size);
1519 if (GNUNET_YES != GNUNET_RECLAIM_id_is_equal (&cred->id,
1520 &le->attribute->credential))
1521 {
1522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1523 "No match.\n");
1524 GNUNET_free (cred);
1525 continue;
1526 }
1527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1528 "Match, creating presentation...\n");
1529 if (GNUNET_OK != GNUNET_RECLAIM_credential_get_presentation (
1530 cred,
1531 tih->attrs,
1532 &pres))
1533 {
1534 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1535 "Unable to retrieve presentation from credential\n");
1536 GNUNET_free (cred);
1537 continue;
1538 }
1539 ple = GNUNET_new (struct GNUNET_RECLAIM_PresentationListEntry);
1540 ple->presentation = pres;
1541 GNUNET_CONTAINER_DLL_insert (tih->presentations->list_head,
1542 tih->presentations->list_tail,
1543 ple);
1544 GNUNET_free (cred);
1545 }
1546 }
1453 if (GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION == rd[i].record_type) 1547 if (GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION == rd[i].record_type)
1454 { 1548 {
1455 for (le = tih->attrs->list_head; NULL != le; le = le->next) 1549 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1456 { 1550 {
1457 pres = rd[i].data; 1551 pres = GNUNET_RECLAIM_presentation_deserialize (rd[i].data,
1458 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (pres->credential_id, 1552 rd[i].data_size);
1553 if (NULL == pres)
1554 {
1555 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1556 "Failed to deserialize presentation\n");
1557 continue;
1558 }
1559 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (&pres->credential_id,
1459 &le->attribute->credential)) 1560 &le->attribute->credential))
1561 {
1460 found_pres_cnt++; 1562 found_pres_cnt++;
1461 // FIXME should we store credentials here for later use?? 1563 ple = GNUNET_new (struct GNUNET_RECLAIM_PresentationListEntry);
1564 ple->presentation = pres;
1565 GNUNET_CONTAINER_DLL_insert (ticket_presentations->list_head,
1566 ticket_presentations->list_tail,
1567 ple);
1568 }
1462 } 1569 }
1463 } 1570 }
1464 } 1571 }
@@ -1472,7 +1579,8 @@ filter_tickets_cb (void *cls,
1472 (NULL != ticket)) 1579 (NULL != ticket))
1473 { 1580 {
1474 GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it); 1581 GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it);
1475 tih->cb (tih->cb_cls, &tih->ticket, GNUNET_OK, NULL); 1582 tih->cb (tih->cb_cls, &tih->ticket, ticket_presentations, GNUNET_OK, NULL);
1583 GNUNET_RECLAIM_presentation_list_destroy (ticket_presentations);
1476 cleanup_issue_handle (tih); 1584 cleanup_issue_handle (tih);
1477 return; 1585 return;
1478 } 1586 }
@@ -1524,6 +1632,7 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1524 tih->cb = cb; 1632 tih->cb = cb;
1525 tih->cb_cls = cb_cls; 1633 tih->cb_cls = cb_cls;
1526 tih->attrs = GNUNET_RECLAIM_attribute_list_dup (attrs); 1634 tih->attrs = GNUNET_RECLAIM_attribute_list_dup (attrs);
1635 tih->presentations = GNUNET_new (struct GNUNET_RECLAIM_PresentationList);
1527 tih->identity = *identity; 1636 tih->identity = *identity;
1528 tih->ticket.audience = *audience; 1637 tih->ticket.audience = *audience;
1529 1638
@@ -1541,8 +1650,8 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1541 1650
1542 1651
1543/************************************ 1652/************************************
1544* Ticket iteration 1653 * Ticket iteration
1545************************************/ 1654 ************************************/
1546 1655
1547/** 1656/**
1548 * Cleanup ticket iterator 1657 * Cleanup ticket iterator
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.h b/src/reclaim/gnunet-service-reclaim_tickets.h
index 404b9c837..0dd790fc7 100644
--- a/src/reclaim/gnunet-service-reclaim_tickets.h
+++ b/src/reclaim/gnunet-service-reclaim_tickets.h
@@ -113,6 +113,7 @@ typedef void (*RECLAIM_TICKETS_TicketIter) (
113 * 113 *
114 * @param cls closure 114 * @param cls closure
115 * @param ticket the ticket 115 * @param ticket the ticket
116 * @param presentations new presentations for ticket (NULL on error)
116 * @param success #GNUNET_SYSERR on failure (including timeout/queue 117 * @param success #GNUNET_SYSERR on failure (including timeout/queue
117 * drop/failure to validate) #GNUNET_OK on success 118 * drop/failure to validate) #GNUNET_OK on success
118 * @param emsg NULL on success, otherwise an error message 119 * @param emsg NULL on success, otherwise an error message
@@ -120,6 +121,7 @@ typedef void (*RECLAIM_TICKETS_TicketIter) (
120typedef void (*RECLAIM_TICKETS_TicketResult) ( 121typedef void (*RECLAIM_TICKETS_TicketResult) (
121 void *cls, 122 void *cls,
122 struct GNUNET_RECLAIM_Ticket *ticket, 123 struct GNUNET_RECLAIM_Ticket *ticket,
124 struct GNUNET_RECLAIM_PresentationList *presentations,
123 int32_t success, 125 int32_t success,
124 const char *emsg); 126 const char *emsg);
125 127
@@ -129,7 +131,8 @@ typedef void (*RECLAIM_TICKETS_TicketResult) (
129 * 131 *
130 * @param cls closure 132 * @param cls closure
131 * @param identity the issuer of the ticket/attributes 133 * @param identity the issuer of the ticket/attributes
132 * @param l attribute list retrieved through ticket 134 * @param attributes attribute list retrieved through ticket
135 * @param presentations attribute presentations (may be NULL)
133 * @param success GNUNET_OK on success 136 * @param success GNUNET_OK on success
134 * @param emsg error message (NULL on success) 137 * @param emsg error message (NULL on success)
135 */ 138 */
@@ -137,7 +140,7 @@ typedef void (*RECLAIM_TICKETS_ConsumeCallback) (
137 void *cls, 140 void *cls,
138 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 141 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
139 const struct GNUNET_RECLAIM_AttributeList *attributes, 142 const struct GNUNET_RECLAIM_AttributeList *attributes,
140 const struct GNUNET_RECLAIM_CredentialList *credentials, 143 const struct GNUNET_RECLAIM_PresentationList *presentations,
141 int32_t success, 144 int32_t success,
142 const char *emsg); 145 const char *emsg);
143 146
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c
index c8b944326..8a3479b8a 100644
--- a/src/reclaim/json_reclaim.c
+++ b/src/reclaim/json_reclaim.c
@@ -335,16 +335,16 @@ parse_credential (void *cls, json_t *root, struct GNUNET_JSON_Specification *spe
335 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Credential value invalid!\n"); 335 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Credential value invalid!\n");
336 return GNUNET_SYSERR; 336 return GNUNET_SYSERR;
337 } 337 }
338 attr = GNUNET_RECLAIM_credential_new (name_str, type, data, data_size); 338 cred = GNUNET_RECLAIM_credential_new (name_str, type, data, data_size);
339 if ((NULL == id_str) || (0 == strlen (id_str))) 339 if ((NULL == id_str) || (0 == strlen (id_str)))
340 memset (&attr->id, 0, sizeof (attr->id)); 340 memset (&cred->id, 0, sizeof (cred->id));
341 else 341 else
342 GNUNET_STRINGS_string_to_data (id_str, 342 GNUNET_STRINGS_string_to_data (id_str,
343 strlen (id_str), 343 strlen (id_str),
344 &attr->id, 344 &cred->id,
345 sizeof(attr->id)); 345 sizeof(cred->id));
346 346
347 *(struct GNUNET_RECLAIM_Credential **) spec->ptr = attr; 347 *(struct GNUNET_RECLAIM_Credential **) spec->ptr = cred;
348 return GNUNET_OK; 348 return GNUNET_OK;
349} 349}
350 350
@@ -383,7 +383,7 @@ GNUNET_RECLAIM_JSON_spec_credential (struct
383 .cleaner = &clean_credential, 383 .cleaner = &clean_credential,
384 .cls = NULL, 384 .cls = NULL,
385 .field = NULL, 385 .field = NULL,
386 .ptr = attr, 386 .ptr = cred,
387 .ptr_size = 0, 387 .ptr_size = 0,
388 .size_ptr = NULL }; 388 .size_ptr = NULL };
389 389
diff --git a/src/reclaim/json_reclaim.h b/src/reclaim/json_reclaim.h
index 8911cf92d..613ddf873 100644
--- a/src/reclaim/json_reclaim.h
+++ b/src/reclaim/json_reclaim.h
@@ -54,4 +54,4 @@ GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket);
54 * @return JSON Specification 54 * @return JSON Specification
55 */ 55 */
56struct GNUNET_JSON_Specification 56struct GNUNET_JSON_Specification
57GNUNET_RECLAIM_JSON_spec_credential (struct GNUNET_RECLAIM_Attestation **cred); 57GNUNET_RECLAIM_JSON_spec_credential (struct GNUNET_RECLAIM_Credential **cred);
diff --git a/src/reclaim/oidc_helper.c b/src/reclaim/oidc_helper.c
index 9c7e79c41..b307a358c 100644
--- a/src/reclaim/oidc_helper.c
+++ b/src/reclaim/oidc_helper.c
@@ -156,8 +156,8 @@ fix_base64 (char *str)
156 156
157static json_t* 157static json_t*
158generate_userinfo_json(const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, 158generate_userinfo_json(const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
159 struct GNUNET_RECLAIM_AttributeList *attrs, 159 const struct GNUNET_RECLAIM_AttributeList *attrs,
160 struct GNUNET_RECLAIM_PresentationList *presentations) 160 const struct GNUNET_RECLAIM_PresentationList *presentations)
161{ 161{
162 struct GNUNET_RECLAIM_AttributeListEntry *le; 162 struct GNUNET_RECLAIM_AttributeListEntry *le;
163 struct GNUNET_RECLAIM_PresentationListEntry *ple; 163 struct GNUNET_RECLAIM_PresentationListEntry *ple;
@@ -296,8 +296,8 @@ generate_userinfo_json(const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
296 */ 296 */
297char * 297char *
298OIDC_generate_userinfo (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, 298OIDC_generate_userinfo (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
299 struct GNUNET_RECLAIM_AttributeList *attrs, 299 const struct GNUNET_RECLAIM_AttributeList *attrs,
300 struct GNUNET_RECLAIM_PresentationList *presentations) 300 const struct GNUNET_RECLAIM_PresentationList *presentations)
301{ 301{
302 char *body_str; 302 char *body_str;
303 json_t* body = generate_userinfo_json (sub_key, 303 json_t* body = generate_userinfo_json (sub_key,
@@ -323,8 +323,8 @@ OIDC_generate_userinfo (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
323char * 323char *
324OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, 324OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
325 const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, 325 const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
326 struct GNUNET_RECLAIM_AttributeList *attrs, 326 const struct GNUNET_RECLAIM_AttributeList *attrs,
327 struct GNUNET_RECLAIM_PresentationList *presentations, 327 const struct GNUNET_RECLAIM_PresentationList *presentations,
328 const struct GNUNET_TIME_Relative *expiration_time, 328 const struct GNUNET_TIME_Relative *expiration_time,
329 const char *nonce, 329 const char *nonce,
330 const char *secret_key) 330 const char *secret_key)
@@ -440,8 +440,8 @@ OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
440char * 440char *
441OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, 441OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
442 const struct GNUNET_RECLAIM_Ticket *ticket, 442 const struct GNUNET_RECLAIM_Ticket *ticket,
443 struct GNUNET_RECLAIM_AttributeList *attrs, 443 const struct GNUNET_RECLAIM_AttributeList *attrs,
444 struct GNUNET_RECLAIM_PresentationList *presentations, 444 const struct GNUNET_RECLAIM_PresentationList *presentations,
445 const char *nonce_str, 445 const char *nonce_str,
446 const char *code_challenge) 446 const char *code_challenge)
447{ 447{
@@ -596,7 +596,7 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *audience,
596 struct GNUNET_CRYPTO_EcdsaSignature *signature; 596 struct GNUNET_CRYPTO_EcdsaSignature *signature;
597 uint32_t code_challenge_len; 597 uint32_t code_challenge_len;
598 uint32_t attrs_ser_len; 598 uint32_t attrs_ser_len;
599 uint32_t presentations_ser_len; 599 uint32_t pres_ser_len;
600 size_t plaintext_len; 600 size_t plaintext_len;
601 size_t code_payload_len; 601 size_t code_payload_len;
602 uint32_t nonce_len = 0; 602 uint32_t nonce_len = 0;
@@ -702,8 +702,8 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *audience,
702 presentations_ser = ((char*) attrs_ser) + attrs_ser_len; 702 presentations_ser = ((char*) attrs_ser) + attrs_ser_len;
703 pres_ser_len = ntohl (params->pres_list_len); 703 pres_ser_len = ntohl (params->pres_list_len);
704 *presentations = 704 *presentations =
705 GNUNET_RECLAIM_presentations_list_deserialize (presentations_ser, 705 GNUNET_RECLAIM_presentation_list_deserialize (presentations_ser,
706 pres_ser_len); 706 pres_ser_len);
707 707
708 GNUNET_free (code_payload); 708 GNUNET_free (code_payload);
709 return GNUNET_OK; 709 return GNUNET_OK;
diff --git a/src/reclaim/oidc_helper.h b/src/reclaim/oidc_helper.h
index 789a2acc7..10a6f3d1f 100644
--- a/src/reclaim/oidc_helper.h
+++ b/src/reclaim/oidc_helper.h
@@ -52,8 +52,8 @@
52char* 52char*
53OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, 53OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
54 const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, 54 const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
55 struct GNUNET_RECLAIM_AttributeList *attrs, 55 const struct GNUNET_RECLAIM_AttributeList *attrs,
56 struct GNUNET_RECLAIM_PresentationList *presentations, 56 const struct GNUNET_RECLAIM_PresentationList *presentations,
57 const struct GNUNET_TIME_Relative *expiration_time, 57 const struct GNUNET_TIME_Relative *expiration_time,
58 const char *nonce, 58 const char *nonce,
59 const char *secret_key); 59 const char *secret_key);
@@ -73,8 +73,8 @@ OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
73char* 73char*
74OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, 74OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
75 const struct GNUNET_RECLAIM_Ticket *ticket, 75 const struct GNUNET_RECLAIM_Ticket *ticket,
76 struct GNUNET_RECLAIM_AttributeList *attrs, 76 const struct GNUNET_RECLAIM_AttributeList *attrs,
77 struct GNUNET_RECLAIM_PresentationList *presentations, 77 const struct GNUNET_RECLAIM_PresentationList *presentations,
78 const char *nonce, 78 const char *nonce,
79 const char *code_challenge); 79 const char *code_challenge);
80 80
@@ -139,8 +139,8 @@ OIDC_access_token_parse (const char* token,
139 * @return GNUNET_YES if attribute is implcitly requested 139 * @return GNUNET_YES if attribute is implcitly requested
140 */ 140 */
141enum GNUNET_GenericReturnValue 141enum GNUNET_GenericReturnValue
142OIDC_check_scopes_for_claim_request (const char*scopes, 142OIDC_check_scopes_for_claim_request (const char *scopes,
143 const char*attr); 143 const char *attr);
144 144
145 145
146/** 146/**
@@ -153,7 +153,7 @@ OIDC_check_scopes_for_claim_request (const char*scopes,
153 */ 153 */
154char * 154char *
155OIDC_generate_userinfo (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, 155OIDC_generate_userinfo (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
156 struct GNUNET_RECLAIM_AttributeList *attrs, 156 const struct GNUNET_RECLAIM_AttributeList *attrs,
157 struct GNUNET_RECLAIM_PresentationList *presentations); 157 const struct GNUNET_RECLAIM_PresentationList *presentations);
158 158
159#endif 159#endif
diff --git a/src/reclaim/plugin_gnsrecord_reclaim.c b/src/reclaim/plugin_gnsrecord_reclaim.c
index b91e123a3..60c49fd6a 100644
--- a/src/reclaim/plugin_gnsrecord_reclaim.c
+++ b/src/reclaim/plugin_gnsrecord_reclaim.c
@@ -51,8 +51,8 @@ value_to_string (void *cls, uint32_t type, const void *data, size_t data_size)
51 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF: 51 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF:
52 case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: 52 case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET:
53 case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: 53 case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER:
54 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION: 54 case GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL:
55 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF: 55 case GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION:
56 return GNUNET_STRINGS_data_to_string_alloc (data, data_size); 56 return GNUNET_STRINGS_data_to_string_alloc (data, data_size);
57 57
58 default: 58 default:
@@ -89,8 +89,8 @@ string_to_value (void *cls, uint32_t type, const char *s, void **data,
89 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF: 89 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF:
90 case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: 90 case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER:
91 case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: 91 case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET:
92 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION: 92 case GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL:
93 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF: 93 case GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION:
94 return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); 94 return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size);
95 95
96 default: 96 default:
@@ -110,8 +110,8 @@ static struct
110} name_map[] = { 110} name_map[] = {
111 { "RECLAIM_ATTRIBUTE", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE }, 111 { "RECLAIM_ATTRIBUTE", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE },
112 { "RECLAIM_ATTRIBUTE_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF }, 112 { "RECLAIM_ATTRIBUTE_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF },
113 { "RECLAIM_ATTESTATION", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION }, 113 { "RECLAIM_CREDENTIAL", GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL },
114 { "RECLAIM_ATTESTATION_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF }, 114 { "RECLAIM_PRESENTATION", GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION },
115 { "RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER }, 115 { "RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER },
116 { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT }, 116 { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT },
117 { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT }, 117 { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT },
diff --git a/src/reclaim/plugin_reclaim_credential_jwt.c b/src/reclaim/plugin_reclaim_credential_jwt.c
index 38effcf78..148865223 100644
--- a/src/reclaim/plugin_reclaim_credential_jwt.c
+++ b/src/reclaim/plugin_reclaim_credential_jwt.c
@@ -48,7 +48,7 @@ jwt_value_to_string (void *cls,
48{ 48{
49 switch (type) 49 switch (type)
50 { 50 {
51 case GNUNET_RECLAIM_credential_TYPE_JWT: 51 case GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT:
52 return GNUNET_strndup (data, data_size); 52 return GNUNET_strndup (data, data_size);
53 53
54 default: 54 default:
@@ -79,7 +79,7 @@ jwt_string_to_value (void *cls,
79 return GNUNET_SYSERR; 79 return GNUNET_SYSERR;
80 switch (type) 80 switch (type)
81 { 81 {
82 case GNUNET_RECLAIM_credential_TYPE_JWT: 82 case GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT:
83 *data = GNUNET_strdup (s); 83 *data = GNUNET_strdup (s);
84 *data_size = strlen (s); 84 *data_size = strlen (s);
85 return GNUNET_OK; 85 return GNUNET_OK;
@@ -98,8 +98,8 @@ static struct
98{ 98{
99 const char *name; 99 const char *name;
100 uint32_t number; 100 uint32_t number;
101} jwt_cred_name_map[] = { { "JWT", GNUNET_RECLAIM_credential_TYPE_JWT }, 101} jwt_cred_name_map[] = { { "JWT", GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT },
102 { NULL, UINT32_MAX } }; 102 { NULL, UINT32_MAX } };
103 103
104/** 104/**
105 * Convert a type name to the corresponding number. 105 * Convert a type name to the corresponding number.
@@ -135,8 +135,8 @@ jwt_number_to_typename (void *cls, uint32_t type)
135 135
136 i = 0; 136 i = 0;
137 while ((NULL != jwt_cred_name_map[i].name) && (type != 137 while ((NULL != jwt_cred_name_map[i].name) && (type !=
138 jwt_cred_name_map[i]. 138 jwt_cred_name_map[i].
139 number)) 139 number))
140 i++; 140 i++;
141 return jwt_cred_name_map[i].name; 141 return jwt_cred_name_map[i].name;
142} 142}
@@ -151,7 +151,7 @@ jwt_number_to_typename (void *cls, uint32_t type)
151 */ 151 */
152struct GNUNET_RECLAIM_AttributeList * 152struct GNUNET_RECLAIM_AttributeList *
153jwt_parse_attributes (void *cls, 153jwt_parse_attributes (void *cls,
154 const struct GNUNET_RECLAIM_Credential *cred) 154 const char *data)
155{ 155{
156 char *jwt_string; 156 char *jwt_string;
157 struct GNUNET_RECLAIM_AttributeList *attrs; 157 struct GNUNET_RECLAIM_AttributeList *attrs;
@@ -162,17 +162,14 @@ jwt_parse_attributes (void *cls,
162 json_t *json_val; 162 json_t *json_val;
163 json_error_t *json_err = NULL; 163 json_error_t *json_err = NULL;
164 164
165 /* GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", cred->data); (not OK: 'data' is not defined as 0-terminated text, but binary) */
166 if (GNUNET_RECLAIM_credential_TYPE_JWT != cred->type)
167 return NULL;
168 attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 165 attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
169 166
170 jwt_string = GNUNET_strdup (cred->data); 167 jwt_string = GNUNET_strdup (data);
171 const char *jwt_body = strtok (jwt_string, delim); 168 const char *jwt_body = strtok (jwt_string, delim);
172 jwt_body = strtok (NULL, delim); 169 jwt_body = strtok (NULL, delim);
173 GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body), 170 GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body),
174 (void **) &decoded_jwt); 171 (void **) &decoded_jwt);
175 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", decoded_jwt); 172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decoded JWT: %s\n", decoded_jwt);
176 GNUNET_assert (NULL != decoded_jwt); 173 GNUNET_assert (NULL != decoded_jwt);
177 json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err); 174 json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
178 const char *key; 175 const char *key;
@@ -203,6 +200,36 @@ jwt_parse_attributes (void *cls,
203 200
204 201
205/** 202/**
203 * Parse a JWT and return the respective claim value as Attribute
204 *
205 * @param cls the plugin
206 * @param cred the jwt credential
207 * @return a GNUNET_RECLAIM_Attribute, containing the new value
208 */
209struct GNUNET_RECLAIM_AttributeList *
210jwt_parse_attributes_c (void *cls,
211 const struct GNUNET_RECLAIM_Credential *cred)
212{
213 return jwt_parse_attributes (cls, cred->data);
214}
215
216
217/**
218 * Parse a JWT and return the respective claim value as Attribute
219 *
220 * @param cls the plugin
221 * @param cred the jwt credential
222 * @return a GNUNET_RECLAIM_Attribute, containing the new value
223 */
224struct GNUNET_RECLAIM_AttributeList *
225jwt_parse_attributes_p (void *cls,
226 const struct GNUNET_RECLAIM_Presentation *cred)
227{
228 return jwt_parse_attributes (cls, cred->data);
229}
230
231
232/**
206 * Parse a JWT and return the issuer 233 * Parse a JWT and return the issuer
207 * 234 *
208 * @param cls the plugin 235 * @param cls the plugin
@@ -211,7 +238,7 @@ jwt_parse_attributes (void *cls,
211 */ 238 */
212char * 239char *
213jwt_get_issuer (void *cls, 240jwt_get_issuer (void *cls,
214 const struct GNUNET_RECLAIM_Credential *cred) 241 const char *data)
215{ 242{
216 const char *jwt_body; 243 const char *jwt_body;
217 char *jwt_string; 244 char *jwt_string;
@@ -223,9 +250,7 @@ jwt_get_issuer (void *cls,
223 json_t *json_val; 250 json_t *json_val;
224 json_error_t *json_err = NULL; 251 json_error_t *json_err = NULL;
225 252
226 if (GNUNET_RECLAIM_credential_TYPE_JWT != cred->type) 253 jwt_string = GNUNET_strdup (data);
227 return NULL;
228 jwt_string = GNUNET_strdup (cred->data);
229 jwt_body = strtok (jwt_string, delim); 254 jwt_body = strtok (jwt_string, delim);
230 jwt_body = strtok (NULL, delim); 255 jwt_body = strtok (NULL, delim);
231 GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body), 256 GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body),
@@ -241,6 +266,40 @@ jwt_get_issuer (void *cls,
241 266
242 267
243/** 268/**
269 * Parse a JWT and return the issuer
270 *
271 * @param cls the plugin
272 * @param cred the jwt credential
273 * @return a string, containing the isser
274 */
275char *
276jwt_get_issuer_c (void *cls,
277 const struct GNUNET_RECLAIM_Credential *cred)
278{
279 if (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT != cred->type)
280 return NULL;
281 return jwt_get_issuer (cls, cred->data);
282}
283
284
285/**
286 * Parse a JWT and return the issuer
287 *
288 * @param cls the plugin
289 * @param cred the jwt credential
290 * @return a string, containing the isser
291 */
292char *
293jwt_get_issuer_p (void *cls,
294 const struct GNUNET_RECLAIM_Presentation *cred)
295{
296 if (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT != cred->type)
297 return NULL;
298 return jwt_get_issuer (cls, cred->data);
299}
300
301
302/**
244 * Parse a JWT and return the expiration 303 * Parse a JWT and return the expiration
245 * 304 *
246 * @param cls the plugin 305 * @param cls the plugin
@@ -249,7 +308,7 @@ jwt_get_issuer (void *cls,
249 */ 308 */
250int 309int
251jwt_get_expiration (void *cls, 310jwt_get_expiration (void *cls,
252 const struct GNUNET_RECLAIM_Credential *cred, 311 const char *data,
253 struct GNUNET_TIME_Absolute *exp) 312 struct GNUNET_TIME_Absolute *exp)
254{ 313{
255 const char *jwt_body; 314 const char *jwt_body;
@@ -261,9 +320,7 @@ jwt_get_expiration (void *cls,
261 json_t *json_val; 320 json_t *json_val;
262 json_error_t *json_err = NULL; 321 json_error_t *json_err = NULL;
263 322
264 if (GNUNET_RECLAIM_credential_TYPE_JWT != cred->type) 323 jwt_string = GNUNET_strdup (data);
265 return GNUNET_NO;
266 jwt_string = GNUNET_strdup (cred->data);
267 jwt_body = strtok (jwt_string, delim); 324 jwt_body = strtok (jwt_string, delim);
268 jwt_body = strtok (NULL, delim); 325 jwt_body = strtok (NULL, delim);
269 GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body), 326 GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body),
@@ -279,6 +336,54 @@ jwt_get_expiration (void *cls,
279 336
280 337
281/** 338/**
339 * Parse a JWT and return the expiration
340 *
341 * @param cls the plugin
342 * @param cred the jwt credential
343 * @return a string, containing the isser
344 */
345int
346jwt_get_expiration_c (void *cls,
347 const struct GNUNET_RECLAIM_Credential *cred,
348 struct GNUNET_TIME_Absolute *exp)
349{
350 return jwt_get_expiration (cls, cred->data, exp);
351}
352
353
354/**
355 * Parse a JWT and return the expiration
356 *
357 * @param cls the plugin
358 * @param cred the jwt credential
359 * @return a string, containing the isser
360 */
361int
362jwt_get_expiration_p (void *cls,
363 const struct GNUNET_RECLAIM_Presentation *cred,
364 struct GNUNET_TIME_Absolute *exp)
365{
366 return jwt_get_expiration (cls, cred->data, exp);
367}
368
369
370int
371jwt_create_presentation (void *cls,
372 const struct GNUNET_RECLAIM_Credential *cred,
373 const struct GNUNET_RECLAIM_AttributeList *attrs,
374 struct GNUNET_RECLAIM_Presentation **pres)
375{
376 // FIXME sanity checks??
377 if (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT != cred->type)
378 return GNUNET_NO;
379 *pres = GNUNET_RECLAIM_presentation_new (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT,
380 cred->data,
381 cred->data_size);
382 return GNUNET_OK;
383}
384
385
386/**
282 * Entry point for the plugin. 387 * Entry point for the plugin.
283 * 388 *
284 * @param cls NULL 389 * @param cls NULL
@@ -294,9 +399,17 @@ libgnunet_plugin_reclaim_credential_jwt_init (void *cls)
294 api->string_to_value = &jwt_string_to_value; 399 api->string_to_value = &jwt_string_to_value;
295 api->typename_to_number = &jwt_typename_to_number; 400 api->typename_to_number = &jwt_typename_to_number;
296 api->number_to_typename = &jwt_number_to_typename; 401 api->number_to_typename = &jwt_number_to_typename;
297 api->get_attributes = &jwt_parse_attributes; 402 api->get_attributes = &jwt_parse_attributes_c;
298 api->get_issuer = &jwt_get_issuer; 403 api->get_issuer = &jwt_get_issuer_c;
299 api->get_expiration = &jwt_get_expiration; 404 api->get_expiration = &jwt_get_expiration_c;
405 api->value_to_string_p = &jwt_value_to_string;
406 api->string_to_value_p = &jwt_string_to_value;
407 api->typename_to_number_p = &jwt_typename_to_number;
408 api->number_to_typename_p = &jwt_number_to_typename;
409 api->get_attributes_p = &jwt_parse_attributes_p;
410 api->get_issuer_p = &jwt_get_issuer_p;
411 api->get_expiration_p = &jwt_get_expiration_p;
412 api->create_presentation = &jwt_create_presentation;
300 return api; 413 return api;
301} 414}
302 415
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c
index 5ae6565af..5b0bb2b6f 100644
--- a/src/reclaim/plugin_rest_openid_connect.c
+++ b/src/reclaim/plugin_rest_openid_connect.c
@@ -439,10 +439,14 @@ struct RequestHandle
439 struct GNUNET_RECLAIM_AttributeList *attr_userinfo_list; 439 struct GNUNET_RECLAIM_AttributeList *attr_userinfo_list;
440 440
441 /** 441 /**
442 * Credential list 442 * Credentials
443 */ 443 */
444 struct GNUNET_RECLAIM_CredentialList *creds_list; 444 struct GNUNET_RECLAIM_CredentialList *credentials;
445 445
446 /**
447 * Presentations
448 */
449 struct GNUNET_RECLAIM_PresentationList *presentations;
446 450
447 /** 451 /**
448 * IDENTITY Operation 452 * IDENTITY Operation
@@ -590,8 +594,10 @@ cleanup_handle (struct RequestHandle *handle)
590 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_idtoken_list); 594 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_idtoken_list);
591 if (NULL!=handle->attr_userinfo_list) 595 if (NULL!=handle->attr_userinfo_list)
592 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_userinfo_list); 596 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_userinfo_list);
593 if (NULL!=handle->creds_list) 597 if (NULL!=handle->credentials)
594 GNUNET_RECLAIM_credential_list_destroy (handle->creds_list); 598 GNUNET_RECLAIM_credential_list_destroy (handle->credentials);
599 if (NULL!=handle->presentations)
600 GNUNET_RECLAIM_presentation_list_destroy (handle->presentations);
595 GNUNET_CONTAINER_DLL_remove (requests_head, 601 GNUNET_CONTAINER_DLL_remove (requests_head,
596 requests_tail, 602 requests_tail,
597 handle); 603 handle);
@@ -934,7 +940,9 @@ oidc_iteration_error (void *cls)
934 * parameter. Otherwise redirects with error 940 * parameter. Otherwise redirects with error
935 */ 941 */
936static void 942static void
937oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) 943oidc_ticket_issue_cb (void *cls,
944 const struct GNUNET_RECLAIM_Ticket *ticket,
945 const struct GNUNET_RECLAIM_PresentationList *pres)
938{ 946{
939 struct RequestHandle *handle = cls; 947 struct RequestHandle *handle = cls;
940 struct MHD_Response *resp; 948 struct MHD_Response *resp;
@@ -957,7 +965,7 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
957 code_string = OIDC_build_authz_code (&handle->priv_key, 965 code_string = OIDC_build_authz_code (&handle->priv_key,
958 &handle->ticket, 966 &handle->ticket,
959 handle->attr_idtoken_list, 967 handle->attr_idtoken_list,
960 handle->creds_list, 968 pres,
961 handle->oidc->nonce, 969 handle->oidc->nonce,
962 handle->oidc->code_challenge); 970 handle->oidc->code_challenge);
963 if ((NULL != handle->redirect_prefix) && (NULL != handle->redirect_suffix) && 971 if ((NULL != handle->redirect_prefix) && (NULL != handle->redirect_suffix) &&
@@ -1086,7 +1094,7 @@ oidc_cred_collect (void *cls,
1086 struct GNUNET_RECLAIM_AttributeListEntry *le; 1094 struct GNUNET_RECLAIM_AttributeListEntry *le;
1087 struct GNUNET_RECLAIM_CredentialListEntry *ale; 1095 struct GNUNET_RECLAIM_CredentialListEntry *ale;
1088 1096
1089 for (ale = handle->creds_list->list_head; NULL != ale; ale = ale->next) 1097 for (ale = handle->credentials->list_head; NULL != ale; ale = ale->next)
1090 { 1098 {
1091 if (GNUNET_NO == GNUNET_RECLAIM_id_is_equal (&ale->credential->id, 1099 if (GNUNET_NO == GNUNET_RECLAIM_id_is_equal (&ale->credential->id,
1092 &cred->id)) 1100 &cred->id))
@@ -1107,8 +1115,8 @@ oidc_cred_collect (void *cls,
1107 cred->type, 1115 cred->type,
1108 cred->data, 1116 cred->data,
1109 cred->data_size); 1117 cred->data_size);
1110 GNUNET_CONTAINER_DLL_insert (handle->creds_list->list_head, 1118 GNUNET_CONTAINER_DLL_insert (handle->credentials->list_head,
1111 handle->creds_list->list_tail, 1119 handle->credentials->list_tail,
1112 ale); 1120 ale);
1113 } 1121 }
1114 GNUNET_RECLAIM_get_credentials_next (handle->cred_it); 1122 GNUNET_RECLAIM_get_credentials_next (handle->cred_it);
@@ -1129,7 +1137,7 @@ oidc_attr_collect_finished_cb (void *cls)
1129 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); 1137 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1130 return; 1138 return;
1131 } 1139 }
1132 handle->creds_list = GNUNET_new (struct GNUNET_RECLAIM_CredentialList); 1140 handle->credentials = GNUNET_new (struct GNUNET_RECLAIM_CredentialList);
1133 handle->cred_it = 1141 handle->cred_it =
1134 GNUNET_RECLAIM_get_credentials_start (idp, 1142 GNUNET_RECLAIM_get_credentials_start (idp,
1135 &handle->priv_key, 1143 &handle->priv_key,
@@ -1982,7 +1990,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1982 const struct EgoEntry *ego_entry; 1990 const struct EgoEntry *ego_entry;
1983 struct GNUNET_TIME_Relative expiration_time; 1991 struct GNUNET_TIME_Relative expiration_time;
1984 struct GNUNET_RECLAIM_AttributeList *cl = NULL; 1992 struct GNUNET_RECLAIM_AttributeList *cl = NULL;
1985 struct GNUNET_RECLAIM_CredentialList *al = NULL; 1993 struct GNUNET_RECLAIM_PresentationList *pl = NULL;
1986 struct GNUNET_RECLAIM_Ticket ticket; 1994 struct GNUNET_RECLAIM_Ticket ticket;
1987 struct GNUNET_CRYPTO_EcdsaPublicKey cid; 1995 struct GNUNET_CRYPTO_EcdsaPublicKey cid;
1988 struct GNUNET_HashCode cache_key; 1996 struct GNUNET_HashCode cache_key;
@@ -2068,7 +2076,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2068 2076
2069 // decode code 2077 // decode code
2070 if (GNUNET_OK != OIDC_parse_authz_code (&cid, code, code_verifier, &ticket, 2078 if (GNUNET_OK != OIDC_parse_authz_code (&cid, code, code_verifier, &ticket,
2071 &cl, &al, &nonce)) 2079 &cl, &pl, &nonce))
2072 { 2080 {
2073 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); 2081 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
2074 handle->edesc = GNUNET_strdup ("invalid code"); 2082 handle->edesc = GNUNET_strdup ("invalid code");
@@ -2108,7 +2116,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2108 id_token = OIDC_generate_id_token (&ticket.audience, 2116 id_token = OIDC_generate_id_token (&ticket.audience,
2109 &ticket.identity, 2117 &ticket.identity,
2110 cl, 2118 cl,
2111 al, 2119 pl,
2112 &expiration_time, 2120 &expiration_time,
2113 (NULL != nonce) ? nonce : NULL, 2121 (NULL != nonce) ? nonce : NULL,
2114 jwt_secret); 2122 jwt_secret);
@@ -2124,7 +2132,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2124 MHD_add_response_header (resp, "Content-Type", "application/json"); 2132 MHD_add_response_header (resp, "Content-Type", "application/json");
2125 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 2133 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
2126 GNUNET_RECLAIM_attribute_list_destroy (cl); 2134 GNUNET_RECLAIM_attribute_list_destroy (cl);
2127 GNUNET_RECLAIM_credential_list_destroy (al); 2135 GNUNET_RECLAIM_presentation_list_destroy (pl);
2128 GNUNET_free (access_token); 2136 GNUNET_free (access_token);
2129 GNUNET_free (json_response); 2137 GNUNET_free (json_response);
2130 GNUNET_free (id_token); 2138 GNUNET_free (id_token);
@@ -2139,11 +2147,11 @@ static void
2139consume_ticket (void *cls, 2147consume_ticket (void *cls,
2140 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 2148 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
2141 const struct GNUNET_RECLAIM_Attribute *attr, 2149 const struct GNUNET_RECLAIM_Attribute *attr,
2142 const struct GNUNET_RECLAIM_Credential *cred) 2150 const struct GNUNET_RECLAIM_Presentation *pres)
2143{ 2151{
2144 struct RequestHandle *handle = cls; 2152 struct RequestHandle *handle = cls;
2145 struct GNUNET_RECLAIM_AttributeListEntry *ale; 2153 struct GNUNET_RECLAIM_AttributeListEntry *ale;
2146 struct GNUNET_RECLAIM_CredentialListEntry *atle; 2154 struct GNUNET_RECLAIM_PresentationListEntry *atle;
2147 struct MHD_Response *resp; 2155 struct MHD_Response *resp;
2148 char *result_str; 2156 char *result_str;
2149 handle->idp_op = NULL; 2157 handle->idp_op = NULL;
@@ -2152,7 +2160,7 @@ consume_ticket (void *cls,
2152 { 2160 {
2153 result_str = OIDC_generate_userinfo (&handle->ticket.identity, 2161 result_str = OIDC_generate_userinfo (&handle->ticket.identity,
2154 handle->attr_userinfo_list, 2162 handle->attr_userinfo_list,
2155 handle->creds_list); 2163 handle->presentations);
2156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Userinfo: %s\n", result_str); 2164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Userinfo: %s\n", result_str);
2157 resp = GNUNET_REST_create_response (result_str); 2165 resp = GNUNET_REST_create_response (result_str);
2158 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 2166 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
@@ -2172,25 +2180,25 @@ consume_ticket (void *cls,
2172 GNUNET_CONTAINER_DLL_insert (handle->attr_userinfo_list->list_head, 2180 GNUNET_CONTAINER_DLL_insert (handle->attr_userinfo_list->list_head,
2173 handle->attr_userinfo_list->list_tail, 2181 handle->attr_userinfo_list->list_tail,
2174 ale); 2182 ale);
2175 if (NULL == cred) 2183 if (NULL == pres)
2176 return; 2184 return;
2177 for (atle = handle->creds_list->list_head; NULL != atle; atle = atle->next) 2185 for (atle = handle->presentations->list_head;
2186 NULL != atle; atle = atle->next)
2178 { 2187 {
2179 if (GNUNET_NO == GNUNET_RECLAIM_id_is_equal (&atle->credential->id, 2188 if (GNUNET_NO == GNUNET_RECLAIM_id_is_equal (&atle->presentation->credential_id,
2180 &cred->id)) 2189 &pres->credential_id))
2181 continue; 2190 continue;
2182 break; /** already in list **/ 2191 break; /** already in list **/
2183 } 2192 }
2184 if (NULL == atle) 2193 if (NULL == atle)
2185 { 2194 {
2186 /** Credential matches for attribute, add **/ 2195 /** Credential matches for attribute, add **/
2187 atle = GNUNET_new (struct GNUNET_RECLAIM_CredentialListEntry); 2196 atle = GNUNET_new (struct GNUNET_RECLAIM_PresentationListEntry);
2188 atle->credential = GNUNET_RECLAIM_credential_new (cred->name, 2197 atle->presentation = GNUNET_RECLAIM_presentation_new (pres->type,
2189 cred->type, 2198 pres->data,
2190 cred->data, 2199 pres->data_size);
2191 cred->data_size); 2200 GNUNET_CONTAINER_DLL_insert (handle->presentations->list_head,
2192 GNUNET_CONTAINER_DLL_insert (handle->creds_list->list_head, 2201 handle->presentations->list_tail,
2193 handle->creds_list->list_tail,
2194 atle); 2202 atle);
2195 } 2203 }
2196} 2204}
@@ -2289,8 +2297,8 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2289 privkey = GNUNET_IDENTITY_ego_get_private_key (aud_ego->ego); 2297 privkey = GNUNET_IDENTITY_ego_get_private_key (aud_ego->ego);
2290 handle->attr_userinfo_list = 2298 handle->attr_userinfo_list =
2291 GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 2299 GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
2292 handle->creds_list = 2300 handle->presentations =
2293 GNUNET_new (struct GNUNET_RECLAIM_CredentialList); 2301 GNUNET_new (struct GNUNET_RECLAIM_PresentationList);
2294 2302
2295 handle->idp_op = GNUNET_RECLAIM_ticket_consume (idp, 2303 handle->idp_op = GNUNET_RECLAIM_ticket_consume (idp,
2296 privkey, 2304 privkey,
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index a51d992e1..ff11d2a56 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -474,7 +474,7 @@ add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle,
474 json_t *data_json; 474 json_t *data_json;
475 json_error_t err; 475 json_error_t err;
476 struct GNUNET_JSON_Specification attrspec[] = 476 struct GNUNET_JSON_Specification attrspec[] =
477 { GNUNET_RECLAIM_JSON_spec_claim_cred (&attribute), 477 { GNUNET_RECLAIM_JSON_spec_credential (&attribute),
478 GNUNET_JSON_spec_end () }; 478 GNUNET_JSON_spec_end () };
479 479
480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -811,7 +811,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
811 json_t *data_json; 811 json_t *data_json;
812 json_error_t err; 812 json_error_t err;
813 struct GNUNET_JSON_Specification attrspec[] = 813 struct GNUNET_JSON_Specification attrspec[] =
814 { GNUNET_RECLAIM_JSON_spec_claim (&attribute), GNUNET_JSON_spec_end () }; 814 { GNUNET_RECLAIM_JSON_spec_attribute (&attribute), GNUNET_JSON_spec_end () };
815 815
816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
817 "Adding an attribute for %s.\n", 817 "Adding an attribute for %s.\n",
@@ -1180,7 +1180,7 @@ static void
1180consume_cont (void *cls, 1180consume_cont (void *cls,
1181 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 1181 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
1182 const struct GNUNET_RECLAIM_Attribute *attr, 1182 const struct GNUNET_RECLAIM_Attribute *attr,
1183 const struct GNUNET_RECLAIM_Credential *cred) 1183 const struct GNUNET_RECLAIM_Presentation *pres)
1184{ 1184{
1185 struct RequestHandle *handle = cls; 1185 struct RequestHandle *handle = cls;
1186 char *val_str; 1186 char *val_str;
diff --git a/src/reclaim/reclaim.h b/src/reclaim/reclaim.h
index 6ba9fdcd7..bc7f34365 100644
--- a/src/reclaim/reclaim.h
+++ b/src/reclaim/reclaim.h
@@ -463,9 +463,16 @@ struct TicketResultMessage
463 uint32_t id GNUNET_PACKED; 463 uint32_t id GNUNET_PACKED;
464 464
465 /** 465 /**
466 * Length of new presentations created
467 */
468 uint32_t presentations_len GNUNET_PACKED;
469
470 /**
466 * The new ticket 471 * The new ticket
467 */ 472 */
468 struct GNUNET_RECLAIM_Ticket ticket; 473 struct GNUNET_RECLAIM_Ticket ticket;
474
475 /* Followed by the serialized GNUNET_RECLAIM_PresentationList */
469}; 476};
470 477
471/** 478/**
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index 2cfcbad09..1e0251519 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -92,6 +92,11 @@ struct GNUNET_RECLAIM_Operation
92 GNUNET_RECLAIM_TicketCallback tr_cb; 92 GNUNET_RECLAIM_TicketCallback tr_cb;
93 93
94 /** 94 /**
95 * Ticket issue result callback
96 */
97 GNUNET_RECLAIM_IssueTicketCallback ti_cb;
98
99 /**
95 * Envelope with the message for this queue entry. 100 * Envelope with the message for this queue entry.
96 */ 101 */
97 struct GNUNET_MQ_Envelope *env; 102 struct GNUNET_MQ_Envelope *env;
@@ -866,6 +871,30 @@ handle_credential_result (void *cls, const struct
866 GNUNET_assert (0); 871 GNUNET_assert (0);
867} 872}
868 873
874/**
875 * Handle an incoming message of type
876 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
877 *
878 * @param cls
879 * @param msg the message we received
880 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
881 */
882static int
883check_ticket_result (void *cls, const struct TicketResultMessage *msg)
884{
885 size_t msg_len;
886 size_t pres_len;
887
888 msg_len = ntohs (msg->header.size);
889 pres_len = ntohs (msg->presentations_len);
890 if (msg_len != sizeof(struct TicketResultMessage) + pres_len)
891 {
892 GNUNET_break (0);
893 return GNUNET_SYSERR;
894 }
895 return GNUNET_OK;
896}
897
869 898
870/** 899/**
871 * Handle an incoming message of type 900 * Handle an incoming message of type
@@ -880,8 +909,10 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
880 struct GNUNET_RECLAIM_Handle *handle = cls; 909 struct GNUNET_RECLAIM_Handle *handle = cls;
881 struct GNUNET_RECLAIM_Operation *op; 910 struct GNUNET_RECLAIM_Operation *op;
882 struct GNUNET_RECLAIM_TicketIterator *it; 911 struct GNUNET_RECLAIM_TicketIterator *it;
912 struct GNUNET_RECLAIM_PresentationList *pres;
883 uint32_t r_id = ntohl (msg->id); 913 uint32_t r_id = ntohl (msg->id);
884 static const struct GNUNET_RECLAIM_Ticket ticket; 914 static const struct GNUNET_RECLAIM_Ticket ticket;
915 uint32_t pres_len = ntohs (msg->presentations_len);
885 916
886 for (op = handle->op_head; NULL != op; op = op->next) 917 for (op = handle->op_head; NULL != op; op = op->next)
887 if (op->r_id == r_id) 918 if (op->r_id == r_id)
@@ -893,18 +924,25 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
893 return; 924 return;
894 if (NULL != op) 925 if (NULL != op)
895 { 926 {
927 if (0 < pres_len)
928 pres = GNUNET_RECLAIM_presentation_list_deserialize ((char*)&msg[1],
929 pres_len);
896 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op); 930 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op);
897 if (0 == 931 if (0 ==
898 memcmp (&msg->ticket, &ticket, sizeof(struct GNUNET_RECLAIM_Ticket))) 932 memcmp (&msg->ticket, &ticket, sizeof(struct GNUNET_RECLAIM_Ticket)))
899 { 933 {
900 if (NULL != op->tr_cb) 934 if (NULL != op->ti_cb)
901 op->tr_cb (op->cls, NULL); 935 op->ti_cb (op->cls, NULL, NULL);
902 } 936 }
903 else 937 else
904 { 938 {
905 if (NULL != op->tr_cb) 939 if (NULL != op->ti_cb)
906 op->tr_cb (op->cls, &msg->ticket); 940 op->ti_cb (op->cls,
941 &msg->ticket,
942 (0 < pres_len) ? pres : NULL);
907 } 943 }
944 if (0 < pres_len)
945 GNUNET_RECLAIM_presentation_list_destroy (pres);
908 free_op (op); 946 free_op (op);
909 return; 947 return;
910 } 948 }
@@ -989,10 +1027,10 @@ reconnect (struct GNUNET_RECLAIM_Handle *h)
989 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_RESULT, 1027 GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_RESULT,
990 struct CredentialResultMessage, 1028 struct CredentialResultMessage,
991 h), 1029 h),
992 GNUNET_MQ_hd_fixed_size (ticket_result, 1030 GNUNET_MQ_hd_var_size (ticket_result,
993 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, 1031 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT,
994 struct TicketResultMessage, 1032 struct TicketResultMessage,
995 h), 1033 h),
996 GNUNET_MQ_hd_var_size (consume_ticket_result, 1034 GNUNET_MQ_hd_var_size (consume_ticket_result,
997 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT, 1035 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT,
998 struct ConsumeTicketResultMessage, 1036 struct ConsumeTicketResultMessage,
@@ -1506,7 +1544,7 @@ GNUNET_RECLAIM_ticket_issue (
1506 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, 1544 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
1507 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, 1545 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
1508 const struct GNUNET_RECLAIM_AttributeList *attrs, 1546 const struct GNUNET_RECLAIM_AttributeList *attrs,
1509 GNUNET_RECLAIM_TicketCallback cb, 1547 GNUNET_RECLAIM_IssueTicketCallback cb,
1510 void *cb_cls) 1548 void *cb_cls)
1511{ 1549{
1512 struct GNUNET_RECLAIM_Operation *op; 1550 struct GNUNET_RECLAIM_Operation *op;
@@ -1516,7 +1554,7 @@ GNUNET_RECLAIM_ticket_issue (
1516 fprintf (stderr, "Issuing ticket\n"); 1554 fprintf (stderr, "Issuing ticket\n");
1517 op = GNUNET_new (struct GNUNET_RECLAIM_Operation); 1555 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1518 op->h = h; 1556 op->h = h;
1519 op->tr_cb = cb; 1557 op->ti_cb = cb;
1520 op->cls = cb_cls; 1558 op->cls = cb_cls;
1521 op->r_id = h->r_id_gen++; 1559 op->r_id = h->r_id_gen++;
1522 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 1560 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
diff --git a/src/reclaim/reclaim_credential.c b/src/reclaim/reclaim_credential.c
index 10b17ae96..5c8974400 100644
--- a/src/reclaim/reclaim_credential.c
+++ b/src/reclaim/reclaim_credential.c
@@ -165,9 +165,9 @@ GNUNET_RECLAIM_credential_number_to_typename (uint32_t type)
165 */ 165 */
166int 166int
167GNUNET_RECLAIM_credential_string_to_value (uint32_t type, 167GNUNET_RECLAIM_credential_string_to_value (uint32_t type,
168 const char *s, 168 const char *s,
169 void **data, 169 void **data,
170 size_t *data_size) 170 size_t *data_size)
171{ 171{
172 unsigned int i; 172 unsigned int i;
173 struct Plugin *plugin; 173 struct Plugin *plugin;
@@ -197,8 +197,8 @@ GNUNET_RECLAIM_credential_string_to_value (uint32_t type,
197 */ 197 */
198char * 198char *
199GNUNET_RECLAIM_credential_value_to_string (uint32_t type, 199GNUNET_RECLAIM_credential_value_to_string (uint32_t type,
200 const void *data, 200 const void *data,
201 size_t data_size) 201 size_t data_size)
202{ 202{
203 unsigned int i; 203 unsigned int i;
204 struct Plugin *plugin; 204 struct Plugin *plugin;
@@ -229,9 +229,9 @@ GNUNET_RECLAIM_credential_value_to_string (uint32_t type,
229 */ 229 */
230struct GNUNET_RECLAIM_Credential * 230struct GNUNET_RECLAIM_Credential *
231GNUNET_RECLAIM_credential_new (const char *attr_name, 231GNUNET_RECLAIM_credential_new (const char *attr_name,
232 uint32_t type, 232 uint32_t type,
233 const void *data, 233 const void *data,
234 size_t data_size) 234 size_t data_size)
235{ 235{
236 struct GNUNET_RECLAIM_Credential *attr; 236 struct GNUNET_RECLAIM_Credential *attr;
237 char *write_ptr; 237 char *write_ptr;
@@ -335,7 +335,7 @@ GNUNET_RECLAIM_credential_list_deserialize (const char *data, size_t data_size)
335 ale = GNUNET_new (struct GNUNET_RECLAIM_CredentialListEntry); 335 ale = GNUNET_new (struct GNUNET_RECLAIM_CredentialListEntry);
336 ale->credential = 336 ale->credential =
337 GNUNET_RECLAIM_credential_deserialize (read_ptr, 337 GNUNET_RECLAIM_credential_deserialize (read_ptr,
338 data_size - (read_ptr - data)); 338 data_size - (read_ptr - data));
339 if (NULL == ale->credential) 339 if (NULL == ale->credential)
340 { 340 {
341 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 341 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -371,9 +371,9 @@ GNUNET_RECLAIM_credential_list_dup (
371 GNUNET_assert (NULL != ale->credential); 371 GNUNET_assert (NULL != ale->credential);
372 result_ale->credential = 372 result_ale->credential =
373 GNUNET_RECLAIM_credential_new (ale->credential->name, 373 GNUNET_RECLAIM_credential_new (ale->credential->name,
374 ale->credential->type, 374 ale->credential->type,
375 ale->credential->data, 375 ale->credential->data,
376 ale->credential->data_size); 376 ale->credential->data_size);
377 result_ale->credential->id = ale->credential->id; 377 result_ale->credential->id = ale->credential->id;
378 GNUNET_CONTAINER_DLL_insert (result->list_head, 378 GNUNET_CONTAINER_DLL_insert (result->list_head,
379 result->list_tail, 379 result->list_tail,
@@ -490,7 +490,7 @@ GNUNET_RECLAIM_credential_deserialize (const char *data, size_t data_size)
490 return NULL; 490 return NULL;
491 } 491 }
492 credential = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Credential) 492 credential = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Credential)
493 + data_len + name_len + 1); 493 + data_len + name_len + 1);
494 credential->type = ntohs (atts->credential_type); 494 credential->type = ntohs (atts->credential_type);
495 credential->flag = ntohl (atts->credential_flag); 495 credential->flag = ntohl (atts->credential_flag);
496 credential->id = atts->credential_id; 496 credential->id = atts->credential_id;
@@ -511,7 +511,7 @@ GNUNET_RECLAIM_credential_deserialize (const char *data, size_t data_size)
511 511
512struct GNUNET_RECLAIM_AttributeList* 512struct GNUNET_RECLAIM_AttributeList*
513GNUNET_RECLAIM_credential_get_attributes (const struct 513GNUNET_RECLAIM_credential_get_attributes (const struct
514 GNUNET_RECLAIM_Credential *credential) 514 GNUNET_RECLAIM_Credential *credential)
515{ 515{
516 unsigned int i; 516 unsigned int i;
517 struct Plugin *plugin; 517 struct Plugin *plugin;
@@ -531,7 +531,7 @@ GNUNET_RECLAIM_credential_get_attributes (const struct
531 531
532char* 532char*
533GNUNET_RECLAIM_credential_get_issuer (const struct 533GNUNET_RECLAIM_credential_get_issuer (const struct
534 GNUNET_RECLAIM_Credential *credential) 534 GNUNET_RECLAIM_Credential *credential)
535{ 535{
536 unsigned int i; 536 unsigned int i;
537 struct Plugin *plugin; 537 struct Plugin *plugin;
@@ -551,8 +551,8 @@ GNUNET_RECLAIM_credential_get_issuer (const struct
551 551
552int 552int
553GNUNET_RECLAIM_credential_get_expiration (const struct 553GNUNET_RECLAIM_credential_get_expiration (const struct
554 GNUNET_RECLAIM_Credential *credential, 554 GNUNET_RECLAIM_Credential *credential,
555 struct GNUNET_TIME_Absolute*exp) 555 struct GNUNET_TIME_Absolute*exp)
556{ 556{
557 unsigned int i; 557 unsigned int i;
558 struct Plugin *plugin; 558 struct Plugin *plugin;
@@ -568,3 +568,470 @@ GNUNET_RECLAIM_credential_get_expiration (const struct
568 } 568 }
569 return GNUNET_SYSERR; 569 return GNUNET_SYSERR;
570} 570}
571
572
573/**
574 * Convert an presentation type name to the corresponding number
575 *
576 * @param typename name to convert
577 * @return corresponding number, UINT32_MAX on error
578 */
579uint32_t
580GNUNET_RECLAIM_presentation_typename_to_number (const char *typename)
581{
582 unsigned int i;
583 struct Plugin *plugin;
584 uint32_t ret;
585 init ();
586 for (i = 0; i < num_plugins; i++)
587 {
588 plugin = credential_plugins[i];
589 if (UINT32_MAX !=
590 (ret = plugin->api->typename_to_number_p (plugin->api->cls,
591 typename)))
592 return ret;
593 }
594 return UINT32_MAX;
595}
596
597
598/**
599 * Convert an presentation type number to the corresponding presentation type string
600 *
601 * @param type number of a type
602 * @return corresponding typestring, NULL on error
603 */
604const char *
605GNUNET_RECLAIM_presentation_number_to_typename (uint32_t type)
606{
607 unsigned int i;
608 struct Plugin *plugin;
609 const char *ret;
610
611 init ();
612 for (i = 0; i < num_plugins; i++)
613 {
614 plugin = credential_plugins[i];
615 if (NULL !=
616 (ret = plugin->api->number_to_typename_p (plugin->api->cls, type)))
617 return ret;
618 }
619 return NULL;
620}
621
622
623/**
624 * Convert human-readable version of a 'claim' of an presentation to the binary
625 * representation
626 *
627 * @param type type of the claim
628 * @param s human-readable string
629 * @param data set to value in binary encoding (will be allocated)
630 * @param data_size set to number of bytes in @a data
631 * @return #GNUNET_OK on success
632 */
633int
634GNUNET_RECLAIM_presentation_string_to_value (uint32_t type,
635 const char *s,
636 void **data,
637 size_t *data_size)
638{
639 unsigned int i;
640 struct Plugin *plugin;
641
642 init ();
643 for (i = 0; i < num_plugins; i++)
644 {
645 plugin = credential_plugins[i];
646 if (GNUNET_OK == plugin->api->string_to_value_p (plugin->api->cls,
647 type,
648 s,
649 data,
650 data_size))
651 return GNUNET_OK;
652 }
653 return GNUNET_SYSERR;
654}
655
656
657/**
658 * Convert the 'claim' of an presentation to a string
659 *
660 * @param type the type of presentation
661 * @param data claim in binary encoding
662 * @param data_size number of bytes in @a data
663 * @return NULL on error, otherwise human-readable representation of the claim
664 */
665char *
666GNUNET_RECLAIM_presentation_value_to_string (uint32_t type,
667 const void *data,
668 size_t data_size)
669{
670 unsigned int i;
671 struct Plugin *plugin;
672 char *ret;
673
674 init ();
675 for (i = 0; i < num_plugins; i++)
676 {
677 plugin = credential_plugins[i];
678 if (NULL != (ret = plugin->api->value_to_string_p (plugin->api->cls,
679 type,
680 data,
681 data_size)))
682 return ret;
683 }
684 return NULL;
685}
686
687
688struct GNUNET_RECLAIM_Presentation *
689GNUNET_RECLAIM_presentation_new (uint32_t type,
690 const void *data,
691 size_t data_size)
692{
693 struct GNUNET_RECLAIM_Presentation *attr;
694 char *write_ptr;
695
696 attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Presentation)
697 + data_size);
698 attr->type = type;
699 attr->data_size = data_size;
700 write_ptr = (char *) &attr[1];
701 GNUNET_memcpy (write_ptr, data, data_size);
702 attr->data = write_ptr;
703 return attr;
704}
705
706
707/**
708 * Get required size for serialization buffer
709 *
710 * @param attrs the attribute list to serialize
711 * @return the required buffer size
712 */
713size_t
714GNUNET_RECLAIM_presentation_list_serialize_get_size (
715 const struct GNUNET_RECLAIM_PresentationList *presentations)
716{
717 struct GNUNET_RECLAIM_PresentationListEntry *le;
718 size_t len = 0;
719
720 for (le = presentations->list_head; NULL != le; le = le->next)
721 {
722 GNUNET_assert (NULL != le->presentation);
723 len += GNUNET_RECLAIM_presentation_serialize_get_size (le->presentation);
724 len += sizeof(struct GNUNET_RECLAIM_PresentationListEntry);
725 }
726 return len;
727}
728
729
730/**
731 * Serialize an attribute list
732 *
733 * @param attrs the attribute list to serialize
734 * @param result the serialized attribute
735 * @return length of serialized data
736 */
737size_t
738GNUNET_RECLAIM_presentation_list_serialize (
739 const struct GNUNET_RECLAIM_PresentationList *presentations,
740 char *result)
741{
742 struct GNUNET_RECLAIM_PresentationListEntry *le;
743 size_t len;
744 size_t total_len;
745 char *write_ptr;
746 write_ptr = result;
747 total_len = 0;
748 for (le = presentations->list_head; NULL != le; le = le->next)
749 {
750 GNUNET_assert (NULL != le->presentation);
751 len = GNUNET_RECLAIM_presentation_serialize (le->presentation, write_ptr);
752 total_len += len;
753 write_ptr += len;
754 }
755 return total_len;
756}
757
758
759/**
760 * Deserialize an presentation list
761 *
762 * @param data the serialized attribute list
763 * @param data_size the length of the serialized data
764 * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller
765 */
766struct GNUNET_RECLAIM_PresentationList *
767GNUNET_RECLAIM_presentation_list_deserialize (const char *data, size_t
768 data_size)
769{
770 struct GNUNET_RECLAIM_PresentationList *al;
771 struct GNUNET_RECLAIM_PresentationListEntry *ale;
772 size_t att_len;
773 const char *read_ptr;
774
775 al = GNUNET_new (struct GNUNET_RECLAIM_PresentationList);
776
777 if ((data_size < sizeof(struct Presentation)
778 + sizeof(struct GNUNET_RECLAIM_PresentationListEntry)))
779 return al;
780
781 read_ptr = data;
782 while (((data + data_size) - read_ptr) >= sizeof(struct Presentation))
783 {
784 ale = GNUNET_new (struct GNUNET_RECLAIM_PresentationListEntry);
785 ale->presentation =
786 GNUNET_RECLAIM_presentation_deserialize (read_ptr,
787 data_size - (read_ptr - data));
788 if (NULL == ale->presentation)
789 {
790 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
791 "Failed to deserialize malformed presentation.\n");
792 GNUNET_free (ale);
793 return al;
794 }
795 GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale);
796 att_len = GNUNET_RECLAIM_presentation_serialize_get_size (
797 ale->presentation);
798 read_ptr += att_len;
799 }
800 return al;
801}
802
803
804/**
805 * Make a (deep) copy of the presentation list
806 * @param attrs claim list to copy
807 * @return copied claim list
808 */
809struct GNUNET_RECLAIM_PresentationList *
810GNUNET_RECLAIM_presentation_list_dup (
811 const struct GNUNET_RECLAIM_PresentationList *al)
812{
813 struct GNUNET_RECLAIM_PresentationListEntry *ale;
814 struct GNUNET_RECLAIM_PresentationListEntry *result_ale;
815 struct GNUNET_RECLAIM_PresentationList *result;
816
817 result = GNUNET_new (struct GNUNET_RECLAIM_PresentationList);
818 for (ale = al->list_head; NULL != ale; ale = ale->next)
819 {
820 result_ale = GNUNET_new (struct GNUNET_RECLAIM_PresentationListEntry);
821 GNUNET_assert (NULL != ale->presentation);
822 result_ale->presentation =
823 GNUNET_RECLAIM_presentation_new (ale->presentation->type,
824 ale->presentation->data,
825 ale->presentation->data_size);
826 result_ale->presentation->credential_id = ale->presentation->credential_id;
827 GNUNET_CONTAINER_DLL_insert (result->list_head,
828 result->list_tail,
829 result_ale);
830 }
831 return result;
832}
833
834
835/**
836 * Destroy presentation list
837 *
838 * @param attrs list to destroy
839 */
840void
841GNUNET_RECLAIM_presentation_list_destroy (
842 struct GNUNET_RECLAIM_PresentationList *al)
843{
844 struct GNUNET_RECLAIM_PresentationListEntry *ale;
845 struct GNUNET_RECLAIM_PresentationListEntry *tmp_ale;
846
847 for (ale = al->list_head; NULL != ale;)
848 {
849 if (NULL != ale->presentation)
850 GNUNET_free (ale->presentation);
851 tmp_ale = ale;
852 ale = ale->next;
853 GNUNET_free (tmp_ale);
854 }
855 GNUNET_free (al);
856}
857
858
859/**
860 * Get required size for serialization buffer
861 *
862 * @param attr the presentation to serialize
863 * @return the required buffer size
864 */
865size_t
866GNUNET_RECLAIM_presentation_serialize_get_size (
867 const struct GNUNET_RECLAIM_Presentation *presentation)
868{
869 return sizeof(struct Presentation) + presentation->data_size;
870}
871
872
873/**
874 * Serialize an presentation
875 *
876 * @param attr the presentation to serialize
877 * @param result the serialized presentation
878 * @return length of serialized data
879 */
880size_t
881GNUNET_RECLAIM_presentation_serialize (
882 const struct GNUNET_RECLAIM_Presentation *presentation,
883 char *result)
884{
885 struct Presentation *atts;
886 char *write_ptr;
887
888 atts = (struct Presentation *) result;
889 atts->presentation_type = htons (presentation->type);
890 atts->credential_id = presentation->credential_id;
891 write_ptr = (char *) &atts[1];
892 GNUNET_memcpy (write_ptr, presentation->data, presentation->data_size);
893 atts->data_size = htons (presentation->data_size);
894
895 return sizeof(struct Presentation) + presentation->data_size;
896}
897
898
899/**
900 * Deserialize an presentation
901 *
902 * @param data the serialized presentation
903 * @param data_size the length of the serialized data
904 *
905 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
906 */
907struct GNUNET_RECLAIM_Presentation *
908GNUNET_RECLAIM_presentation_deserialize (const char *data, size_t data_size)
909{
910 struct GNUNET_RECLAIM_Presentation *presentation;
911 struct Presentation *atts;
912 size_t data_len;
913 char *write_ptr;
914
915 if (data_size < sizeof(struct Presentation))
916 return NULL;
917
918 atts = (struct Presentation *) data;
919 data_len = ntohs (atts->data_size);
920 if (data_size < sizeof(struct Presentation) + data_len)
921 {
922 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
923 "Buffer too small to deserialize\n");
924 return NULL;
925 }
926 presentation = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Presentation)
927 + data_len);
928 presentation->type = ntohs (atts->presentation_type);
929 presentation->credential_id = atts->credential_id;
930 presentation->data_size = data_len;
931
932 write_ptr = (char *) &presentation[1];
933 GNUNET_memcpy (write_ptr, &atts[1], data_len);
934 presentation->data = write_ptr;
935 return presentation;
936}
937
938
939struct GNUNET_RECLAIM_AttributeList*
940GNUNET_RECLAIM_presentation_get_attributes (const struct
941 GNUNET_RECLAIM_Presentation *
942 presentation)
943{
944 unsigned int i;
945 struct Plugin *plugin;
946 struct GNUNET_RECLAIM_AttributeList *ret;
947 init ();
948 for (i = 0; i < num_plugins; i++)
949 {
950 plugin = credential_plugins[i];
951 if (NULL !=
952 (ret = plugin->api->get_attributes_p (plugin->api->cls,
953 presentation)))
954 return ret;
955 }
956 return NULL;
957}
958
959
960char*
961GNUNET_RECLAIM_presentation_get_issuer (const struct
962 GNUNET_RECLAIM_Presentation *
963 presentation)
964{
965 unsigned int i;
966 struct Plugin *plugin;
967 char *ret;
968 init ();
969 for (i = 0; i < num_plugins; i++)
970 {
971 plugin = credential_plugins[i];
972 if (NULL !=
973 (ret = plugin->api->get_issuer_p (plugin->api->cls,
974 presentation)))
975 return ret;
976 }
977 return NULL;
978}
979
980
981int
982GNUNET_RECLAIM_presentation_get_expiration (const struct
983 GNUNET_RECLAIM_Presentation *
984 presentation,
985 struct GNUNET_TIME_Absolute*exp)
986{
987 unsigned int i;
988 struct Plugin *plugin;
989 init ();
990 for (i = 0; i < num_plugins; i++)
991 {
992 plugin = credential_plugins[i];
993 if (GNUNET_OK != plugin->api->get_expiration_p (plugin->api->cls,
994 presentation,
995 exp))
996 continue;
997 return GNUNET_OK;
998 }
999 return GNUNET_SYSERR;
1000}
1001
1002/**
1003 * Create a presentation from a credential and a lift of (selected)
1004 * attributes in the credential.
1005 * FIXME not yet implemented
1006 *
1007 * @param cred the credential to use
1008 * @param attrs the attributes to present from the credential
1009 * @return the credential presentation presenting the attributes according
1010 * to the presentation mechanism of the credential
1011 * or NULL on error.
1012 */
1013int
1014GNUNET_RECLAIM_credential_get_presentation (
1015 const struct GNUNET_RECLAIM_Credential *cred,
1016 const struct GNUNET_RECLAIM_AttributeList *attrs,
1017 struct GNUNET_RECLAIM_Presentation **pres)
1018{
1019 unsigned int i;
1020 struct Plugin *plugin;
1021 init ();
1022 for (i = 0; i < num_plugins; i++)
1023 {
1024 plugin = credential_plugins[i];
1025 if (GNUNET_OK != plugin->api->create_presentation (plugin->api->cls,
1026 cred,
1027 attrs,
1028 pres))
1029 continue;
1030 (*pres)->credential_id = cred->id;
1031 return GNUNET_OK;
1032 }
1033 return GNUNET_SYSERR;
1034}
1035
1036
1037
diff --git a/src/reclaim/reclaim_credential.h b/src/reclaim/reclaim_credential.h
index cd3a9539a..7704ed968 100644
--- a/src/reclaim/reclaim_credential.h
+++ b/src/reclaim/reclaim_credential.h
@@ -61,4 +61,39 @@ struct Credential
61 // followed by data_size Credential value data 61 // followed by data_size Credential value data
62}; 62};
63 63
64
65/**
66 * Serialized presentation claim
67 */
68struct Presentation
69{
70 /**
71 * Presentation type
72 */
73 uint32_t presentation_type;
74
75 /**
76 * Presentation flag
77 */
78 uint32_t presentation_flag;
79
80 /**
81 * Credential ID
82 */
83 struct GNUNET_RECLAIM_Identifier credential_id;
84
85 /**
86 * Name length
87 */
88 uint32_t name_len;
89
90 /**
91 * Data size
92 */
93 uint32_t data_size;
94
95 // followed by data_size Presentation value data
96};
97
98
64#endif 99#endif