diff options
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 410 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim_tickets.c | 439 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim_tickets.h | 38 | ||||
-rw-r--r-- | src/reclaim/reclaim.h | 5 |
4 files changed, 503 insertions, 389 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index 634de0dfe..c8ae8a238 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -30,8 +30,6 @@ | |||
30 | #include "gnunet_identity_service.h" | 30 | #include "gnunet_identity_service.h" |
31 | #include "gnunet_gnsrecord_lib.h" | 31 | #include "gnunet_gnsrecord_lib.h" |
32 | #include "gnunet_namestore_service.h" | 32 | #include "gnunet_namestore_service.h" |
33 | #include "gnunet_statistics_service.h" | ||
34 | #include "gnunet_gns_service.h" | ||
35 | #include "gnunet_reclaim_plugin.h" | 33 | #include "gnunet_reclaim_plugin.h" |
36 | #include "gnunet_reclaim_attribute_lib.h" | 34 | #include "gnunet_reclaim_attribute_lib.h" |
37 | #include "gnunet_signatures.h" | 35 | #include "gnunet_signatures.h" |
@@ -84,11 +82,6 @@ static struct GNUNET_TIME_Relative token_expiration_interval; | |||
84 | static struct GNUNET_NAMESTORE_Handle *nsh; | 82 | static struct GNUNET_NAMESTORE_Handle *nsh; |
85 | 83 | ||
86 | /** | 84 | /** |
87 | * GNS handle | ||
88 | */ | ||
89 | static struct GNUNET_GNS_Handle *gns_handle; | ||
90 | |||
91 | /** | ||
92 | * Timeout task | 85 | * Timeout task |
93 | */ | 86 | */ |
94 | static struct GNUNET_SCHEDULER_Task *timeout_task; | 87 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
@@ -100,11 +93,6 @@ static struct GNUNET_SCHEDULER_Task *update_task; | |||
100 | 93 | ||
101 | 94 | ||
102 | /** | 95 | /** |
103 | * Handle to the statistics service. | ||
104 | */ | ||
105 | static struct GNUNET_STATISTICS_Handle *stats; | ||
106 | |||
107 | /** | ||
108 | * Our configuration. | 96 | * Our configuration. |
109 | */ | 97 | */ |
110 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 98 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -248,12 +236,12 @@ struct IdpClient | |||
248 | /** | 236 | /** |
249 | * Head of DLL of ticket consume ops | 237 | * Head of DLL of ticket consume ops |
250 | */ | 238 | */ |
251 | struct ConsumeTicketHandle *consume_op_head; | 239 | struct ConsumeTicketOperation *consume_op_head; |
252 | 240 | ||
253 | /** | 241 | /** |
254 | * Tail of DLL of ticket consume ops | 242 | * Tail of DLL of ticket consume ops |
255 | */ | 243 | */ |
256 | struct ConsumeTicketHandle *consume_op_tail; | 244 | struct ConsumeTicketOperation *consume_op_tail; |
257 | 245 | ||
258 | /** | 246 | /** |
259 | * Head of DLL of attribute store ops | 247 | * Head of DLL of attribute store ops |
@@ -316,20 +304,17 @@ struct AttributeStoreHandle | |||
316 | }; | 304 | }; |
317 | 305 | ||
318 | 306 | ||
319 | /* Prototype */ | 307 | struct ConsumeTicketOperation |
320 | struct ParallelLookup; | ||
321 | |||
322 | struct ConsumeTicketHandle | ||
323 | { | 308 | { |
324 | /** | 309 | /** |
325 | * DLL | 310 | * DLL |
326 | */ | 311 | */ |
327 | struct ConsumeTicketHandle *next; | 312 | struct ConsumeTicketOperation *next; |
328 | 313 | ||
329 | /** | 314 | /** |
330 | * DLL | 315 | * DLL |
331 | */ | 316 | */ |
332 | struct ConsumeTicketHandle *prev; | 317 | struct ConsumeTicketOperation *prev; |
333 | 318 | ||
334 | /** | 319 | /** |
335 | * Client connection | 320 | * Client connection |
@@ -337,82 +322,17 @@ struct ConsumeTicketHandle | |||
337 | struct IdpClient *client; | 322 | struct IdpClient *client; |
338 | 323 | ||
339 | /** | 324 | /** |
340 | * Ticket | ||
341 | */ | ||
342 | struct GNUNET_RECLAIM_Ticket ticket; | ||
343 | |||
344 | /** | ||
345 | * LookupRequest | ||
346 | */ | ||
347 | struct GNUNET_GNS_LookupRequest *lookup_request; | ||
348 | |||
349 | /** | ||
350 | * Audience Key | ||
351 | */ | ||
352 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | ||
353 | |||
354 | /** | ||
355 | * Audience Key | ||
356 | */ | ||
357 | struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub; | ||
358 | |||
359 | /** | ||
360 | * Lookup DLL | ||
361 | */ | ||
362 | struct ParallelLookup *parallel_lookups_head; | ||
363 | |||
364 | /** | ||
365 | * Lookup DLL | ||
366 | */ | ||
367 | struct ParallelLookup *parallel_lookups_tail; | ||
368 | |||
369 | /** | ||
370 | * Kill task | ||
371 | */ | ||
372 | struct GNUNET_SCHEDULER_Task *kill_task; | ||
373 | |||
374 | /** | ||
375 | * Attributes | ||
376 | */ | ||
377 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; | ||
378 | |||
379 | /** | ||
380 | * Lookup time | ||
381 | */ | ||
382 | struct GNUNET_TIME_Absolute lookup_start_time; | ||
383 | |||
384 | /** | ||
385 | * request id | 325 | * request id |
386 | */ | 326 | */ |
387 | uint32_t r_id; | 327 | uint32_t r_id; |
388 | }; | ||
389 | |||
390 | /** | ||
391 | * Handle for a parallel GNS lookup job | ||
392 | */ | ||
393 | struct ParallelLookup | ||
394 | { | ||
395 | /* DLL */ | ||
396 | struct ParallelLookup *next; | ||
397 | |||
398 | /* DLL */ | ||
399 | struct ParallelLookup *prev; | ||
400 | |||
401 | /* The GNS request */ | ||
402 | struct GNUNET_GNS_LookupRequest *lookup_request; | ||
403 | |||
404 | /* The handle the return to */ | ||
405 | struct ConsumeTicketHandle *handle; | ||
406 | 328 | ||
407 | /** | 329 | /** |
408 | * Lookup time | 330 | * Ticket consume handle |
409 | */ | 331 | */ |
410 | struct GNUNET_TIME_Absolute lookup_start_time; | 332 | struct RECLAIM_TICKETS_ConsumeHandle *ch; |
411 | |||
412 | /* The label to look up */ | ||
413 | char *label; | ||
414 | }; | 333 | }; |
415 | 334 | ||
335 | |||
416 | /** | 336 | /** |
417 | * Updated attribute IDs | 337 | * Updated attribute IDs |
418 | */ | 338 | */ |
@@ -578,11 +498,6 @@ cleanup() | |||
578 | "Cleaning up\n"); | 498 | "Cleaning up\n"); |
579 | 499 | ||
580 | RECLAIM_TICKETS_deinit (); | 500 | RECLAIM_TICKETS_deinit (); |
581 | if (NULL != stats) | ||
582 | { | ||
583 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
584 | stats = NULL; | ||
585 | } | ||
586 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, | 501 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, |
587 | TKT_database)); | 502 | TKT_database)); |
588 | GNUNET_free (db_lib_name); | 503 | GNUNET_free (db_lib_name); |
@@ -593,8 +508,6 @@ cleanup() | |||
593 | GNUNET_SCHEDULER_cancel (update_task); | 508 | GNUNET_SCHEDULER_cancel (update_task); |
594 | if (NULL != identity_handle) | 509 | if (NULL != identity_handle) |
595 | GNUNET_IDENTITY_disconnect (identity_handle); | 510 | GNUNET_IDENTITY_disconnect (identity_handle); |
596 | if (NULL != gns_handle) | ||
597 | GNUNET_GNS_disconnect (gns_handle); | ||
598 | if (NULL != nsh) | 511 | if (NULL != nsh) |
599 | GNUNET_NAMESTORE_disconnect (nsh); | 512 | GNUNET_NAMESTORE_disconnect (nsh); |
600 | } | 513 | } |
@@ -729,11 +642,11 @@ handle_issue_ticket_message (void *cls, | |||
729 | GNUNET_CONTAINER_DLL_insert (idp->issue_op_head, | 642 | GNUNET_CONTAINER_DLL_insert (idp->issue_op_head, |
730 | idp->issue_op_tail, | 643 | idp->issue_op_tail, |
731 | tio); | 644 | tio); |
732 | RECLAIM_TICKETS_issue_ticket (&im->identity, | 645 | RECLAIM_TICKETS_issue (&im->identity, |
733 | attrs, | 646 | attrs, |
734 | &im->rp, | 647 | &im->rp, |
735 | &issue_ticket_result_cb, | 648 | &issue_ticket_result_cb, |
736 | tio); | 649 | tio); |
737 | GNUNET_SERVICE_client_continue (idp->client); | 650 | GNUNET_SERVICE_client_continue (idp->client); |
738 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); | 651 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); |
739 | } | 652 | } |
@@ -1275,39 +1188,9 @@ handle_revoke_ticket_message (void *cls, | |||
1275 | 1188 | ||
1276 | } | 1189 | } |
1277 | 1190 | ||
1278 | /** | ||
1279 | * Cleanup ticket consume handle | ||
1280 | * @param handle the handle to clean up | ||
1281 | */ | ||
1282 | static void | ||
1283 | cleanup_consume_ticket_handle (struct ConsumeTicketHandle *handle) | ||
1284 | { | ||
1285 | struct ParallelLookup *lu; | ||
1286 | struct ParallelLookup *tmp; | ||
1287 | if (NULL != handle->lookup_request) | ||
1288 | GNUNET_GNS_lookup_cancel (handle->lookup_request); | ||
1289 | for (lu = handle->parallel_lookups_head; | ||
1290 | NULL != lu;) { | ||
1291 | GNUNET_GNS_lookup_cancel (lu->lookup_request); | ||
1292 | GNUNET_free (lu->label); | ||
1293 | tmp = lu->next; | ||
1294 | GNUNET_CONTAINER_DLL_remove (handle->parallel_lookups_head, | ||
1295 | handle->parallel_lookups_tail, | ||
1296 | lu); | ||
1297 | GNUNET_free (lu); | ||
1298 | lu = tmp; | ||
1299 | } | ||
1300 | |||
1301 | if (NULL != handle->attrs) | ||
1302 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (handle->attrs); | ||
1303 | GNUNET_free (handle); | ||
1304 | } | ||
1305 | |||
1306 | |||
1307 | |||
1308 | static int | 1191 | static int |
1309 | check_consume_ticket_message(void *cls, | 1192 | check_consume_ticket_message (void *cls, |
1310 | const struct ConsumeTicketMessage *cm) | 1193 | const struct ConsumeTicketMessage *cm) |
1311 | { | 1194 | { |
1312 | uint16_t size; | 1195 | uint16_t size; |
1313 | 1196 | ||
@@ -1321,239 +1204,68 @@ check_consume_ticket_message(void *cls, | |||
1321 | } | 1204 | } |
1322 | 1205 | ||
1323 | static void | 1206 | static void |
1324 | process_parallel_lookup2 (void *cls, uint32_t rd_count, | 1207 | consume_result_cb (void *cls, |
1325 | const struct GNUNET_GNSRECORD_Data *rd) | 1208 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
1209 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | ||
1210 | uint32_t success, | ||
1211 | const char *emsg) | ||
1326 | { | 1212 | { |
1327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1213 | struct ConsumeTicketOperation *cop = cls; |
1328 | "Parallel lookup finished (count=%u)\n", rd_count); | ||
1329 | struct ParallelLookup *parallel_lookup = cls; | ||
1330 | struct ConsumeTicketHandle *handle = parallel_lookup->handle; | ||
1331 | struct ConsumeTicketResultMessage *crm; | 1214 | struct ConsumeTicketResultMessage *crm; |
1332 | struct GNUNET_MQ_Envelope *env; | 1215 | struct GNUNET_MQ_Envelope *env; |
1333 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le; | ||
1334 | char *data_tmp; | 1216 | char *data_tmp; |
1335 | size_t attrs_len; | 1217 | size_t attrs_len; |
1336 | 1218 | if (GNUNET_OK != success) | |
1337 | GNUNET_CONTAINER_DLL_remove (handle->parallel_lookups_head, | ||
1338 | handle->parallel_lookups_tail, | ||
1339 | parallel_lookup); | ||
1340 | GNUNET_free (parallel_lookup->label); | ||
1341 | |||
1342 | GNUNET_STATISTICS_update (stats, | ||
1343 | "attribute_lookup_time_total", | ||
1344 | GNUNET_TIME_absolute_get_duration (parallel_lookup->lookup_start_time).rel_value_us, | ||
1345 | GNUNET_YES); | ||
1346 | GNUNET_STATISTICS_update (stats, | ||
1347 | "attribute_lookups_count", | ||
1348 | 1, | ||
1349 | GNUNET_YES); | ||
1350 | |||
1351 | |||
1352 | GNUNET_free (parallel_lookup); | ||
1353 | if (1 != rd_count) | ||
1354 | GNUNET_break(0);//TODO | ||
1355 | if (rd->record_type == GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR) | ||
1356 | { | 1219 | { |
1357 | attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | ||
1358 | attr_le->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, | ||
1359 | rd->data_size); | ||
1360 | GNUNET_CONTAINER_DLL_insert (handle->attrs->list_head, | ||
1361 | handle->attrs->list_tail, | ||
1362 | attr_le); | ||
1363 | } | ||
1364 | if (NULL != handle->parallel_lookups_head) | ||
1365 | return; //Wait for more | ||
1366 | /* Else we are done */ | ||
1367 | |||
1368 | /** Store ticket in DB | ||
1369 | * TODO: Store in GNS? | ||
1370 | */ | ||
1371 | /**if (GNUNET_OK != TKT_database->store_ticket (TKT_database->cls, | ||
1372 | &handle->ticket, | ||
1373 | handle->attrs)) | ||
1374 | { | ||
1375 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1376 | "Unable to store ticket after consume\n"); | 1221 | "Error consuming ticket: %s\n", |
1377 | GNUNET_break (0); | 1222 | emsg); |
1378 | }*/ | 1223 | } |
1379 | 1224 | attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); | |
1380 | GNUNET_SCHEDULER_cancel (handle->kill_task); | ||
1381 | attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (handle->attrs); | ||
1382 | env = GNUNET_MQ_msg_extra (crm, | 1225 | env = GNUNET_MQ_msg_extra (crm, |
1383 | attrs_len, | 1226 | attrs_len, |
1384 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT); | 1227 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT); |
1385 | crm->id = htonl (handle->r_id); | 1228 | crm->id = htonl (cop->r_id); |
1386 | crm->attrs_len = htons (attrs_len); | 1229 | crm->attrs_len = htons (attrs_len); |
1387 | crm->identity = handle->ticket.identity; | 1230 | crm->identity = *identity; |
1231 | crm->result = htonl (success); | ||
1388 | data_tmp = (char *) &crm[1]; | 1232 | data_tmp = (char *) &crm[1]; |
1389 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (handle->attrs, | 1233 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, |
1390 | data_tmp); | 1234 | data_tmp); |
1391 | GNUNET_MQ_send (handle->client->mq, env); | 1235 | GNUNET_MQ_send (cop->client->mq, env); |
1392 | GNUNET_CONTAINER_DLL_remove (handle->client->consume_op_head, | 1236 | GNUNET_CONTAINER_DLL_remove (cop->client->consume_op_head, |
1393 | handle->client->consume_op_tail, | 1237 | cop->client->consume_op_tail, |
1394 | handle); | 1238 | cop); |
1395 | cleanup_consume_ticket_handle (handle); | 1239 | GNUNET_free (cop); |
1396 | } | ||
1397 | |||
1398 | void | ||
1399 | abort_parallel_lookups2 (void *cls) | ||
1400 | { | ||
1401 | struct ConsumeTicketHandle *handle = cls; | ||
1402 | struct ParallelLookup *lu; | ||
1403 | struct ParallelLookup *tmp; | ||
1404 | struct AttributeResultMessage *arm; | ||
1405 | struct GNUNET_MQ_Envelope *env; | ||
1406 | |||
1407 | handle->kill_task = NULL; | ||
1408 | for (lu = handle->parallel_lookups_head; | ||
1409 | NULL != lu;) { | ||
1410 | GNUNET_GNS_lookup_cancel (lu->lookup_request); | ||
1411 | GNUNET_free (lu->label); | ||
1412 | tmp = lu->next; | ||
1413 | GNUNET_CONTAINER_DLL_remove (handle->parallel_lookups_head, | ||
1414 | handle->parallel_lookups_tail, | ||
1415 | lu); | ||
1416 | GNUNET_free (lu); | ||
1417 | lu = tmp; | ||
1418 | } | ||
1419 | env = GNUNET_MQ_msg (arm, | ||
1420 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); | ||
1421 | arm->id = htonl (handle->r_id); | ||
1422 | arm->attr_len = htons (0); | ||
1423 | GNUNET_MQ_send (handle->client->mq, env); | ||
1424 | |||
1425 | } | ||
1426 | |||
1427 | |||
1428 | static void | ||
1429 | process_attr_labels (void *cls, uint32_t rd_count, | ||
1430 | const struct GNUNET_GNSRECORD_Data *rd) | ||
1431 | { | ||
1432 | struct ConsumeTicketHandle *handle = cls; | ||
1433 | struct GNUNET_HashCode new_key_hash; | ||
1434 | struct GNUNET_CRYPTO_SymmetricSessionKey enc_key; | ||
1435 | struct GNUNET_CRYPTO_SymmetricInitializationVector enc_iv; | ||
1436 | struct GNUNET_CRYPTO_EcdhePublicKey *ecdh_key; | ||
1437 | struct ParallelLookup *parallel_lookup; | ||
1438 | size_t size; | ||
1439 | char *buf; | ||
1440 | char *attr_lbl; | ||
1441 | char *lbls; | ||
1442 | |||
1443 | handle->lookup_request = NULL; | ||
1444 | if (1 != rd_count) | ||
1445 | { | ||
1446 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1447 | "Number of keys %d != 1.", | ||
1448 | rd_count); | ||
1449 | cleanup_consume_ticket_handle (handle); | ||
1450 | GNUNET_CONTAINER_DLL_remove (handle->client->consume_op_head, | ||
1451 | handle->client->consume_op_tail, | ||
1452 | handle); | ||
1453 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
1454 | return; | ||
1455 | } | ||
1456 | |||
1457 | //Decrypt | ||
1458 | ecdh_key = (struct GNUNET_CRYPTO_EcdhePublicKey *)rd->data; | ||
1459 | |||
1460 | buf = GNUNET_malloc (rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | ||
1461 | |||
1462 | //Calculate symmetric key from ecdh parameters | ||
1463 | GNUNET_assert (GNUNET_OK == | ||
1464 | GNUNET_CRYPTO_ecdsa_ecdh (&handle->identity, | ||
1465 | ecdh_key, | ||
1466 | &new_key_hash)); | ||
1467 | create_sym_key_from_ecdh (&new_key_hash, | ||
1468 | &enc_key, | ||
1469 | &enc_iv); | ||
1470 | size = GNUNET_CRYPTO_symmetric_decrypt (rd->data + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), | ||
1471 | rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), | ||
1472 | &enc_key, | ||
1473 | &enc_iv, | ||
1474 | buf); | ||
1475 | |||
1476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1477 | "Decrypted bytes: %zd Expected bytes: %zd\n", | ||
1478 | size, rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | ||
1479 | GNUNET_STATISTICS_update (stats, | ||
1480 | "reclaim_authz_lookup_time_total", | ||
1481 | GNUNET_TIME_absolute_get_duration (handle->lookup_start_time).rel_value_us, | ||
1482 | GNUNET_YES); | ||
1483 | GNUNET_STATISTICS_update (stats, | ||
1484 | "reclaim_authz_lookups_count", | ||
1485 | 1, | ||
1486 | GNUNET_YES); | ||
1487 | lbls = GNUNET_strdup (buf); | ||
1488 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1489 | "Attributes found %s\n", lbls); | ||
1490 | 1240 | ||
1491 | for (attr_lbl = strtok (lbls, ","); | ||
1492 | NULL != attr_lbl; | ||
1493 | attr_lbl = strtok (NULL, ",")) | ||
1494 | { | ||
1495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1496 | "Looking up %s\n", attr_lbl); | ||
1497 | parallel_lookup = GNUNET_new (struct ParallelLookup); | ||
1498 | parallel_lookup->handle = handle; | ||
1499 | parallel_lookup->label = GNUNET_strdup (attr_lbl); | ||
1500 | parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get(); | ||
1501 | parallel_lookup->lookup_request | ||
1502 | = GNUNET_GNS_lookup (gns_handle, | ||
1503 | attr_lbl, | ||
1504 | &handle->ticket.identity, | ||
1505 | GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, | ||
1506 | GNUNET_GNS_LO_DEFAULT, | ||
1507 | &process_parallel_lookup2, | ||
1508 | parallel_lookup); | ||
1509 | GNUNET_CONTAINER_DLL_insert (handle->parallel_lookups_head, | ||
1510 | handle->parallel_lookups_tail, | ||
1511 | parallel_lookup); | ||
1512 | } | ||
1513 | GNUNET_free (lbls); | ||
1514 | GNUNET_free (buf); | ||
1515 | handle->kill_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES,3), | ||
1516 | &abort_parallel_lookups2, | ||
1517 | handle); | ||
1518 | } | 1241 | } |
1519 | 1242 | ||
1520 | |||
1521 | static void | 1243 | static void |
1522 | handle_consume_ticket_message (void *cls, | 1244 | handle_consume_ticket_message (void *cls, |
1523 | const struct ConsumeTicketMessage *cm) | 1245 | const struct ConsumeTicketMessage *cm) |
1524 | { | 1246 | { |
1525 | struct ConsumeTicketHandle *ch; | 1247 | struct ConsumeTicketOperation *cop; |
1248 | struct GNUNET_RECLAIM_Ticket *ticket; | ||
1526 | struct IdpClient *idp = cls; | 1249 | struct IdpClient *idp = cls; |
1527 | char* rnd_label; | 1250 | |
1528 | 1251 | cop = GNUNET_new (struct ConsumeTicketOperation); | |
1529 | ch = GNUNET_new (struct ConsumeTicketHandle); | 1252 | cop->r_id = ntohl (cm->id); |
1530 | ch->r_id = ntohl (cm->id); | 1253 | cop->client = idp; |
1531 | ch->client = idp; | 1254 | ticket = (struct GNUNET_RECLAIM_Ticket*)&cm[1]; |
1532 | ch->identity = cm->identity; | 1255 | cop->ch = RECLAIM_TICKETS_consume (&cm->identity, |
1533 | ch->attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 1256 | ticket, |
1534 | GNUNET_CRYPTO_ecdsa_key_get_public (&ch->identity, | 1257 | &consume_result_cb, |
1535 | &ch->identity_pub); | 1258 | cop); |
1536 | ch->ticket = *((struct GNUNET_RECLAIM_Ticket*)&cm[1]); | ||
1537 | rnd_label = GNUNET_STRINGS_data_to_string_alloc (&ch->ticket.rnd, | ||
1538 | sizeof (uint64_t)); | ||
1539 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1540 | "Looking for ABE key under %s\n", rnd_label); | ||
1541 | ch->lookup_start_time = GNUNET_TIME_absolute_get (); | ||
1542 | ch->lookup_request | ||
1543 | = GNUNET_GNS_lookup (gns_handle, | ||
1544 | rnd_label, | ||
1545 | &ch->ticket.identity, | ||
1546 | GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ, | ||
1547 | GNUNET_GNS_LO_DEFAULT, | ||
1548 | &process_attr_labels, | ||
1549 | ch); | ||
1550 | GNUNET_CONTAINER_DLL_insert (idp->consume_op_head, | 1259 | GNUNET_CONTAINER_DLL_insert (idp->consume_op_head, |
1551 | idp->consume_op_tail, | 1260 | idp->consume_op_tail, |
1552 | ch); | 1261 | cop); |
1553 | GNUNET_free (rnd_label); | ||
1554 | GNUNET_SERVICE_client_continue (idp->client); | 1262 | GNUNET_SERVICE_client_continue (idp->client); |
1555 | } | 1263 | } |
1556 | 1264 | ||
1265 | /***************************************** | ||
1266 | * Attribute store | ||
1267 | *****************************************/ | ||
1268 | |||
1557 | /** | 1269 | /** |
1558 | * Cleanup attribute store handle | 1270 | * Cleanup attribute store handle |
1559 | * | 1271 | * |
@@ -1694,6 +1406,10 @@ handle_attribute_store_message (void *cls, | |||
1694 | GNUNET_SCHEDULER_add_now (&attr_store_task, ash); | 1406 | GNUNET_SCHEDULER_add_now (&attr_store_task, ash); |
1695 | } | 1407 | } |
1696 | 1408 | ||
1409 | /************************************************* | ||
1410 | * Attrubute iteration | ||
1411 | *************************************************/ | ||
1412 | |||
1697 | static void | 1413 | static void |
1698 | cleanup_attribute_iter_handle (struct AttributeIterator *ai) | 1414 | cleanup_attribute_iter_handle (struct AttributeIterator *ai) |
1699 | { | 1415 | { |
@@ -1856,6 +1572,10 @@ handle_iteration_next (void *cls, | |||
1856 | GNUNET_SERVICE_client_continue (idp->client); | 1572 | GNUNET_SERVICE_client_continue (idp->client); |
1857 | } | 1573 | } |
1858 | 1574 | ||
1575 | /****************************************************** | ||
1576 | * Ticket iteration | ||
1577 | ******************************************************/ | ||
1578 | |||
1859 | static void | 1579 | static void |
1860 | ticket_iter_cb (void *cls, | 1580 | ticket_iter_cb (void *cls, |
1861 | struct GNUNET_RECLAIM_Ticket *ticket) | 1581 | struct GNUNET_RECLAIM_Ticket *ticket) |
@@ -1979,7 +1699,6 @@ run (void *cls, | |||
1979 | char *database; | 1699 | char *database; |
1980 | cfg = c; | 1700 | cfg = c; |
1981 | 1701 | ||
1982 | stats = GNUNET_STATISTICS_create ("reclaim", cfg); | ||
1983 | 1702 | ||
1984 | if (GNUNET_OK != RECLAIM_TICKETS_init (cfg)) | 1703 | if (GNUNET_OK != RECLAIM_TICKETS_init (cfg)) |
1985 | { | 1704 | { |
@@ -1995,11 +1714,6 @@ run (void *cls, | |||
1995 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to namestore"); | 1714 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to namestore"); |
1996 | } | 1715 | } |
1997 | 1716 | ||
1998 | gns_handle = GNUNET_GNS_connect (cfg); | ||
1999 | if (NULL == gns_handle) | ||
2000 | { | ||
2001 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to gns"); | ||
2002 | } | ||
2003 | identity_handle = GNUNET_IDENTITY_connect (cfg, | 1717 | identity_handle = GNUNET_IDENTITY_connect (cfg, |
2004 | NULL, | 1718 | NULL, |
2005 | NULL); | 1719 | NULL); |
@@ -2060,7 +1774,7 @@ client_disconnect_cb (void *cls, | |||
2060 | struct TicketIteration *ti; | 1774 | struct TicketIteration *ti; |
2061 | struct TicketRevocationHandle *rh; | 1775 | struct TicketRevocationHandle *rh; |
2062 | struct TicketIssueOperation *iss; | 1776 | struct TicketIssueOperation *iss; |
2063 | struct ConsumeTicketHandle *ct; | 1777 | struct ConsumeTicketOperation *ct; |
2064 | struct AttributeStoreHandle *as; | 1778 | struct AttributeStoreHandle *as; |
2065 | 1779 | ||
2066 | //TODO other operations | 1780 | //TODO other operations |
@@ -2081,7 +1795,9 @@ client_disconnect_cb (void *cls, | |||
2081 | GNUNET_CONTAINER_DLL_remove (idp->consume_op_head, | 1795 | GNUNET_CONTAINER_DLL_remove (idp->consume_op_head, |
2082 | idp->consume_op_tail, | 1796 | idp->consume_op_tail, |
2083 | ct); | 1797 | ct); |
2084 | cleanup_consume_ticket_handle (ct); | 1798 | if (NULL != ct->ch) |
1799 | RECLAIM_TICKETS_consume_cancel (ct->ch); | ||
1800 | GNUNET_free (ct); | ||
2085 | } | 1801 | } |
2086 | while (NULL != (as = idp->store_op_head)) | 1802 | while (NULL != (as = idp->store_op_head)) |
2087 | { | 1803 | { |
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c index 033684f71..a39a4be5a 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.c +++ b/src/reclaim/gnunet-service-reclaim_tickets.c | |||
@@ -26,6 +26,94 @@ | |||
26 | */ | 26 | */ |
27 | #include "gnunet-service-reclaim_tickets.h" | 27 | #include "gnunet-service-reclaim_tickets.h" |
28 | 28 | ||
29 | struct ParallelLookup; | ||
30 | |||
31 | struct RECLAIM_TICKETS_ConsumeHandle | ||
32 | { | ||
33 | /** | ||
34 | * Ticket | ||
35 | */ | ||
36 | struct GNUNET_RECLAIM_Ticket ticket; | ||
37 | |||
38 | /** | ||
39 | * LookupRequest | ||
40 | */ | ||
41 | struct GNUNET_GNS_LookupRequest *lookup_request; | ||
42 | |||
43 | /** | ||
44 | * Audience Key | ||
45 | */ | ||
46 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | ||
47 | |||
48 | /** | ||
49 | * Audience Key | ||
50 | */ | ||
51 | struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub; | ||
52 | |||
53 | /** | ||
54 | * Lookup DLL | ||
55 | */ | ||
56 | struct ParallelLookup *parallel_lookups_head; | ||
57 | |||
58 | /** | ||
59 | * Lookup DLL | ||
60 | */ | ||
61 | struct ParallelLookup *parallel_lookups_tail; | ||
62 | |||
63 | /** | ||
64 | * Kill task | ||
65 | */ | ||
66 | struct GNUNET_SCHEDULER_Task *kill_task; | ||
67 | |||
68 | /** | ||
69 | * Attributes | ||
70 | */ | ||
71 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; | ||
72 | |||
73 | /** | ||
74 | * Lookup time | ||
75 | */ | ||
76 | struct GNUNET_TIME_Absolute lookup_start_time; | ||
77 | |||
78 | /** | ||
79 | * Callback | ||
80 | */ | ||
81 | RECLAIM_TICKETS_ConsumeCallback cb; | ||
82 | |||
83 | /** | ||
84 | * Callbacl closure | ||
85 | */ | ||
86 | void *cb_cls; | ||
87 | |||
88 | }; | ||
89 | |||
90 | /** | ||
91 | * Handle for a parallel GNS lookup job | ||
92 | */ | ||
93 | struct ParallelLookup | ||
94 | { | ||
95 | /* DLL */ | ||
96 | struct ParallelLookup *next; | ||
97 | |||
98 | /* DLL */ | ||
99 | struct ParallelLookup *prev; | ||
100 | |||
101 | /* The GNS request */ | ||
102 | struct GNUNET_GNS_LookupRequest *lookup_request; | ||
103 | |||
104 | /* The handle the return to */ | ||
105 | struct RECLAIM_TICKETS_ConsumeHandle *handle; | ||
106 | |||
107 | /** | ||
108 | * Lookup time | ||
109 | */ | ||
110 | struct GNUNET_TIME_Absolute lookup_start_time; | ||
111 | |||
112 | /* The label to look up */ | ||
113 | char *label; | ||
114 | }; | ||
115 | |||
116 | |||
29 | /** | 117 | /** |
30 | * A reference to a ticket stored in GNS | 118 | * A reference to a ticket stored in GNS |
31 | */ | 119 | */ |
@@ -146,8 +234,295 @@ struct RECLAIM_TICKETS_Iterator | |||
146 | struct TicketReference *tickets_tail; | 234 | struct TicketReference *tickets_tail; |
147 | }; | 235 | }; |
148 | 236 | ||
237 | /* Namestore handle */ | ||
149 | static struct GNUNET_NAMESTORE_Handle *nsh; | 238 | static struct GNUNET_NAMESTORE_Handle *nsh; |
150 | 239 | ||
240 | /* GNS handle */ | ||
241 | static struct GNUNET_GNS_Handle *gns; | ||
242 | |||
243 | /* Handle to the statistics service */ | ||
244 | static struct GNUNET_STATISTICS_Handle *stats; | ||
245 | |||
246 | static int | ||
247 | create_sym_key_from_ecdh (const struct GNUNET_HashCode *new_key_hash, | ||
248 | struct GNUNET_CRYPTO_SymmetricSessionKey *skey, | ||
249 | struct GNUNET_CRYPTO_SymmetricInitializationVector *iv) | ||
250 | { | ||
251 | struct GNUNET_CRYPTO_HashAsciiEncoded new_key_hash_str; | ||
252 | |||
253 | GNUNET_CRYPTO_hash_to_enc (new_key_hash, | ||
254 | &new_key_hash_str); | ||
255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating symmetric rsa key from %s\n", (char*)&new_key_hash_str); | ||
256 | static const char ctx_key[] = "gnuid-aes-ctx-key"; | ||
257 | GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), | ||
258 | new_key_hash, sizeof (struct GNUNET_HashCode), | ||
259 | ctx_key, strlen (ctx_key), | ||
260 | NULL, 0); | ||
261 | static const char ctx_iv[] = "gnuid-aes-ctx-iv"; | ||
262 | GNUNET_CRYPTO_kdf (iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector), | ||
263 | new_key_hash, sizeof (struct GNUNET_HashCode), | ||
264 | ctx_iv, strlen (ctx_iv), | ||
265 | NULL, 0); | ||
266 | return GNUNET_OK; | ||
267 | } | ||
268 | |||
269 | |||
270 | /** | ||
271 | * Cleanup ticket consume handle | ||
272 | * @param cth the handle to clean up | ||
273 | */ | ||
274 | static void | ||
275 | cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth) | ||
276 | { | ||
277 | struct ParallelLookup *lu; | ||
278 | struct ParallelLookup *tmp; | ||
279 | if (NULL != cth->lookup_request) | ||
280 | GNUNET_GNS_lookup_cancel (cth->lookup_request); | ||
281 | for (lu = cth->parallel_lookups_head; | ||
282 | NULL != lu;) { | ||
283 | GNUNET_GNS_lookup_cancel (lu->lookup_request); | ||
284 | GNUNET_free (lu->label); | ||
285 | tmp = lu->next; | ||
286 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | ||
287 | cth->parallel_lookups_tail, | ||
288 | lu); | ||
289 | GNUNET_free (lu); | ||
290 | lu = tmp; | ||
291 | } | ||
292 | |||
293 | if (NULL != cth->attrs) | ||
294 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (cth->attrs); | ||
295 | GNUNET_free (cth); | ||
296 | } | ||
297 | |||
298 | |||
299 | static void | ||
300 | process_parallel_lookup_result (void *cls, | ||
301 | uint32_t rd_count, | ||
302 | const struct GNUNET_GNSRECORD_Data *rd) | ||
303 | { | ||
304 | struct ParallelLookup *parallel_lookup = cls; | ||
305 | struct RECLAIM_TICKETS_ConsumeHandle *cth = parallel_lookup->handle; | ||
306 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le; | ||
307 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
308 | "Parallel lookup finished (count=%u)\n", rd_count); | ||
309 | |||
310 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | ||
311 | cth->parallel_lookups_tail, | ||
312 | parallel_lookup); | ||
313 | GNUNET_free (parallel_lookup->label); | ||
314 | |||
315 | GNUNET_STATISTICS_update (stats, | ||
316 | "attribute_lookup_time_total", | ||
317 | GNUNET_TIME_absolute_get_duration (parallel_lookup->lookup_start_time).rel_value_us, | ||
318 | GNUNET_YES); | ||
319 | GNUNET_STATISTICS_update (stats, | ||
320 | "attribute_lookups_count", | ||
321 | 1, | ||
322 | GNUNET_YES); | ||
323 | |||
324 | |||
325 | GNUNET_free (parallel_lookup); | ||
326 | if (1 != rd_count) | ||
327 | GNUNET_break(0);//TODO | ||
328 | if (rd->record_type == GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR) | ||
329 | { | ||
330 | attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | ||
331 | attr_le->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, | ||
332 | rd->data_size); | ||
333 | GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head, | ||
334 | cth->attrs->list_tail, | ||
335 | attr_le); | ||
336 | } | ||
337 | if (NULL != cth->parallel_lookups_head) | ||
338 | return; //Wait for more | ||
339 | /* Else we are done */ | ||
340 | |||
341 | GNUNET_SCHEDULER_cancel (cth->kill_task); | ||
342 | cth->cb (cth->cb_cls, | ||
343 | &cth->ticket.identity, | ||
344 | cth->attrs, | ||
345 | GNUNET_OK, | ||
346 | NULL); | ||
347 | cleanup_cth (cth); | ||
348 | } | ||
349 | |||
350 | |||
351 | static void | ||
352 | abort_parallel_lookups (void *cls) | ||
353 | { | ||
354 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; | ||
355 | struct ParallelLookup *lu; | ||
356 | struct ParallelLookup *tmp; | ||
357 | |||
358 | cth->kill_task = NULL; | ||
359 | for (lu = cth->parallel_lookups_head; | ||
360 | NULL != lu;) { | ||
361 | GNUNET_GNS_lookup_cancel (lu->lookup_request); | ||
362 | GNUNET_free (lu->label); | ||
363 | tmp = lu->next; | ||
364 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | ||
365 | cth->parallel_lookups_tail, | ||
366 | lu); | ||
367 | GNUNET_free (lu); | ||
368 | lu = tmp; | ||
369 | } | ||
370 | cth->cb (cth->cb_cls, | ||
371 | NULL, | ||
372 | NULL, | ||
373 | GNUNET_SYSERR, | ||
374 | "Aborted"); | ||
375 | |||
376 | } | ||
377 | |||
378 | |||
379 | |||
380 | static void | ||
381 | lookup_authz_cb (void *cls, | ||
382 | uint32_t rd_count, | ||
383 | const struct GNUNET_GNSRECORD_Data *rd) | ||
384 | { | ||
385 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; | ||
386 | struct GNUNET_HashCode new_key_hash; | ||
387 | struct GNUNET_CRYPTO_SymmetricSessionKey enc_key; | ||
388 | struct GNUNET_CRYPTO_SymmetricInitializationVector enc_iv; | ||
389 | struct GNUNET_CRYPTO_EcdhePublicKey *ecdh_key; | ||
390 | struct ParallelLookup *parallel_lookup; | ||
391 | size_t size; | ||
392 | char *buf; | ||
393 | char *attr_lbl; | ||
394 | char *lbls; | ||
395 | |||
396 | cth->lookup_request = NULL; | ||
397 | if (1 != rd_count) | ||
398 | { | ||
399 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
400 | "Number of keys %d != 1.", | ||
401 | rd_count); | ||
402 | cth->cb (cth->cb_cls, | ||
403 | NULL, | ||
404 | NULL, | ||
405 | GNUNET_SYSERR, | ||
406 | "Number of keys %d != 1."); | ||
407 | cleanup_cth (cth); | ||
408 | return; | ||
409 | } | ||
410 | |||
411 | //Decrypt | ||
412 | ecdh_key = (struct GNUNET_CRYPTO_EcdhePublicKey *)rd->data; | ||
413 | |||
414 | buf = GNUNET_malloc (rd->data_size | ||
415 | - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | ||
416 | |||
417 | //Calculate symmetric key from ecdh parameters | ||
418 | GNUNET_assert (GNUNET_OK == | ||
419 | GNUNET_CRYPTO_ecdsa_ecdh (&cth->identity, | ||
420 | ecdh_key, | ||
421 | &new_key_hash)); | ||
422 | create_sym_key_from_ecdh (&new_key_hash, | ||
423 | &enc_key, | ||
424 | &enc_iv); | ||
425 | size = GNUNET_CRYPTO_symmetric_decrypt (rd->data | ||
426 | + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), | ||
427 | rd->data_size | ||
428 | - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), | ||
429 | &enc_key, | ||
430 | &enc_iv, | ||
431 | buf); | ||
432 | |||
433 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
434 | "Decrypted bytes: %zd Expected bytes: %zd\n", | ||
435 | size, | ||
436 | rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | ||
437 | GNUNET_STATISTICS_update (stats, | ||
438 | "reclaim_authz_lookup_time_total", | ||
439 | GNUNET_TIME_absolute_get_duration (cth->lookup_start_time).rel_value_us, | ||
440 | GNUNET_YES); | ||
441 | GNUNET_STATISTICS_update (stats, | ||
442 | "reclaim_authz_lookups_count", | ||
443 | 1, | ||
444 | GNUNET_YES); | ||
445 | lbls = GNUNET_strdup (buf); | ||
446 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
447 | "Attributes found %s\n", lbls); | ||
448 | |||
449 | for (attr_lbl = strtok (lbls, ","); | ||
450 | NULL != attr_lbl; | ||
451 | attr_lbl = strtok (NULL, ",")) | ||
452 | { | ||
453 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
454 | "Looking up %s\n", attr_lbl); | ||
455 | parallel_lookup = GNUNET_new (struct ParallelLookup); | ||
456 | parallel_lookup->handle = cth; | ||
457 | parallel_lookup->label = GNUNET_strdup (attr_lbl); | ||
458 | parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get(); | ||
459 | parallel_lookup->lookup_request | ||
460 | = GNUNET_GNS_lookup (gns, | ||
461 | attr_lbl, | ||
462 | &cth->ticket.identity, | ||
463 | GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, | ||
464 | GNUNET_GNS_LO_DEFAULT, | ||
465 | &process_parallel_lookup_result, | ||
466 | parallel_lookup); | ||
467 | GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, | ||
468 | cth->parallel_lookups_tail, | ||
469 | parallel_lookup); | ||
470 | } | ||
471 | GNUNET_free (lbls); | ||
472 | GNUNET_free (buf); | ||
473 | cth->kill_task = GNUNET_SCHEDULER_add_delayed ( | ||
474 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES,3), | ||
475 | &abort_parallel_lookups, | ||
476 | cth); | ||
477 | } | ||
478 | |||
479 | |||
480 | |||
481 | struct RECLAIM_TICKETS_ConsumeHandle* | ||
482 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | ||
483 | const struct GNUNET_RECLAIM_Ticket *ticket, | ||
484 | RECLAIM_TICKETS_ConsumeCallback cb, | ||
485 | void* cb_cls) | ||
486 | { | ||
487 | struct RECLAIM_TICKETS_ConsumeHandle *cth; | ||
488 | char *label; | ||
489 | cth = GNUNET_new (struct RECLAIM_TICKETS_ConsumeHandle); | ||
490 | |||
491 | cth->identity = *id; | ||
492 | GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, | ||
493 | &cth->identity_pub); | ||
494 | cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | ||
495 | cth->ticket = *ticket; | ||
496 | cth->cb = cb; | ||
497 | cth->cb_cls = cb_cls; | ||
498 | label = GNUNET_STRINGS_data_to_string_alloc (&cth->ticket.rnd, | ||
499 | sizeof (uint64_t)); | ||
500 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
501 | "Looking for AuthZ info under %s\n", label); | ||
502 | cth->lookup_start_time = GNUNET_TIME_absolute_get (); | ||
503 | cth->lookup_request = GNUNET_GNS_lookup (gns, | ||
504 | label, | ||
505 | &cth->ticket.identity, | ||
506 | GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ, | ||
507 | GNUNET_GNS_LO_DEFAULT, | ||
508 | &lookup_authz_cb, | ||
509 | cth); | ||
510 | GNUNET_free (label); | ||
511 | return cth; | ||
512 | } | ||
513 | |||
514 | void | ||
515 | RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth) | ||
516 | { | ||
517 | cleanup_cth (cth); | ||
518 | return; | ||
519 | } | ||
520 | |||
521 | |||
522 | /******************************* | ||
523 | * Ticket issue | ||
524 | *******************************/ | ||
525 | |||
151 | /** | 526 | /** |
152 | * Cleanup ticket consume handle | 527 | * Cleanup ticket consume handle |
153 | * @param handle the handle to clean up | 528 | * @param handle the handle to clean up |
@@ -325,29 +700,6 @@ store_ticket_issue_cont (void *cls, | |||
325 | handle); | 700 | handle); |
326 | } | 701 | } |
327 | 702 | ||
328 | static int | ||
329 | create_sym_key_from_ecdh (const struct GNUNET_HashCode *new_key_hash, | ||
330 | struct GNUNET_CRYPTO_SymmetricSessionKey *skey, | ||
331 | struct GNUNET_CRYPTO_SymmetricInitializationVector *iv) | ||
332 | { | ||
333 | struct GNUNET_CRYPTO_HashAsciiEncoded new_key_hash_str; | ||
334 | |||
335 | GNUNET_CRYPTO_hash_to_enc (new_key_hash, | ||
336 | &new_key_hash_str); | ||
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating symmetric rsa key from %s\n", (char*)&new_key_hash_str); | ||
338 | static const char ctx_key[] = "gnuid-aes-ctx-key"; | ||
339 | GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), | ||
340 | new_key_hash, sizeof (struct GNUNET_HashCode), | ||
341 | ctx_key, strlen (ctx_key), | ||
342 | NULL, 0); | ||
343 | static const char ctx_iv[] = "gnuid-aes-ctx-iv"; | ||
344 | GNUNET_CRYPTO_kdf (iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector), | ||
345 | new_key_hash, sizeof (struct GNUNET_HashCode), | ||
346 | ctx_iv, strlen (ctx_iv), | ||
347 | NULL, 0); | ||
348 | return GNUNET_OK; | ||
349 | } | ||
350 | |||
351 | 703 | ||
352 | static int | 704 | static int |
353 | serialize_authz_record (const struct GNUNET_RECLAIM_Ticket *ticket, | 705 | serialize_authz_record (const struct GNUNET_RECLAIM_Ticket *ticket, |
@@ -459,11 +811,11 @@ issue_ticket (struct TicketIssueHandle *ih) | |||
459 | 811 | ||
460 | 812 | ||
461 | void | 813 | void |
462 | RECLAIM_TICKETS_issue_ticket (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 814 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
463 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 815 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
464 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | 816 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, |
465 | RECLAIM_TICKETS_TicketResult cb, | 817 | RECLAIM_TICKETS_TicketResult cb, |
466 | void* cb_cls) | 818 | void* cb_cls) |
467 | { | 819 | { |
468 | struct TicketIssueHandle *tih; | 820 | struct TicketIssueHandle *tih; |
469 | tih = GNUNET_new (struct TicketIssueHandle); | 821 | tih = GNUNET_new (struct TicketIssueHandle); |
@@ -480,6 +832,9 @@ RECLAIM_TICKETS_issue_ticket (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identi | |||
480 | issue_ticket (tih); | 832 | issue_ticket (tih); |
481 | } | 833 | } |
482 | 834 | ||
835 | /************************************ | ||
836 | * Ticket iteration | ||
837 | ************************************/ | ||
483 | 838 | ||
484 | static void | 839 | static void |
485 | cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) | 840 | cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) |
@@ -536,10 +891,10 @@ run_ticket_iteration_round (struct RECLAIM_TICKETS_Iterator *iter) | |||
536 | 891 | ||
537 | static void | 892 | static void |
538 | collect_tickets_cb (void *cls, | 893 | collect_tickets_cb (void *cls, |
539 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 894 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
540 | const char *label, | 895 | const char *label, |
541 | unsigned int rd_count, | 896 | unsigned int rd_count, |
542 | const struct GNUNET_GNSRECORD_Data *rd) | 897 | const struct GNUNET_GNSRECORD_Data *rd) |
543 | { | 898 | { |
544 | struct RECLAIM_TICKETS_Iterator *iter = cls; | 899 | struct RECLAIM_TICKETS_Iterator *iter = cls; |
545 | struct TicketReference *tr; | 900 | struct TicketReference *tr; |
@@ -628,10 +983,18 @@ RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
628 | nsh = GNUNET_NAMESTORE_connect (c); | 983 | nsh = GNUNET_NAMESTORE_connect (c); |
629 | if (NULL == nsh) | 984 | if (NULL == nsh) |
630 | { | 985 | { |
631 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 986 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
632 | "Error connecting to namestore\n"); | 987 | "error connecting to namestore"); |
633 | return GNUNET_SYSERR; | 988 | return GNUNET_SYSERR; |
634 | } | 989 | } |
990 | gns = GNUNET_GNS_connect (c); | ||
991 | if (NULL == gns) | ||
992 | { | ||
993 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
994 | "error connecting to gns"); | ||
995 | return GNUNET_SYSERR; | ||
996 | } | ||
997 | stats = GNUNET_STATISTICS_create ("reclaim", c); | ||
635 | return GNUNET_OK; | 998 | return GNUNET_OK; |
636 | } | 999 | } |
637 | 1000 | ||
@@ -641,4 +1004,12 @@ RECLAIM_TICKETS_deinit (void) | |||
641 | if (NULL != nsh) | 1004 | if (NULL != nsh) |
642 | GNUNET_NAMESTORE_disconnect (nsh); | 1005 | GNUNET_NAMESTORE_disconnect (nsh); |
643 | nsh = NULL; | 1006 | nsh = NULL; |
1007 | if (NULL != gns) | ||
1008 | GNUNET_GNS_disconnect (gns); | ||
1009 | gns = NULL; | ||
1010 | if (NULL != stats) | ||
1011 | { | ||
1012 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
1013 | stats = NULL; | ||
1014 | } | ||
644 | } | 1015 | } |
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.h b/src/reclaim/gnunet-service-reclaim_tickets.h index 81455fe53..43bb902fd 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.h +++ b/src/reclaim/gnunet-service-reclaim_tickets.h | |||
@@ -17,6 +17,17 @@ | |||
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | |||
21 | /** | ||
22 | * @author Martin Schanzenbach | ||
23 | * @file src/reclaim/gnunet-service-reclaim_tickets.h | ||
24 | * @brief reclaim tickets | ||
25 | * | ||
26 | */ | ||
27 | |||
28 | #ifndef GNUNET_SERVICE_RECLAIM_TICKETS_H | ||
29 | #define GNUNET_SERVICE_RECLAIM_TICKETS_H | ||
30 | |||
20 | #include "platform.h" | 31 | #include "platform.h" |
21 | #include "gnunet_util_lib.h" | 32 | #include "gnunet_util_lib.h" |
22 | #include "gnunet_constants.h" | 33 | #include "gnunet_constants.h" |
@@ -31,6 +42,7 @@ | |||
31 | #include "reclaim.h" | 42 | #include "reclaim.h" |
32 | 43 | ||
33 | struct RECLAIM_TICKETS_Iterator; | 44 | struct RECLAIM_TICKETS_Iterator; |
45 | struct RECLAIM_TICKETS_ConsumeHandle; | ||
34 | 46 | ||
35 | /** | 47 | /** |
36 | * Continuation called with ticket. | 48 | * Continuation called with ticket. |
@@ -59,14 +71,24 @@ typedef void | |||
59 | const char *emsg); | 71 | const char *emsg); |
60 | 72 | ||
61 | 73 | ||
62 | /** | 74 | typedef void |
63 | * @author Martin Schanzenbach | 75 | (*RECLAIM_TICKETS_ConsumeCallback) (void *cls, |
64 | * @file src/reclaim/gnunet-service-reclaim_tickets.h | 76 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
65 | * @brief reclaim tickets | 77 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *l, |
66 | * | 78 | uint32_t success, |
67 | */ | 79 | const char *emsg); |
80 | |||
81 | struct RECLAIM_TICKETS_ConsumeHandle* | ||
82 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | ||
83 | const struct GNUNET_RECLAIM_Ticket *ticket, | ||
84 | RECLAIM_TICKETS_ConsumeCallback cb, | ||
85 | void* cb_cls); | ||
86 | |||
68 | void | 87 | void |
69 | RECLAIM_TICKETS_issue_ticket (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 88 | RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth); |
89 | |||
90 | void | ||
91 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | ||
70 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 92 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
71 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | 93 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, |
72 | RECLAIM_TICKETS_TicketResult cb, | 94 | RECLAIM_TICKETS_TicketResult cb, |
@@ -91,4 +113,4 @@ RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c); | |||
91 | 113 | ||
92 | void | 114 | void |
93 | RECLAIM_TICKETS_deinit (void); | 115 | RECLAIM_TICKETS_deinit (void); |
94 | 116 | #endif | |
diff --git a/src/reclaim/reclaim.h b/src/reclaim/reclaim.h index cff12c6e4..c29902ab1 100644 --- a/src/reclaim/reclaim.h +++ b/src/reclaim/reclaim.h | |||
@@ -382,6 +382,11 @@ struct ConsumeTicketResultMessage | |||
382 | uint32_t id GNUNET_PACKED; | 382 | uint32_t id GNUNET_PACKED; |
383 | 383 | ||
384 | /** | 384 | /** |
385 | * Result | ||
386 | */ | ||
387 | uint32_t result GNUNET_PACKED; | ||
388 | |||
389 | /** | ||
385 | * Length of serialized attribute data | 390 | * Length of serialized attribute data |
386 | */ | 391 | */ |
387 | uint16_t attrs_len GNUNET_PACKED; | 392 | uint16_t attrs_len GNUNET_PACKED; |