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.c197
1 files changed, 153 insertions, 44 deletions
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