diff options
Diffstat (limited to 'src')
57 files changed, 1642 insertions, 808 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index e4d7d8924f..68878b5a01 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,7 @@ endif if HAVE_JSON if HAVE_MHD + ATTRIBUTE_DIR = identity-attribute PROVIDER_DIR = identity-provider endif endif @@ -131,6 +132,7 @@ SUBDIRS = \ social \ $(AUCTION_DIR) \ $(EXP_DIR) \ + $(ATTRIBUTE_DIR) \ $(PROVIDER_DIR) endif diff --git a/src/arm/Makefile.am b/src/arm/Makefile.am index 373847fde2..b1706a4793 100644 --- a/src/arm/Makefile.am +++ b/src/arm/Makefile.am @@ -92,7 +92,8 @@ test_gnunet_service_arm_SOURCES = \ do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' -%.py: %.py.in Makefile +SUFFIXES = .py.in .py +.py.in.py: $(do_subst) < $(srcdir)/$< > $@ chmod +x $@ diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 5ec7693b1a..d88e6d523a 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c @@ -872,8 +872,8 @@ run (void *cls, for (c = 0; c < strlen (opt_type_str); c++) { - if (isupper (opt_type_str[c])) - opt_type_str[c] = tolower (opt_type_str[c]); + if (isupper ((unsigned char) opt_type_str[c])) + opt_type_str[c] = tolower ((unsigned char) opt_type_str[c]); } if (0 == strcasecmp ("latency", opt_type_str)) @@ -974,7 +974,7 @@ main (int argc, gettext_noop ("set preference for the given peer"), &opt_set_pref), - GNUNET_GETOPT_option_flag ('q', + GNUNET_GETOPT_option_flag ('q', "quotas", gettext_noop ("print all configured quotas"), &opt_print_quotas), diff --git a/src/cadet/gnunet-service-cadet_paths.c b/src/cadet/gnunet-service-cadet_paths.c index 13752643c3..79eed0dccd 100644 --- a/src/cadet/gnunet-service-cadet_paths.c +++ b/src/cadet/gnunet-service-cadet_paths.c @@ -179,7 +179,7 @@ GCPP_del_connection (struct CadetPeerPath *path, GCC_2s (cc), GCPP_2s (path), off); - GNUNET_assert (off < path->entries_length); + GNUNET_assert (off < path->entries_length); /* FIXME: This assertion fails sometimes! */ entry = path->entries[off]; GNUNET_assert (cc == entry->cc); entry->cc = NULL; @@ -498,8 +498,8 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path, const struct GNUNET_PeerIdentity *pid; pid = (off < get_path_length) - ? &get_path[get_path_length - off] - : &put_path[get_path_length + put_path_length - off]; + ? &get_path[get_path_length - off - 1] + : &put_path[get_path_length + put_path_length - off - 1]; cpath[off - skip] = GCP_get (pid, GNUNET_YES); /* Check that no peer is twice on the path */ diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c index 8f9ddec257..00ab65680d 100644 --- a/src/conversation/gnunet-conversation.c +++ b/src/conversation/gnunet-conversation.c @@ -1091,7 +1091,7 @@ handle_command_string (char *message, strlen (commands[i].command)))) i++; ptr = &message[strlen (commands[i].command)]; - while (isspace ((int) *ptr)) + while (isspace ((unsigned char) *ptr)) ptr++; if ('\0' == *ptr) ptr = NULL; diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c index 034f2e8838..5d34b7c26c 100644 --- a/src/core/gnunet-service-core_sessions.c +++ b/src/core/gnunet-service-core_sessions.c @@ -975,6 +975,7 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, session = find_session (peer); if (NULL == session) { + GSC_TYPEMAP_destroy (nmap); GNUNET_break (0); return; } diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index 900c9f7327..528093c994 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c @@ -381,6 +381,7 @@ process_hello (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received (my) `%s' from transport service\n", "HELLO"); GNUNET_assert (message != NULL); + GNUNET_free_non_null (p->hello); p->hello = GNUNET_copy_message (message); if ((p == &p1) && (NULL == p2.oh)) p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, @@ -518,6 +519,8 @@ main (int argc, &ok); stop_arm (&p1); stop_arm (&p2); + GNUNET_free_non_null (p1.hello); + GNUNET_free_non_null (p2.hello); GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 31f7a997f7..2ad864987f 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c @@ -651,6 +651,46 @@ process_queue (struct GNUNET_DATASTORE_Handle *h) } +/** + * Get the entry at the head of the message queue. + * + * @param h handle to the datastore + * @param response_type the expected response type + * @return the queue entry + */ +static struct GNUNET_DATASTORE_QueueEntry * +get_queue_head (struct GNUNET_DATASTORE_Handle *h, + uint16_t response_type) +{ + struct GNUNET_DATASTORE_QueueEntry *qe; + + if (h->skip_next_messages > 0) + { + h->skip_next_messages--; + process_queue (h); + return NULL; + } + qe = h->queue_head; + if (NULL == qe) + { + GNUNET_break (0); + do_disconnect (h); + return NULL; + } + if (NULL != qe->env) + { + GNUNET_break (0); + do_disconnect (h); + return NULL; + } + if (response_type != qe->response_type) + { + GNUNET_break (0); + do_disconnect (h); + return NULL; + } + return qe; +} /** @@ -702,30 +742,10 @@ handle_status (void *cls, const char *emsg; int32_t status = ntohl (sm->status); - if (h->skip_next_messages > 0) - { - h->skip_next_messages--; - process_queue (h); - return; - } - if (NULL == (qe = h->queue_head)) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (NULL != qe->env) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (GNUNET_MESSAGE_TYPE_DATASTORE_STATUS != qe->response_type) - { - GNUNET_break (0); - do_disconnect (h); + qe = get_queue_head (h, + GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); + if (NULL == qe) return; - } rc = qe->qc.sc; free_queue_entry (qe); if (ntohs (sm->header.size) > sizeof (struct StatusMessage)) @@ -785,30 +805,10 @@ handle_data (void *cls, struct GNUNET_DATASTORE_QueueEntry *qe; struct ResultContext rc; - if (h->skip_next_messages > 0) - { - process_queue (h); - return; - } - qe = h->queue_head; + qe = get_queue_head (h, + GNUNET_MESSAGE_TYPE_DATASTORE_DATA); if (NULL == qe) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (NULL != qe->env) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (GNUNET_MESSAGE_TYPE_DATASTORE_DATA != qe->response_type) - { - GNUNET_break (0); - do_disconnect (h); return; - } #if INSANE_STATISTICS GNUNET_STATISTICS_update (h->stats, gettext_noop ("# Results received"), @@ -854,31 +854,10 @@ handle_data_end (void *cls, struct GNUNET_DATASTORE_QueueEntry *qe; struct ResultContext rc; - if (h->skip_next_messages > 0) - { - h->skip_next_messages--; - process_queue (h); - return; - } - qe = h->queue_head; + qe = get_queue_head (h, + GNUNET_MESSAGE_TYPE_DATASTORE_DATA); if (NULL == qe) - { - GNUNET_break (0); - do_disconnect (h); return; - } - if (NULL != qe->env) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (GNUNET_MESSAGE_TYPE_DATASTORE_DATA != qe->response_type) - { - GNUNET_break (0); - do_disconnect (h); - return; - } rc = qe->qc.rc; free_queue_entry (qe); LOG (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index 00ce0e9344..4a78ea4c79 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am @@ -213,7 +213,8 @@ endif do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' -e 's,[@]bindir[@],$(bindir),g' -%.py: %.py.in Makefile +SUFFIXES = .py.in .py +.py.in.py: $(do_subst) < $(srcdir)/$< > $@ chmod +x $@ diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c index 36b4c36f17..30d9245ff7 100644 --- a/src/dns/dnsparser.c +++ b/src/dns/dnsparser.c @@ -1278,8 +1278,8 @@ GNUNET_DNSPARSER_hex_to_bin (const char *hex, in[2] = '\0'; for (off = 0; off < data_size; off++) { - in[0] = tolower ((int) hex[off * 2]); - in[1] = tolower ((int) hex[off * 2 + 1]); + in[0] = tolower ((unsigned char) hex[off * 2]); + in[1] = tolower ((unsigned char) hex[off * 2 + 1]); if (1 != sscanf (in, "%x", &h)) return off; idata[off] = (uint8_t) h; diff --git a/src/fs/fs_misc.c b/src/fs/fs_misc.c index bcb8620cfa..b26de431cc 100644 --- a/src/fs/fs_misc.c +++ b/src/fs/fs_misc.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2010, 2011 GNUnet e.V. + Copyright (C) 2010, 2011, 2017 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -43,6 +43,8 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData {"application/gnunet-directory", ".gnd"}, {"application/java", ".class"}, {"application/msword", ".doc"}, + {"application/nar", ".nar"}, + {"application/narinfo", ".narinfo"}, {"application/ogg", ".ogg"}, {"application/pdf", ".pdf"}, {"application/pgp-keys", ".key"}, @@ -53,8 +55,8 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData {"application/xml", ".xml"}, {"application/x-debian-package", ".deb"}, {"application/x-dvi", ".dvi"}, - {"applixation/x-flac", ".flac"}, - {"applixation/x-gzip", ".gz"}, + {"application/x-flac", ".flac"}, + {"application/x-gzip", ".gz"}, {"application/x-java-archive", ".jar"}, {"application/x-java-vm", ".class"}, {"application/x-python-code", ".pyc"}, diff --git a/src/fs/fs_publish_ublock.c b/src/fs/fs_publish_ublock.c index e21443ccbf..189a6909a2 100644 --- a/src/fs/fs_publish_ublock.c +++ b/src/fs/fs_publish_ublock.c @@ -301,6 +301,7 @@ GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, uc->task = GNUNET_SCHEDULER_add_now (&run_cont, uc); } + GNUNET_free (ub_enc); return uc; } diff --git a/src/identity-attribute/Makefile.am b/src/identity-attribute/Makefile.am new file mode 100644 index 0000000000..b84ad34926 --- /dev/null +++ b/src/identity-attribute/Makefile.am @@ -0,0 +1,45 @@ +# This Makefile.am is in the public domain +AM_CPPFLAGS = -I$(top_srcdir)/src/include + +plugindir = $(libdir)/gnunet + +pkgcfgdir= $(pkgdatadir)/config.d/ + +libexecdir= $(pkglibdir)/libexec/ + +if MINGW + WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols +endif + +if USE_COVERAGE + AM_CFLAGS = --coverage -O0 + XLIBS = -lgcov +endif + +lib_LTLIBRARIES = \ + libgnunetidentityattribute.la + +libgnunetidentityattribute_la_SOURCES = \ + identity_attribute.c \ + jwt.c +libgnunetidentityattribute_la_LIBADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(GN_LIBINTL) +libgnunetidentityattribute_la_LDFLAGS = \ + $(GN_LIB_LDFLAGS) $(WINFLAGS) \ + -version-info 0:0:0 + + +plugin_LTLIBRARIES = \ + libgnunet_plugin_identity_attribute_gnuid.la + + +libgnunet_plugin_identity_attribute_gnuid_la_SOURCES = \ + plugin_identity_attribute_gnuid.c +libgnunet_plugin_identity_attribute_gnuid_la_LIBADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(LTLIBINTL) +libgnunet_plugin_identity_attribute_gnuid_la_LDFLAGS = \ + $(GN_PLUGIN_LDFLAGS) + + diff --git a/src/identity-attribute/identity_attribute.c b/src/identity-attribute/identity_attribute.c new file mode 100644 index 0000000000..a8aae6ced7 --- /dev/null +++ b/src/identity-attribute/identity_attribute.c @@ -0,0 +1,421 @@ +/* + This file is part of GNUnet + Copyright (C) 2010-2015 GNUnet e.V. + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +/** + * @file identity-provider/identity_attribute.c + * @brief helper library to manage identity attributes + * @author Martin Schanzenbach + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "identity_attribute.h" +#include "gnunet_identity_attribute_plugin.h" + +/** + * Handle for a plugin + */ +struct Plugin +{ + /** + * Name of the plugin + */ + char *library_name; + + /** + * Plugin API + */ + struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api; +}; + +/** + * Plugins + */ +static struct Plugin **attr_plugins; + +/** + * Number of plugins + */ +static unsigned int num_plugins; + +/** + * Init canary + */ +static int initialized; + +/** + * Add a plugin + */ +static void +add_plugin (void* cls, + const char *library_name, + void *lib_ret) +{ + struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api = lib_ret; + struct Plugin *plugin; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Loading attribute plugin `%s'\n", + library_name); + plugin = GNUNET_new (struct Plugin); + plugin->api = api; + plugin->library_name = GNUNET_strdup (library_name); + GNUNET_array_append (attr_plugins, num_plugins, plugin); +} + +/** + * Load plugins + */ +static void +init() +{ + if (GNUNET_YES == initialized) + return; + initialized = GNUNET_YES; + GNUNET_PLUGIN_load_all ("libgnunet_plugin_identity_attribute_", NULL, + &add_plugin, NULL); +} + +/** + * Convert a type name to the corresponding number + * + * @param typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +uint32_t +GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (const char *typename) +{ + unsigned int i; + struct Plugin *plugin; + uint32_t ret; + + init (); + for (i = 0; i < num_plugins; i++) + { + plugin = attr_plugins[i]; + if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls, + typename))) + return ret; + } + return UINT32_MAX; +} + +/** + * Convert a type number to the corresponding type string + * + * @param type number of a type + * @return corresponding typestring, NULL on error + */ +const char* +GNUNET_IDENTITY_ATTRIBUTE_number_to_typename (uint32_t type) +{ + unsigned int i; + struct Plugin *plugin; + const char *ret; + + init (); + for (i = 0; i < num_plugins; i++) + { + plugin = attr_plugins[i]; + if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls, + type))) + return ret; + } + return NULL; +} + +/** + * Convert human-readable version of a 'claim' of an attribute to the binary + * representation + * + * @param type type of the claim + * @param s human-readable string + * @param data set to value in binary encoding (will be allocated) + * @param data_size set to number of bytes in @a data + * @return #GNUNET_OK on success + */ +int +GNUNET_IDENTITY_ATTRIBUTE_string_to_value (uint32_t type, + const char *s, + void **data, + size_t *data_size) +{ + unsigned int i; + struct Plugin *plugin; + + init (); + for (i = 0; i < num_plugins; i++) + { + plugin = attr_plugins[i]; + if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, + type, + s, + data, + data_size)) + return GNUNET_OK; + } + return GNUNET_SYSERR; +} + +/** + * Convert the 'claim' of an attribute to a string + * + * @param type the type of attribute + * @param data claim in binary encoding + * @param data_size number of bytes in @a data + * @return NULL on error, otherwise human-readable representation of the claim + */ +char * +GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type, + const void* data, + size_t data_size) +{ + unsigned int i; + struct Plugin *plugin; + char *ret; + + init(); + for (i = 0; i < num_plugins; i++) + { + plugin = attr_plugins[i]; + if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, + type, + data, + data_size))) + return ret; + } + return NULL; +} + +/** + * Create a new attribute. + * + * @param name the attribute name + * @param type the attribute type + * @param data the attribute value + * @param data_size the attribute value size + * @return the new attribute + */ +struct GNUNET_IDENTITY_ATTRIBUTE_Claim * +GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name, + uint32_t attr_type, + const void* data, + size_t data_size) +{ + struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr; + char *write_ptr; + + attr = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_ATTRIBUTE_Claim) + + strlen (attr_name) + 1 + + data_size); + attr->type = attr_type; + attr->data_size = data_size; + attr->version = 0; + write_ptr = (char*)&attr[1]; + GNUNET_memcpy (write_ptr, + attr_name, + strlen (attr_name) + 1); + attr->name = write_ptr; + write_ptr += strlen (attr->name) + 1; + GNUNET_memcpy (write_ptr, + data, + data_size); + attr->data = write_ptr; + return attr; +} + +size_t +GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) +{ + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; + size_t len = 0; + for (le = attrs->list_head; NULL != le; le = le->next) + len += GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (le->claim); + return len; +} + +size_t +GNUNET_IDENTITY_ATTRIBUTE_list_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, + char *result) +{ + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; + size_t len; + size_t total_len; + char* write_ptr; + + write_ptr = result; + total_len = 0; + for (le = attrs->list_head; NULL != le; le = le->next) + { + len = GNUNET_IDENTITY_ATTRIBUTE_serialize (le->claim, + write_ptr); + total_len += len; + write_ptr += len; + } + return total_len; +} + +struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList * +GNUNET_IDENTITY_ATTRIBUTE_list_deserialize (const char* data, + size_t data_size) +{ + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; + size_t attr_len; + const char* read_ptr; + + if (data_size < sizeof (struct Attribute)) + return NULL; + + attrs = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList); + read_ptr = data; + while (((data + data_size) - read_ptr) >= sizeof (struct Attribute)) + { + + le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); + le->claim = GNUNET_IDENTITY_ATTRIBUTE_deserialize (read_ptr, + data_size - (read_ptr - data)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Deserialized attribute %s\n", le->claim->name); + GNUNET_CONTAINER_DLL_insert (attrs->list_head, + attrs->list_tail, + le); + attr_len = GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (le->claim); + read_ptr += attr_len; + } + return attrs; +} + +struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList* +GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) +{ + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *result_le; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *result; + size_t len; + + result = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList); + for (le = attrs->list_head; NULL != le; le = le->next) + { + result_le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); + len = sizeof (struct GNUNET_IDENTITY_ATTRIBUTE_Claim) + le->claim->data_size; + result_le->claim = GNUNET_malloc (len); + GNUNET_memcpy (result_le->claim, + le->claim, + len); + result_le->claim->name = (const char*)&result_le->claim[1]; + GNUNET_CONTAINER_DLL_insert (result->list_head, + result->list_tail, + result_le); + } + return result; +} + + +void +GNUNET_IDENTITY_ATTRIBUTE_list_destroy (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) +{ + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *tmp_le; + + for (le = attrs->list_head; NULL != le;) + { + GNUNET_free (le->claim); + tmp_le = le; + le = le->next; + GNUNET_free (tmp_le); + } + GNUNET_free (attrs); + +} + +size_t +GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) +{ + return sizeof (struct Attribute) + + strlen (attr->name) + + attr->data_size; +} + +size_t +GNUNET_IDENTITY_ATTRIBUTE_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr, + char *result) +{ + size_t data_len_ser; + size_t name_len; + struct Attribute *attr_ser; + char* write_ptr; + + attr_ser = (struct Attribute*)result; + attr_ser->attribute_type = htons (attr->type); + attr_ser->attribute_version = htonl (attr->version); + name_len = strlen (attr->name); + attr_ser->name_len = htons (name_len); + write_ptr = (char*)&attr_ser[1]; + GNUNET_memcpy (write_ptr, attr->name, name_len); + write_ptr += name_len; + //TODO plugin-ize + //data_len_ser = plugin->serialize_attribute_value (attr, + // &attr_ser[1]); + data_len_ser = attr->data_size; + GNUNET_memcpy (write_ptr, attr->data, attr->data_size); + attr_ser->data_size = htons (data_len_ser); + + return sizeof (struct Attribute) + strlen (attr->name) + attr->data_size; +} + +struct GNUNET_IDENTITY_ATTRIBUTE_Claim * +GNUNET_IDENTITY_ATTRIBUTE_deserialize (const char* data, + size_t data_size) +{ + struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr; + struct Attribute *attr_ser; + size_t data_len; + size_t name_len; + char* write_ptr; + + if (data_size < sizeof (struct Attribute)) + return NULL; + + attr_ser = (struct Attribute*)data; + data_len = ntohs (attr_ser->data_size); + name_len = ntohs (attr_ser->name_len); + attr = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_ATTRIBUTE_Claim) + + data_len + name_len + 1); + attr->type = ntohs (attr_ser->attribute_type); + attr->version = ntohl (attr_ser->attribute_version); + attr->data_size = ntohs (attr_ser->data_size); + + write_ptr = (char*)&attr[1]; + GNUNET_memcpy (write_ptr, + &attr_ser[1], + name_len); + write_ptr[name_len] = '\0'; + attr->name = write_ptr; + + write_ptr += name_len + 1; + GNUNET_memcpy (write_ptr, + (char*)&attr_ser[1] + name_len, + attr->data_size); + attr->data = write_ptr; + return attr; + +} + +/* end of identity_attribute.c */ diff --git a/src/identity-attribute/identity_attribute.h b/src/identity-attribute/identity_attribute.h new file mode 100644 index 0000000000..0463218078 --- /dev/null +++ b/src/identity-attribute/identity_attribute.h @@ -0,0 +1,56 @@ +/* + This file is part of GNUnet. + Copyright (C) 2012-2015 GNUnet e.V. + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ +/** + * @author Martin Schanzenbach + * @file identity-provider/identity_attribute.h + * @brief GNUnet Identity Provider library + * + */ +#ifndef IDENTITY_ATTRIBUTE_H +#define IDENTITY_ATTRIBUTE_H + +#include "gnunet_identity_provider_service.h" + +struct Attribute +{ + /** + * Attribute type + */ + uint32_t attribute_type; + + /** + * Attribute version + */ + uint32_t attribute_version; + + /** + * Name length + */ + uint32_t name_len; + + /** + * Data size + */ + uint32_t data_size; + + //followed by data_size Attribute value data +}; + +#endif diff --git a/src/identity-provider/jwt.c b/src/identity-attribute/jwt.c index c8bc67806b..935e0a79d1 100644 --- a/src/identity-provider/jwt.c +++ b/src/identity-attribute/jwt.c @@ -26,7 +26,7 @@ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_signatures.h" -#include "identity_attribute.h" +#include "gnunet_identity_attribute_lib.h" #include <jansson.h> @@ -55,18 +55,20 @@ create_jwt_header(void) } /** - * Create a JWT from a ticket and attributes + * Create a JWT from attributes * - * @param ticket the ticket + * @param sub_key the public of the subject * @param attrs the attribute list + * @param priv_key the key used to sign the JWT * @return a new base64-encoded JWT string. */ char* -jwt_create (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key) +GNUNET_IDENTITY_ATTRIBUTE_jwt_create_from_list (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key) { - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_CRYPTO_EcdsaPublicKey iss_key; struct GNUNET_CRYPTO_EcdsaSignature signature; struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; char* audience; @@ -79,12 +81,14 @@ jwt_create (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, char* body_base64; char* signature_target; char* signature_base64; + char* attr_val_str; json_t* body; + GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &iss_key); /* TODO maybe we should use a local identity here */ - issuer = GNUNET_STRINGS_data_to_string_alloc (&ticket->identity, + issuer = GNUNET_STRINGS_data_to_string_alloc (&iss_key, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); - audience = GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, + audience = GNUNET_STRINGS_data_to_string_alloc (sub_key, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); header = create_jwt_header (); body = json_object (); @@ -103,9 +107,13 @@ jwt_create (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, * calls the Attribute plugins to create a * json representation for its value */ + attr_val_str = GNUNET_IDENTITY_ATTRIBUTE_value_to_string (le->claim->type, + le->claim->data, + le->claim->data_size); json_object_set_new (body, - le->attribute->name, - json_string (le->attribute->data)); + le->claim->name, + json_string (attr_val_str)); + GNUNET_free (attr_val_str); } body_str = json_dumps (body, JSON_INDENT(0)); json_decref (body); diff --git a/src/identity-attribute/plugin_identity_attribute_gnuid.c b/src/identity-attribute/plugin_identity_attribute_gnuid.c new file mode 100644 index 0000000000..0ff44d1993 --- /dev/null +++ b/src/identity-attribute/plugin_identity_attribute_gnuid.c @@ -0,0 +1,184 @@ +/* + This file is part of GNUnet + Copyright (C) 2013, 2014, 2016 GNUnet e.V. + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +/** + * @file identity-provider/plugin_identity_attribute_gnuid.c + * @brief identity attribute plugin to provide the API for fundamental + * attribute types. + * + * @author Martin Schanzenbach + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_identity_attribute_plugin.h" +#include <inttypes.h> + + +/** + * Convert the 'value' of an attribute to a string. + * + * @param cls closure, unused + * @param type type of the attribute + * @param data value in binary encoding + * @param data_size number of bytes in @a data + * @return NULL on error, otherwise human-readable representation of the value + */ +static char * +gnuid_value_to_string (void *cls, + uint32_t type, + const void *data, + size_t data_size) +{ + + switch (type) + { + case GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING: + return GNUNET_strndup (data, data_size); + default: + return NULL; + } +} + + +/** + * Convert human-readable version of a 'value' of an attribute to the binary + * representation. + * + * @param cls closure, unused + * @param type type of the attribute + * @param s human-readable string + * @param data set to value in binary encoding (will be allocated) + * @param data_size set to number of bytes in @a data + * @return #GNUNET_OK on success + */ +static int +gnuid_string_to_value (void *cls, + uint32_t type, + const char *s, + void **data, + size_t *data_size) +{ + if (NULL == s) + return GNUNET_SYSERR; + switch (type) + { + + case GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING: + *data = GNUNET_strdup (s); + *data_size = strlen (s); + return GNUNET_OK; + default: + return GNUNET_SYSERR; + } +} + + +/** + * Mapping of attribute type numbers to human-readable + * attribute type names. + */ +static struct { + const char *name; + uint32_t number; +} gnuid_name_map[] = { + { "STRING", GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING }, + { NULL, UINT32_MAX } +}; + + +/** + * Convert a type name to the corresponding number. + * + * @param cls closure, unused + * @param gnuid_typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +static uint32_t +gnuid_typename_to_number (void *cls, + const char *gnuid_typename) +{ + unsigned int i; + + i=0; + while ( (NULL != gnuid_name_map[i].name) && + (0 != strcasecmp (gnuid_typename, + gnuid_name_map[i].name)) ) + i++; + return gnuid_name_map[i].number; +} + + +/** + * Convert a type number (i.e. 1) to the corresponding type string + * + * @param cls closure, unused + * @param type number of a type to convert + * @return corresponding typestring, NULL on error + */ +static const char * +gnuid_number_to_typename (void *cls, + uint32_t type) +{ + unsigned int i; + + i=0; + while ( (NULL != gnuid_name_map[i].name) && + (type != gnuid_name_map[i].number) ) + i++; + return gnuid_name_map[i].name; +} + + +/** + * Entry point for the plugin. + * + * @param cls NULL + * @return the exported block API + */ +void * +libgnunet_plugin_identity_attribute_gnuid_init (void *cls) +{ + struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api; + + api = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions); + api->value_to_string = &gnuid_value_to_string; + api->string_to_value = &gnuid_string_to_value; + api->typename_to_number = &gnuid_typename_to_number; + api->number_to_typename = &gnuid_number_to_typename; + return api; +} + + +/** + * Exit point from the plugin. + * + * @param cls the return value from #libgnunet_plugin_block_test_init() + * @return NULL + */ +void * +libgnunet_plugin_identity_attribute_gnuid_done (void *cls) +{ + struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api = cls; + + GNUNET_free (api); + return NULL; +} + +/* end of plugin_identity_attribute_type_gnuid.c */ diff --git a/src/identity-provider/Makefile.am b/src/identity-provider/Makefile.am index f64f1aa687..3b072e59d8 100644 --- a/src/identity-provider/Makefile.am +++ b/src/identity-provider/Makefile.am @@ -63,8 +63,7 @@ libgnunet_plugin_identity_provider_sqlite_la_LDFLAGS = \ gnunet_service_identity_provider_SOURCES = \ - gnunet-service-identity-provider.c \ - identity_attribute.h + gnunet-service-identity-provider.c gnunet_service_identity_provider_LDADD = \ $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ $(top_builddir)/src/util/libgnunetutil.la \ @@ -72,14 +71,14 @@ gnunet_service_identity_provider_LDADD = \ $(top_builddir)/src/identity/libgnunetidentity.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/credential/libgnunetcredential.la \ + $(top_builddir)/src/identity-attribute/libgnunetidentityattribute.la \ libgnunetidentityprovider.la \ $(top_builddir)/src/gns/libgnunetgns.la \ $(GN_LIBINTL) libgnunetidentityprovider_la_SOURCES = \ identity_provider_api.c \ - identity_provider.h \ - identity_attribute.c + identity_provider.h libgnunetidentityprovider_la_LIBADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) $(XLIB) @@ -88,13 +87,13 @@ libgnunetidentityprovider_la_LDFLAGS = \ -version-info 0:0:0 libgnunet_plugin_rest_identity_provider_la_SOURCES = \ - plugin_rest_identity_provider.c \ - jwt.c + plugin_rest_identity_provider.c libgnunet_plugin_rest_identity_provider_la_LIBADD = \ $(top_builddir)/src/identity/libgnunetidentity.la \ libgnunetidentityprovider.la \ $(top_builddir)/src/rest/libgnunetrest.la \ $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \ + $(top_builddir)/src/identity-attribute/libgnunetidentityattribute.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la \ $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ $(LTLIBINTL) -ljansson -lmicrohttpd @@ -108,6 +107,7 @@ gnunet_idp_LDADD = \ $(top_builddir)/src/namestore/libgnunetnamestore.la \ libgnunetidentityprovider.la \ $(top_builddir)/src/identity/libgnunetidentity.la \ + $(top_builddir)/src/identity-attribute/libgnunetidentityattribute.la \ $(GN_LIBINTL) check_SCRIPTS = \ diff --git a/src/identity-provider/gnunet-idp.c b/src/identity-provider/gnunet-idp.c index 88136c1243..62f07842b9 100644 --- a/src/identity-provider/gnunet-idp.c +++ b/src/identity-provider/gnunet-idp.c @@ -67,6 +67,11 @@ static char* issue_attrs; static char* consume_ticket; /** + * Attribute type + */ +static char* type_str; + +/** * Ticket to revoke */ static char* revoke_ticket; @@ -119,7 +124,7 @@ static struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; /** * Attribute list */ -static struct GNUNET_IDENTITY_PROVIDER_AttributeList *attr_list; +static struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attr_list; static void do_cleanup(void *cls) @@ -166,8 +171,9 @@ store_attr_cont (void *cls, static void process_attrs (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr) + const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) { + char *value_str; if (NULL == identity) { GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); @@ -178,8 +184,11 @@ process_attrs (void *cls, ret = 1; return; } + value_str = GNUNET_IDENTITY_ATTRIBUTE_value_to_string (attr->type, + attr->data, + attr->data_size); GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - "%s: %s\n", attr->name, (char*)attr->data); + "%s: %s\n", attr->name, value_str); } @@ -207,7 +216,10 @@ process_rvk (void *cls, int success, const char* msg) static void iter_finished (void *cls) { - struct GNUNET_IDENTITY_PROVIDER_Attribute *attr; + struct GNUNET_IDENTITY_ATTRIBUTE_Claim *claim; + char *data; + size_t data_size; + int type; attr_iterator = NULL; if (list) @@ -244,13 +256,22 @@ iter_finished (void *cls) NULL); return; } - attr = GNUNET_IDENTITY_PROVIDER_attribute_new (attr_name, - GNUNET_IDENTITY_PROVIDER_AT_STRING, - attr_value, - strlen (attr_value) + 1); + if (NULL == type_str) + type = GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING; + else + type = GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (type_str); + + GNUNET_assert (GNUNET_SYSERR != GNUNET_IDENTITY_ATTRIBUTE_string_to_value (type, + attr_value, + (void**)&data, + &data_size)); + claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr_name, + type, + data, + data_size); idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle, pkey, - attr, + claim, &store_attr_cont, NULL); @@ -260,9 +281,9 @@ iter_finished (void *cls) static void iter_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr) + const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) { - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; char *attrs_tmp; char *attr_str; @@ -275,11 +296,11 @@ iter_cb (void *cls, attr_str = strtok (NULL, ","); continue; } - le = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry); - le->attribute = GNUNET_IDENTITY_PROVIDER_attribute_new (attr->name, - attr->attribute_type, - attr->data, - attr->data_size); + le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); + le->claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr->name, + attr->type, + attr->data, + attr->data_size); GNUNET_CONTAINER_DLL_insert (attr_list->list_head, attr_list->list_tail, le); @@ -321,7 +342,7 @@ ego_cb (void *cls, sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket)); - attr_list = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeList); + attr_list = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList); attr_iterator = GNUNET_IDENTITY_PROVIDER_get_attributes_start (idp_handle, pkey, @@ -404,6 +425,11 @@ main(int argc, char *const argv[]) NULL, gettext_noop ("Revoke a ticket"), &revoke_ticket), + GNUNET_GETOPT_option_string ('t', + "type", + NULL, + gettext_noop ("Type of attribute"), + &type_str), GNUNET_GETOPT_OPTION_END }; GNUNET_PROGRAM_run (argc, argv, "ct", diff --git a/src/identity-provider/gnunet-service-identity-provider.c b/src/identity-provider/gnunet-service-identity-provider.c index 2e67dc1eba..a5c178aa59 100644 --- a/src/identity-provider/gnunet-service-identity-provider.c +++ b/src/identity-provider/gnunet-service-identity-provider.c @@ -34,9 +34,9 @@ #include "gnunet_statistics_service.h" #include "gnunet_gns_service.h" #include "gnunet_identity_provider_plugin.h" +#include "gnunet_identity_attribute_lib.h" #include "gnunet_signatures.h" #include "identity_provider.h" -#include "identity_attribute.h" /** * First pass state @@ -365,7 +365,7 @@ struct AttributeStoreHandle /** * The attribute to store */ - struct GNUNET_IDENTITY_PROVIDER_Attribute *attribute; + struct GNUNET_IDENTITY_ATTRIBUTE_Claim *claim; /** * request id @@ -428,7 +428,7 @@ struct ConsumeTicketHandle /** * Attributes */ - struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; /** * Lookup time @@ -490,12 +490,12 @@ struct TicketRevocationHandle /** * Attributes to reissue */ - struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; /** * Attributes to revoke */ - struct GNUNET_IDENTITY_PROVIDER_AttributeList *rvk_attrs; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *rvk_attrs; /** * Issuer Key @@ -549,7 +549,7 @@ struct TicketIssueHandle /** * Attributes to issue */ - struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; /** * Issuer Key @@ -809,7 +809,7 @@ static void cleanup_ticket_issue_handle (struct TicketIssueHandle *handle) { if (NULL != handle->attrs) - attribute_list_destroy (handle->attrs); + GNUNET_IDENTITY_ATTRIBUTE_list_destroy (handle->attrs); if (NULL != handle->ns_qe) GNUNET_NAMESTORE_cancel (handle->ns_qe); GNUNET_free (handle); @@ -820,7 +820,7 @@ static void send_ticket_result (struct IdpClient *client, uint32_t r_id, const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs) + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) { struct TicketResultMessage *irm; struct GNUNET_MQ_Envelope *env; @@ -873,13 +873,13 @@ store_ticket_issue_cont (void *cls, int serialize_abe_keyinfo2 (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs, + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, const struct GNUNET_CRYPTO_AbeKey *rp_key, struct GNUNET_CRYPTO_EcdhePrivateKey **ecdh_privkey, char **result) { struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey; - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; char *enc_keyinfo; char *serialized_key; char *buf; @@ -896,7 +896,7 @@ serialize_abe_keyinfo2 (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, (void**)&serialized_key); attrs_str_len = 0; for (le = attrs->list_head; NULL != le; le = le->next) { - attrs_str_len += strlen (le->attribute->name) + 1; + attrs_str_len += strlen (le->claim->name) + 1; } buf = GNUNET_malloc (attrs_str_len + size); write_ptr = buf; @@ -904,14 +904,14 @@ serialize_abe_keyinfo2 (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, "Writing attributes\n"); for (le = attrs->list_head; NULL != le; le = le->next) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "%s\n", le->attribute->name); + "%s\n", le->claim->name); GNUNET_memcpy (write_ptr, - le->attribute->name, - strlen (le->attribute->name)); - write_ptr[strlen (le->attribute->name)] = ','; - write_ptr += strlen (le->attribute->name) + 1; + le->claim->name, + strlen (le->claim->name)); + write_ptr[strlen (le->claim->name)] = ','; + write_ptr += strlen (le->claim->name) + 1; } write_ptr--; write_ptr[0] = '\0'; //replace last , with a 0-terminator @@ -954,7 +954,7 @@ issue_ticket_after_abe_bootstrap (void *cls, struct GNUNET_CRYPTO_AbeMasterKey *abe_key) { struct TicketIssueHandle *ih = cls; - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; struct GNUNET_GNSRECORD_Data code_record[1]; struct GNUNET_CRYPTO_AbeKey *rp_key; @@ -974,8 +974,8 @@ issue_ticket_after_abe_bootstrap (void *cls, i = 0; for (le = ih->attrs->list_head; NULL != le; le = le->next) { GNUNET_asprintf (&policy, "%s_%lu", - le->attribute->name, - le->attribute->attribute_version); + le->claim->name, + le->claim->version); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute to key: %s\n", policy); @@ -1061,7 +1061,7 @@ handle_issue_ticket_message (void *cls, ih = GNUNET_new (struct TicketIssueHandle); attrs_len = ntohs (im->attr_len); - ih->attrs = attribute_list_deserialize ((char*)&im[1], attrs_len); + ih->attrs = GNUNET_IDENTITY_ATTRIBUTE_list_deserialize ((char*)&im[1], attrs_len); ih->r_id = ntohl (im->id); ih->client = idp; ih->identity = im->identity; @@ -1087,9 +1087,9 @@ static void cleanup_revoke_ticket_handle (struct TicketRevocationHandle *handle) { if (NULL != handle->attrs) - attribute_list_destroy (handle->attrs); + GNUNET_IDENTITY_ATTRIBUTE_list_destroy (handle->attrs); if (NULL != handle->rvk_attrs) - attribute_list_destroy (handle->rvk_attrs); + GNUNET_IDENTITY_ATTRIBUTE_list_destroy (handle->rvk_attrs); if (NULL != handle->abe_key) GNUNET_CRYPTO_cpabe_delete_master_key (handle->abe_key); if (NULL != handle->ns_qe) @@ -1132,7 +1132,7 @@ send_revocation_finished (struct TicketRevocationHandle *rh, static void ticket_reissue_proc (void *cls, const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs); + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); static void revocation_reissue_tickets (struct TicketRevocationHandle *rh); @@ -1176,11 +1176,11 @@ reissue_ticket_cont (void *cls, static void ticket_reissue_proc (void *cls, const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs) + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) { struct TicketRevocationHandle *rh = cls; - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le_rollover; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le_rollover; struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; struct GNUNET_GNSRECORD_Data code_record[1]; struct GNUNET_CRYPTO_AbeKey *rp_key; @@ -1223,11 +1223,11 @@ ticket_reissue_proc (void *cls, NULL != le_rollover; le_rollover = le_rollover->next) { - if (0 == strcmp (le_rollover->attribute->name, - le->attribute->name)) + if (0 == strcmp (le_rollover->claim->name, + le->claim->name)) { reissue_ticket = GNUNET_YES; - le->attribute->attribute_version = le_rollover->attribute->attribute_version; + le->claim->version = le_rollover->claim->version; } } } @@ -1255,8 +1255,8 @@ ticket_reissue_proc (void *cls, i = 0; for (le = attrs->list_head; NULL != le; le = le->next) { GNUNET_asprintf (&policy, "%s_%lu", - le->attribute->name, - le->attribute->attribute_version); + le->claim->name, + le->claim->version); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recreating key with %s\n", policy); attr_arr[i] = policy; @@ -1349,14 +1349,14 @@ reenc_next_attribute (struct TicketRevocationHandle *rh) revocation_reissue_tickets (rh); return; } - buf_size = attribute_serialize_get_size (rh->attrs->list_head->attribute); + buf_size = GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (rh->attrs->list_head->claim); buf = GNUNET_malloc (buf_size); - attribute_serialize (rh->attrs->list_head->attribute, + GNUNET_IDENTITY_ATTRIBUTE_serialize (rh->attrs->list_head->claim, buf); - rh->attrs->list_head->attribute->attribute_version++; + rh->attrs->list_head->claim->version++; GNUNET_asprintf (&policy, "%s_%lu", - rh->attrs->list_head->attribute->name, - rh->attrs->list_head->attribute->attribute_version); + rh->attrs->list_head->claim->name, + rh->attrs->list_head->claim->version); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with policy %s\n", policy); /** @@ -1371,7 +1371,7 @@ reenc_next_attribute (struct TicketRevocationHandle *rh) GNUNET_free (policy); rd[0].data_size = enc_size + sizeof (uint32_t); rd_buf = GNUNET_malloc (rd[0].data_size); - attr_ver = htonl (rh->attrs->list_head->attribute->attribute_version); + attr_ver = htonl (rh->attrs->list_head->claim->version); GNUNET_memcpy (rd_buf, &attr_ver, sizeof (uint32_t)); @@ -1384,7 +1384,7 @@ reenc_next_attribute (struct TicketRevocationHandle *rh) rd[0].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; //TODO sane? rh->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle, &rh->identity, - rh->attrs->list_head->attribute->name, + rh->attrs->list_head->claim->name, 1, rd, &attr_reenc_cont, @@ -1403,7 +1403,7 @@ attr_reenc_cont (void *cls, const char *emsg) { struct TicketRevocationHandle *rh = cls; - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; if (GNUNET_SYSERR == success) { @@ -1437,11 +1437,11 @@ attr_reenc_cont (void *cls, static void process_attributes_to_update (void *cls, const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs) + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) { struct TicketRevocationHandle *rh = cls; - rh->attrs = attribute_list_dup (attrs); + rh->attrs = GNUNET_IDENTITY_ATTRIBUTE_list_dup (attrs); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Revocation Phase I: Collecting attributes\n"); /* Reencrypt all attributes with new key */ @@ -1514,7 +1514,7 @@ handle_revoke_ticket_message (void *cls, rh = GNUNET_new (struct TicketRevocationHandle); ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket*)&rm[1]; - rh->rvk_attrs = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeList); + rh->rvk_attrs = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList); rh->ticket = *ticket; rh->r_id = ntohl (rm->id); rh->client = idp; @@ -1537,7 +1537,7 @@ cleanup_consume_ticket_handle (struct ConsumeTicketHandle *handle) GNUNET_CRYPTO_cpabe_delete_key (handle->key, GNUNET_YES); if (NULL != handle->attrs) - attribute_list_destroy (handle->attrs); + GNUNET_IDENTITY_ATTRIBUTE_list_destroy (handle->attrs); GNUNET_free (handle); } @@ -1575,7 +1575,8 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count, struct ConsumeTicketHandle *handle = parallel_lookup->handle; struct ConsumeTicketResultMessage *crm; struct GNUNET_MQ_Envelope *env; - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *attr_le; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *attr_le; + struct GNUNET_TIME_Absolute decrypt_duration; char *data; char *data_tmp; ssize_t attr_len; @@ -1601,16 +1602,26 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count, GNUNET_break(0);//TODO if (rd->record_type == GNUNET_GNSRECORD_TYPE_ID_ATTR) { + decrypt_duration = GNUNET_TIME_absolute_get (); attr_len = GNUNET_CRYPTO_cpabe_decrypt (rd->data + sizeof (uint32_t), rd->data_size - sizeof (uint32_t), handle->key, (void**)&data); if (GNUNET_SYSERR != attr_len) { - attr_le = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry); - attr_le->attribute = attribute_deserialize (data, + GNUNET_STATISTICS_update (stats_handle, + "abe_decrypt_time_total", + GNUNET_TIME_absolute_get_duration (decrypt_duration).rel_value_us, + GNUNET_YES); + GNUNET_STATISTICS_update (stats_handle, + "abe_decrypt_count", + 1, + GNUNET_YES); + + attr_le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); + attr_le->claim = GNUNET_IDENTITY_ATTRIBUTE_deserialize (data, attr_len); - attr_le->attribute->attribute_version = ntohl(*(uint32_t*)rd->data); + attr_le->claim->version = ntohl(*(uint32_t*)rd->data); GNUNET_CONTAINER_DLL_insert (handle->attrs->list_head, handle->attrs->list_tail, attr_le); @@ -1632,7 +1643,7 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count, } GNUNET_SCHEDULER_cancel (handle->kill_task); - attrs_len = attribute_list_serialize_get_size (handle->attrs); + attrs_len = GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (handle->attrs); env = GNUNET_MQ_msg_extra (crm, attrs_len, GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT); @@ -1640,7 +1651,7 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count, crm->attrs_len = htons (attrs_len); crm->identity = handle->ticket.identity; data_tmp = (char *) &crm[1]; - attribute_list_serialize (handle->attrs, + GNUNET_IDENTITY_ATTRIBUTE_list_serialize (handle->attrs, data_tmp); GNUNET_MQ_send (handle->client->mq, env); cleanup_consume_ticket_handle (handle); @@ -1791,7 +1802,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); + ch->attrs = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList); GNUNET_CRYPTO_ecdsa_key_get_public (&ch->identity, &ch->identity_pub); ch->ticket = *((struct GNUNET_IDENTITY_PROVIDER_Ticket*)&cm[1]); @@ -1819,8 +1830,8 @@ handle_consume_ticket_message (void *cls, static void cleanup_as_handle (struct AttributeStoreHandle *handle) { - if (NULL != handle->attribute) - GNUNET_free (handle->attribute); + if (NULL != handle->claim) + GNUNET_free (handle->claim); if (NULL != handle->abe_key) GNUNET_CRYPTO_cpabe_delete_master_key (handle->abe_key); GNUNET_free (handle); @@ -1871,16 +1882,16 @@ attr_store_task (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing attribute\n"); - buf_size = attribute_serialize_get_size (as_handle->attribute); + buf_size = GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (as_handle->claim); buf = GNUNET_malloc (buf_size); - attribute_serialize (as_handle->attribute, + GNUNET_IDENTITY_ATTRIBUTE_serialize (as_handle->claim, buf); GNUNET_asprintf (&policy, "%s_%lu", - as_handle->attribute->name, - as_handle->attribute->attribute_version); + as_handle->claim->name, + as_handle->claim->version); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with policy %s\n", policy); /** @@ -1895,7 +1906,7 @@ attr_store_task (void *cls) GNUNET_free (policy); rd[0].data_size = enc_size + sizeof (uint32_t); rd_buf = GNUNET_malloc (rd[0].data_size); - attr_ver = htonl (as_handle->attribute->attribute_version); + attr_ver = htonl (as_handle->claim->version); GNUNET_memcpy (rd_buf, &attr_ver, sizeof (uint32_t)); @@ -1908,7 +1919,7 @@ attr_store_task (void *cls) rd[0].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; //TODO sane? as_handle->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle, &as_handle->identity, - as_handle->attribute->name, + as_handle->claim->name, 1, rd, &attr_store_cont, @@ -1973,7 +1984,7 @@ handle_attribute_store_message (void *cls, data_len = ntohs (sam->attr_len); as_handle = GNUNET_new (struct AttributeStoreHandle); - as_handle->attribute = attribute_deserialize ((char*)&sam[1], + as_handle->claim = GNUNET_IDENTITY_ATTRIBUTE_deserialize ((char*)&sam[1], data_len); as_handle->r_id = ntohl (sam->id); @@ -2269,7 +2280,7 @@ cleanup_ticket_iter_handle (struct TicketIteration *ti) static void ticket_iterate_proc (void *cls, const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs) + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) { struct TicketIterationProcResult *proc = cls; diff --git a/src/identity-provider/identity_attribute.c b/src/identity-provider/identity_attribute.c deleted file mode 100644 index c7e833326c..0000000000 --- a/src/identity-provider/identity_attribute.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - This file is part of GNUnet - Copyright (C) 2010-2015 GNUnet e.V. - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ - -/** - * @file identity-provider/identity_attribute.c - * @brief helper library to manage identity attributes - * @author Martin Schanzenbach - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "identity_attribute.h" - -/** - * Create a new attribute. - * - * @param name the attribute name - * @param type the attribute type - * @param data the attribute value - * @param data_size the attribute value size - * @return the new attribute - */ -struct GNUNET_IDENTITY_PROVIDER_Attribute * -attribute_new (const char* attr_name, - uint32_t attr_type, - const void* data, - size_t data_size) -{ - struct GNUNET_IDENTITY_PROVIDER_Attribute *attr; - char *write_ptr; - - attr = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_PROVIDER_Attribute) + - strlen (attr_name) + 1 + - data_size); - attr->attribute_type = attr_type; - attr->data_size = data_size; - write_ptr = (char*)&attr[1]; - GNUNET_memcpy (write_ptr, - attr_name, - strlen (attr_name) + 1); - attr->name = write_ptr; - write_ptr += strlen (attr->name) + 1; - GNUNET_memcpy (write_ptr, - data, - data_size); - attr->data = write_ptr; - return attr; -} - -size_t -attribute_list_serialize_get_size (const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs) -{ - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; - size_t len = 0; - for (le = attrs->list_head; NULL != le; le = le->next) - len += attribute_serialize_get_size (le->attribute); - return len; -} - -size_t -attribute_list_serialize (const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs, - char *result) -{ - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; - size_t len; - size_t total_len; - char* write_ptr; - - write_ptr = result; - total_len = 0; - for (le = attrs->list_head; NULL != le; le = le->next) - { - len = attribute_serialize (le->attribute, - write_ptr); - total_len += len; - write_ptr += len; - } - return total_len; -} - -struct GNUNET_IDENTITY_PROVIDER_AttributeList * -attribute_list_deserialize (const char* data, - size_t data_size) -{ - struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs; - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; - size_t attr_len; - const char* read_ptr; - - if (data_size < sizeof (struct Attribute)) - return NULL; - - attrs = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeList); - read_ptr = data; - while (((data + data_size) - read_ptr) >= sizeof (struct Attribute)) - { - - le = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry); - le->attribute = attribute_deserialize (read_ptr, - data_size - (read_ptr - data)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Deserialized attribute %s\n", le->attribute->name); - GNUNET_CONTAINER_DLL_insert (attrs->list_head, - attrs->list_tail, - le); - attr_len = attribute_serialize_get_size (le->attribute); - read_ptr += attr_len; - } - return attrs; -} - -struct GNUNET_IDENTITY_PROVIDER_AttributeList* -attribute_list_dup (const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs) -{ - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *result_le; - struct GNUNET_IDENTITY_PROVIDER_AttributeList *result; - size_t len; - - result = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeList); - for (le = attrs->list_head; NULL != le; le = le->next) - { - result_le = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry); - len = sizeof (struct GNUNET_IDENTITY_PROVIDER_Attribute) + le->attribute->data_size; - result_le->attribute = GNUNET_malloc (len); - GNUNET_memcpy (result_le->attribute, - le->attribute, - len); - result_le->attribute->name = (const char*)&result_le->attribute[1]; - GNUNET_CONTAINER_DLL_insert (result->list_head, - result->list_tail, - result_le); - } - return result; -} - - -void -attribute_list_destroy (struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs) -{ - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *tmp_le; - - for (le = attrs->list_head; NULL != le;) - { - GNUNET_free (le->attribute); - tmp_le = le; - le = le->next; - GNUNET_free (tmp_le); - } - GNUNET_free (attrs); - -} - -size_t -attribute_serialize_get_size (const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr) -{ - return sizeof (struct Attribute) - + strlen (attr->name) - + attr->data_size; //TODO get data_size from plugin -} - -size_t -attribute_serialize (const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr, - char *result) -{ - size_t data_len_ser; - size_t name_len; - struct Attribute *attr_ser; - char* write_ptr; - - attr_ser = (struct Attribute*)result; - attr_ser->attribute_type = htons (attr->attribute_type); - attr_ser->attribute_version = htonl (attr->attribute_version); - name_len = strlen (attr->name); - attr_ser->name_len = htons (name_len); - write_ptr = (char*)&attr_ser[1]; - GNUNET_memcpy (write_ptr, attr->name, name_len); - write_ptr += name_len; - //TODO plugin-ize - //data_len_ser = plugin->serialize_attribute_value (attr, - // &attr_ser[1]); - data_len_ser = attr->data_size; - GNUNET_memcpy (write_ptr, attr->data, attr->data_size); - attr_ser->data_size = htons (data_len_ser); - - return sizeof (struct Attribute) + strlen (attr->name) + attr->data_size; -} - -struct GNUNET_IDENTITY_PROVIDER_Attribute * -attribute_deserialize (const char* data, - size_t data_size) -{ - struct GNUNET_IDENTITY_PROVIDER_Attribute *attr; - struct Attribute *attr_ser; - size_t data_len; - size_t name_len; - char* write_ptr; - - if (data_size < sizeof (struct Attribute)) - return NULL; - - attr_ser = (struct Attribute*)data; - //TODO use plugin. - data_len = ntohs (attr_ser->data_size); - name_len = ntohs (attr_ser->name_len); - attr = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_PROVIDER_Attribute) - + data_len + name_len + 1); - attr->attribute_type = ntohs (attr_ser->attribute_type); - attr->attribute_version = ntohl (attr_ser->attribute_version); - attr->data_size = ntohs (attr_ser->data_size); - - write_ptr = (char*)&attr[1]; - GNUNET_memcpy (write_ptr, - &attr_ser[1], - name_len); - write_ptr[name_len] = '\0'; - attr->name = write_ptr; - - write_ptr += name_len + 1; - GNUNET_memcpy (write_ptr, - (char*)&attr_ser[1] + name_len, - attr->data_size); - attr->data = write_ptr; - return attr; - -} - -/* end of identity_attribute.c */ diff --git a/src/identity-provider/identity_attribute.h b/src/identity-provider/identity_attribute.h deleted file mode 100644 index 3e8fadccf7..0000000000 --- a/src/identity-provider/identity_attribute.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2012-2015 GNUnet e.V. - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ -/** - * @author Martin Schanzenbach - * @file identity-provider/identity_attribute.h - * @brief GNUnet Identity Provider library - * - */ -#ifndef IDENTITY_ATTRIBUTE_H -#define IDENTITY_ATTRIBUTE_H - -#include "gnunet_identity_provider_service.h" - -struct Attribute -{ - /** - * Attribute type - */ - uint32_t attribute_type; - - /** - * Attribute version - */ - uint32_t attribute_version; - - /** - * Name length - */ - uint32_t name_len; - - /** - * Data size - */ - uint32_t data_size; - - //followed by data_size Attribute value data -}; - -/** - * Get required size for serialization buffer - * - * @param attrs the attribute list to serialize - * - * @return the required buffer size - */ -size_t -attribute_list_serialize_get_size (const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs); - -void -attribute_list_destroy (struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs); - - -/** - * Serialize an attribute list - * - * @param attrs the attribute list to serialize - * @param result the serialized attribute - * - * @return length of serialized data - */ -size_t -attribute_list_serialize (const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs, - char *result); - -/** - * Deserialize an attribute list - * - * @param data the serialized attribute list - * @param data_size the length of the serialized data - * - * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller - */ -struct GNUNET_IDENTITY_PROVIDER_AttributeList * -attribute_list_deserialize (const char* data, - size_t data_size); - - -/** - * Get required size for serialization buffer - * - * @param attr the attribute to serialize - * - * @return the required buffer size - */ -size_t -attribute_serialize_get_size (const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr); - - - -/** - * Serialize an attribute - * - * @param attr the attribute to serialize - * @param result the serialized attribute - * - * @return length of serialized data - */ -size_t -attribute_serialize (const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr, - char *result); - -/** - * Deserialize an attribute - * - * @param data the serialized attribute - * @param data_size the length of the serialized data - * - * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller - */ -struct GNUNET_IDENTITY_PROVIDER_Attribute * -attribute_deserialize (const char* data, - size_t data_size); - -/** - * Create a new attribute. - * - * @param name the attribute name - * @param type the attribute type - * @param data the attribute value - * @param data_size the attribute value size - * @return the new attribute - */ -struct GNUNET_IDENTITY_PROVIDER_Attribute * -attribute_new (const char* attr_name, - uint32_t attr_type, - const void* data, - size_t data_size); - -struct GNUNET_IDENTITY_PROVIDER_AttributeList* -attribute_list_dup (const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs); - -#endif diff --git a/src/identity-provider/identity_provider_api.c b/src/identity-provider/identity_provider_api.c index 6d28709dfe..6fc8d228a5 100644 --- a/src/identity-provider/identity_provider_api.c +++ b/src/identity-provider/identity_provider_api.c @@ -29,13 +29,12 @@ #include "gnunet_protocols.h" #include "gnunet_mq_lib.h" #include "gnunet_identity_provider_service.h" +#include "gnunet_identity_attribute_lib.h" #include "identity_provider.h" -#include "identity_attribute.h" #define LOG(kind,...) GNUNET_log_from (kind, "identity-api",__VA_ARGS__) - /** * Handle for an operation with the service. */ @@ -495,9 +494,9 @@ handle_consume_ticket_result (void *cls, return; { - struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs; - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le; - attrs = attribute_list_deserialize ((char*)&msg[1], + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; + attrs = GNUNET_IDENTITY_ATTRIBUTE_list_deserialize ((char*)&msg[1], attrs_len); if (NULL != op->ar_cb) { @@ -512,8 +511,8 @@ handle_consume_ticket_result (void *cls, for (le = attrs->list_head; NULL != le; le = le->next) op->ar_cb (op->cls, &msg->identity, - le->attribute); - attribute_list_destroy (attrs); + le->claim); + GNUNET_IDENTITY_ATTRIBUTE_list_destroy (attrs); } } op->ar_cb (op->cls, @@ -619,9 +618,9 @@ handle_attribute_result (void *cls, } { - struct GNUNET_IDENTITY_PROVIDER_Attribute *attr; - attr = attribute_deserialize ((char*)&msg[1], - attr_len); + struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr; + attr = GNUNET_IDENTITY_ATTRIBUTE_deserialize ((char*)&msg[1], + attr_len); if (NULL != it) { if (NULL != it->proc) @@ -905,7 +904,7 @@ GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h) struct GNUNET_IDENTITY_PROVIDER_Operation * GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, - const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr, + const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr, GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cont, void *cont_cls) { @@ -921,14 +920,14 @@ GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - attr_len = attribute_serialize_get_size (attr); + attr_len = GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (attr); op->env = GNUNET_MQ_msg_extra (sam, attr_len, GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE); sam->identity = *pkey; sam->id = htonl (op->r_id); - attribute_serialize (attr, + GNUNET_IDENTITY_ATTRIBUTE_serialize (attr, (char*)&sam[1]); sam->attr_len = htons (attr_len); @@ -941,24 +940,6 @@ GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle /** - * Create a new attribute. - * - * @param name the attribute name - * @param type the attribute type - * @param data the attribute value - * @param data_size the attribute value size - * @return the new attribute - */ -struct GNUNET_IDENTITY_PROVIDER_Attribute * -GNUNET_IDENTITY_PROVIDER_attribute_new (const char* attr_name, - uint32_t attr_type, - const void* data, - size_t data_size) -{ - return attribute_new (attr_name, attr_type, data, data_size); -} - -/** * List all attributes for a local identity. * This MUST lock the `struct GNUNET_IDENTITY_PROVIDER_Handle` * for any other calls than #GNUNET_IDENTITY_PROVIDER_get_attributes_next() and @@ -1089,7 +1070,7 @@ struct GNUNET_IDENTITY_PROVIDER_Operation * GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs, + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, GNUNET_IDENTITY_PROVIDER_TicketCallback cb, void *cb_cls) { @@ -1105,7 +1086,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - attr_len = attribute_list_serialize_get_size (attrs); + attr_len = GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (attrs); op->env = GNUNET_MQ_msg_extra (tim, attr_len, GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_TICKET); @@ -1113,7 +1094,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h tim->rp = *rp; tim->id = htonl (op->r_id); - attribute_list_serialize (attrs, + GNUNET_IDENTITY_ATTRIBUTE_list_serialize (attrs, (char*)&tim[1]); tim->attr_len = htons (attr_len); diff --git a/src/identity-provider/plugin_identity_provider_sqlite.c b/src/identity-provider/plugin_identity_provider_sqlite.c index c87f30e1ca..594e4788d4 100644 --- a/src/identity-provider/plugin_identity_provider_sqlite.c +++ b/src/identity-provider/plugin_identity_provider_sqlite.c @@ -27,7 +27,7 @@ #include "platform.h" #include "gnunet_identity_provider_service.h" #include "gnunet_identity_provider_plugin.h" -#include "identity_attribute.h" +#include "gnunet_identity_attribute_lib.h" #include "gnunet_sq_lib.h" #include <sqlite3.h> @@ -373,7 +373,7 @@ database_shutdown (struct Plugin *plugin) static int identity_provider_sqlite_store_ticket (void *cls, const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs) + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) { struct Plugin *plugin = cls; size_t attrs_len; @@ -402,9 +402,9 @@ identity_provider_sqlite_store_ticket (void *cls, GNUNET_SQ_reset (plugin->dbh, plugin->delete_ticket); - attrs_len = attribute_list_serialize_get_size (attrs); + attrs_len = GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (attrs); attrs_ser = GNUNET_malloc (attrs_len); - attribute_list_serialize (attrs, + GNUNET_IDENTITY_ATTRIBUTE_list_serialize (attrs, attrs_ser); struct GNUNET_SQ_QueryParam sparams[] = { GNUNET_SQ_query_param_auto_from_type (&ticket->identity), @@ -526,7 +526,7 @@ get_ticket_and_call_iterator (struct Plugin *plugin, void *iter_cls) { struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; - struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs; + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; int ret; int sret; size_t attrs_len; @@ -553,13 +553,13 @@ get_ticket_and_call_iterator (struct Plugin *plugin, } else { - attrs = attribute_list_deserialize (attrs_ser, + attrs = GNUNET_IDENTITY_ATTRIBUTE_list_deserialize (attrs_ser, attrs_len); if (NULL != iter) iter (iter_cls, &ticket, attrs); - attribute_list_destroy (attrs); + GNUNET_IDENTITY_ATTRIBUTE_list_destroy (attrs); ret = GNUNET_YES; } GNUNET_SQ_cleanup_result (rs); diff --git a/src/identity-provider/plugin_rest_identity_provider.c b/src/identity-provider/plugin_rest_identity_provider.c index ff28b592e3..d5e453a0e6 100644 --- a/src/identity-provider/plugin_rest_identity_provider.c +++ b/src/identity-provider/plugin_rest_identity_provider.c @@ -37,6 +37,7 @@ #include <jansson.h> #include <inttypes.h> #include "gnunet_signatures.h" +#include "gnunet_identity_attribute_lib.h" #include "gnunet_identity_provider_service.h" /** @@ -514,7 +515,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; struct MHD_Response *resp; - struct GNUNET_IDENTITY_PROVIDER_Attribute *attribute; + struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attribute; struct GNUNET_JSONAPI_Document *json_obj; struct GNUNET_JSONAPI_Resource *json_res; char term_data[handle->rest_handle->data_size+1]; @@ -602,8 +603,8 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, value_json = GNUNET_JSONAPI_resource_read_attr (json_res, "value"); value_str = json_string_value (value_json); - attribute = GNUNET_IDENTITY_PROVIDER_attribute_new (name_str, - GNUNET_IDENTITY_PROVIDER_AT_STRING, + attribute = GNUNET_IDENTITY_ATTRIBUTE_claim_new (name_str, + GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING, value_str, strlen (value_str) + 1); handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); @@ -625,7 +626,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, static void attr_collect (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr) + const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) { struct GNUNET_JSONAPI_Resource *json_resource; struct RequestHandle *handle = cls; @@ -839,7 +840,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_IDENTITY_PROVIDER_Attribute *attr) + const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) { struct RequestHandle *handle = cls; struct GNUNET_JSONAPI_Resource *json_resource; diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 2b6718557c..2fd67ae1b1 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -1115,6 +1115,16 @@ GNUNET_CRYPTO_ecdsa_public_key_to_string (const struct GNUNET_CRYPTO_EcdsaPublic /** + * Convert a private key to a string. + * + * @param priv key to convert + * @return string representing @a pub + */ +char * +GNUNET_CRYPTO_eddsa_private_key_to_string (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv); + + +/** * Convert a public key to a string. * * @param pub key to convert @@ -2021,13 +2031,14 @@ GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1, * @param pkey the public key of the signer * @param[out] buf set to a buffer with the blinded message to be signed * @param[out] buf_size number of bytes stored in @a buf - * @return GNUNET_YES if successful, GNUNET_NO if RSA key is malicious + * @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious */ int GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey, - char **buf, size_t *buf_size); + char **buf, + size_t *buf_size); /** @@ -2040,7 +2051,8 @@ GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, */ struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, - const void *msg, size_t msg_len); + const void *msg, + size_t msg_len); /** @@ -2110,7 +2122,7 @@ GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig); * @return unblinded signature on success, NULL if RSA key is bad or malicious. */ struct GNUNET_CRYPTO_RsaSignature * -GNUNET_CRYPTO_rsa_unblind (struct GNUNET_CRYPTO_RsaSignature *sig, +GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey); diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h index f707bb0919..e38925f147 100644 --- a/src/include/gnunet_getopt_lib.h +++ b/src/include/gnunet_getopt_lib.h @@ -230,11 +230,11 @@ GNUNET_GETOPT_option_filename (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_base32_fixed_size (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - void *val, - size_t val_size); + const char *name, + const char *argumentHelp, + const char *description, + void *val, + size_t val_size); /** @@ -264,9 +264,9 @@ GNUNET_GETOPT_option_base32_fixed_size (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag (char shortName, - const char *name, - const char *description, - int *val); + const char *name, + const char *description, + int *val); /** @@ -280,10 +280,10 @@ GNUNET_GETOPT_option_flag (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - unsigned int *val); + const char *name, + const char *argumentHelp, + const char *description, + unsigned int *val); /** @@ -297,10 +297,10 @@ GNUNET_GETOPT_option_uint (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_ulong (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - unsigned long long *val); + const char *name, + const char *argumentHelp, + const char *description, + unsigned long long *val); /** @@ -315,10 +315,10 @@ GNUNET_GETOPT_option_ulong (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - struct GNUNET_TIME_Relative *val); + const char *name, + const char *argumentHelp, + const char *description, + struct GNUNET_TIME_Relative *val); /** @@ -333,10 +333,10 @@ GNUNET_GETOPT_option_relative_time (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_absolute_time (char shortName, - const char *name, - const char *argumentHelp, - const char *description, - struct GNUNET_TIME_Absolute *val); + const char *name, + const char *argumentHelp, + const char *description, + struct GNUNET_TIME_Absolute *val); /** @@ -350,9 +350,9 @@ GNUNET_GETOPT_option_absolute_time (char shortName, */ struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_increment_uint (char shortName, - const char *name, - const char *description, - unsigned int *val); + const char *name, + const char *description, + unsigned int *val); /** diff --git a/src/include/gnunet_identity_attribute_lib.h b/src/include/gnunet_identity_attribute_lib.h new file mode 100644 index 0000000000..4c765515b7 --- /dev/null +++ b/src/include/gnunet_identity_attribute_lib.h @@ -0,0 +1,290 @@ +/* + This file is part of GNUnet. + Copyright (C) 2017 GNUnet e.V. + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +/** + * @author Martin Schanzenbach + * + * @file + * Identity attribute definitions + * + * @defgroup identity-provider Identity Provider service + * @{ + */ +#ifndef GNUNET_IDENTITY_ATTRIBUTE_LIB_H +#define GNUNET_IDENTITY_ATTRIBUTE_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_util_lib.h" + + +/** + * No value attribute. + */ +#define GNUNET_IDENTITY_ATTRIBUTE_TYPE_NONE 0 + +/** + * String attribute. + */ +#define GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING 1 + + + +/** + * An attribute. + */ +struct GNUNET_IDENTITY_ATTRIBUTE_Claim +{ + /** + * The name of the attribute. Note "name" must never be individually + * free'd + */ + const char* name; + + /** + * Type of Claim + */ + uint32_t type; + + /** + * Version + */ + uint32_t version; + + /** + * Number of bytes in @e data. + */ + size_t data_size; + + /** + * Binary value stored as attribute value. Note: "data" must never + * be individually 'malloc'ed, but instead always points into some + * existing data area. + */ + const void *data; + +}; + +struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList +{ + /** + * List head + */ + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *list_head; + + /** + * List tail + */ + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *list_tail; +}; + +struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry +{ + /** + * DLL + */ + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *prev; + + /** + * DLL + */ + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *next; + + /** + * The attribute claim + */ + struct GNUNET_IDENTITY_ATTRIBUTE_Claim *claim; +}; + +/** + * Create a new attribute claim. + * + * @param name the attribute name + * @param type the attribute type + * @param data the attribute value + * @param data_size the attribute value size + * @return the new attribute + */ +struct GNUNET_IDENTITY_ATTRIBUTE_Claim * +GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name, + uint32_t type, + const void* data, + size_t data_size); + + +/** + * Get required size for serialization buffer + * + * @param attrs the attribute list to serialize + * + * @return the required buffer size + */ +size_t +GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); + +void +GNUNET_IDENTITY_ATTRIBUTE_list_destroy (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); + + +/** + * Serialize an attribute list + * + * @param attrs the attribute list to serialize + * @param result the serialized attribute + * + * @return length of serialized data + */ +size_t +GNUNET_IDENTITY_ATTRIBUTE_list_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, + char *result); + +/** + * Deserialize an attribute list + * + * @param data the serialized attribute list + * @param data_size the length of the serialized data + * + * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller + */ +struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList * +GNUNET_IDENTITY_ATTRIBUTE_list_deserialize (const char* data, + size_t data_size); + + +/** + * Get required size for serialization buffer + * + * @param attr the attribute to serialize + * + * @return the required buffer size + */ +size_t +GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr); + + + +/** + * Serialize an attribute + * + * @param attr the attribute to serialize + * @param result the serialized attribute + * + * @return length of serialized data + */ +size_t +GNUNET_IDENTITY_ATTRIBUTE_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr, + char *result); + +/** + * Deserialize an attribute + * + * @param data the serialized attribute + * @param data_size the length of the serialized data + * + * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller + */ +struct GNUNET_IDENTITY_ATTRIBUTE_Claim * +GNUNET_IDENTITY_ATTRIBUTE_deserialize (const char* data, + size_t data_size); + +struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList* +GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); + +/** + * Convert a type name to the corresponding number + * + * @param typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +uint32_t +GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (const char *typename); + +/** + * Convert human-readable version of a 'claim' of an attribute to the binary + * representation + * + * @param type type of the claim + * @param s human-readable string + * @param data set to value in binary encoding (will be allocated) + * @param data_size set to number of bytes in @a data + * @return #GNUNET_OK on success + */ +int +GNUNET_IDENTITY_ATTRIBUTE_string_to_value (uint32_t type, + const char *s, + void **data, + size_t *data_size); + +/** + * Convert the 'claim' of an attribute to a string + * + * @param type the type of attribute + * @param data claim in binary encoding + * @param data_size number of bytes in @a data + * @return NULL on error, otherwise human-readable representation of the claim + */ +char * +GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type, + const void* data, + size_t data_size); + +/** + * Convert a type number to the corresponding type string + * + * @param type number of a type + * @return corresponding typestring, NULL on error + */ +const char* +GNUNET_IDENTITY_ATTRIBUTE_number_to_typename (uint32_t type); + + +/** + * Create a JWT from attributes + * + * @param sub_key the public of the subject + * @param attrs the attribute list + * @param priv_key the key used to sign the JWT + * @return a new base64-encoded JWT string. + */ +char* +GNUNET_IDENTITY_ATTRIBUTE_jwt_create_from_list (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key); + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* ifndef GNUNET_IDENTITY_ATTRIBUTE_LIB_H */ +#endif + +/** @} */ /* end of group identity */ + +/* end of gnunet_identity_attribute_lib.h */ diff --git a/src/include/gnunet_identity_attribute_plugin.h b/src/include/gnunet_identity_attribute_plugin.h new file mode 100644 index 0000000000..edeed57fd4 --- /dev/null +++ b/src/include/gnunet_identity_attribute_plugin.h @@ -0,0 +1,149 @@ +/* + This file is part of GNUnet + Copyright (C) 2012, 2013 GNUnet e.V. + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +/** + * @author Martin Schanzenbach + * + * @file + * Plugin API for the idp database backend + * + * @defgroup identity-provider-plugin IdP service plugin API + * Plugin API for the idp database backend + * @{ + */ +#ifndef GNUNET_IDENTITY_ATTRIBUTE_PLUGIN_H +#define GNUNET_IDENTITY_ATTRIBUTE_PLUGIN_H + +#include "gnunet_util_lib.h" +#include "gnunet_identity_attribute_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Function called to convert the binary value @a data of an attribute of + * type @a type to a human-readable string. + * + * @param cls closure + * @param type type of the attribute + * @param data value in binary encoding + * @param data_size number of bytes in @a data + * @return NULL on error, otherwise human-readable representation of the value + */ +typedef char * (*GNUNET_IDENTITY_ATTRIBUTE_ValueToStringFunction) (void *cls, + uint32_t type, + const void *data, + size_t data_size); + + +/** + * Function called to convert human-readable version of the value @a s + * of an attribute of type @a type to the respective binary + * representation. + * + * @param cls closure + * @param type type of the attribute + * @param s human-readable string + * @param data set to value in binary encoding (will be allocated) + * @param data_size set to number of bytes in @a data + * @return #GNUNET_OK on success + */ +typedef int (*GNUNET_IDENTITY_ATTRIBUTE_StringToValueFunction) (void *cls, + uint32_t type, + const char *s, + void **data, + size_t *data_size); + + +/** + * Function called to convert a type name to the + * corresponding number. + * + * @param cls closure + * @param typename name to convert + * @return corresponding number, UINT32_MAX on error + */ +typedef uint32_t (*GNUNET_IDENTITY_ATTRIBUTE_TypenameToNumberFunction) (void *cls, + const char *typename); + + +/** + * Function called to convert a type number (i.e. 1) to the + * corresponding type string + * + * @param cls closure + * @param type number of a type to convert + * @return corresponding typestring, NULL on error + */ +typedef const char * (*GNUNET_IDENTITY_ATTRIBUTE_NumberToTypenameFunction) (void *cls, + uint32_t type); + + +/** + * Each plugin is required to return a pointer to a struct of this + * type as the return value from its entry point. + */ +struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions +{ + + /** + * Closure for all of the callbacks. + */ + void *cls; + + /** + * Conversion to string. + */ + GNUNET_IDENTITY_ATTRIBUTE_ValueToStringFunction value_to_string; + + /** + * Conversion to binary. + */ + GNUNET_IDENTITY_ATTRIBUTE_StringToValueFunction string_to_value; + + /** + * Typename to number. + */ + GNUNET_IDENTITY_ATTRIBUTE_TypenameToNumberFunction typename_to_number; + + /** + * Number to typename. + */ + GNUNET_IDENTITY_ATTRIBUTE_NumberToTypenameFunction number_to_typename; + +}; + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif + +/** @} */ /* end of group */ diff --git a/src/include/gnunet_identity_provider_plugin.h b/src/include/gnunet_identity_provider_plugin.h index c0a258ab63..4b5098d585 100644 --- a/src/include/gnunet_identity_provider_plugin.h +++ b/src/include/gnunet_identity_provider_plugin.h @@ -51,7 +51,7 @@ extern "C" */ typedef void (*GNUNET_IDENTITY_PROVIDER_TicketIterator) (void *cls, const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs); + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); /** @@ -74,7 +74,7 @@ struct GNUNET_IDENTITY_PROVIDER_PluginFunctions */ int (*store_ticket) (void *cls, const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs); + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); /** * Delete a ticket from the database. @@ -111,7 +111,6 @@ struct GNUNET_IDENTITY_PROVIDER_PluginFunctions void *iter_cls); }; - #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_identity_provider_service.h b/src/include/gnunet_identity_provider_service.h index d17a1cc9ca..6bc05d0f4d 100644 --- a/src/include/gnunet_identity_provider_service.h +++ b/src/include/gnunet_identity_provider_service.h @@ -39,7 +39,7 @@ extern "C" #endif #include "gnunet_util_lib.h" - +#include "gnunet_identity_attribute_lib.h" /** * Version number of GNUnet Identity Provider API. @@ -82,92 +82,6 @@ struct GNUNET_IDENTITY_PROVIDER_Ticket */ struct GNUNET_IDENTITY_PROVIDER_Operation; -/** - * Flags that can be set for an attribute. - */ -enum GNUNET_IDENTITY_PROVIDER_AttributeType -{ - - /** - * No value attribute. - */ - GNUNET_IDENTITY_PROVIDER_AT_NULL = 0, - - /** - * String attribute. - */ - GNUNET_IDENTITY_PROVIDER_AT_STRING = 1, - -}; - - - -/** - * An attribute. - */ -struct GNUNET_IDENTITY_PROVIDER_Attribute -{ - - /** - * Type of Attribute. - */ - uint32_t attribute_type; - - /** - * Attribute version - */ - uint32_t attribute_version; - - /** - * Number of bytes in @e data. - */ - size_t data_size; - - /** - * The name of the attribute. Note "name" must never be individually - * free'd - */ - const char* name; - - /** - * Binary value stored as attribute value. Note: "data" must never - * be individually 'malloc'ed, but instead always points into some - * existing data area. - */ - const void *data; - -}; - -struct GNUNET_IDENTITY_PROVIDER_AttributeList -{ - /** - * List head - */ - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *list_head; - - /** - * List tail - */ - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *list_tail; -}; - -struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry -{ - /** - * DLL - */ - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *prev; - - /** - * DLL - */ - struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *next; - - /** - * The attribute - */ - struct GNUNET_IDENTITY_PROVIDER_Attribute *attribute; -}; /** * Connect to the identity provider service. @@ -208,27 +122,12 @@ typedef void struct GNUNET_IDENTITY_PROVIDER_Operation * GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, - const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr, + const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr, GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cont, void *cont_cls); /** - * Create a new attribute. - * - * @param name the attribute name - * @param type the attribute type - * @param data the attribute value - * @param data_size the attribute value size - * @return the new attribute - */ -struct GNUNET_IDENTITY_PROVIDER_Attribute * -GNUNET_IDENTITY_PROVIDER_attribute_new (const char* attr_name, - uint32_t attr_type, - const void* data, - size_t data_size); - -/** * Process an attribute that was stored in the idp. * * @param cls closure @@ -237,7 +136,7 @@ GNUNET_IDENTITY_PROVIDER_attribute_new (const char* attr_name, typedef void (*GNUNET_IDENTITY_PROVIDER_AttributeResult) (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, - const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr); + const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr); @@ -327,7 +226,7 @@ struct GNUNET_IDENTITY_PROVIDER_Operation * GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *id, const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, - const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs, + const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, GNUNET_IDENTITY_PROVIDER_TicketCallback cb, void *cb_cls); diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h index f2682bea7d..c12badcd9c 100644 --- a/src/include/gnunet_json_lib.h +++ b/src/include/gnunet_json_lib.h @@ -343,6 +343,16 @@ GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp); /** + * Convert absolute timestamp to a json string. + * + * @param stamp the time stamp + * @return a json string with the timestamp in @a stamp + */ +json_t * +GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp); + + +/** * Convert relative timestamp to a json string. * * @param stamp the time stamp diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h index 875f5043a4..a855ab8aba 100644 --- a/src/include/gnunet_scheduler_lib.h +++ b/src/include/gnunet_scheduler_lib.h @@ -400,6 +400,22 @@ void GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task, void *task_cls); +/** + * Initialize and run scheduler. This function will return when all + * tasks have completed. When @ install_signals is GNUNET_YES, then + * this function behaves in the same was as GNUNET_SCHEDULER_run does. + * If @ install_signals is GNUNET_NO then no signal handlers are + * installed. + * + * @param install_signals whether to install signals (GNUNET_YES/NO) + * @param task task to run first (and immediately) + * @param task_cls closure of @a task + */ +void +GNUNET_SCHEDULER_run_with_optional_signals (int install_signals, + GNUNET_SCHEDULER_TaskCallback task, + void *task_cls); + /** * Request the shutdown of a scheduler. Marks all tasks diff --git a/src/integration-tests/Makefile.am b/src/integration-tests/Makefile.am index 6fff0b407b..368980064e 100644 --- a/src/integration-tests/Makefile.am +++ b/src/integration-tests/Makefile.am @@ -42,7 +42,8 @@ endif do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' -%.py: %.py.in Makefile +SUFFIXES = .py.in .py +.py.in.py: $(do_subst) < $(srcdir)/$< > $@ chmod +x $@ diff --git a/src/json/json_generator.c b/src/json/json_generator.c index e660e10c53..98f7163bcc 100644 --- a/src/json/json_generator.c +++ b/src/json/json_generator.c @@ -73,6 +73,19 @@ GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp) /** + * Convert absolute timestamp to a json string. + * + * @param stamp the time stamp + * @return a json string with the timestamp in @a stamp + */ +json_t * +GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp) +{ + return GNUNET_JSON_from_time_abs (GNUNET_TIME_absolute_ntoh (stamp)); +} + + +/** * Convert relative timestamp to a json string. * * @param stamp the time stamp diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 9d077f874d..8281e9a166 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c @@ -509,6 +509,7 @@ transmit_task_cb (void *cls) "Starting set exchange with peer `%s'\n", GNUNET_i2s (&peer_entry->id)); peer_entry->transmit_task = NULL; + GNUNET_assert (NULL == peer_entry->so); peer_entry->so = GNUNET_SET_prepare (&peer_entry->id, &revocation_set_union_app_id, NULL, @@ -758,6 +759,7 @@ handle_revocation_union_request (void *cls, { peer_entry = new_peer_entry (other_peer); } + GNUNET_assert (NULL == peer_entry->so); peer_entry->so = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED, (struct GNUNET_SET_Option[]) {{ 0 }}, diff --git a/src/secretsharing/Makefile.am b/src/secretsharing/Makefile.am index 5ab8739af0..c808e82006 100644 --- a/src/secretsharing/Makefile.am +++ b/src/secretsharing/Makefile.am @@ -47,7 +47,7 @@ libgnunetsecretsharing_la_SOURCES = \ secretsharing_api.c \ secretsharing_common.c \ secretsharing.h -libgnunetsecretsharing_la_LIBADD = \ +libgnunetsecretsharing_la_LIBADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(LIBGCRYPT_LIBS) \ $(LTLIBINTL) diff --git a/src/social/gnunet-social.c b/src/social/gnunet-social.c index 0e52dccfa0..de680b11c5 100644 --- a/src/social/gnunet-social.c +++ b/src/social/gnunet-social.c @@ -281,7 +281,7 @@ exit_fail () * This also indicates the end of the connection to the service. */ static void -host_left () +host_left (void *cls) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "The host has left the place.\n"); diff --git a/src/social/social_api.c b/src/social/social_api.c index af1d6e57ee..d57d16cfbe 100644 --- a/src/social/social_api.c +++ b/src/social/social_api.c @@ -2693,6 +2693,8 @@ GNUNET_SOCIAL_app_disconnect (struct GNUNET_SOCIAL_App *app, GNUNET_ContinuationCallback disconnect_cb, void *disconnect_cls) { + if (NULL == app) return; + app->disconnect_cb = disconnect_cb; app->disconnect_cls = disconnect_cls; diff --git a/src/sq/sq_result_helper.c b/src/sq/sq_result_helper.c index 9579863b23..f2986a0532 100644 --- a/src/sq/sq_result_helper.c +++ b/src/sq/sq_result_helper.c @@ -620,7 +620,7 @@ extract_uint16 (void *cls, void *dst) { uint64_t v; - uint32_t *u = dst; + uint16_t *u = dst; GNUNET_assert (sizeof (uint16_t) == *dst_size); if (SQLITE_INTEGER != diff --git a/src/statistics/Makefile.am b/src/statistics/Makefile.am index b2e256960e..16a1ea2d0f 100644 --- a/src/statistics/Makefile.am +++ b/src/statistics/Makefile.am @@ -90,7 +90,8 @@ endif do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' -%.py: %.py.in Makefile +SUFFIXES = .py.in .py +.py.in.py: $(do_subst) < $(srcdir)/$< > $@ chmod +x $@ diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c index 7bc36d1b47..7d0ccd269a 100644 --- a/src/testbed/testbed_api_topology.c +++ b/src/testbed/testbed_api_topology.c @@ -1051,7 +1051,7 @@ gen_topo_from_file (struct TopologyContext *tc, state = PEER_INDEX; while (offset < fs) { - if (0 != isspace (data[offset])) + if (0 != isspace ((unsigned char) data[offset])) { offset++; continue; diff --git a/src/topology/friends.c b/src/topology/friends.c index a960fad174..65f2700bb3 100644 --- a/src/topology/friends.c +++ b/src/topology/friends.c @@ -95,7 +95,7 @@ GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg, pos = 0; while (pos < fsize) { - while ((pos < fsize) && (! isspace ((int) data[pos]))) + while ((pos < fsize) && (! isspace ((unsigned char) data[pos]))) pos++; if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (&data[start], diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index ec4d821649..6b354df986 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -541,6 +541,13 @@ client_disconnect_cb (void *cls, GNUNET_CONTAINER_multipeermap_iterate (active_stccs, &mark_match_down, tc); + for (struct AddressToStringContext *cur = a2s_head; + NULL != cur; + cur = cur->next) + { + if (cur->tc == tc) + cur->tc = NULL; + } GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); @@ -864,6 +871,8 @@ transmit_address_to_client (void *cls, GNUNET_assert ( (GNUNET_OK == res) || (GNUNET_SYSERR == res) ); + if (NULL == actx->tc) + return; if (NULL == buf) { env = GNUNET_MQ_msg (atsm, @@ -878,6 +887,7 @@ transmit_address_to_client (void *cls, GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx); + GNUNET_free (actx); return; } if (GNUNET_SYSERR == res) diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c index a20c998b34..c780f9a78f 100644 --- a/src/transport/gnunet-service-transport_ats.c +++ b/src/transport/gnunet-service-transport_ats.c @@ -344,8 +344,7 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address, } if (NULL == ai->ar) { - /* already blocked, how did it get used!? */ - GNUNET_break (0); + /* already blocked but this might be a blacklist check callback */ return; } ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off); diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 4a6d427bec..27c3c70419 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c @@ -784,15 +784,24 @@ revalidate_address (void *cls) GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# address revalidations started"), 1, GNUNET_NO); + if (NULL != ve->bc) + { + GST_blacklist_test_cancel (ve->bc); + ve->bc = NULL; + } bc = GST_blacklist_test_allowed (&ve->address->peer, - ve->address->transport_name, + ve->address->transport_name, &transmit_ping_if_allowed, - ve, - NULL, - NULL); + ve, + NULL, + NULL); if (NULL != bc) - ve->bc = bc; /* only set 'bc' if 'transmit_ping_if_allowed' was not already - * called... */ + { + /* If transmit_ping_if_allowed was already called it may have freed ve, + * so only set ve->bc if it has not been called. + */ + ve->bc = bc; + } } diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c index 595177e036..06275055da 100644 --- a/src/transport/test_transport_testing_restart.c +++ b/src/transport/test_transport_testing_restart.c @@ -71,7 +71,8 @@ restart_cb (void *cls) p->no, GNUNET_i2s (&p->id)); ret = 0; - end (); + GNUNET_SCHEDULER_add_now (&end, + NULL); } diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c index 6ac0250cc0..931e922c47 100644 --- a/src/transport/test_transport_testing_startstop.c +++ b/src/transport/test_transport_testing_startstop.c @@ -71,7 +71,8 @@ start_cb (void *cls) p->no, GNUNET_i2s (&p->id)); ret = 0; - end (); + GNUNET_SCHEDULER_add_now (&end, + NULL); } diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 2aa6cdbb0e..68cda3bd7e 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c @@ -384,7 +384,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth { char *emsg = NULL; struct GNUNET_TRANSPORT_TESTING_PeerContext *p; - struct GNUNET_PeerIdentity *dummy; + struct GNUNET_PeerIdentity dummy; unsigned int i; if (GNUNET_NO == GNUNET_DISK_file_test (cfgname)) @@ -678,6 +678,11 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext GNUNET_CONFIGURATION_destroy (p->cfg); p->cfg = NULL; } + if (NULL != p->handlers) + { + GNUNET_free (p->handlers); + p->handlers = NULL; + } GNUNET_CONTAINER_DLL_remove (tth->p_head, tth->p_tail, p); diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index eaa49a9919..7845932ee7 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c @@ -354,6 +354,37 @@ GNUNET_CRYPTO_eddsa_public_key_to_string (const struct GNUNET_CRYPTO_EddsaPublic /** + * Convert a private key to a string. + * + * @param priv key to convert + * @return string representing @a pub + */ +char * +GNUNET_CRYPTO_eddsa_private_key_to_string (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) +{ + char *privkeybuf; + size_t keylen = (sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8; + char *end; + + if (keylen % 5 > 0) + keylen += 5 - keylen % 5; + keylen /= 5; + privkeybuf = GNUNET_malloc (keylen + 1); + end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv, + sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey), + privkeybuf, + keylen); + if (NULL == end) + { + GNUNET_free (privkeybuf); + return NULL; + } + *end = '\0'; + return privkeybuf; +} + + +/** * Convert a string representing a public key to a public key. * * @param enc encoded public key @@ -374,9 +405,10 @@ GNUNET_CRYPTO_ecdsa_public_key_from_string (const char *enc, if (enclen != keylen) return GNUNET_SYSERR; - if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen, - pub, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) + if (GNUNET_OK != + GNUNET_STRINGS_string_to_data (enc, enclen, + pub, + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) return GNUNET_SYSERR; return GNUNET_OK; } @@ -403,9 +435,10 @@ GNUNET_CRYPTO_eddsa_public_key_from_string (const char *enc, if (enclen != keylen) return GNUNET_SYSERR; - if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen, - pub, - sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))) + if (GNUNET_OK != + GNUNET_STRINGS_string_to_data (enc, enclen, + pub, + sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))) return GNUNET_SYSERR; return GNUNET_OK; } diff --git a/src/util/crypto_paillier.c b/src/util/crypto_paillier.c index 3ed025a2ac..530a2957fc 100644 --- a/src/util/crypto_paillier.c +++ b/src/util/crypto_paillier.c @@ -370,9 +370,11 @@ GNUNET_CRYPTO_paillier_decrypt (const struct GNUNET_CRYPTO_PaillierPrivateKey *p /* mod = cmum1 / n (mod n) */ GNUNET_assert (0 != (mod = gcry_mpi_new (0))); gcry_mpi_div (mod, NULL, cmum1, n, 0); + gcry_mpi_release (cmum1); /* m = mod * mu mod n */ gcry_mpi_mulm (m, mod, mu, n); + gcry_mpi_release (mod); gcry_mpi_release (mu); gcry_mpi_release (n); } diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 7a108c21b1..a985d8e596 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -1046,7 +1046,7 @@ GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key) * @return unblinded signature on success, NULL if RSA key is bad or malicious. */ struct GNUNET_CRYPTO_RsaSignature * -GNUNET_CRYPTO_rsa_unblind (struct GNUNET_CRYPTO_RsaSignature *sig, +GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey) { diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c index 42ecc2101d..66a4bd3e91 100644 --- a/src/util/gnunet-ecc.c +++ b/src/util/gnunet-ecc.c @@ -49,6 +49,11 @@ static unsigned int list_keys_count; static int print_public_key; /** + * Flag for printing private key. + */ +static int print_private_key; + +/** * Flag for printing public key in hex. */ static int print_public_key_hex; @@ -377,7 +382,7 @@ run (void *cls, char *const *args, const char *cfgfile, create_keys (args[0], args[1]); return; } - if (print_public_key || print_public_key_hex) + if (print_public_key || print_public_key_hex || print_private_key) { char *str; struct GNUNET_DISK_FileHandle *keyfile; @@ -388,19 +393,26 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_DISK_PERM_NONE); if (NULL == keyfile) return; - while (sizeof (pk) == GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk))) + while (sizeof (pk) == + GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk))) { GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub); if (print_public_key_hex) { print_hex ("HEX:", &pub, sizeof (pub)); } - else + else if (print_public_key) { str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); FPRINTF (stdout, "%s\n", str); GNUNET_free (str); } + else if (print_private_key) + { + str = GNUNET_CRYPTO_eddsa_private_key_to_string (&pk); + FPRINTF (stdout, "%s\n", str); + GNUNET_free (str); + } } GNUNET_DISK_file_close (keyfile); } @@ -438,6 +450,10 @@ main (int argc, "print-public-key", gettext_noop ("print the public key in ASCII format"), &print_public_key), + GNUNET_GETOPT_option_flag ('P', + "print-private-key", + gettext_noop ("print the private key in ASCII format"), + &print_private_key), GNUNET_GETOPT_option_flag ('x', "print-hex", gettext_noop ("print the public key in HEX format"), diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 33a340729d..11b8134d6d 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c @@ -469,6 +469,7 @@ handle_response (void *cls, uint16_t size; char *nret; + GNUNET_assert (NULL != rh); size = ntohs (msg->size); if (size == sizeof (struct GNUNET_MessageHeader)) { diff --git a/src/util/scheduler.c b/src/util/scheduler.c index e9c25d68a8..540a605573 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c @@ -787,6 +787,14 @@ void GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task, void *task_cls) { + GNUNET_SCHEDULER_run_with_optional_signals(GNUNET_YES, task, task_cls); +} + +void +GNUNET_SCHEDULER_run_with_optional_signals (int install_signals, + GNUNET_SCHEDULER_TaskCallback task, + void *task_cls) +{ struct GNUNET_NETWORK_FDSet *rs; struct GNUNET_NETWORK_FDSet *ws; struct GNUNET_TIME_Relative timeout; @@ -820,24 +828,29 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task, GNUNET_DISK_PIPE_END_READ); GNUNET_assert (NULL != pr); my_pid = getpid (); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Registering signal handlers\n"); - shc_int = GNUNET_SIGNAL_handler_install (SIGINT, + + if (GNUNET_YES == install_signals) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Registering signal handlers\n"); + shc_int = GNUNET_SIGNAL_handler_install (SIGINT, + &sighandler_shutdown); + shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); - shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, - &sighandler_shutdown); #if (SIGTERM != GNUNET_TERM_SIG) - shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG, + shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG, &sighandler_shutdown); #endif #ifndef MINGW - shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE, + shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE, &sighandler_pipe); - shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, + shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, &sighandler_shutdown); - shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, + shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown); #endif + } + current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; current_lifeness = GNUNET_YES; GNUNET_SCHEDULER_add_with_reason_and_priority (task, @@ -953,16 +966,21 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task, busy_wait_warning = 0; } } - GNUNET_SIGNAL_handler_uninstall (shc_int); - GNUNET_SIGNAL_handler_uninstall (shc_term); + + if (GNUNET_YES == install_signals) + { + GNUNET_SIGNAL_handler_uninstall (shc_int); + GNUNET_SIGNAL_handler_uninstall (shc_term); #if (SIGTERM != GNUNET_TERM_SIG) - GNUNET_SIGNAL_handler_uninstall (shc_gterm); + GNUNET_SIGNAL_handler_uninstall (shc_gterm); #endif #ifndef MINGW - GNUNET_SIGNAL_handler_uninstall (shc_pipe); - GNUNET_SIGNAL_handler_uninstall (shc_quit); - GNUNET_SIGNAL_handler_uninstall (shc_hup); + GNUNET_SIGNAL_handler_uninstall (shc_pipe); + GNUNET_SIGNAL_handler_uninstall (shc_quit); + GNUNET_SIGNAL_handler_uninstall (shc_hup); #endif + } + GNUNET_DISK_pipe_close (shutdown_pipe_handle); shutdown_pipe_handle = NULL; GNUNET_NETWORK_fdset_destroy (rs); diff --git a/src/util/test_crypto_paillier.c b/src/util/test_crypto_paillier.c index 9950978c14..1e7e0b301a 100644 --- a/src/util/test_crypto_paillier.c +++ b/src/util/test_crypto_paillier.c @@ -37,6 +37,7 @@ test_crypto () struct GNUNET_CRYPTO_PaillierCiphertext ciphertext; struct GNUNET_CRYPTO_PaillierPublicKey public_key; struct GNUNET_CRYPTO_PaillierPrivateKey private_key; + int ret = 0; GNUNET_CRYPTO_paillier_create (&public_key, &private_key); @@ -54,7 +55,6 @@ test_crypto () &public_key, &ciphertext, plaintext_result); - if (0 != gcry_mpi_cmp (plaintext, plaintext_result)) { @@ -65,9 +65,11 @@ test_crypto () plaintext); gcry_log_debugmpi ("\n", plaintext_result); - return 1; + ret = 1; } - return 0; + gcry_mpi_release (plaintext); + gcry_mpi_release (plaintext_result); + return ret; } @@ -84,6 +86,7 @@ test_hom_simple (unsigned int a, struct GNUNET_CRYPTO_PaillierCiphertext c_result; struct GNUNET_CRYPTO_PaillierPublicKey public_key; struct GNUNET_CRYPTO_PaillierPrivateKey private_key; + int ret = 0; GNUNET_CRYPTO_paillier_create (&public_key, &private_key); @@ -119,9 +122,13 @@ test_hom_simple (unsigned int a, "GNUNET_CRYPTO_paillier failed simple math!\n"); gcry_log_debugmpi ("got ", hom_result); gcry_log_debugmpi ("wanted ", result); - return 1; + ret = 1; } - return 0; + gcry_mpi_release (m1); + gcry_mpi_release (m2); + gcry_mpi_release (result); + gcry_mpi_release (hom_result); + return ret; } @@ -168,7 +175,8 @@ test_hom () fprintf (stderr, "GNUNET_CRYPTO_paillier_encrypt 1 failed, should return 1 allowed operation, got %d!\n", ret); - return 1; + ret = 1; + goto out; } if (2 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m2, @@ -178,7 +186,8 @@ test_hom () fprintf (stderr, "GNUNET_CRYPTO_paillier_encrypt 2 failed, should return 2 allowed operation, got %d!\n", ret); - return 1; + ret = 1; + goto out; } if (0 != (ret = GNUNET_CRYPTO_paillier_hom_add (&public_key, @@ -189,7 +198,8 @@ test_hom () fprintf (stderr, "GNUNET_CRYPTO_paillier_hom_add failed, expected 0 remaining operations, got %d!\n", ret); - return 1; + ret = 1; + goto out; } GNUNET_CRYPTO_paillier_decrypt (&private_key, @@ -203,9 +213,14 @@ test_hom () "GNUNET_CRYPTO_paillier miscalculated with large numbers!\n"); gcry_log_debugmpi ("got", hom_result); gcry_log_debugmpi ("wanted", result); - return 1; + ret = 1; } - return 0; +out: + gcry_mpi_release (m1); + gcry_mpi_release (m2); + gcry_mpi_release (result); + gcry_mpi_release (hom_result); + return ret; } diff --git a/src/util/test_mq.c b/src/util/test_mq.c index 442c110dbd..9e8fc844ee 100644 --- a/src/util/test_mq.c +++ b/src/util/test_mq.c @@ -51,6 +51,7 @@ test1 () GNUNET_assert (NULL != mm); GNUNET_assert (42 == ntohs (mm->header.type)); GNUNET_assert (sizeof (struct MyMessage) == ntohs (mm->header.size)); + GNUNET_MQ_discard (mqm); } |