aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim
diff options
context:
space:
mode:
authorMarkus Voggenreiter <Markus.Voggenreiter@tum.de>2019-10-19 11:30:24 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-01-13 13:31:02 +0100
commit4eda8d33675ba1e004792635b33342c04c5cbe32 (patch)
tree93eab84b3b93dace71ec4f31988991abcd692a2d /src/reclaim
parent483bc7e3095dff908fe8c032ea96995d44304868 (diff)
downloadgnunet-4eda8d33675ba1e004792635b33342c04c5cbe32.tar.gz
gnunet-4eda8d33675ba1e004792635b33342c04c5cbe32.zip
Listing Attestations through service
Diffstat (limited to 'src/reclaim')
-rw-r--r--src/reclaim/gnunet-service-reclaim.c47
-rw-r--r--src/reclaim/plugin_rest_reclaim.c111
-rw-r--r--src/reclaim/reclaim_api.c102
3 files changed, 242 insertions, 18 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index 7929d36d9..45b2a57c5 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -1616,7 +1616,7 @@ attr_iter_error (void *cls)
1616 1616
1617 1617
1618/** 1618/**
1619 * Got record. Return if it is an attribute. 1619 * Got record. Return if it is an attribute or attestation.
1620 * 1620 *
1621 * @param cls our attribute iterator 1621 * @param cls our attribute iterator
1622 * @param zone zone we are iterating 1622 * @param zone zone we are iterating
@@ -1642,22 +1642,43 @@ attr_iter_cb (void *cls,
1642 return; 1642 return;
1643 } 1643 }
1644 1644
1645 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd->record_type) 1645 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd->record_type) &&
1646 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd->record_type) )
1646 { 1647 {
1647 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); 1648 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1);
1648 return; 1649 return;
1649 } 1650 }
1650 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", label); 1651
1651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n"); 1652 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd->record_type )
1652 env = GNUNET_MQ_msg_extra (arm, 1653 {
1653 rd->data_size, 1654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attestation under: %s\n",
1654 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); 1655 label);
1655 arm->id = htonl (ai->request_id); 1656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1656 arm->attr_len = htons (rd->data_size); 1657 "Sending ATTESTATION_RESULT message\n");
1657 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); 1658 env = GNUNET_MQ_msg_extra (arm,
1658 data_tmp = (char *) &arm[1]; 1659 rd->data_size,
1659 GNUNET_memcpy (data_tmp, rd->data, rd->data_size); 1660 GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT);
1660 GNUNET_MQ_send (ai->client->mq, env); 1661 arm->id = htonl (ai->request_id);
1662 arm->attr_len = htons (rd->data_size);
1663 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity);
1664 data_tmp = (char *) &arm[1];
1665 GNUNET_memcpy (data_tmp, rd->data, rd->data_size);
1666 GNUNET_MQ_send (ai->client->mq, env);
1667 }
1668 else
1669 {
1670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", label);
1671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n");
1672 env = GNUNET_MQ_msg_extra (arm,
1673 rd->data_size,
1674 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT);
1675 arm->id = htonl (ai->request_id);
1676 arm->attr_len = htons (rd->data_size);
1677 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity);
1678 data_tmp = (char *) &arm[1];
1679 GNUNET_memcpy (data_tmp, rd->data, rd->data_size);
1680 GNUNET_MQ_send (ai->client->mq, env);
1681 }
1661} 1682}
1662 1683
1663 1684
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index 5e586152c..5908a38dd 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -535,15 +535,110 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
535 handle); 535 handle);
536 GNUNET_JSON_parse_free (attrspec); 536 GNUNET_JSON_parse_free (attrspec);
537} 537}
538/*Placeholder*/ 538
539
540/**
541 * Collect all attestations for an ego
542 *
543 */
544static void
545attest_collect (void *cls,
546 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
547 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
548 const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest)
549{
550 struct RequestHandle *handle = cls;
551 json_t *attr_obj;
552 const char *type;
553 char *tmp_value;
554 char *id_str;
555
556 if (NULL == attest)
557 {
558 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
559 return;
560 }
561
562 if ((NULL == attest->name) || (NULL == attest->data))
563 {
564 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
565 return;
566 }
567
568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attestation: %s\n",
569 attest->name);
570
571 tmp_value = GNUNET_RECLAIM_ATTESTATION_value_to_string (attest->type,
572 attest->data,
573 attest->data_size);
574 attr_obj = json_object ();
575 json_object_set_new (attr_obj, "value", json_string (tmp_value));
576 json_object_set_new (attr_obj, "name", json_string (attest->name));
577 type = GNUNET_RECLAIM_ATTESTATION_number_to_typename (attest->type);
578 json_object_set_new (attr_obj, "type", json_string (type));
579 id_str = GNUNET_STRINGS_data_to_string_alloc (&attest->id, sizeof(uint64_t));
580 json_object_set_new (attr_obj, "id", json_string (id_str));
581 json_array_append (handle->resp_object, attr_obj);
582 json_decref (attr_obj);
583 GNUNET_free (tmp_value);
584 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
585}
586
587
588/**
589 * Lists attestation for identity request
590 *
591 * @param con_handle the connection handle
592 * @param url the url
593 * @param cls the RequestHandle
594 */
539static void 595static void
540list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, 596list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
541 const char *url, 597 const char *url,
542 void *cls) 598 void *cls)
543{ 599{
544 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Listing Attestations not supported\n"); 600 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
545 GNUNET_SCHEDULER_add_now (&do_error, cls); 601 struct RequestHandle *handle = cls;
546 return; 602 struct EgoEntry *ego_entry;
603 char *identity;
604
605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
606 "Getting attestations for %s.\n",
607 handle->url);
608 if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) >= strlen (
609 handle->url))
610 {
611 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
612 GNUNET_SCHEDULER_add_now (&do_error, handle);
613 return;
614 }
615 identity = handle->url + strlen (
616 GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + 1;
617
618 for (ego_entry = handle->ego_head; NULL != ego_entry;
619 ego_entry = ego_entry->next)
620 if (0 == strcmp (identity, ego_entry->identifier))
621 break;
622 handle->resp_object = json_array ();
623
624
625 if (NULL == ego_entry)
626 {
627 // Done
628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
629 GNUNET_SCHEDULER_add_now (&return_response, handle);
630 return;
631 }
632 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
633 handle->idp = GNUNET_RECLAIM_connect (cfg);
634 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp,
635 priv_key,
636 &collect_error_cb,
637 handle,
638 &attest_collect,
639 handle,
640 &collect_finished_cb,
641 handle);
547} 642}
548 643
549/** 644/**
@@ -764,6 +859,12 @@ attr_collect (void *cls,
764 char *tmp_value; 859 char *tmp_value;
765 char *id_str; 860 char *id_str;
766 861
862 if (NULL == attr)
863 {
864 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
865 return;
866 }
867
767 if ((NULL == attr->name) || (NULL == attr->data)) 868 if ((NULL == attr->name) || (NULL == attr->data))
768 { 869 {
769 GNUNET_RECLAIM_get_attributes_next (handle->attr_it); 870 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
@@ -988,7 +1089,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
988static void 1089static void
989consume_cont (void *cls, 1090consume_cont (void *cls,
990 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 1091 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
991 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, 1092 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
992 const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest) 1093 const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest)
993{ 1094{
994 struct RequestHandle *handle = cls; 1095 struct RequestHandle *handle = cls;
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index a66bb69f2..860a0f0ab 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -623,6 +623,104 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
623 GNUNET_assert (0); 623 GNUNET_assert (0);
624} 624}
625 625
626/**
627 * Handle an incoming message of type
628 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT
629 *
630 * @param cls
631 * @param msg the message we received
632 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
633 */
634static int
635check_attestation_result (void *cls, const struct AttributeResultMessage *msg)
636{
637 size_t msg_len;
638 size_t attr_len;
639
640 msg_len = ntohs (msg->header.size);
641 attr_len = ntohs (msg->attr_len);
642 if (msg_len != sizeof(struct AttributeResultMessage) + attr_len)
643 {
644 GNUNET_break (0);
645 return GNUNET_SYSERR;
646 }
647 return GNUNET_OK;
648}
649
650
651/**
652 * Handle an incoming message of type
653 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT
654 *
655 * @param cls
656 * @param msg the message we received
657 */
658static void
659handle_attestation_result (void *cls, const struct AttributeResultMessage *msg)
660{
661 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
662 struct GNUNET_RECLAIM_Handle *h = cls;
663 struct GNUNET_RECLAIM_AttributeIterator *it;
664 struct GNUNET_RECLAIM_Operation *op;
665 size_t attr_len;
666 uint32_t r_id = ntohl (msg->id);
667
668 attr_len = ntohs (msg->attr_len);
669 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attestation result.\n");
670
671
672 for (it = h->it_head; NULL != it; it = it->next)
673 if (it->r_id == r_id)
674 break;
675 for (op = h->op_head; NULL != op; op = op->next)
676 if (op->r_id == r_id)
677 break;
678 if ((NULL == it) && (NULL == op))
679 return;
680
681 if ((0 ==
682 (memcmp (&msg->identity, &identity_dummy, sizeof(identity_dummy)))))
683 {
684 if ((NULL == it) && (NULL == op))
685 {
686 GNUNET_break (0);
687 force_reconnect (h);
688 return;
689 }
690 if (NULL != it)
691 {
692 if (NULL != it->finish_cb)
693 it->finish_cb (it->finish_cb_cls);
694 free_it (it);
695 }
696 if (NULL != op)
697 {
698 if (NULL != op->ar_cb)
699 op->ar_cb (op->cls, NULL, NULL, NULL);
700 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
701 free_op (op);
702 }
703 return;
704 }
705
706 {
707 struct GNUNET_RECLAIM_ATTESTATION_Claim *attr;
708 attr = GNUNET_RECLAIM_ATTESTATION_deserialize ((char *) &msg[1], attr_len);
709 if (NULL != it)
710 {
711 if (NULL != it->proc)
712 it->proc (it->proc_cls, &msg->identity, NULL, attr);
713 }
714 else if (NULL != op)
715 {
716 if (NULL != op->ar_cb)
717 op->ar_cb (op->cls, &msg->identity, NULL, attr);
718 }
719 GNUNET_free (attr);
720 return;
721 }
722 GNUNET_assert (0);
723}
626 724
627/** 725/**
628 * Handle an incoming message of type 726 * Handle an incoming message of type
@@ -742,6 +840,10 @@ reconnect (struct GNUNET_RECLAIM_Handle *h)
742 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT, 840 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT,
743 struct AttributeResultMessage, 841 struct AttributeResultMessage,
744 h), 842 h),
843 GNUNET_MQ_hd_var_size (attestation_result,
844 GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT,
845 struct AttributeResultMessage,
846 h),
745 GNUNET_MQ_hd_fixed_size (ticket_result, 847 GNUNET_MQ_hd_fixed_size (ticket_result,
746 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, 848 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT,
747 struct TicketResultMessage, 849 struct TicketResultMessage,