summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-08-17 17:06:36 +0200
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-08-17 17:06:36 +0200
commit31487d74b36541f0d97caf6d844da52a7667cd97 (patch)
treeff42114d4167d823140d2d4e814703467ac7bad0
parenta6581f9ede6cae352c71a4a632513d74bb45695a (diff)
issue done
-rw-r--r--src/include/gnunet_zklaim_service.h17
-rw-r--r--src/zklaim/Makefile.am16
-rw-r--r--src/zklaim/gnunet-service-zklaim.c19
-rw-r--r--src/zklaim/gnunet-zklaim.c91
-rw-r--r--src/zklaim/plugin_gnsrecord_zklaim.c178
-rw-r--r--src/zklaim/zklaim_api.c30
-rw-r--r--src/zklaim/zklaim_functions.c14
-rw-r--r--src/zklaim/zklaim_functions.h2
8 files changed, 336 insertions, 31 deletions
diff --git a/src/include/gnunet_zklaim_service.h b/src/include/gnunet_zklaim_service.h
index 0a551e703..f4337966b 100644
--- a/src/include/gnunet_zklaim_service.h
+++ b/src/include/gnunet_zklaim_service.h
@@ -146,6 +146,23 @@ GNUNET_ZKLAIM_context_create (struct GNUNET_ZKLAIM_Handle *h,
GNUNET_ZKLAIM_ContinuationWithStatus cont,
void *cont_cls);
+int
+GNUNET_ZKLAIM_issue_from_context (struct GNUNET_ZKLAIM_Context *ctx,
+ struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
+ GNUNET_ZKLAIM_PayloadIterator iter,
+ void* iter_cls);
+
+/**
+ * Lookup context
+ */
+struct GNUNET_ZKLAIM_Operation*
+GNUNET_ZKLAIM_lookup_context (struct GNUNET_ZKLAIM_Handle *h,
+ const char *name,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
+ GNUNET_ZKLAIM_ContextResult cont,
+ void* cont_cls);
+
+
/**
* Disconnect from service.
*
diff --git a/src/zklaim/Makefile.am b/src/zklaim/Makefile.am
index b28683d1a..22600c882 100644
--- a/src/zklaim/Makefile.am
+++ b/src/zklaim/Makefile.am
@@ -12,8 +12,12 @@ if USE_COVERAGE
XLIB = -lgcov
endif
+pkgcfg_DATA = \
+ zklaim.conf
+
plugin_LTLIBRARIES = \
- libgnunet_plugin_reclaim_attribute_zklaim.la
+ libgnunet_plugin_reclaim_attribute_zklaim.la \
+ libgnunet_plugin_gnsrecord_zklaim.la
lib_LTLIBRARIES = \
libgnunetzklaim.la
@@ -21,6 +25,16 @@ lib_LTLIBRARIES = \
libexec_PROGRAMS = \
gnunet-service-zklaim
+libgnunet_plugin_gnsrecord_zklaim_la_SOURCES = \
+ plugin_gnsrecord_zklaim.c
+libgnunet_plugin_gnsrecord_zklaim_la_LIBADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(LTLIBINTL)
+libgnunet_plugin_gnsrecord_zklaim_la_LDFLAGS = \
+ $(GN_PLUGIN_LDFLAGS)
+
+
+
libgnunetzklaim_la_SOURCES = \
zklaim_api.c \
zklaim_functions.c
diff --git a/src/zklaim/gnunet-service-zklaim.c b/src/zklaim/gnunet-service-zklaim.c
index 100a87f07..baf6b20de 100644
--- a/src/zklaim/gnunet-service-zklaim.c
+++ b/src/zklaim/gnunet-service-zklaim.c
@@ -221,7 +221,6 @@ cleanup_create_handle (struct CreateContextHandle *handle)
if (NULL != handle->ns_qe)
GNUNET_NAMESTORE_cancel (handle->ns_qe);
GNUNET_free_non_null (handle->name);
- GNUNET_free_non_null (handle->name);
GNUNET_free_non_null (handle->attrs);
GNUNET_free (handle);
}
@@ -241,10 +240,10 @@ send_result (int32_t status,
r_msg->result_code = htonl (status);
GNUNET_MQ_send (cch->client->mq,
env);
- cleanup_create_handle (cch);
GNUNET_CONTAINER_DLL_remove (cch->client->create_op_head,
cch->client->create_op_tail,
cch);
+ cleanup_create_handle (cch);
}
static void
@@ -299,7 +298,7 @@ handle_create_context_message (void *cls,
int i;
zklaim_ctx *ctx;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
"Received CREATE_REQUEST message\n");
str_len = ntohs (crm->name_len);
@@ -307,6 +306,7 @@ handle_create_context_message (void *cls,
cch = GNUNET_new (struct CreateContextHandle);
cch->name = GNUNET_strndup ((char*)&crm[1], str_len-1);
str_len = ntohs(crm->attrs_len);
+ fprintf(stderr, "%s\n", cch->name);
cch->attrs = GNUNET_strndup (((char*)&crm[1]) + strlen (cch->name) + 1,
str_len-1);
cch->private_key = crm->private_key;
@@ -336,12 +336,14 @@ handle_create_context_message (void *cls,
pos = strtok(NULL, ",");
}
GNUNET_free (tmp);
- num_pl = num_attrs / 5;
- zklaim_payload pl[num_pl];
+ num_pl = (num_attrs / 5) + 1;
+ zklaim_payload *pl = GNUNET_malloc (num_pl * sizeof (zklaim_payload));
ctx = zklaim_context_new ();
for (i = 0; i < num_pl; i++)
zklaim_add_pl (ctx, pl[i]);
zklaim_hash_ctx (ctx);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Starting trusted setup (%d payloads)... this might take a while...\n", num_pl);
if (0 != zklaim_trusted_setup (ctx))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -350,6 +352,8 @@ handle_create_context_message (void *cls,
zklaim_ctx_free (ctx);
return;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Finished trusted setup.\n");
data_len = zklaim_ctx_serialize (ctx, &data);
rdata_len = data_len + strlen (cch->attrs) + 1;
zklaim_ctx_free (ctx);
@@ -411,10 +415,11 @@ send_ctx_result (struct LookupHandle *lh,
len);
GNUNET_MQ_send (lh->client->mq,
env);
- cleanup_lookup_handle (lh);
GNUNET_CONTAINER_DLL_remove (lh->client->lookup_op_head,
lh->client->lookup_op_tail,
lh);
+
+ cleanup_lookup_handle (lh);
}
@@ -439,7 +444,7 @@ ctx_found_cb (void *cls,
const struct GNUNET_GNSRECORD_Data *rd)
{
struct LookupHandle *lh = cls;
-
+ lh->ns_qe = NULL;
send_ctx_result (lh, (char*) rd->data, rd->data_size);
}
diff --git a/src/zklaim/gnunet-zklaim.c b/src/zklaim/gnunet-zklaim.c
index 053482362..a97bca5d4 100644
--- a/src/zklaim/gnunet-zklaim.c
+++ b/src/zklaim/gnunet-zklaim.c
@@ -55,6 +55,11 @@ static char* context_name;
static char* issue_attrs;
/**
+ * Attribute names for issuer context data
+ */
+static char* create_attrs;
+
+/**
* Ego name
*/
static char* ego_name;
@@ -119,25 +124,97 @@ context_create_cb (void *cls,
int32_t success,
const char* emsg)
{
+ if (GNUNET_OK == success)
+ fprintf (stdout,
+ "Created.\n");
+ else
+ fprintf(stderr,
+ "Failed.\n");
+ if (NULL == cleanup_task)
+ cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
+ return;
+}
+
+static void
+issue_iter (void *cls,
+ const char* attr_name,
+ uint64_t *data)
+{
+ char *tmp;
+ char *key;
+ char *val;
+ tmp = GNUNET_strdup (issue_attrs);
+ key = strtok (tmp, "=");
+ while (NULL != key)
+ {
+ val = strtok (NULL, ";");
+ if (0 != strcmp (attr_name, key))
+ {
+ key = strtok (NULL, "=");
+ continue;
+ }
+ if (1 != sscanf (val, "%lu", data))
+ fprintf (stderr,
+ "Failed to fill %s with %s\n",
+ key, val);
+ key = strtok (NULL, "=");
+ }
+ GNUNET_free (tmp);
+ fprintf (stdout, "Setting %s=%lu\n", attr_name, *data);
+}
+
+static void
+context_cb (void *cls,
+ const struct GNUNET_ZKLAIM_Context *ctx)
+{
+ int ret;
+ if (NULL == ctx)
+ {
+ fprintf (stderr,
+ "Context does not exist!\n");
+ }
+ else
+ {
+ ret = GNUNET_ZKLAIM_issue_from_context ((struct GNUNET_ZKLAIM_Context*)ctx,
+ (struct GNUNET_CRYPTO_EcdsaPrivateKey*)pkey,
+ &issue_iter,
+ NULL);
+ fprintf (stdout,
+ "Issued (%d)\n", ret);
+ }
+ if (NULL == cleanup_task)
+ cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
return;
+
}
static void
handle_arguments ()
{
- timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
+ timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60),
&timeout_task,
NULL);
if (create)
{
+ fprintf (stdout,
+ "Creating context...\n");
zklaim_op = GNUNET_ZKLAIM_context_create (zklaim_handle,
pkey,
context_name,
- issue_attrs,
+ create_attrs,
&context_create_cb,
NULL);
return;
}
+ if (issue_attrs)
+ {
+ zklaim_op = GNUNET_ZKLAIM_lookup_context (zklaim_handle,
+ context_name,
+ pkey,
+ &context_cb,
+ NULL);
+ return;
+ }
cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
}
@@ -182,7 +259,7 @@ run (void *cls,
_("Context name missing!\n"));
return;
}
- if ( (create) && (NULL == issue_attrs) )
+ if ( (create) && (NULL == create_attrs) )
{
ret = 1;
fprintf (stderr,
@@ -192,6 +269,7 @@ run (void *cls,
zklaim_handle = GNUNET_ZKLAIM_connect (c);
//Get Ego
+ init = GNUNET_YES;
identity_handle = GNUNET_IDENTITY_connect (c,
&ego_cb,
NULL);
@@ -215,7 +293,7 @@ main(int argc, char *const argv[])
"attributes",
NULL,
gettext_noop ("Context attributes (comma separated)"),
- &issue_attrs),
+ &create_attrs),
GNUNET_GETOPT_option_string ('e',
"ego",
NULL,
@@ -225,6 +303,11 @@ main(int argc, char *const argv[])
"create",
gettext_noop ("Create new issuer context"),
&create),
+ GNUNET_GETOPT_option_string ('I',
+ "issue",
+ gettext_noop ("Issue a credential with the given attributes and given zklaim context"),
+ NULL,
+ &issue_attrs),
GNUNET_GETOPT_OPTION_END
};
if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",
diff --git a/src/zklaim/plugin_gnsrecord_zklaim.c b/src/zklaim/plugin_gnsrecord_zklaim.c
new file mode 100644
index 000000000..7e032d210
--- /dev/null
+++ b/src/zklaim/plugin_gnsrecord_zklaim.c
@@ -0,0 +1,178 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 2013, 2014 GNUnet e.V.
+
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ 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
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file zklaim/plugin_gnsrecord_zklaim.c
+ * @brief gnsrecord plugin to provide the API for identity records
+ * @author Martin Schanzenbach
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_gnsrecord_lib.h"
+#include "gnunet_gnsrecord_plugin.h"
+
+
+/**
+ * Convert the 'value' of a record to a string.
+ *
+ * @param cls closure, unused
+ * @param type type of the record
+ * @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 *
+value_to_string (void *cls,
+ uint32_t type,
+ const void *data,
+ size_t data_size)
+{
+ switch (type)
+ {
+ case GNUNET_GNSRECORD_TYPE_ZKLAIM_CTX:
+ return GNUNET_STRINGS_data_to_string_alloc (data, data_size);
+ default:
+ return NULL;
+ }
+}
+
+
+/**
+ * Convert human-readable version of a 'value' of a record to the binary
+ * representation.
+ *
+ * @param cls closure, unused
+ * @param type type of the record
+ * @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
+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_GNSRECORD_TYPE_ZKLAIM_CTX:
+ return GNUNET_STRINGS_string_to_data (s,
+ strlen (s),
+ *data,
+ *data_size);
+ default:
+ return GNUNET_SYSERR;
+ }
+}
+
+
+/**
+ * Mapping of record type numbers to human-readable
+ * record type names.
+ */
+static struct {
+ const char *name;
+ uint32_t number;
+} name_map[] = {
+ { "ZKLAIM_CTX", GNUNET_GNSRECORD_TYPE_ZKLAIM_CTX },
+ { NULL, UINT32_MAX }
+};
+
+
+/**
+ * Convert a type name (i.e. "AAAA") to the corresponding number.
+ *
+ * @param cls closure, unused
+ * @param dns_typename name to convert
+ * @return corresponding number, UINT32_MAX on error
+ */
+static uint32_t
+typename_to_number (void *cls,
+ const char *dns_typename)
+{
+ unsigned int i;
+
+ i=0;
+ while ( (NULL != name_map[i].name) &&
+ (0 != strcasecmp (dns_typename, name_map[i].name)) )
+ i++;
+ return name_map[i].number;
+}
+
+
+/**
+ * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
+ *
+ * @param cls closure, unused
+ * @param type number of a type to convert
+ * @return corresponding typestring, NULL on error
+ */
+static const char *
+number_to_typename (void *cls,
+ uint32_t type)
+{
+ unsigned int i;
+
+ i=0;
+ while ( (NULL != name_map[i].name) &&
+ (type != name_map[i].number) )
+ i++;
+ return name_map[i].name;
+}
+
+
+/**
+ * Entry point for the plugin.
+ *
+ * @param cls NULL
+ * @return the exported block API
+ */
+void *
+libgnunet_plugin_gnsrecord_zklaim_init (void *cls)
+{
+ struct GNUNET_GNSRECORD_PluginFunctions *api;
+
+ api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
+ api->value_to_string = &value_to_string;
+ api->string_to_value = &string_to_value;
+ api->typename_to_number = &typename_to_number;
+ api->number_to_typename = &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_gnsrecord_zklaim_done (void *cls)
+{
+ struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
+
+ GNUNET_free (api);
+ return NULL;
+}
+
+/* end of plugin_gnsrecord_dns.c */
diff --git a/src/zklaim/zklaim_api.c b/src/zklaim/zklaim_api.c
index 73998925b..6e9da67f3 100644
--- a/src/zklaim/zklaim_api.c
+++ b/src/zklaim/zklaim_api.c
@@ -247,7 +247,7 @@ handle_zklaim_result_code (void *cls,
op);
if (NULL != op->cont)
op->cont (op->cls,
- GNUNET_OK,
+ ntohl(rcm->result_code),
str);
GNUNET_free (op);
}
@@ -282,7 +282,7 @@ handle_zklaim_result_ctx (void *cls,
struct GNUNET_ZKLAIM_Handle *h = cls;
struct GNUNET_ZKLAIM_Operation *op;
struct GNUNET_ZKLAIM_Context ctx;
- uint16_t ctx_len = ntohs (cm->ctx_len);
+ uint16_t ctx_len = ntohl (cm->ctx_len);
op = h->op_head;
if (NULL == op)
@@ -297,8 +297,8 @@ handle_zklaim_result_ctx (void *cls,
ctx.attrs = (char*)&cm[1];
ctx.ctx = zklaim_context_new ();
zklaim_ctx_deserialize (ctx.ctx,
- (unsigned char *) &cm[1]+ strlen (ctx.attrs) + 1,
- ctx_len);
+ (unsigned char *) &cm[1] + strlen (ctx.attrs) + 1,
+ ctx_len - strlen (ctx.attrs) - 1);
if (NULL != op->ctx_cont)
{
if (0 > ctx_len)
@@ -395,11 +395,13 @@ GNUNET_ZKLAIM_context_create (struct GNUNET_ZKLAIM_Handle *h,
struct GNUNET_MQ_Envelope *env;
struct CreateRequestMessage *crm;
size_t slen;
+ size_t alen;
if (NULL == h->mq)
return NULL;
slen = strlen (name) + 1;
- if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct CreateRequestMessage))
+ alen = strlen (attr_list) + 1;
+ if (slen+alen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct CreateRequestMessage))
{
GNUNET_break (0);
return NULL;
@@ -412,14 +414,18 @@ GNUNET_ZKLAIM_context_create (struct GNUNET_ZKLAIM_Handle *h,
h->op_tail,
op);
env = GNUNET_MQ_msg_extra (crm,
- slen,
+ slen + alen,
GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE);
crm->name_len = htons (slen);
+ crm->attrs_len = htons (alen);
crm->reserved = htons (0);
crm->private_key = *pk;
GNUNET_memcpy (&crm[1],
name,
slen);
+ GNUNET_memcpy (((char*)&crm[1]) + slen,
+ attr_list,
+ alen);
GNUNET_MQ_send (h->mq,
env);
//TODO add attrs
@@ -506,7 +512,7 @@ GNUNET_ZKLAIM_lookup_context (struct GNUNET_ZKLAIM_Handle *h,
op);
env = GNUNET_MQ_msg_extra (lm,
slen,
- GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE);
+ GNUNET_MESSAGE_TYPE_ZKLAIM_LOOKUP_CTX);
lm->name_len = htons (slen);
lm->reserved = htons (0);
lm->private_key = *key;
@@ -518,16 +524,16 @@ GNUNET_ZKLAIM_lookup_context (struct GNUNET_ZKLAIM_Handle *h,
return op;
}
-void
+int
GNUNET_ZKLAIM_issue_from_context (struct GNUNET_ZKLAIM_Context *ctx,
struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
GNUNET_ZKLAIM_PayloadIterator iter,
void* iter_cls)
{
- ZKLAIM_context_issue (ctx,
- key,
- iter,
- iter_cls);
+ return ZKLAIM_context_issue (ctx,
+ key,
+ iter,
+ iter_cls);
}
/* end of zklaim_api.c */
diff --git a/src/zklaim/zklaim_functions.c b/src/zklaim/zklaim_functions.c
index 3c968cfea..7f83ecb22 100644
--- a/src/zklaim/zklaim_functions.c
+++ b/src/zklaim/zklaim_functions.c
@@ -67,18 +67,20 @@ ZKLAIM_context_attributes_iterate (const struct GNUNET_ZKLAIM_Context *ctx,
tmp = GNUNET_strdup (ctx->attrs);
attr_name = strtok (tmp, ",");
plw = ctx->ctx->pl_ctx_head;
-
for (i = 0; i < ctx->ctx->num_of_payloads; i++)
{
for (j = 0; j < ZKLAIM_MAX_PAYLOAD_ATTRIBUTES; j++)
{
- GNUNET_assert (NULL != attr_name);
+ if (NULL == attr_name)
+ break;
iter (iter_cls, attr_name, &data);
zklaim_set_attr (&plw->pl,
data,
j);
- attr_name = strtok (NULL, ",");
+ attr_name = strtok (attr_name + strlen (attr_name) + 1, ",");
}
+ if (NULL == attr_name)
+ break;
plw = plw->next;
GNUNET_assert (NULL != plw);
}
@@ -86,7 +88,7 @@ ZKLAIM_context_attributes_iterate (const struct GNUNET_ZKLAIM_Context *ctx,
}
-void
+int
ZKLAIM_context_issue (struct GNUNET_ZKLAIM_Context *ctx,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
GNUNET_ZKLAIM_PayloadIterator iter,
@@ -95,8 +97,8 @@ ZKLAIM_context_issue (struct GNUNET_ZKLAIM_Context *ctx,
ZKLAIM_context_attributes_iterate (ctx,
iter,
iter_cls);
- ZKLAIM_context_sign (ctx,
- key);
+ return ZKLAIM_context_sign (ctx,
+ key);
}
void
diff --git a/src/zklaim/zklaim_functions.h b/src/zklaim/zklaim_functions.h
index 0497d5eb7..8542023db 100644
--- a/src/zklaim/zklaim_functions.h
+++ b/src/zklaim/zklaim_functions.h
@@ -63,7 +63,7 @@ ZKLAIM_context_attributes_iterate (const struct GNUNET_ZKLAIM_Context *ctx,
void *iter_cls);
-void
+int
ZKLAIM_context_issue (struct GNUNET_ZKLAIM_Context *ctx,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
GNUNET_ZKLAIM_PayloadIterator iter,