#include "gnunet_gns_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_namestore_service.h"
+#include "gnunet_zklaim_service.h"
#include "zklaim_api.h"
+#include "zklaim_functions.h"
#include "zklaim/zklaim.h"
/**
*/
static const struct GNUNET_CONFIGURATION_Handle *cfg;
+/**
+ * Proving key directory
+ */
+static char *pk_directory;
+
/**
* An idp client
*/
*/
struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
- /**
- * The context name
- */
- char *name;
-
- /**
- * The attributes to support
- */
- char *attrs;
-
};
struct LookupHandle
GNUNET_GNS_disconnect (gns_handle);
if (NULL != ns_handle)
GNUNET_NAMESTORE_disconnect (ns_handle);
+ GNUNET_free (pk_directory);
+ pk_directory = NULL;
}
/**
{
if (NULL != handle->ns_qe)
GNUNET_NAMESTORE_cancel (handle->ns_qe);
- GNUNET_free_non_null (handle->name);
- GNUNET_free_non_null (handle->attrs);
GNUNET_free (handle);
}
return GNUNET_OK;
}
+static char*
+get_pk_filename (char *ctx_name)
+{
+ char *filename;
+
+ GNUNET_asprintf (&filename,
+ "%s%s%s",
+ pk_directory,
+ DIR_SEPARATOR_STR,
+ ctx_name);
+ return filename;
+}
static void
handle_create_context_message (void *cls,
struct CreateContextHandle *cch;
struct ZkClient *zkc = cls;
struct GNUNET_GNSRECORD_Data ctx_record;
+ struct GNUNET_ZKLAIM_Context *ctx;
size_t str_len;
char *tmp;
char *pos;
- unsigned char *data;
char *rdata;
- size_t data_len;
+ char *fn;
size_t rdata_len;
int num_attrs;
int num_pl;
int i;
- zklaim_ctx *ctx;
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);
+ ctx = GNUNET_new (struct GNUNET_ZKLAIM_Context);
+ ctx->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,
+ fprintf(stderr, "%s\n", ctx->name);
+ ctx->attrs = GNUNET_strndup (((char*)&crm[1]) + strlen (ctx->name) + 1,
str_len-1);
cch->private_key = crm->private_key;
GNUNET_CRYPTO_ecdsa_key_get_public (&crm->private_key,
zkc->create_op_tail,
cch);
- tmp = GNUNET_strdup (cch->attrs);
+ tmp = GNUNET_strdup (ctx->attrs);
pos = strtok(tmp, ",");
num_attrs = 0;
if (NULL == pos)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No attributes given.\n");
+ GNUNET_ZKLAIM_context_destroy (ctx);
send_result(GNUNET_SYSERR, cch);
GNUNET_free (tmp);
return;
GNUNET_free (tmp);
num_pl = (num_attrs / 5) + 1;
zklaim_payload *pl = GNUNET_malloc (num_pl * sizeof (zklaim_payload));
- ctx = zklaim_context_new ();
+ ctx->ctx = zklaim_context_new ();
for (i = 0; i < num_pl; i++)
- zklaim_add_pl (ctx, pl[i]);
- zklaim_hash_ctx (ctx);
+ zklaim_add_pl (ctx->ctx, pl[i]);
+ zklaim_hash_ctx (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))
+ if (0 != zklaim_trusted_setup (ctx->ctx))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Trusted Setup failed.\n");
send_result (GNUNET_SYSERR, cch);
- zklaim_ctx_free (ctx);
+ GNUNET_ZKLAIM_context_destroy (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);
- rdata = GNUNET_malloc (rdata_len);
- memcpy (rdata,
- cch->attrs,
- strlen (cch->attrs) + 1);
- memcpy (rdata + strlen (cch->attrs) + 1,
- data,
- data_len);
+ "Finished trusted setup. PK size=%lu bytes\n",
+ ctx->ctx->pk_size);
+ fn = get_pk_filename (ctx->name);
+ (void) GNUNET_DISK_directory_create_for_file (fn);
+ if (ctx->ctx->pk_size != GNUNET_DISK_fn_write (fn,
+ ctx->ctx->pk,
+ ctx->ctx->pk_size,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "write", fn);
+ GNUNET_free (fn);
+ rdata_len = GNUNET_ZKLAIM_context_serialize (ctx, &rdata);
ctx_record.data_size = rdata_len;
ctx_record.data = rdata;
ctx_record.expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; //TODO config
ctx_record.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
cch->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle,
&cch->private_key,
- cch->name,
+ ctx->name,
1,
&ctx_record,
&context_store_cont,
cch);
GNUNET_free (rdata);
- GNUNET_free (data);
+ GNUNET_ZKLAIM_context_destroy (ctx);
}
/**
env = GNUNET_MQ_msg_extra (r_msg,
len,
GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CTX);
- r_msg->ctx_len = htonl (len);
+ r_msg->ctx_len = htons (len);
memcpy ((char*)&r_msg[1],
ctx,
len);
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to namestore");
}
-
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "zklaim",
+ "PKDIR",
+ &pk_directory))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "zklaim", "PKDIR");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
gns_handle = GNUNET_GNS_connect (cfg);
if (NULL == gns_handle)
{
{
struct GNUNET_ZKLAIM_Handle *h = cls;
struct GNUNET_ZKLAIM_Operation *op;
- struct GNUNET_ZKLAIM_Context ctx;
- uint16_t ctx_len = ntohl (cm->ctx_len);
+ struct GNUNET_ZKLAIM_Context *ctx;
+ uint16_t ctx_len = ntohs (cm->ctx_len);
op = h->op_head;
if (NULL == op)
GNUNET_CONTAINER_DLL_remove (h->op_head,
h->op_tail,
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 - strlen (ctx.attrs) - 1);
if (NULL != op->ctx_cont)
{
- if (0 > ctx_len)
+ fprintf (stderr,
+ "ctx_len %d\n", ctx_len);
+ if (0 < ctx_len)
+ {
+ ctx = GNUNET_ZKLAIM_context_deserialize ((char*)&cm[1],
+ ctx_len);
op->ctx_cont (op->cls,
- &ctx);
+ ctx);
+ GNUNET_ZKLAIM_context_destroy (ctx);
+ }
else
op->ctx_cont (op->cls,
- &ctx);
+ NULL);
}
- zklaim_ctx_free (ctx.ctx);
GNUNET_free (op);
}
GNUNET_free (h);
}
+void
+GNUNET_ZKLAIM_context_destroy (struct GNUNET_ZKLAIM_Context *ctx)
+{
+ GNUNET_free_non_null (ctx->name);
+ GNUNET_free_non_null (ctx->attrs);
+ zklaim_ctx_free (ctx->ctx);
+ GNUNET_free (ctx);
+}
+
/**
* Lookup context
*/
char *pos;
char *tmp;
size_t len;
- size_t len_w;
+ uint64_t len_w;
size_t ret_len = 0;
+ size_t alen = strlen (ctx->attrs) + 1;
+ size_t nlen = strlen (ctx->name) + 1;
len = zklaim_ctx_serialize (ctx->ctx,
(unsigned char**) &tmp);
- ret_len += strlen (ctx->attrs) + 1 + sizeof (size_t) + len;
+ ret_len += alen + nlen + sizeof (size_t) + len;
*buf = GNUNET_malloc (ret_len);
pos = *buf;
- memcpy (pos, ctx->attrs, strlen (ctx->attrs) + 1);
- pos += strlen (ctx->attrs) + 1;
- len_w = htonl (len);
- memcpy (pos, &len_w, sizeof (size_t));
- pos += sizeof (size_t);
+ memcpy (pos, ctx->attrs, alen);
+ pos += alen;
+ memcpy (pos, ctx->name, nlen);
+ pos += nlen;
+ len_w = htons (len);
+ memcpy (pos, &len_w, sizeof (uint16_t));
+ pos += sizeof (uint16_t);
memcpy (pos, tmp, len);
GNUNET_free (tmp);
return ret_len;
ctx = GNUNET_new (struct GNUNET_ZKLAIM_Context);
ctx->attrs = GNUNET_strdup (data);
pos = data + strlen (ctx->attrs) + 1;
- len = ntohl (*((size_t*)pos));
+ ctx->name = GNUNET_strdup (pos);
+ pos += strlen (ctx->name) + 1;
+ len = ntohs (*((uint16_t*)pos));
ctx->ctx = zklaim_context_new ();
- pos += sizeof (size_t);
+ pos += sizeof (uint16_t);
if (0 != zklaim_ctx_deserialize (ctx->ctx,
(unsigned char*) pos,
len))
return ctx;
}
+
+int
+GNUNET_ZKLAIM_context_prove_with_keyfile (struct GNUNET_ZKLAIM_Context *ctx,
+ const char* pkey_fn,
+ GNUNET_ZKLAIM_PredicateIterator iter,
+ void* iter_cls)
+{
+ if (GNUNET_SYSERR == GNUNET_DISK_file_size (pkey_fn,
+ &ctx->ctx->pk_size,
+ GNUNET_NO,
+ GNUNET_YES))
+ {
+ return GNUNET_SYSERR;
+ }
+ ctx->ctx->pk = GNUNET_malloc (ctx->ctx->pk_size);
+ if (GNUNET_SYSERR == GNUNET_DISK_fn_read (pkey_fn,
+ ctx->ctx->pk,
+ ctx->ctx->pk_size))
+ {
+ GNUNET_free (ctx->ctx->pk);
+ ctx->ctx->pk = NULL;
+ ctx->ctx->pk_size = 0;
+ return GNUNET_SYSERR;
+ }
+
+ return GNUNET_ZKLAIM_context_prove (ctx,
+ iter,
+ iter_cls);
+}
+
+
int
GNUNET_ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx,
GNUNET_ZKLAIM_PredicateIterator iter,