Listing Attestations through service
authorMarkus Voggenreiter <Markus.Voggenreiter@tum.de>
Sat, 19 Oct 2019 09:30:24 +0000 (11:30 +0200)
committerSchanzenbach, Martin <mschanzenbach@posteo.de>
Mon, 13 Jan 2020 12:31:02 +0000 (13:31 +0100)
src/include/gnunet_protocols.h
src/include/gnunet_reclaim_attribute_lib.h
src/reclaim-attribute/reclaim_attribute.c
src/reclaim/gnunet-service-reclaim.c
src/reclaim/plugin_rest_reclaim.c
src/reclaim/reclaim_api.c

index 45b3c6728d187af2e5416f535ee1992cff135ace..f1dc74462653ed7475d80a6e253407b89ad74a38 100644 (file)
@@ -2718,6 +2718,8 @@ extern "C" {
 
 #define GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_DELETE 978
 
+#define GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT 979
+
 /**************************************************
  *
  * ABD MESSAGE TYPES
index c23b393830ee8af6e75bdda2282e2bc8d233c554..34429da51045bf9b73146bf3ab3257a5eaeba59c 100644 (file)
@@ -53,12 +53,12 @@ extern "C" {
 /**
 * No value attestation.
 */
-#define GNUNET_RECLAIM_ATTESTATION_TYPE_NONE 0
+#define GNUNET_RECLAIM_ATTESTATION_TYPE_NONE 10
 
 /**
 * A JSON Web Token attestation.
 */
-#define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT 1
+#define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT 11
 
 /**
  * An attribute.
index 6dd1632fdf4388502689655945b9ec52d35023d2..9ac75dfba6160388c7425a09bbccadb4830f90dc 100644 (file)
@@ -229,7 +229,6 @@ GNUNET_RECLAIM_ATTESTATION_typename_to_number (const char *typename)
   unsigned int i;
   struct Plugin *plugin;
   uint32_t ret;
-
   init ();
   for (i = 0; i < num_plugins; i++)
   {
@@ -699,8 +698,8 @@ GNUNET_RECLAIM_ATTESTATION_serialize (
 
   attr_ser = (struct Attestation *) result;
   attr_ser->attestation_type = htons (attr->type);
-  attr_ser->attestation_type = htonl (attr->version);
-  attr_ser->attestation_type = GNUNET_htonll (attr->id);
+  attr_ser->attestation_version = htonl (attr->version);
+  attr_ser->attestation_id = GNUNET_htonll (attr->id);
   name_len = strlen (attr->name);
   attr_ser->name_len = htons (name_len);
   write_ptr = (char *) &attr_ser[1];
index 7929d36d96406fe82c3042bc8c44a05d6af15260..45b2a57c5e65a487eff3bec6ae2db9688ea599da 100644 (file)
@@ -1616,7 +1616,7 @@ attr_iter_error (void *cls)
 
 
 /**
- * Got record. Return if it is an attribute.
+ * Got record. Return if it is an attribute or attestation.
  *
  * @param cls our attribute iterator
  * @param zone zone we are iterating
@@ -1642,22 +1642,43 @@ attr_iter_cb (void *cls,
     return;
   }
 
-  if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd->record_type)
+  if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd->record_type) &&
+      (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd->record_type) )
   {
     GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1);
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", label);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n");
-  env = GNUNET_MQ_msg_extra (arm,
-                             rd->data_size,
-                             GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT);
-  arm->id = htonl (ai->request_id);
-  arm->attr_len = htons (rd->data_size);
-  GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity);
-  data_tmp = (char *) &arm[1];
-  GNUNET_memcpy (data_tmp, rd->data, rd->data_size);
-  GNUNET_MQ_send (ai->client->mq, env);
+
+  if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd->record_type )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attestation under: %s\n",
+                label);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Sending ATTESTATION_RESULT message\n");
+    env = GNUNET_MQ_msg_extra (arm,
+                               rd->data_size,
+                               GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT);
+    arm->id = htonl (ai->request_id);
+    arm->attr_len = htons (rd->data_size);
+    GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity);
+    data_tmp = (char *) &arm[1];
+    GNUNET_memcpy (data_tmp, rd->data, rd->data_size);
+    GNUNET_MQ_send (ai->client->mq, env);
+  }
+  else
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", label);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n");
+    env = GNUNET_MQ_msg_extra (arm,
+                               rd->data_size,
+                               GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT);
+    arm->id = htonl (ai->request_id);
+    arm->attr_len = htons (rd->data_size);
+    GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity);
+    data_tmp = (char *) &arm[1];
+    GNUNET_memcpy (data_tmp, rd->data, rd->data_size);
+    GNUNET_MQ_send (ai->client->mq, env);
+  }
 }
 
 
index 5e586152cc35fdced49933253cb15f08b17d7577..5908a38dd9d02c8e2a56eb0e2d73f982a3435721 100644 (file)
@@ -535,15 +535,110 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
                                                      handle);
   GNUNET_JSON_parse_free (attrspec);
 }
-/*Placeholder*/
+
+
+/**
+ * Collect all attestations for an ego
+ *
+ */
+static void
+attest_collect (void *cls,
+                const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
+                const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
+                const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest)
+{
+  struct RequestHandle *handle = cls;
+  json_t *attr_obj;
+  const char *type;
+  char *tmp_value;
+  char *id_str;
+
+  if (NULL == attest)
+  {
+    GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
+    return;
+  }
+
+  if ((NULL == attest->name) || (NULL == attest->data))
+  {
+    GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
+    return;
+  }
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attestation: %s\n",
+              attest->name);
+
+  tmp_value = GNUNET_RECLAIM_ATTESTATION_value_to_string (attest->type,
+                                                          attest->data,
+                                                          attest->data_size);
+  attr_obj = json_object ();
+  json_object_set_new (attr_obj, "value", json_string (tmp_value));
+  json_object_set_new (attr_obj, "name", json_string (attest->name));
+  type = GNUNET_RECLAIM_ATTESTATION_number_to_typename (attest->type);
+  json_object_set_new (attr_obj, "type", json_string (type));
+  id_str = GNUNET_STRINGS_data_to_string_alloc (&attest->id, sizeof(uint64_t));
+  json_object_set_new (attr_obj, "id", json_string (id_str));
+  json_array_append (handle->resp_object, attr_obj);
+  json_decref (attr_obj);
+  GNUNET_free (tmp_value);
+  GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
+}
+
+
+/**
+ * Lists attestation for identity request
+ *
+ * @param con_handle the connection handle
+ * @param url the url
+ * @param cls the RequestHandle
+ */
 static void
 list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
                        const char *url,
                        void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Listing Attestations not supported\n");
-  GNUNET_SCHEDULER_add_now (&do_error, cls);
-  return;
+  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
+  struct RequestHandle *handle = cls;
+  struct EgoEntry *ego_entry;
+  char *identity;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Getting attestations for %s.\n",
+              handle->url);
+  if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) >= strlen (
+        handle->url))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  identity = handle->url + strlen (
+    GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + 1;
+
+  for (ego_entry = handle->ego_head; NULL != ego_entry;
+       ego_entry = ego_entry->next)
+    if (0 == strcmp (identity, ego_entry->identifier))
+      break;
+  handle->resp_object = json_array ();
+
+
+  if (NULL == ego_entry)
+  {
+    // Done
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
+    GNUNET_SCHEDULER_add_now (&return_response, handle);
+    return;
+  }
+  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
+  handle->idp = GNUNET_RECLAIM_connect (cfg);
+  handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp,
+                                                         priv_key,
+                                                         &collect_error_cb,
+                                                         handle,
+                                                         &attest_collect,
+                                                         handle,
+                                                         &collect_finished_cb,
+                                                         handle);
 }
 
 /**
@@ -764,6 +859,12 @@ attr_collect (void *cls,
   char *tmp_value;
   char *id_str;
 
+  if (NULL == attr)
+  {
+    GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
+    return;
+  }
+
   if ((NULL == attr->name) || (NULL == attr->data))
   {
     GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
@@ -988,7 +1089,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
 static void
 consume_cont (void *cls,
               const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
-              const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, 
+              const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
               const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest)
 {
   struct RequestHandle *handle = cls;
index a66bb69f2fea87d0bba318a4277b6e0bbb01e8da..860a0f0ab6d198f31d0270fe82905cbce08d8a79 100644 (file)
@@ -623,6 +623,104 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
   GNUNET_assert (0);
 }
 
+/**
+   * Handle an incoming message of type
+   * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT
+   *
+   * @param cls
+   * @param msg the message we received
+   * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+   */
+static int
+check_attestation_result (void *cls, const struct AttributeResultMessage *msg)
+{
+  size_t msg_len;
+  size_t attr_len;
+
+  msg_len = ntohs (msg->header.size);
+  attr_len = ntohs (msg->attr_len);
+  if (msg_len != sizeof(struct AttributeResultMessage) + attr_len)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_OK;
+}
+
+
+/**
+ * Handle an incoming message of type
+ * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT
+ *
+ * @param cls
+ * @param msg the message we received
+ */
+static void
+handle_attestation_result (void *cls, const struct AttributeResultMessage *msg)
+{
+  static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
+  struct GNUNET_RECLAIM_Handle *h = cls;
+  struct GNUNET_RECLAIM_AttributeIterator *it;
+  struct GNUNET_RECLAIM_Operation *op;
+  size_t attr_len;
+  uint32_t r_id = ntohl (msg->id);
+
+  attr_len = ntohs (msg->attr_len);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attestation result.\n");
+
+
+  for (it = h->it_head; NULL != it; it = it->next)
+    if (it->r_id == r_id)
+      break;
+  for (op = h->op_head; NULL != op; op = op->next)
+    if (op->r_id == r_id)
+      break;
+  if ((NULL == it) && (NULL == op))
+    return;
+
+  if ((0 ==
+       (memcmp (&msg->identity, &identity_dummy, sizeof(identity_dummy)))))
+  {
+    if ((NULL == it) && (NULL == op))
+    {
+      GNUNET_break (0);
+      force_reconnect (h);
+      return;
+    }
+    if (NULL != it)
+    {
+      if (NULL != it->finish_cb)
+        it->finish_cb (it->finish_cb_cls);
+      free_it (it);
+    }
+    if (NULL != op)
+    {
+      if (NULL != op->ar_cb)
+        op->ar_cb (op->cls, NULL, NULL, NULL);
+      GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
+      free_op (op);
+    }
+    return;
+  }
+
+  {
+    struct GNUNET_RECLAIM_ATTESTATION_Claim *attr;
+    attr = GNUNET_RECLAIM_ATTESTATION_deserialize ((char *) &msg[1], attr_len);
+    if (NULL != it)
+    {
+      if (NULL != it->proc)
+        it->proc (it->proc_cls, &msg->identity, NULL, attr);
+    }
+    else if (NULL != op)
+    {
+      if (NULL != op->ar_cb)
+        op->ar_cb (op->cls, &msg->identity, NULL, attr);
+    }
+    GNUNET_free (attr);
+    return;
+  }
+  GNUNET_assert (0);
+}
 
 /**
  * Handle an incoming message of type
@@ -742,6 +840,10 @@ reconnect (struct GNUNET_RECLAIM_Handle *h)
                            GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT,
                            struct AttributeResultMessage,
                            h),
+    GNUNET_MQ_hd_var_size (attestation_result,
+                           GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT,
+                           struct AttributeResultMessage,
+                           h),
     GNUNET_MQ_hd_fixed_size (ticket_result,
                              GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT,
                              struct TicketResultMessage,