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.c343
1 files changed, 233 insertions, 110 deletions
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c
index 7e6b07514..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;
@@ -694,8 +699,9 @@ rvk_move_attr_cb (void *cls,
694 { 699 {
695 /** find a new place for this attribute **/ 700 /** find a new place for this attribute **/
696 struct GNUNET_RECLAIM_Attribute *claim; 701 struct GNUNET_RECLAIM_Attribute *claim;
697 claim = GNUNET_RECLAIM_attribute_deserialize (rd[i].data, 702 GNUNET_RECLAIM_attribute_deserialize (rd[i].data,
698 rd[i].data_size); 703 rd[i].data_size,
704 &claim);
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
700 "Attribute to update: Name=%s\n", 706 "Attribute to update: Name=%s\n",
701 claim->name); 707 claim->name);
@@ -714,20 +720,20 @@ rvk_move_attr_cb (void *cls,
714 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);
715 GNUNET_free (claim); 721 GNUNET_free (claim);
716 } 722 }
717 else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION == rd[i].record_type) 723 else if (GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL == rd[i].record_type)
718 { 724 {
719 struct GNUNET_RECLAIM_Attestation *attest; 725 struct GNUNET_RECLAIM_Credential *credential;
720 attest = GNUNET_RECLAIM_attestation_deserialize (rd[i].data, 726 credential = GNUNET_RECLAIM_credential_deserialize (rd[i].data,
721 rd[i].data_size); 727 rd[i].data_size);
722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
723 "Attestation to update: Name=%s\n", 729 "Credential to update: Name=%s\n",
724 attest->name); 730 credential->name);
725 attest->id = rvk->move_attr->new_id; 731 credential->id = rvk->move_attr->new_id;
726 new_rd[i].data_size = 732 new_rd[i].data_size =
727 GNUNET_RECLAIM_attestation_serialize_get_size (attest); 733 GNUNET_RECLAIM_credential_serialize_get_size (credential);
728 attr_data = GNUNET_malloc (rd[i].data_size); 734 attr_data = GNUNET_malloc (rd[i].data_size);
729 new_rd[i].data_size = GNUNET_RECLAIM_attestation_serialize (attest, 735 new_rd[i].data_size = GNUNET_RECLAIM_credential_serialize (credential,
730 attr_data); 736 attr_data);
731 new_rd[i].data = attr_data; 737 new_rd[i].data = attr_data;
732 new_rd[i].record_type = rd[i].record_type; 738 new_rd[i].record_type = rd[i].record_type;
733 new_rd[i].flags = rd[i].flags; 739 new_rd[i].flags = rd[i].flags;
@@ -735,9 +741,9 @@ rvk_move_attr_cb (void *cls,
735 new_label = 741 new_label =
736 GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, 742 GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id,
737 sizeof (rvk->move_attr->new_id)); 743 sizeof (rvk->move_attr->new_id));
738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attestation %s\n", 744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding credential %s\n",
739 new_label); 745 new_label);
740 GNUNET_free (attest); 746 GNUNET_free (credential);
741 } 747 }
742 } 748 }
743 rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, 749 rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
@@ -980,8 +986,8 @@ cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth)
980 986
981 if (NULL != cth->attrs) 987 if (NULL != cth->attrs)
982 GNUNET_RECLAIM_attribute_list_destroy (cth->attrs); 988 GNUNET_RECLAIM_attribute_list_destroy (cth->attrs);
983 if (NULL != cth->attests) 989 if (NULL != cth->presentations)
984 GNUNET_RECLAIM_attestation_list_destroy (cth->attests); 990 GNUNET_RECLAIM_presentation_list_destroy (cth->presentations);
985 GNUNET_free (cth); 991 GNUNET_free (cth);
986} 992}
987 993
@@ -1026,40 +1032,20 @@ process_parallel_lookup_result (void *cls,
1026 // REMARK: It is possible now to find rd_count > 1 1032 // REMARK: It is possible now to find rd_count > 1
1027 for (int i = 0; i < rd_count; i++) 1033 for (int i = 0; i < rd_count; i++)
1028 { 1034 {
1029 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE == rd[i].record_type) 1035 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE != rd[i].record_type)
1030 {
1031 attr_le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
1032 attr_le->attribute =
1033 GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size);
1034 GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head,
1035 cth->attrs->list_tail,
1036 attr_le);
1037 }
1038 else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION == rd[i].record_type)
1039 {
1040 struct GNUNET_RECLAIM_AttestationListEntry *ale;
1041 ale = GNUNET_new (struct GNUNET_RECLAIM_AttestationListEntry);
1042 ale->attestation =
1043 GNUNET_RECLAIM_attestation_deserialize (rd[i].data,
1044 rd[i].data_size);
1045 GNUNET_CONTAINER_DLL_insert (cth->attests->list_head,
1046 cth->attests->list_tail,
1047 ale);
1048 }
1049 else
1050 {
1051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1052 "Parallel Lookup of Reference without Attestation");
1053 continue; 1036 continue;
1054 } 1037 attr_le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
1055 1038 GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size,
1056 1039 &attr_le->attribute);
1040 GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head,
1041 cth->attrs->list_tail,
1042 attr_le);
1057 } 1043 }
1058 if (NULL != cth->parallel_lookups_head) 1044 if (NULL != cth->parallel_lookups_head)
1059 return; // Wait for more 1045 return; // Wait for more
1060 /* Else we are done */ 1046 /* Else we are done */
1061 cth->cb (cth->cb_cls, &cth->ticket.identity, 1047 cth->cb (cth->cb_cls, &cth->ticket.identity,
1062 cth->attrs, cth->attests, GNUNET_OK, NULL); 1048 cth->attrs, cth->presentations, GNUNET_OK, NULL);
1063 cleanup_cth (cth); 1049 cleanup_cth (cth);
1064} 1050}
1065 1051
@@ -1109,6 +1095,7 @@ lookup_authz_cb (void *cls,
1109 struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; 1095 struct RECLAIM_TICKETS_ConsumeHandle *cth = cls;
1110 struct ParallelLookup *parallel_lookup; 1096 struct ParallelLookup *parallel_lookup;
1111 char *lbl; 1097 char *lbl;
1098 struct GNUNET_RECLAIM_PresentationListEntry *ale;
1112 1099
1113 cth->lookup_request = NULL; 1100 cth->lookup_request = NULL;
1114 1101
@@ -1125,26 +1112,44 @@ lookup_authz_cb (void *cls,
1125 1112
1126 for (int i = 0; i < rd_count; i++) 1113 for (int i = 0; i < rd_count; i++)
1127 { 1114 {
1128 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) && 1115 /**
1129 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF != rd[i].record_type)) 1116 * Check if record is a credential presentation or an attribute
1130 continue; 1117 * reference.
1131 lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size); 1118 */
1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ticket reference found %s\n", lbl); 1119 switch (rd[i].record_type)
1133 parallel_lookup = GNUNET_new (struct ParallelLookup); 1120 {
1134 parallel_lookup->handle = cth; 1121 case GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION:
1135 parallel_lookup->label = lbl; 1122 ale = GNUNET_new (struct GNUNET_RECLAIM_PresentationListEntry);
1136 parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get (); 1123 ale->presentation =
1137 parallel_lookup->lookup_request = 1124 GNUNET_RECLAIM_presentation_deserialize (rd[i].data,
1138 GNUNET_GNS_lookup (gns, 1125 rd[i].data_size);
1139 lbl, 1126 GNUNET_CONTAINER_DLL_insert (cth->presentations->list_head,
1140 &cth->ticket.identity, 1127 cth->presentations->list_tail,
1141 GNUNET_GNSRECORD_TYPE_ANY, 1128 ale);
1142 GNUNET_GNS_LO_DEFAULT, 1129 break;
1143 &process_parallel_lookup_result, 1130 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF:
1144 parallel_lookup); 1131 lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size);
1145 GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, 1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ticket reference found %s\n", lbl);
1146 cth->parallel_lookups_tail, 1133 parallel_lookup = GNUNET_new (struct ParallelLookup);
1147 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 }
1148 } 1153 }
1149 /** 1154 /**
1150 * We started lookups. Add a timeout task. 1155 * We started lookups. Add a timeout task.
@@ -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->attests, 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->attests = GNUNET_new (struct GNUNET_RECLAIM_AttestationList); 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,48 +1293,92 @@ 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 attestation 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;
1299 for (le = ih->attrs->list_head; NULL != le; le = le->next) 1310 for (le = ih->attrs->list_head; NULL != le; le = le->next)
1300 { 1311 {
1312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1313 "Adding list entry: %s\n", le->attribute->name);
1314
1301 attrs_record[i].data = &le->attribute->id; 1315 attrs_record[i].data = &le->attribute->id;
1302 attrs_record[i].data_size = sizeof(le->attribute->id); 1316 attrs_record[i].data_size = sizeof(le->attribute->id);
1303 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; 1317 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us;
1304 attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF; 1318 attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF;
1305 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 1319 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1306 i++; 1320 i++;
1307 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) 1321 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->credential))
1308 { 1322 {
1309 int j; 1323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1324 "Attribute is backed by credential. Adding...\n");
1325 struct GNUNET_RECLAIM_Presentation *pres = NULL;
1310 for (j = 0; j < i; j++) 1326 for (j = 0; j < i; j++)
1311 { 1327 {
1312 if (attrs_record[j].record_type 1328 if (attrs_record[j].record_type
1313 != GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF) 1329 != GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION)
1330 continue;
1331 pres = GNUNET_RECLAIM_presentation_deserialize (attrs_record[j].data,
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");
1314 continue; 1338 continue;
1315 if (0 == memcmp (attrs_record[j].data, 1339 }
1316 &le->attribute->attestation, 1340 if (0 == memcmp (&pres->credential_id,
1317 sizeof (le->attribute->attestation))) 1341 &le->attribute->credential,
1342 sizeof (le->attribute->credential)))
1318 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;
1319 } 1381 }
1320 if (j < i)
1321 continue; // Skip as we have already added this attestation.
1322 attrs_record[i].data = &le->attribute->attestation;
1323 attrs_record[i].data_size = sizeof(le->attribute->attestation);
1324 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us;
1325 attrs_record[i].record_type =
1326 GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF;
1327 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1328 i++;
1329 } 1382 }
1330 } 1383 }
1331 attrs_record[i].data = &ih->ticket; 1384 attrs_record[i].data = &ih->ticket;
@@ -1347,14 +1400,23 @@ issue_ticket (struct TicketIssueHandle *ih)
1347 attrs_record, 1400 attrs_record,
1348 &store_ticket_issue_cont, 1401 &store_ticket_issue_cont,
1349 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 }
1350 GNUNET_free (attrs_record); 1412 GNUNET_free (attrs_record);
1351 GNUNET_free (label); 1413 GNUNET_free (label);
1352} 1414}
1353 1415
1354 1416
1355/************************************************* 1417/*************************************************
1356* Ticket iteration (finding a specific ticket) 1418 * Ticket iteration (finding a specific ticket)
1357*************************************************/ 1419 *************************************************/
1358 1420
1359 1421
1360/** 1422/**
@@ -1370,6 +1432,7 @@ filter_tickets_error_cb (void *cls)
1370 tih->ns_it = NULL; 1432 tih->ns_it = NULL;
1371 tih->cb (tih->cb_cls, 1433 tih->cb (tih->cb_cls,
1372 &tih->ticket, 1434 &tih->ticket,
1435 NULL,
1373 GNUNET_SYSERR, 1436 GNUNET_SYSERR,
1374 "Error storing AuthZ ticket in GNS"); 1437 "Error storing AuthZ ticket in GNS");
1375 cleanup_issue_handle (tih); 1438 cleanup_issue_handle (tih);
@@ -1397,22 +1460,25 @@ filter_tickets_cb (void *cls,
1397{ 1460{
1398 struct TicketIssueHandle *tih = cls; 1461 struct TicketIssueHandle *tih = cls;
1399 struct GNUNET_RECLAIM_Ticket *ticket = NULL; 1462 struct GNUNET_RECLAIM_Ticket *ticket = NULL;
1400 1463 struct GNUNET_RECLAIM_Presentation *pres;
1401 // 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;
1402 struct GNUNET_RECLAIM_AttributeListEntry *le; 1467 struct GNUNET_RECLAIM_AttributeListEntry *le;
1403 unsigned int attr_cnt = 0; 1468 unsigned int attr_cnt = 0;
1404 unsigned int attest_cnt = 0; 1469 unsigned int pres_cnt = 0;
1405 1470
1406 for (le = tih->attrs->list_head; NULL != le; le = le->next) 1471 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1407 { 1472 {
1408 attr_cnt++; 1473 attr_cnt++;
1409 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) 1474 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->credential))
1410 attest_cnt++; 1475 pres_cnt++;
1411 } 1476 }
1412 1477
1413 // ticket search 1478 // ticket search
1414 unsigned int found_attrs_cnt = 0; 1479 unsigned int found_attrs_cnt = 0;
1415 unsigned int found_attests_cnt = 0; 1480 unsigned int found_pres_cnt = 0;
1481 ticket_presentations = GNUNET_new (struct GNUNET_RECLAIM_PresentationList);
1416 1482
1417 for (int i = 0; i < rd_count; i++) 1483 for (int i = 0; i < rd_count; i++)
1418 { 1484 {
@@ -1432,20 +1498,75 @@ filter_tickets_cb (void *cls,
1432 } 1498 }
1433 1499
1434 // cmp requested attributes with ticket attributes 1500 // cmp requested attributes with ticket attributes
1435 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) && 1501 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF == rd[i].record_type)
1436 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF != rd[i].record_type))
1437 continue;
1438 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1439 { 1502 {
1440 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, 1503 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1441 &le->attribute->id)) 1504 {
1442 found_attrs_cnt++; 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)
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 }
1443 } 1546 }
1444 for (le = tih->attrs->list_head; NULL != le; le = le->next) 1547 if (GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION == rd[i].record_type)
1445 { 1548 {
1446 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, 1549 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1447 &le->attribute->attestation)) 1550 {
1448 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 }
1449 } 1570 }
1450 } 1571 }
1451 1572
@@ -1454,11 +1575,12 @@ filter_tickets_cb (void *cls,
1454 * we are done. 1575 * we are done.
1455 */ 1576 */
1456 if ((attr_cnt == found_attrs_cnt) && 1577 if ((attr_cnt == found_attrs_cnt) &&
1457 (attest_cnt == found_attests_cnt) && 1578 (pres_cnt == found_pres_cnt) &&
1458 (NULL != ticket)) 1579 (NULL != ticket))
1459 { 1580 {
1460 GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it); 1581 GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it);
1461 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);
1462 cleanup_issue_handle (tih); 1584 cleanup_issue_handle (tih);
1463 return; 1585 return;
1464 } 1586 }
@@ -1510,6 +1632,7 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1510 tih->cb = cb; 1632 tih->cb = cb;
1511 tih->cb_cls = cb_cls; 1633 tih->cb_cls = cb_cls;
1512 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);
1513 tih->identity = *identity; 1636 tih->identity = *identity;
1514 tih->ticket.audience = *audience; 1637 tih->ticket.audience = *audience;
1515 1638
@@ -1527,8 +1650,8 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1527 1650
1528 1651
1529/************************************ 1652/************************************
1530* Ticket iteration 1653 * Ticket iteration
1531************************************/ 1654 ************************************/
1532 1655
1533/** 1656/**
1534 * Cleanup ticket iterator 1657 * Cleanup ticket iterator