aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/gnunet-service-reclaim_tickets.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reclaim/gnunet-service-reclaim_tickets.c')
-rw-r--r--src/reclaim/gnunet-service-reclaim_tickets.c335
1 files changed, 227 insertions, 108 deletions
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c
index af01d8ec7..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 * Attestations 117 * Presentations
118 */ 118 */
119 struct GNUNET_RECLAIM_AttestationList *attests; 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;
@@ -715,20 +720,20 @@ rvk_move_attr_cb (void *cls,
715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label); 720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label);
716 GNUNET_free (claim); 721 GNUNET_free (claim);
717 } 722 }
718 else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION == rd[i].record_type) 723 else if (GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL == rd[i].record_type)
719 { 724 {
720 struct GNUNET_RECLAIM_Attestation *attest; 725 struct GNUNET_RECLAIM_Credential *credential;
721 attest = GNUNET_RECLAIM_attestation_deserialize (rd[i].data, 726 credential = GNUNET_RECLAIM_credential_deserialize (rd[i].data,
722 rd[i].data_size); 727 rd[i].data_size);
723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
724 "Attestation to update: Name=%s\n", 729 "Credential to update: Name=%s\n",
725 attest->name); 730 credential->name);
726 attest->id = rvk->move_attr->new_id; 731 credential->id = rvk->move_attr->new_id;
727 new_rd[i].data_size = 732 new_rd[i].data_size =
728 GNUNET_RECLAIM_attestation_serialize_get_size (attest); 733 GNUNET_RECLAIM_credential_serialize_get_size (credential);
729 attr_data = GNUNET_malloc (rd[i].data_size); 734 attr_data = GNUNET_malloc (rd[i].data_size);
730 new_rd[i].data_size = GNUNET_RECLAIM_attestation_serialize (attest, 735 new_rd[i].data_size = GNUNET_RECLAIM_credential_serialize (credential,
731 attr_data); 736 attr_data);
732 new_rd[i].data = attr_data; 737 new_rd[i].data = attr_data;
733 new_rd[i].record_type = rd[i].record_type; 738 new_rd[i].record_type = rd[i].record_type;
734 new_rd[i].flags = rd[i].flags; 739 new_rd[i].flags = rd[i].flags;
@@ -736,9 +741,9 @@ rvk_move_attr_cb (void *cls,
736 new_label = 741 new_label =
737 GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, 742 GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id,
738 sizeof (rvk->move_attr->new_id)); 743 sizeof (rvk->move_attr->new_id));
739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attestation %s\n", 744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding credential %s\n",
740 new_label); 745 new_label);
741 GNUNET_free (attest); 746 GNUNET_free (credential);
742 } 747 }
743 } 748 }
744 rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, 749 rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
@@ -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->attests) 989 if (NULL != cth->presentations)
985 GNUNET_RECLAIM_attestation_list_destroy (cth->attests); 990 GNUNET_RECLAIM_presentation_list_destroy (cth->presentations);
986 GNUNET_free (cth); 991 GNUNET_free (cth);
987} 992}
988 993
@@ -1027,40 +1032,20 @@ process_parallel_lookup_result (void *cls,
1027 // REMARK: It is possible now to find rd_count > 1 1032 // REMARK: It is possible now to find rd_count > 1
1028 for (int i = 0; i < rd_count; i++) 1033 for (int i = 0; i < rd_count; i++)
1029 { 1034 {
1030 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE == rd[i].record_type) 1035 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE != rd[i].record_type)
1031 {
1032 attr_le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
1033 GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size,
1034 &attr_le->attribute);
1035 GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head,
1036 cth->attrs->list_tail,
1037 attr_le);
1038 }
1039 else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION == rd[i].record_type)
1040 {
1041 struct GNUNET_RECLAIM_AttestationListEntry *ale;
1042 ale = GNUNET_new (struct GNUNET_RECLAIM_AttestationListEntry);
1043 ale->attestation =
1044 GNUNET_RECLAIM_attestation_deserialize (rd[i].data,
1045 rd[i].data_size);
1046 GNUNET_CONTAINER_DLL_insert (cth->attests->list_head,
1047 cth->attests->list_tail,
1048 ale);
1049 }
1050 else
1051 {
1052 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1053 "Parallel Lookup of Reference without Attestation");
1054 continue; 1036 continue;
1055 } 1037 attr_le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
1056 1038 GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size,
1057 1039 &attr_le->attribute);
1040 GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head,
1041 cth->attrs->list_tail,
1042 attr_le);
1058 } 1043 }
1059 if (NULL != cth->parallel_lookups_head) 1044 if (NULL != cth->parallel_lookups_head)
1060 return; // Wait for more 1045 return; // Wait for more
1061 /* Else we are done */ 1046 /* Else we are done */
1062 cth->cb (cth->cb_cls, &cth->ticket.identity, 1047 cth->cb (cth->cb_cls, &cth->ticket.identity,
1063 cth->attrs, cth->attests, GNUNET_OK, NULL); 1048 cth->attrs, cth->presentations, GNUNET_OK, NULL);
1064 cleanup_cth (cth); 1049 cleanup_cth (cth);
1065} 1050}
1066 1051
@@ -1110,6 +1095,7 @@ lookup_authz_cb (void *cls,
1110 struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; 1095 struct RECLAIM_TICKETS_ConsumeHandle *cth = cls;
1111 struct ParallelLookup *parallel_lookup; 1096 struct ParallelLookup *parallel_lookup;
1112 char *lbl; 1097 char *lbl;
1098 struct GNUNET_RECLAIM_PresentationListEntry *ale;
1113 1099
1114 cth->lookup_request = NULL; 1100 cth->lookup_request = NULL;
1115 1101
@@ -1126,26 +1112,44 @@ lookup_authz_cb (void *cls,
1126 1112
1127 for (int i = 0; i < rd_count; i++) 1113 for (int i = 0; i < rd_count; i++)
1128 { 1114 {
1129 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) && 1115 /**
1130 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF != rd[i].record_type)) 1116 * Check if record is a credential presentation or an attribute
1131 continue; 1117 * reference.
1132 lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size); 1118 */
1133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ticket reference found %s\n", lbl); 1119 switch (rd[i].record_type)
1134 parallel_lookup = GNUNET_new (struct ParallelLookup); 1120 {
1135 parallel_lookup->handle = cth; 1121 case GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION:
1136 parallel_lookup->label = lbl; 1122 ale = GNUNET_new (struct GNUNET_RECLAIM_PresentationListEntry);
1137 parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get (); 1123 ale->presentation =
1138 parallel_lookup->lookup_request = 1124 GNUNET_RECLAIM_presentation_deserialize (rd[i].data,
1139 GNUNET_GNS_lookup (gns, 1125 rd[i].data_size);
1140 lbl, 1126 GNUNET_CONTAINER_DLL_insert (cth->presentations->list_head,
1141 &cth->ticket.identity, 1127 cth->presentations->list_tail,
1142 GNUNET_GNSRECORD_TYPE_ANY, 1128 ale);
1143 GNUNET_GNS_LO_DEFAULT, 1129 break;
1144 &process_parallel_lookup_result, 1130 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF:
1145 parallel_lookup); 1131 lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size);
1146 GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, 1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ticket reference found %s\n", lbl);
1147 cth->parallel_lookups_tail, 1133 parallel_lookup = GNUNET_new (struct ParallelLookup);
1148 parallel_lookup); 1134 parallel_lookup->handle = cth;
1135 parallel_lookup->label = lbl;
1136 parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get ();
1137 parallel_lookup->lookup_request =
1138 GNUNET_GNS_lookup (gns,
1139 lbl,
1140 &cth->ticket.identity,
1141 GNUNET_GNSRECORD_TYPE_ANY,
1142 GNUNET_GNS_LO_DEFAULT,
1143 &process_parallel_lookup_result,
1144 parallel_lookup);
1145 GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head,
1146 cth->parallel_lookups_tail,
1147 parallel_lookup);
1148 break;
1149 default:
1150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1151 "Ignoring unknown record type %d", rd[i].record_type);
1152 }
1149 } 1153 }
1150 /** 1154 /**
1151 * We started lookups. Add a timeout task. 1155 * We started lookups. Add a timeout task.
@@ -1163,7 +1167,7 @@ lookup_authz_cb (void *cls,
1163 * No references found, return empty attribute list 1167 * No references found, return empty attribute list
1164 */ 1168 */
1165 cth->cb (cth->cb_cls, &cth->ticket.identity, 1169 cth->cb (cth->cb_cls, &cth->ticket.identity,
1166 cth->attrs, cth->attests, GNUNET_OK, NULL); 1170 cth->attrs, NULL, GNUNET_OK, NULL);
1167 cleanup_cth (cth); 1171 cleanup_cth (cth);
1168} 1172}
1169 1173
@@ -1193,7 +1197,7 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id,
1193 cth->identity = *id; 1197 cth->identity = *id;
1194 GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub); 1198 GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub);
1195 cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 1199 cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
1196 cth->attests = GNUNET_new (struct GNUNET_RECLAIM_AttestationList); 1200 cth->presentations = GNUNET_new (struct GNUNET_RECLAIM_PresentationList);
1197 cth->ticket = *ticket; 1201 cth->ticket = *ticket;
1198 cth->cb = cb; 1202 cth->cb = cb;
1199 cth->cb_cls = cb_cls; 1203 cth->cb_cls = cb_cls;
@@ -1231,8 +1235,8 @@ RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth)
1231 1235
1232 1236
1233/******************************* 1237/*******************************
1234* Ticket issue 1238 * Ticket issue
1235*******************************/ 1239 *******************************/
1236 1240
1237/** 1241/**
1238 * Cleanup ticket consume handle 1242 * Cleanup ticket consume handle
@@ -1265,11 +1269,15 @@ store_ticket_issue_cont (void *cls, int32_t success, const char *emsg)
1265 { 1269 {
1266 handle->cb (handle->cb_cls, 1270 handle->cb (handle->cb_cls,
1267 &handle->ticket, 1271 &handle->ticket,
1272 NULL,
1268 GNUNET_SYSERR, 1273 GNUNET_SYSERR,
1269 "Error storing AuthZ ticket in GNS"); 1274 "Error storing AuthZ ticket in GNS");
1270 return; 1275 return;
1271 } 1276 }
1272 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);
1273 cleanup_issue_handle (handle); 1281 cleanup_issue_handle (handle);
1274} 1282}
1275 1283
@@ -1285,15 +1293,17 @@ static void
1285issue_ticket (struct TicketIssueHandle *ih) 1293issue_ticket (struct TicketIssueHandle *ih)
1286{ 1294{
1287 struct GNUNET_RECLAIM_AttributeListEntry *le; 1295 struct GNUNET_RECLAIM_AttributeListEntry *le;
1296 struct GNUNET_RECLAIM_PresentationListEntry *ple;
1288 struct GNUNET_GNSRECORD_Data *attrs_record; 1297 struct GNUNET_GNSRECORD_Data *attrs_record;
1289 char *label; 1298 char *label;
1290 int i; 1299 int i;
1300 int j;
1291 int attrs_count = 0; 1301 int attrs_count = 0;
1292 1302
1293 for (le = ih->attrs->list_head; NULL != le; le = le->next) 1303 for (le = ih->attrs->list_head; NULL != le; le = le->next)
1294 attrs_count++; 1304 attrs_count++;
1295 1305
1296 // Worst case we have one attestation per attribute 1306 // Worst case we have one presentation per attribute
1297 attrs_record = 1307 attrs_record =
1298 GNUNET_malloc (2 * attrs_count * sizeof(struct GNUNET_GNSRECORD_Data)); 1308 GNUNET_malloc (2 * attrs_count * sizeof(struct GNUNET_GNSRECORD_Data));
1299 i = 0; 1309 i = 0;
@@ -1308,28 +1318,67 @@ issue_ticket (struct TicketIssueHandle *ih)
1308 attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF; 1318 attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF;
1309 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 1319 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1310 i++; 1320 i++;
1311 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) 1321 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->credential))
1312 { 1322 {
1313 int j; 1323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
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_ATTESTATION_REF) 1329 != GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION)
1318 continue; 1330 continue;
1319 if (0 == memcmp (attrs_record[j].data, 1331 pres = GNUNET_RECLAIM_presentation_deserialize (attrs_record[j].data,
1320 &le->attribute->attestation, 1332 attrs_record[j].
1321 sizeof (le->attribute->attestation))) 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,
1341 &le->attribute->credential,
1342 sizeof (le->attribute->credential)))
1322 break; 1343 break;
1344 GNUNET_free (pres);
1345 pres = NULL;
1346 }
1347 if (NULL != pres)
1348 {
1349 GNUNET_free (pres);
1350 continue; // Skip as we have already added this credential presentation.
1351 }
1352 for (ple = ih->presentations->list_head; NULL != ple; ple = ple->next)
1353 {
1354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1355 "Checking presentation....\n");
1356
1357 if (0 != memcmp (&le->attribute->credential,
1358 &ple->presentation->credential_id,
1359 sizeof (le->attribute->credential)))
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;
1323 } 1381 }
1324 if (j < i)
1325 continue; // Skip as we have already added this attestation.
1326 attrs_record[i].data = &le->attribute->attestation;
1327 attrs_record[i].data_size = sizeof(le->attribute->attestation);
1328 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us;
1329 attrs_record[i].record_type =
1330 GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF;
1331 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1332 i++;
1333 } 1382 }
1334 } 1383 }
1335 attrs_record[i].data = &ih->ticket; 1384 attrs_record[i].data = &ih->ticket;
@@ -1351,14 +1400,23 @@ issue_ticket (struct TicketIssueHandle *ih)
1351 attrs_record, 1400 attrs_record,
1352 &store_ticket_issue_cont, 1401 &store_ticket_issue_cont,
1353 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 }
1354 GNUNET_free (attrs_record); 1412 GNUNET_free (attrs_record);
1355 GNUNET_free (label); 1413 GNUNET_free (label);
1356} 1414}
1357 1415
1358 1416
1359/************************************************* 1417/*************************************************
1360* Ticket iteration (finding a specific ticket) 1418 * Ticket iteration (finding a specific ticket)
1361*************************************************/ 1419 *************************************************/
1362 1420
1363 1421
1364/** 1422/**
@@ -1374,6 +1432,7 @@ filter_tickets_error_cb (void *cls)
1374 tih->ns_it = NULL; 1432 tih->ns_it = NULL;
1375 tih->cb (tih->cb_cls, 1433 tih->cb (tih->cb_cls,
1376 &tih->ticket, 1434 &tih->ticket,
1435 NULL,
1377 GNUNET_SYSERR, 1436 GNUNET_SYSERR,
1378 "Error storing AuthZ ticket in GNS"); 1437 "Error storing AuthZ ticket in GNS");
1379 cleanup_issue_handle (tih); 1438 cleanup_issue_handle (tih);
@@ -1401,22 +1460,25 @@ filter_tickets_cb (void *cls,
1401{ 1460{
1402 struct TicketIssueHandle *tih = cls; 1461 struct TicketIssueHandle *tih = cls;
1403 struct GNUNET_RECLAIM_Ticket *ticket = NULL; 1462 struct GNUNET_RECLAIM_Ticket *ticket = NULL;
1404 1463 struct GNUNET_RECLAIM_Presentation *pres;
1405 // figure out the number of requested attributes 1464 struct GNUNET_RECLAIM_PresentationList *ticket_presentations;
1465 struct GNUNET_RECLAIM_Credential *cred;
1466 struct GNUNET_RECLAIM_PresentationListEntry *ple;
1406 struct GNUNET_RECLAIM_AttributeListEntry *le; 1467 struct GNUNET_RECLAIM_AttributeListEntry *le;
1407 unsigned int attr_cnt = 0; 1468 unsigned int attr_cnt = 0;
1408 unsigned int attest_cnt = 0; 1469 unsigned int pres_cnt = 0;
1409 1470
1410 for (le = tih->attrs->list_head; NULL != le; le = le->next) 1471 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1411 { 1472 {
1412 attr_cnt++; 1473 attr_cnt++;
1413 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) 1474 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->credential))
1414 attest_cnt++; 1475 pres_cnt++;
1415 } 1476 }
1416 1477
1417 // ticket search 1478 // ticket search
1418 unsigned int found_attrs_cnt = 0; 1479 unsigned int found_attrs_cnt = 0;
1419 unsigned int found_attests_cnt = 0; 1480 unsigned int found_pres_cnt = 0;
1481 ticket_presentations = GNUNET_new (struct GNUNET_RECLAIM_PresentationList);
1420 1482
1421 for (int i = 0; i < rd_count; i++) 1483 for (int i = 0; i < rd_count; i++)
1422 { 1484 {
@@ -1436,20 +1498,75 @@ filter_tickets_cb (void *cls,
1436 } 1498 }
1437 1499
1438 // cmp requested attributes with ticket attributes 1500 // cmp requested attributes with ticket attributes
1439 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) && 1501 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF == rd[i].record_type)
1440 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF != rd[i].record_type)) 1502 {
1441 continue; 1503 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1442 for (le = tih->attrs->list_head; NULL != le; le = le->next) 1504 {
1505 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data,
1506 &le->attribute->id))
1507 found_attrs_cnt++;
1508 }
1509 }
1510 if (GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL == rd[i].record_type)
1443 { 1511 {
1444 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, 1512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1445 &le->attribute->id)) 1513 "Found credential...\n");
1446 found_attrs_cnt++; 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 }
1447 } 1546 }
1448 for (le = tih->attrs->list_head; NULL != le; le = le->next) 1547 if (GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION == rd[i].record_type)
1449 { 1548 {
1450 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, 1549 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1451 &le->attribute->attestation)) 1550 {
1452 found_attests_cnt++; 1551 pres = GNUNET_RECLAIM_presentation_deserialize (rd[i].data,
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,
1560 &le->attribute->credential))
1561 {
1562 found_pres_cnt++;
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 }
1569 }
1453 } 1570 }
1454 } 1571 }
1455 1572
@@ -1458,11 +1575,12 @@ filter_tickets_cb (void *cls,
1458 * we are done. 1575 * we are done.
1459 */ 1576 */
1460 if ((attr_cnt == found_attrs_cnt) && 1577 if ((attr_cnt == found_attrs_cnt) &&
1461 (attest_cnt == found_attests_cnt) && 1578 (pres_cnt == found_pres_cnt) &&
1462 (NULL != ticket)) 1579 (NULL != ticket))
1463 { 1580 {
1464 GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it); 1581 GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it);
1465 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);
1466 cleanup_issue_handle (tih); 1584 cleanup_issue_handle (tih);
1467 return; 1585 return;
1468 } 1586 }
@@ -1514,6 +1632,7 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1514 tih->cb = cb; 1632 tih->cb = cb;
1515 tih->cb_cls = cb_cls; 1633 tih->cb_cls = cb_cls;
1516 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);
1517 tih->identity = *identity; 1636 tih->identity = *identity;
1518 tih->ticket.audience = *audience; 1637 tih->ticket.audience = *audience;
1519 1638
@@ -1531,8 +1650,8 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1531 1650
1532 1651
1533/************************************ 1652/************************************
1534* Ticket iteration 1653 * Ticket iteration
1535************************************/ 1654 ************************************/
1536 1655
1537/** 1656/**
1538 * Cleanup ticket iterator 1657 * Cleanup ticket iterator