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.
*
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
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
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);
}
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
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);
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;
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,
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);
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);
}
const struct GNUNET_GNSRECORD_Data *rd)
{
struct LookupHandle *lh = cls;
-
+ lh->ns_qe = NULL;
send_ctx_result (lh, (char*) rd->data, rd->data_size);
}
*/
static char* issue_attrs;
+/**
+ * Attribute names for issuer context data
+ */
+static char* create_attrs;
+
/**
* Ego name
*/
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);
}
_("Context name missing!\n"));
return;
}
- if ( (create) && (NULL == issue_attrs) )
+ if ( (create) && (NULL == create_attrs) )
{
ret = 1;
fprintf (stderr,
zklaim_handle = GNUNET_ZKLAIM_connect (c);
//Get Ego
+ init = GNUNET_YES;
identity_handle = GNUNET_IDENTITY_connect (c,
&ego_cb,
NULL);
"attributes",
NULL,
gettext_noop ("Context attributes (comma separated)"),
- &issue_attrs),
+ &create_attrs),
GNUNET_GETOPT_option_string ('e',
"ego",
NULL,
"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",
--- /dev/null
+/*
+ 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 */
op);
if (NULL != op->cont)
op->cont (op->cls,
- GNUNET_OK,
+ ntohl(rcm->result_code),
str);
GNUNET_free (op);
}
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)
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)
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;
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
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;
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 */
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);
}
}
-void
+int
ZKLAIM_context_issue (struct GNUNET_ZKLAIM_Context *ctx,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
GNUNET_ZKLAIM_PayloadIterator iter,
ZKLAIM_context_attributes_iterate (ctx,
iter,
iter_cls);
- ZKLAIM_context_sign (ctx,
- key);
+ return ZKLAIM_context_sign (ctx,
+ key);
}
void
void *iter_cls);
-void
+int
ZKLAIM_context_issue (struct GNUNET_ZKLAIM_Context *ctx,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
GNUNET_ZKLAIM_PayloadIterator iter,