aboutsummaryrefslogtreecommitdiff
path: root/src/zklaim/gnunet-service-zklaim.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zklaim/gnunet-service-zklaim.c')
-rw-r--r--src/zklaim/gnunet-service-zklaim.c98
1 files changed, 59 insertions, 39 deletions
diff --git a/src/zklaim/gnunet-service-zklaim.c b/src/zklaim/gnunet-service-zklaim.c
index baf6b20de..0619432e6 100644
--- a/src/zklaim/gnunet-service-zklaim.c
+++ b/src/zklaim/gnunet-service-zklaim.c
@@ -29,7 +29,9 @@
29#include "gnunet_gns_service.h" 29#include "gnunet_gns_service.h"
30#include "gnunet_statistics_service.h" 30#include "gnunet_statistics_service.h"
31#include "gnunet_namestore_service.h" 31#include "gnunet_namestore_service.h"
32#include "gnunet_zklaim_service.h"
32#include "zklaim_api.h" 33#include "zklaim_api.h"
34#include "zklaim_functions.h"
33#include "zklaim/zklaim.h" 35#include "zklaim/zklaim.h"
34 36
35/** 37/**
@@ -53,6 +55,11 @@ static struct GNUNET_STATISTICS_Handle *stats;
53static const struct GNUNET_CONFIGURATION_Handle *cfg; 55static const struct GNUNET_CONFIGURATION_Handle *cfg;
54 56
55/** 57/**
58 * Proving key directory
59 */
60static char *pk_directory;
61
62/**
56 * An idp client 63 * An idp client
57 */ 64 */
58struct ZkClient 65struct ZkClient
@@ -123,16 +130,6 @@ struct CreateContextHandle
123 */ 130 */
124 struct GNUNET_NAMESTORE_QueueEntry *ns_qe; 131 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
125 132
126 /**
127 * The context name
128 */
129 char *name;
130
131 /**
132 * The attributes to support
133 */
134 char *attrs;
135
136}; 133};
137 134
138struct LookupHandle 135struct LookupHandle
@@ -193,6 +190,8 @@ cleanup()
193 GNUNET_GNS_disconnect (gns_handle); 190 GNUNET_GNS_disconnect (gns_handle);
194 if (NULL != ns_handle) 191 if (NULL != ns_handle)
195 GNUNET_NAMESTORE_disconnect (ns_handle); 192 GNUNET_NAMESTORE_disconnect (ns_handle);
193 GNUNET_free (pk_directory);
194 pk_directory = NULL;
196} 195}
197 196
198/** 197/**
@@ -220,8 +219,6 @@ cleanup_create_handle (struct CreateContextHandle *handle)
220{ 219{
221 if (NULL != handle->ns_qe) 220 if (NULL != handle->ns_qe)
222 GNUNET_NAMESTORE_cancel (handle->ns_qe); 221 GNUNET_NAMESTORE_cancel (handle->ns_qe);
223 GNUNET_free_non_null (handle->name);
224 GNUNET_free_non_null (handle->attrs);
225 GNUNET_free (handle); 222 GNUNET_free (handle);
226} 223}
227 224
@@ -278,6 +275,18 @@ check_create_context_message(void *cls,
278 return GNUNET_OK; 275 return GNUNET_OK;
279} 276}
280 277
278static char*
279get_pk_filename (char *ctx_name)
280{
281 char *filename;
282
283 GNUNET_asprintf (&filename,
284 "%s%s%s",
285 pk_directory,
286 DIR_SEPARATOR_STR,
287 ctx_name);
288 return filename;
289}
281 290
282static void 291static void
283handle_create_context_message (void *cls, 292handle_create_context_message (void *cls,
@@ -286,17 +295,16 @@ handle_create_context_message (void *cls,
286 struct CreateContextHandle *cch; 295 struct CreateContextHandle *cch;
287 struct ZkClient *zkc = cls; 296 struct ZkClient *zkc = cls;
288 struct GNUNET_GNSRECORD_Data ctx_record; 297 struct GNUNET_GNSRECORD_Data ctx_record;
298 struct GNUNET_ZKLAIM_Context *ctx;
289 size_t str_len; 299 size_t str_len;
290 char *tmp; 300 char *tmp;
291 char *pos; 301 char *pos;
292 unsigned char *data;
293 char *rdata; 302 char *rdata;
294 size_t data_len; 303 char *fn;
295 size_t rdata_len; 304 size_t rdata_len;
296 int num_attrs; 305 int num_attrs;
297 int num_pl; 306 int num_pl;
298 int i; 307 int i;
299 zklaim_ctx *ctx;
300 308
301 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 309 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
302 "Received CREATE_REQUEST message\n"); 310 "Received CREATE_REQUEST message\n");
@@ -304,10 +312,11 @@ handle_create_context_message (void *cls,
304 str_len = ntohs (crm->name_len); 312 str_len = ntohs (crm->name_len);
305 313
306 cch = GNUNET_new (struct CreateContextHandle); 314 cch = GNUNET_new (struct CreateContextHandle);
307 cch->name = GNUNET_strndup ((char*)&crm[1], str_len-1); 315 ctx = GNUNET_new (struct GNUNET_ZKLAIM_Context);
316 ctx->name = GNUNET_strndup ((char*)&crm[1], str_len-1);
308 str_len = ntohs(crm->attrs_len); 317 str_len = ntohs(crm->attrs_len);
309 fprintf(stderr, "%s\n", cch->name); 318 fprintf(stderr, "%s\n", ctx->name);
310 cch->attrs = GNUNET_strndup (((char*)&crm[1]) + strlen (cch->name) + 1, 319 ctx->attrs = GNUNET_strndup (((char*)&crm[1]) + strlen (ctx->name) + 1,
311 str_len-1); 320 str_len-1);
312 cch->private_key = crm->private_key; 321 cch->private_key = crm->private_key;
313 GNUNET_CRYPTO_ecdsa_key_get_public (&crm->private_key, 322 GNUNET_CRYPTO_ecdsa_key_get_public (&crm->private_key,
@@ -319,13 +328,14 @@ handle_create_context_message (void *cls,
319 zkc->create_op_tail, 328 zkc->create_op_tail,
320 cch); 329 cch);
321 330
322 tmp = GNUNET_strdup (cch->attrs); 331 tmp = GNUNET_strdup (ctx->attrs);
323 pos = strtok(tmp, ","); 332 pos = strtok(tmp, ",");
324 num_attrs = 0; 333 num_attrs = 0;
325 if (NULL == pos) 334 if (NULL == pos)
326 { 335 {
327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 336 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
328 "No attributes given.\n"); 337 "No attributes given.\n");
338 GNUNET_ZKLAIM_context_destroy (ctx);
329 send_result(GNUNET_SYSERR, cch); 339 send_result(GNUNET_SYSERR, cch);
330 GNUNET_free (tmp); 340 GNUNET_free (tmp);
331 return; 341 return;
@@ -338,32 +348,34 @@ handle_create_context_message (void *cls,
338 GNUNET_free (tmp); 348 GNUNET_free (tmp);
339 num_pl = (num_attrs / 5) + 1; 349 num_pl = (num_attrs / 5) + 1;
340 zklaim_payload *pl = GNUNET_malloc (num_pl * sizeof (zklaim_payload)); 350 zklaim_payload *pl = GNUNET_malloc (num_pl * sizeof (zklaim_payload));
341 ctx = zklaim_context_new (); 351 ctx->ctx = zklaim_context_new ();
342 for (i = 0; i < num_pl; i++) 352 for (i = 0; i < num_pl; i++)
343 zklaim_add_pl (ctx, pl[i]); 353 zklaim_add_pl (ctx->ctx, pl[i]);
344 zklaim_hash_ctx (ctx); 354 zklaim_hash_ctx (ctx->ctx);
345 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 355 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
346 "Starting trusted setup (%d payloads)... this might take a while...\n", num_pl); 356 "Starting trusted setup (%d payloads)... this might take a while...\n", num_pl);
347 if (0 != zklaim_trusted_setup (ctx)) 357 if (0 != zklaim_trusted_setup (ctx->ctx))
348 { 358 {
349 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
350 "Trusted Setup failed.\n"); 360 "Trusted Setup failed.\n");
351 send_result (GNUNET_SYSERR, cch); 361 send_result (GNUNET_SYSERR, cch);
352 zklaim_ctx_free (ctx); 362 GNUNET_ZKLAIM_context_destroy (ctx);
353 return; 363 return;
354 } 364 }
355 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 365 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
356 "Finished trusted setup.\n"); 366 "Finished trusted setup. PK size=%lu bytes\n",
357 data_len = zklaim_ctx_serialize (ctx, &data); 367 ctx->ctx->pk_size);
358 rdata_len = data_len + strlen (cch->attrs) + 1; 368 fn = get_pk_filename (ctx->name);
359 zklaim_ctx_free (ctx); 369 (void) GNUNET_DISK_directory_create_for_file (fn);
360 rdata = GNUNET_malloc (rdata_len); 370 if (ctx->ctx->pk_size != GNUNET_DISK_fn_write (fn,
361 memcpy (rdata, 371 ctx->ctx->pk,
362 cch->attrs, 372 ctx->ctx->pk_size,
363 strlen (cch->attrs) + 1); 373 GNUNET_DISK_PERM_USER_READ |
364 memcpy (rdata + strlen (cch->attrs) + 1, 374 GNUNET_DISK_PERM_USER_WRITE))
365 data, 375 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
366 data_len); 376 "write", fn);
377 GNUNET_free (fn);
378 rdata_len = GNUNET_ZKLAIM_context_serialize (ctx, &rdata);
367 ctx_record.data_size = rdata_len; 379 ctx_record.data_size = rdata_len;
368 ctx_record.data = rdata; 380 ctx_record.data = rdata;
369 ctx_record.expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; //TODO config 381 ctx_record.expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; //TODO config
@@ -371,13 +383,13 @@ handle_create_context_message (void *cls,
371 ctx_record.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 383 ctx_record.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
372 cch->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle, 384 cch->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle,
373 &cch->private_key, 385 &cch->private_key,
374 cch->name, 386 ctx->name,
375 1, 387 1,
376 &ctx_record, 388 &ctx_record,
377 &context_store_cont, 389 &context_store_cont,
378 cch); 390 cch);
379 GNUNET_free (rdata); 391 GNUNET_free (rdata);
380 GNUNET_free (data); 392 GNUNET_ZKLAIM_context_destroy (ctx);
381} 393}
382 394
383/** 395/**
@@ -409,7 +421,7 @@ send_ctx_result (struct LookupHandle *lh,
409 env = GNUNET_MQ_msg_extra (r_msg, 421 env = GNUNET_MQ_msg_extra (r_msg,
410 len, 422 len,
411 GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CTX); 423 GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CTX);
412 r_msg->ctx_len = htonl (len); 424 r_msg->ctx_len = htons (len);
413 memcpy ((char*)&r_msg[1], 425 memcpy ((char*)&r_msg[1],
414 ctx, 426 ctx,
415 len); 427 len);
@@ -524,7 +536,15 @@ run (void *cls,
524 { 536 {
525 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to namestore"); 537 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to namestore");
526 } 538 }
527 539 if (GNUNET_OK !=
540 GNUNET_CONFIGURATION_get_value_filename (cfg, "zklaim",
541 "PKDIR",
542 &pk_directory))
543 {
544 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "zklaim", "PKDIR");
545 GNUNET_SCHEDULER_shutdown ();
546 return;
547 }
528 gns_handle = GNUNET_GNS_connect (cfg); 548 gns_handle = GNUNET_GNS_connect (cfg);
529 if (NULL == gns_handle) 549 if (NULL == gns_handle)
530 { 550 {