aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/reclaim_api.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2020-02-04 21:15:59 +0100
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-02-09 20:38:10 +0100
commitad342b7e0870185522c7dcb846e71029fcfda335 (patch)
tree22dfa48bc4334d6b381bdb76458eb4c078ff9ac6 /src/reclaim/reclaim_api.c
parent55f6d26b7424d660c99bc89f3677b20294e87a27 (diff)
downloadgnunet-ad342b7e0870185522c7dcb846e71029fcfda335.tar.gz
gnunet-ad342b7e0870185522c7dcb846e71029fcfda335.zip
add attestation API
Diffstat (limited to 'src/reclaim/reclaim_api.c')
-rw-r--r--src/reclaim/reclaim_api.c139
1 files changed, 125 insertions, 14 deletions
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index 0fcf95ee3..89b9ea0f7 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -72,6 +72,11 @@ struct GNUNET_RECLAIM_Operation
72 GNUNET_RECLAIM_AttributeResult ar_cb; 72 GNUNET_RECLAIM_AttributeResult ar_cb;
73 73
74 /** 74 /**
75 * Attribute result callback
76 */
77 GNUNET_RECLAIM_AttributeTicketResult atr_cb;
78
79 /**
75 * Attestation result callback 80 * Attestation result callback
76 */ 81 */
77 GNUNET_RECLAIM_AttestationResult at_cb; 82 GNUNET_RECLAIM_AttestationResult at_cb;
@@ -607,11 +612,11 @@ handle_consume_ticket_result (void *cls,
607 read_ptr = ((char *) &msg[1]) + attrs_len; 612 read_ptr = ((char *) &msg[1]) + attrs_len;
608 attests = 613 attests =
609 GNUNET_RECLAIM_attestation_list_deserialize (read_ptr, attests_len); 614 GNUNET_RECLAIM_attestation_list_deserialize (read_ptr, attests_len);
610 if (NULL != op->ar_cb) 615 if (NULL != op->atr_cb)
611 { 616 {
612 if (NULL == attrs) 617 if (NULL == attrs)
613 { 618 {
614 op->ar_cb (op->cls, &msg->identity, NULL, NULL); 619 op->atr_cb (op->cls, &msg->identity, NULL, NULL);
615 } 620 }
616 else 621 else
617 { 622 {
@@ -626,7 +631,7 @@ handle_consume_ticket_result (void *cls,
626 GNUNET_RECLAIM_id_is_equal (&le->attribute->id, 631 GNUNET_RECLAIM_id_is_equal (&le->attribute->id,
627 &ale->attestation->id)) 632 &ale->attestation->id))
628 { 633 {
629 op->ar_cb (op->cls, &msg->identity, 634 op->atr_cb (op->cls, &msg->identity,
630 le->attribute, ale->attestation); 635 le->attribute, ale->attestation);
631 break; 636 break;
632 } 637 }
@@ -635,7 +640,7 @@ handle_consume_ticket_result (void *cls,
635 } 640 }
636 else // No attestations 641 else // No attestations
637 { 642 {
638 op->ar_cb (op->cls, &msg->identity, 643 op->atr_cb (op->cls, &msg->identity,
639 le->attribute, NULL); 644 le->attribute, NULL);
640 } 645 }
641 } 646 }
@@ -644,7 +649,7 @@ handle_consume_ticket_result (void *cls,
644 attrs = NULL; 649 attrs = NULL;
645 attests = NULL; 650 attests = NULL;
646 } 651 }
647 op->ar_cb (op->cls, NULL, NULL, NULL); 652 op->atr_cb (op->cls, NULL, NULL, NULL);
648 } 653 }
649 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); 654 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
650 free_op (op); 655 free_op (op);
@@ -730,7 +735,7 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
730 if (NULL != op) 735 if (NULL != op)
731 { 736 {
732 if (NULL != op->ar_cb) 737 if (NULL != op->ar_cb)
733 op->ar_cb (op->cls, NULL, NULL, NULL); 738 op->ar_cb (op->cls, NULL, NULL);
734 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); 739 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
735 free_op (op); 740 free_op (op);
736 } 741 }
@@ -739,20 +744,16 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
739 744
740 { 745 {
741 struct GNUNET_RECLAIM_Attribute *attr; 746 struct GNUNET_RECLAIM_Attribute *attr;
742 struct GNUNET_RECLAIM_Attestation *attest;
743 char *read_ptr;
744 attr = GNUNET_RECLAIM_attribute_deserialize ((char *) &msg[1], attr_len); 747 attr = GNUNET_RECLAIM_attribute_deserialize ((char *) &msg[1], attr_len);
745 read_ptr = ((char *) &msg[1]) + attr_len;
746 attest = GNUNET_RECLAIM_attestation_deserialize (read_ptr, attest_len);
747 if (NULL != it) 748 if (NULL != it)
748 { 749 {
749 if (NULL != it->proc) 750 if (NULL != it->proc)
750 it->proc (it->proc_cls, &msg->identity, attr, attest); 751 it->proc (it->proc_cls, &msg->identity, attr);
751 } 752 }
752 else if (NULL != op) 753 else if (NULL != op)
753 { 754 {
754 if (NULL != op->ar_cb) 755 if (NULL != op->ar_cb)
755 op->ar_cb (op->cls, &msg->identity, attr, attest); 756 op->ar_cb (op->cls, &msg->identity, attr);
756 } 757 }
757 GNUNET_free (attr); 758 GNUNET_free (attr);
758 return; 759 return;
@@ -1370,6 +1371,116 @@ GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it)
1370 1371
1371 1372
1372/** 1373/**
1374 * List all attestations for a local identity.
1375 * This MUST lock the `struct GNUNET_RECLAIM_Handle`
1376 * for any other calls than #GNUNET_RECLAIM_get_attestations_next() and
1377 * #GNUNET_RECLAIM_get_attestations_stop. @a proc will be called once
1378 * immediately, and then again after
1379 * #GNUNET_RECLAIM_get_attestations_next() is invoked.
1380 *
1381 * On error (disconnect), @a error_cb will be invoked.
1382 * On normal completion, @a finish_cb proc will be
1383 * invoked.
1384 *
1385 * @param h Handle to the re:claimID service
1386 * @param identity Identity to iterate over
1387 * @param error_cb Function to call on error (i.e. disconnect),
1388 * the handle is afterwards invalid
1389 * @param error_cb_cls Closure for @a error_cb
1390 * @param proc Function to call on each attestation
1391 * @param proc_cls Closure for @a proc
1392 * @param finish_cb Function to call on completion
1393 * the handle is afterwards invalid
1394 * @param finish_cb_cls Closure for @a finish_cb
1395 * @return an iterator Handle to use for iteration
1396 */
1397struct GNUNET_RECLAIM_AttestationIterator *
1398GNUNET_RECLAIM_get_attestations_start (
1399 struct GNUNET_RECLAIM_Handle *h,
1400 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1401 GNUNET_SCHEDULER_TaskCallback error_cb,
1402 void *error_cb_cls,
1403 GNUNET_RECLAIM_AttestationResult proc,
1404 void *proc_cls,
1405 GNUNET_SCHEDULER_TaskCallback finish_cb,
1406 void *finish_cb_cls)
1407{
1408 struct GNUNET_RECLAIM_AttestationIterator *ait;
1409 struct GNUNET_MQ_Envelope *env;
1410 struct AttestationIterationStartMessage *msg;
1411 uint32_t rid;
1412
1413 rid = h->r_id_gen++;
1414 ait = GNUNET_new (struct GNUNET_RECLAIM_AttestationIterator);
1415 ait->h = h;
1416 ait->error_cb = error_cb;
1417 ait->error_cb_cls = error_cb_cls;
1418 ait->finish_cb = finish_cb;
1419 ait->finish_cb_cls = finish_cb_cls;
1420 ait->proc = proc;
1421 ait->proc_cls = proc_cls;
1422 ait->r_id = rid;
1423 ait->identity = *identity;
1424 GNUNET_CONTAINER_DLL_insert_tail (h->ait_head, h->ait_tail, ait);
1425 env =
1426 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START);
1427 msg->id = htonl (rid);
1428 msg->identity = *identity;
1429 if (NULL == h->mq)
1430 ait->env = env;
1431 else
1432 GNUNET_MQ_send (h->mq, env);
1433 return ait;
1434}
1435
1436
1437/**
1438 * Calls the record processor specified in #GNUNET_RECLAIM_get_attestation_start
1439 * for the next record.
1440 *
1441 * @param it the iterator
1442 */
1443void
1444GNUNET_RECLAIM_get_attestations_next (struct GNUNET_RECLAIM_AttestationIterator *ait)
1445{
1446 struct GNUNET_RECLAIM_Handle *h = ait->h;
1447 struct AttestationIterationNextMessage *msg;
1448 struct GNUNET_MQ_Envelope *env;
1449
1450 env =
1451 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_ITERATION_NEXT);
1452 msg->id = htonl (ait->r_id);
1453 GNUNET_MQ_send (h->mq, env);
1454}
1455
1456
1457/**
1458 * Stops iteration and releases the handle for further calls. Must
1459 * be called on any iteration that has not yet completed prior to calling
1460 * #GNUNET_RECLAIM_disconnect.
1461 *
1462 * @param it the iterator
1463 */
1464void
1465GNUNET_RECLAIM_get_attestations_stop (struct GNUNET_RECLAIM_AttestationIterator *ait)
1466{
1467 struct GNUNET_RECLAIM_Handle *h = ait->h;
1468 struct GNUNET_MQ_Envelope *env;
1469 struct AttestationIterationStopMessage *msg;
1470
1471 if (NULL != h->mq)
1472 {
1473 env =
1474 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_ITERATION_STOP);
1475 msg->id = htonl (ait->r_id);
1476 GNUNET_MQ_send (h->mq, env);
1477 }
1478 free_ait (ait);
1479}
1480
1481
1482
1483/**
1373 * Issues a ticket to another relying party. The identity may use 1484 * Issues a ticket to another relying party. The identity may use
1374 * @GNUNET_RECLAIM_ticket_consume to consume the ticket 1485 * @GNUNET_RECLAIM_ticket_consume to consume the ticket
1375 * and retrieve the attributes specified in the attribute list. 1486 * and retrieve the attributes specified in the attribute list.
@@ -1436,7 +1547,7 @@ GNUNET_RECLAIM_ticket_consume (
1436 struct GNUNET_RECLAIM_Handle *h, 1547 struct GNUNET_RECLAIM_Handle *h,
1437 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, 1548 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1438 const struct GNUNET_RECLAIM_Ticket *ticket, 1549 const struct GNUNET_RECLAIM_Ticket *ticket,
1439 GNUNET_RECLAIM_AttributeResult cb, 1550 GNUNET_RECLAIM_AttributeTicketResult cb,
1440 void *cb_cls) 1551 void *cb_cls)
1441{ 1552{
1442 struct GNUNET_RECLAIM_Operation *op; 1553 struct GNUNET_RECLAIM_Operation *op;
@@ -1444,7 +1555,7 @@ GNUNET_RECLAIM_ticket_consume (
1444 1555
1445 op = GNUNET_new (struct GNUNET_RECLAIM_Operation); 1556 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1446 op->h = h; 1557 op->h = h;
1447 op->ar_cb = cb; 1558 op->atr_cb = cb;
1448 op->cls = cb_cls; 1559 op->cls = cb_cls;
1449 op->r_id = h->r_id_gen++; 1560 op->r_id = h->r_id_gen++;
1450 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); 1561 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);