From 1731fbd017731df1f3f88bd4b3beac765996a1ad Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Thu, 5 Oct 2017 22:44:56 +0200 Subject: [PATCH] -fix bugs --- .../gnunet-service-identity-provider.c | 70 +++++++++------ src/identity-provider/identity-provider.conf | 1 + src/identity-provider/identity_provider.h | 36 ++++++++ src/identity-provider/identity_provider_api.c | 86 ++++++++++++++++++- .../plugin_identity_provider_sqlite.c | 8 +- src/identity-provider/test_idp_issue.sh | 2 +- src/include/gnunet_protocols.h | 8 +- 7 files changed, 178 insertions(+), 33 deletions(-) diff --git a/src/identity-provider/gnunet-service-identity-provider.c b/src/identity-provider/gnunet-service-identity-provider.c index f77eebd6d..0b7f3389e 100644 --- a/src/identity-provider/gnunet-service-identity-provider.c +++ b/src/identity-provider/gnunet-service-identity-provider.c @@ -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; diff --git a/src/identity-provider/identity-provider.conf b/src/identity-provider/identity-provider.conf index 826b2419e..7ee5e50d8 100644 --- a/src/identity-provider/identity-provider.conf +++ b/src/identity-provider/identity-provider.conf @@ -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 diff --git a/src/identity-provider/identity_provider.h b/src/identity-provider/identity_provider.h index 434af4d8c..96bed18f4 100644 --- a/src/identity-provider/identity_provider.h +++ b/src/identity-provider/identity_provider.h @@ -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 diff --git a/src/identity-provider/identity_provider_api.c b/src/identity-provider/identity_provider_api.c index 7c9576d05..6e0ce7b42 100644 --- a/src/identity-provider/identity_provider_api.c +++ b/src/identity-provider/identity_provider_api.c @@ -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; diff --git a/src/identity-provider/plugin_identity_provider_sqlite.c b/src/identity-provider/plugin_identity_provider_sqlite.c index d05baa79d..f31e2e68a 100644 --- a/src/identity-provider/plugin_identity_provider_sqlite.c +++ b/src/identity-provider/plugin_identity_provider_sqlite.c @@ -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; diff --git a/src/identity-provider/test_idp_issue.sh b/src/identity-provider/test_idp_issue.sh index aca98e390..38369a33e 100755 --- a/src/identity-provider/test_idp_issue.sh +++ b/src/identity-provider/test_idp_issue.sh @@ -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 ] diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 743a28946..b22e1b417 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -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 /************************************************** * -- 2.25.1