-fix bugs
authorSchanzenbach, Martin <mschanzenbach@posteo.de>
Thu, 5 Oct 2017 20:44:56 +0000 (22:44 +0200)
committerSchanzenbach, Martin <mschanzenbach@posteo.de>
Thu, 5 Oct 2017 20:44:56 +0000 (22:44 +0200)
src/identity-provider/gnunet-service-identity-provider.c
src/identity-provider/identity-provider.conf
src/identity-provider/identity_provider.h
src/identity-provider/identity_provider_api.c
src/identity-provider/plugin_identity_provider_sqlite.c
src/identity-provider/test_idp_issue.sh
src/include/gnunet_protocols.h

index f77eebd6d0dbe74aa61c1b4c8ea5eb20b57ed236..0b7f3389e4bde75d9a064e2e655db85eb33aa443 100644 (file)
@@ -411,14 +411,30 @@ struct ConsumeTicketHandle
   struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub;
 
   /**
-   * ParallelLookups DLL
+   * Lookup DLL
    */
   struct ParallelLookup2 *parallel_lookups_head;
+
+  /**
+   * Lookup DLL
+   */
   struct ParallelLookup2 *parallel_lookups_tail;
   
+  /**
+   * Kill task
+   */
   struct GNUNET_SCHEDULER_Task *kill_task;
+
+  /**
+   * The ABE key
+   */
   struct GNUNET_CRYPTO_AbeKey *key;
 
+  /**
+   * Attributes
+   */
+  struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs;
+
   /**
    * request id
    */
@@ -2029,11 +2045,13 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count,
               "Parallel lookup finished (count=%u)\n", rd_count);
   struct ParallelLookup2 *parallel_lookup = cls;
   struct ConsumeTicketHandle *handle = parallel_lookup->handle;
-  struct AttributeResultMessage *arm;
+  struct ConsumeTicketResultMessage *crm;
   struct GNUNET_MQ_Envelope *env;
+  struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *attr_le;
   char *data;
   char *data_tmp;
-  size_t msg_extra_len;
+  size_t attr_len;
+  size_t attrs_len;
 
   GNUNET_CONTAINER_DLL_remove (handle->parallel_lookups_head,
                                handle->parallel_lookups_tail,
@@ -2043,31 +2061,32 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count,
     GNUNET_break(0);//TODO
   if (rd->record_type == GNUNET_GNSRECORD_TYPE_ID_ATTR)
   {
-    msg_extra_len = GNUNET_CRYPTO_cpabe_decrypt (rd->data,
-                                                 rd->data_size,
-                                                 handle->key,
-                                                 (void**)&data);
-    env = GNUNET_MQ_msg_extra (arm,
-                               msg_extra_len,
-                               GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT);
-    arm->id = htonl (handle->r_id);
-    arm->attr_len = htons (msg_extra_len);
-    arm->identity = handle->ticket.identity;
-    data_tmp = (char *) &arm[1];
-    GNUNET_memcpy (data_tmp,
-                   data,
-                   msg_extra_len);
-    GNUNET_MQ_send (handle->client->mq, env);
+    attr_len = GNUNET_CRYPTO_cpabe_decrypt (rd->data,
+                                            rd->data_size,
+                                            handle->key,
+                                            (void**)&data);
+    attr_le = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry);
+    attr_le->attribute = attribute_deserialize (data,
+                                                attr_len);
+    GNUNET_CONTAINER_DLL_insert (handle->attrs->list_head,
+                                 handle->attrs->list_tail,
+                                 attr_le);
     GNUNET_free (data);
   }
   if (NULL != handle->parallel_lookups_head)
     return; //Wait for more
   //Else we are done
   GNUNET_SCHEDULER_cancel (handle->kill_task);
-  env = GNUNET_MQ_msg (arm,
-                       GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT);
-  arm->id = htonl (handle->r_id);
-  arm->attr_len = htons (0);
+  attrs_len = attribute_list_serialize_get_size (handle->attrs);
+  env = GNUNET_MQ_msg_extra (crm,
+                             attrs_len,
+                             GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT);
+  crm->id = htonl (handle->r_id);
+  crm->attrs_len = htons (attrs_len);
+  crm->identity = handle->ticket.identity;
+  data_tmp = (char *) &crm[1];
+  attribute_list_serialize (handle->attrs,
+                            data_tmp);
   GNUNET_MQ_send (handle->client->mq, env);
 }
 
@@ -2213,6 +2232,7 @@ handle_consume_ticket_message (void *cls,
   ch->r_id = ntohl (cm->id);
   ch->client = idp;
   ch->identity = cm->identity;
+  ch->attrs = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeList);
   GNUNET_CRYPTO_ecdsa_key_get_public (&ch->identity,
                                       &ch->identity_pub);
   ch->ticket = *((struct GNUNET_IDENTITY_PROVIDER_Ticket2*)&cm[1]);
@@ -2713,7 +2733,7 @@ run_ticket_iteration_round (struct TicketIteration *ti)
  */
 static void
 handle_ticket_iteration_start (void *cls,
-                        const struct TicketIterationStartMessage *tis_msg)
+                               const struct TicketIterationStartMessage *tis_msg)
 {
   struct IdpClient *client = cls;
   struct TicketIteration *ti;
@@ -2743,7 +2763,7 @@ handle_ticket_iteration_start (void *cls,
  */
 static void
 handle_ticket_iteration_stop (void *cls,
-                       const struct TicketIterationStopMessage *tis_msg)
+                              const struct TicketIterationStopMessage *tis_msg)
 {
   struct IdpClient *client = cls;
   struct TicketIteration *ti;
@@ -2778,7 +2798,7 @@ handle_ticket_iteration_stop (void *cls,
  */
 static void
 handle_ticket_iteration_next (void *cls,
-                       const struct TicketIterationNextMessage *tis_msg)
+                              const struct TicketIterationNextMessage *tis_msg)
 {
   struct IdpClient *client = cls;
   struct TicketIteration *ti;
index 826b2419e4596630b275fc741bae054604839fca..7ee5e50d88748a38c6d11dae8401472c7325b601 100644 (file)
@@ -10,6 +10,7 @@ UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-identity-provider.sock
 UNIX_MATCH_UID = NO
 UNIX_MATCH_GID = YES
 TOKEN_EXPIRATION_INTERVAL = 30 m
+DATABASE = sqlite
 
 [identity-provider-sqlite]
 FILENAME = $GNUNET_DATA_HOME/identity-provider/sqlite.db
index 434af4d8c844d1ae7e07a60395b78498284880a9..96bed18f41c687163232698537ead26888ad3374 100644 (file)
@@ -455,6 +455,42 @@ struct ConsumeTicketMessage
   //Followed by a serialized ticket
 };
 
+/**
+ * Attribute list is returned from the idp.
+ */
+struct ConsumeTicketResultMessage
+{
+  /**
+   * Message header
+   */
+  struct GNUNET_MessageHeader header;
+
+   /**
+   * Unique identifier for this request (for key collisions).
+   */
+  uint32_t id GNUNET_PACKED;
+
+  /**
+   * Length of serialized attribute data
+   */
+  uint16_t attrs_len GNUNET_PACKED;
+
+  /**
+   * always zero (for alignment)
+   */
+  uint16_t reserved GNUNET_PACKED;
+
+  /**
+   * The public key of the identity.
+   */
+  struct GNUNET_CRYPTO_EcdsaPublicKey identity;
+
+  /* followed by:
+   * serialized attributes data
+   */
+};
+
+
 
 GNUNET_NETWORK_STRUCT_END
 
index 7c9576d05ff9ffa5f4f305ecf31b0ac0f1a883a8..6e0ce7b4208c90122235e5e2e20664fa667f7550 100644 (file)
@@ -516,6 +516,86 @@ handle_attribute_store_response (void *cls,
 
 }
 
+
+/**
+ * Handle an incoming message of type
+ * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT
+ *
+ * @param cls
+ * @param msg the message we received
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ */
+static int
+check_consume_ticket_result (void *cls,
+                             const struct ConsumeTicketResultMessage *msg)
+{
+  size_t msg_len;
+  size_t attrs_len;
+
+  msg_len = ntohs (msg->header.size);
+  attrs_len = ntohs (msg->attrs_len);
+  if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_OK;
+}
+
+
+/**
+ * Handle an incoming message of type
+ * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT
+ *
+ * @param cls
+ * @param msg the message we received
+ */
+static void
+handle_consume_ticket_result (void *cls,
+                              const struct ConsumeTicketResultMessage *msg)
+{
+  struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
+  struct GNUNET_IDENTITY_PROVIDER_Operation *op;
+  size_t attrs_len;
+  uint32_t r_id = ntohl (msg->id);
+
+  attrs_len = ntohs (msg->attrs_len);
+  LOG (GNUNET_ERROR_TYPE_MESSAGE,
+       "Processing attribute result.\n");
+
+
+  for (op = h->op_head; NULL != op; op = op->next)
+    if (op->r_id == r_id)
+      break;
+  if (NULL == op)
+    return;
+
+  {
+    struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs;
+    struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le;
+    attrs = attribute_list_deserialize ((char*)&msg[1],
+                                        attrs_len);
+    if (NULL != op->ar_cb)
+    {
+      for (le = attrs->list_head; NULL != le; le = le->next)
+        op->ar_cb (op->cls,
+                   &msg->identity,
+                   le->attribute);
+    }
+    attribute_list_destroy (attrs);
+    op->ar_cb (op->cls,
+               NULL,
+               NULL);
+    GNUNET_CONTAINER_DLL_remove (h->op_head,
+                                 h->op_tail,
+                                 op);
+    GNUNET_free (op);
+    return;
+  }
+  GNUNET_assert (0);
+}
+
+
 /**
  * Handle an incoming message of type
  * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT
@@ -551,7 +631,7 @@ check_attribute_result (void *cls,
  */
 static void
 handle_attribute_result (void *cls,
-                     const struct AttributeResultMessage *msg)
+                         const struct AttributeResultMessage *msg)
 {
   static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
   struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
@@ -716,6 +796,10 @@ reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
                            GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT,
                            struct TicketResultMessage,
                            h),
+    GNUNET_MQ_hd_var_size (consume_ticket_result,
+                           GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT,
+                           struct ConsumeTicketResultMessage,
+                           h),
     GNUNET_MQ_handler_end ()
   };
   struct GNUNET_IDENTITY_PROVIDER_Operation *op;
index d05baa79d94d5ccac57a01f4414aa597f3cbf525..f31e2e68a73ed0adc8db1e322cd0b3b6da43aefd 100644 (file)
@@ -49,9 +49,9 @@
  * a failure of the command 'cmd' on file 'filename'
  * with the message given by strerror(errno).
  */
-#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "namestore-identity-provider", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0)
+#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "identity-provider", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0)
 
-#define LOG(kind,...) GNUNET_log_from (kind, "namestore-sqlite", __VA_ARGS__)
+#define LOG(kind,...) GNUNET_log_from (kind, "identity-provider-sqlite", __VA_ARGS__)
 
 
 /**
@@ -315,6 +315,8 @@ database_shutdown (struct Plugin *plugin)
     sqlite3_finalize (plugin->delete_ticket);
   if (NULL != plugin->iterate_tickets)
     sqlite3_finalize (plugin->iterate_tickets);
+  if (NULL != plugin->iterate_tickets_by_audience)
+    sqlite3_finalize (plugin->iterate_tickets_by_audience);
   result = sqlite3_close (plugin->dbh);
   if (result == SQLITE_BUSY)
   {
@@ -653,7 +655,7 @@ libgnunet_plugin_identity_provider_sqlite_init (void *cls)
  * @return always NULL
  */
 void *
-libgnunet_plugin_namestore_sqlite_done (void *cls)
+libgnunet_plugin_identity_provider_sqlite_done (void *cls)
 {
   struct GNUNET_IDENTITY_PROVIDER_PluginFunctions *api = cls;
   struct Plugin *plugin = api->cls;
index aca98e3902c5cb8def89d1af03c7d3b7354f80fc..38369a33ec161788c50a8b20b03da2f2158c6c44 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/bash
-trap "gnunet-arm -e -c test_idp_lookup.conf" SIGINT
+trap "gnunet-arm -e -c test_idp.conf" SIGINT
 
 LOCATION=$(which gnunet-config)
 if [ -z $LOCATION ]
index 743a28946eb09a15ba4b231fb55d51534c0b8f9f..b22e1b417ce06a686fb7b8feea8362b0131bf3d5 100644 (file)
@@ -2646,11 +2646,13 @@ extern "C"
 
 #define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET 973
 
-#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START 974
+#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT 974
 
-#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP 975
+#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START 975
 
-#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT 976
+#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP 976
+
+#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT 977
 
 /**************************************************
  *