aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-08-17 15:04:19 +0200
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-08-17 15:04:19 +0200
commit9dfd05ddd6933e9e46804d7db47cea149f24d8d4 (patch)
treeecbc0b1e52ea72cfadb4cbcaa226da7db1d1376a
parent8cd6146318d890c5cb18a2edb72090feee9729b2 (diff)
downloadgnunet-9dfd05ddd6933e9e46804d7db47cea149f24d8d4.tar.gz
gnunet-9dfd05ddd6933e9e46804d7db47cea149f24d8d4.zip
towards zklaim prove
-rw-r--r--src/include/gnunet_protocols.h6
-rw-r--r--src/include/gnunet_zklaim_lib.h131
-rw-r--r--src/include/gnunet_zklaim_service.h168
-rw-r--r--src/zklaim/Makefile.am2
-rw-r--r--src/zklaim/gnunet-service-zklaim.c202
-rw-r--r--src/zklaim/zklaim_api.c154
-rw-r--r--src/zklaim/zklaim_api.h52
-rw-r--r--src/zklaim/zklaim_functions.c75
-rw-r--r--src/zklaim/zklaim_functions.h46
9 files changed, 662 insertions, 174 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 0081138e0..f4a5dd82e 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -2706,6 +2706,12 @@ extern "C"
2706 2706
2707#define GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CODE 991 2707#define GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CODE 991
2708 2708
2709#define GNUNET_MESSAGE_TYPE_ZKLAIM_ISSUE 992
2710
2711#define GNUNET_MESSAGE_TYPE_ZKLAIM_LOOKUP_CTX 993
2712
2713#define GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CTX 994
2714
2709/******************************************************************************/ 2715/******************************************************************************/
2710/*********************************** CADET **********************************/ 2716/*********************************** CADET **********************************/
2711/******************************************************************************/ 2717/******************************************************************************/
diff --git a/src/include/gnunet_zklaim_lib.h b/src/include/gnunet_zklaim_lib.h
deleted file mode 100644
index a1fd1f017..000000000
--- a/src/include/gnunet_zklaim_lib.h
+++ /dev/null
@@ -1,131 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001-2018 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file include/gnunet_zklaim_lib.h
23 * @brief ZKlaim functions for GNUnet
24 *
25 * @author Martin Schanzenbach
26 *
27 * @defgroup zklaim ZKlaim library: Zero-Knowledge Credentials
28 *
29 */
30#ifndef GNUNET_ZKLAIM_LIB_H
31#define GNUNET_ZKLAIM_LIB_H
32
33#ifdef __cplusplus
34extern "C"
35{
36#if 0 /* keep Emacsens' auto-indent happy */
37}
38#endif
39#endif
40
41#include "gnunet_common.h"
42
43/**
44 * @brief type for ZKlaim context
45 */
46struct GNUNET_ZKLAIM_Context;
47
48/**
49 * @brief type for ZKlaim payload
50 */
51struct GNUNET_ZKLAIM_Payload;
52
53
54/**
55 * @ingroup zklaim
56 * Create a new ZKlaim context. Caller must free return value.
57 * TODO: parameters: keys etc.
58 *
59 * @return fresh context; free using #GNUNET_free
60 */
61struct GNUNET_ZKLAIM_Context *
62GNUNET_ZKLAIM_context_create (void);
63
64/**
65 * @ingroup zklaim
66 * Create a payload.
67 * TODO: parameters, attributes etc.
68 *
69 * @return fresh payload; free using #GNUNET_free
70 */
71void
72GNUNET_ZKLAIM_payload_create (void);
73
74/**
75 * @ingroup zklaim
76 * Create a payload.
77 * TODO: parameters, attributes etc.
78 *
79 * @return GNUNET_OK is successful
80 */
81int
82GNUNET_ZKLAIM_context_add_payload (struct GNUNET_ZKLAIM_Context *ctx,
83 struct GNUNET_ZKLAIM_Payload* pl);
84
85
86/**
87 * @ingroup zklaim
88 * Create a payload.
89 * TODO: parameters, attributes etc.
90 *
91 * @return size needed for serialized context, -1 on error
92 */
93ssize_t
94GNUNET_ZKLAIM_context_serialize_get_size (struct GNUNET_ZKLAIM_Context *ctx);
95
96
97/**
98 * @ingroup zklaim
99 * Create a payload.
100 * TODO: parameters, attributes etc.
101 *
102 */
103void
104GNUNET_ZKLAIM_context_serialize (struct GNUNET_ZKLAIM_Context *ctx,
105 char* buf);
106
107
108/**
109 * @ingroup zklaim
110 * Create a payload.
111 * TODO: parameters, attributes etc.
112 *
113 * @return fresh payload; free using #GNUNET_free
114 */
115char *
116GNUNET_ZKLAIM_context_to_string (struct GNUNET_ZKLAIM_Context *ctx);
117
118
119
120
121#if 0 /* keep Emacsens' auto-indent happy */
122{
123#endif
124#ifdef __cplusplus
125}
126#endif
127
128
129/* ifndef GNUNET_ZKLAIM_LIB_H */
130#endif
131/* end of gnunet_zklaim_lib.h */
diff --git a/src/include/gnunet_zklaim_service.h b/src/include/gnunet_zklaim_service.h
new file mode 100644
index 000000000..6654555ab
--- /dev/null
+++ b/src/include/gnunet_zklaim_service.h
@@ -0,0 +1,168 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/**
20 * @author Martin Schanzenbach
21 *
22 * @file
23 * ZKlaim service. Manage ZKlaim issuers etc.
24 *
25 * @defgroup zklaim ZKlaim service
26 * @{
27 */
28#ifndef GNUNET_ZKLAIM_SERVICE_H
29#define GNUNET_ZKLAIM_SERVICE_H
30
31#ifdef __cplusplus
32extern "C"
33{
34#if 0 /* keep Emacsens' auto-indent happy */
35}
36#endif
37#endif
38
39#include "gnunet_util_lib.h"
40
41/**
42 * Version number of GNUnet Identity Provider API.
43 */
44#define GNUNET_ZKLAIM_VERSION 0x00000000
45
46/**
47 * Handle to access the identity service.
48 */
49struct GNUNET_ZKLAIM_Handle;
50
51/**
52 * Handle for an operation with the zklaim service.
53 */
54struct GNUNET_ZKLAIM_Operation;
55
56/**
57 * Context
58 */
59struct GNUNET_ZKLAIM_Context;
60
61/**
62 * Connect to the ZKlaim service.
63 *
64 * @param cfg Configuration to contact the service.
65 * @return handle to communicate with the service
66 */
67struct GNUNET_ZKLAIM_Handle *
68GNUNET_ZKLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
69
70/**
71 * Iterator called for each attribute and data.
72 *
73 * @param cls closure
74 * @param name name of attribute
75 * @param data attribute data (can be modified)
76 */
77typedef void
78(*GNUNET_ZKLAIM_PayloadIterator) (void *cls,
79 const char* name,
80 uint64_t *data);
81
82
83
84/**
85 * Continuation called to notify client about result of the
86 * operation.
87 *
88 * @param cls closure
89 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
90 * #GNUNET_NO if content was already there or not found
91 * #GNUNET_YES (or other positive value) on success
92 * @param emsg NULL on success, otherwise an error message
93 */
94typedef void
95(*GNUNET_ZKLAIM_ContextResult) (void *cls,
96 const struct GNUNET_ZKLAIM_Context *ctx);
97
98
99
100/**
101 * Continuation called to notify client about result of the
102 * operation.
103 *
104 * @param cls closure
105 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
106 * #GNUNET_NO if content was already there or not found
107 * #GNUNET_YES (or other positive value) on success
108 * @param emsg NULL on success, otherwise an error message
109 */
110typedef void
111(*GNUNET_ZKLAIM_ContinuationWithStatus) (void *cls,
112 int32_t success,
113 const char *emsg);
114
115
116/**
117 * Create a new issuer context
118 *
119 * @param h handle to the identity provider
120 * @param pkey private key of the identity
121 * @param attr the attribute
122 * @param exp_interval the relative expiration interval for the attribute
123 * @param cont continuation to call when done
124 * @param cont_cls closure for @a cont
125 * @return handle to abort the request
126 */
127struct GNUNET_ZKLAIM_Operation *
128GNUNET_ZKLAIM_context_create (struct GNUNET_ZKLAIM_Handle *h,
129 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
130 const char *context_name,
131 const char *attr_list,
132 GNUNET_ZKLAIM_ContinuationWithStatus cont,
133 void *cont_cls);
134
135/**
136 * Disconnect from service.
137 *
138 * @param h service to disconnect
139 */
140void
141GNUNET_ZKLAIM_disconnect (struct GNUNET_ZKLAIM_Handle *h);
142
143
144/**
145 * Cancel an operation. Note that the operation MAY still
146 * be executed; this merely cancels the continuation; if the request
147 * was already transmitted, the service may still choose to complete
148 * the operation.
149 *
150 * @param op operation to cancel
151 */
152void
153GNUNET_ZKLAIM_cancel (struct GNUNET_ZKLAIM_Operation *op);
154
155#if 0 /* keep Emacsens' auto-indent happy */
156{
157#endif
158#ifdef __cplusplus
159}
160#endif
161
162
163/* ifndef GNUNET_ZKLAIM_SERVICE_H */
164#endif
165
166/** @} */ /* end of group identity */
167
168/* end of gnunet_zklaim_service.h */
diff --git a/src/zklaim/Makefile.am b/src/zklaim/Makefile.am
index c718ae28f..b28683d1a 100644
--- a/src/zklaim/Makefile.am
+++ b/src/zklaim/Makefile.am
@@ -23,7 +23,7 @@ libexec_PROGRAMS = \
23 23
24libgnunetzklaim_la_SOURCES = \ 24libgnunetzklaim_la_SOURCES = \
25 zklaim_api.c \ 25 zklaim_api.c \
26 zklaim_api.h 26 zklaim_functions.c
27libgnunetzklaim_la_LIBADD = \ 27libgnunetzklaim_la_LIBADD = \
28 $(top_builddir)/src/util/libgnunetutil.la \ 28 $(top_builddir)/src/util/libgnunetutil.la \
29 $(GN_LIBINTL) $(XLIB) 29 $(GN_LIBINTL) $(XLIB)
diff --git a/src/zklaim/gnunet-service-zklaim.c b/src/zklaim/gnunet-service-zklaim.c
index 91e70fc99..100a87f07 100644
--- a/src/zklaim/gnunet-service-zklaim.c
+++ b/src/zklaim/gnunet-service-zklaim.c
@@ -78,6 +78,17 @@ struct ZkClient
78 */ 78 */
79 struct CreateContextHandle *create_op_tail; 79 struct CreateContextHandle *create_op_tail;
80 80
81 /**
82 * Head of DLL of context issue ops
83 */
84 struct LookupHandle *lookup_op_head;
85
86 /**
87 * Tail of DLL of attribute store ops
88 */
89 struct LookupHandle *lookup_op_tail;
90
91
81}; 92};
82 93
83struct CreateContextHandle 94struct CreateContextHandle
@@ -124,6 +135,46 @@ struct CreateContextHandle
124 135
125}; 136};
126 137
138struct LookupHandle
139{
140 /**
141 * DLL
142 */
143 struct LookupHandle *next;
144
145 /**
146 * DLL
147 */
148 struct LookupHandle *prev;
149
150 /**
151 * Client connection
152 */
153 struct ZkClient *client;
154
155 /**
156 * Issuer private key
157 */
158 struct GNUNET_CRYPTO_EcdsaPrivateKey private_key;
159
160 /**
161 * Issuer public key
162 */
163 struct GNUNET_CRYPTO_EcdsaPublicKey public_key;
164
165 /**
166 * QueueEntry
167 */
168 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
169
170 /**
171 * The context name
172 */
173 char *name;
174
175};
176
177
127/** 178/**
128 * Cleanup task 179 * Cleanup task
129 */ 180 */
@@ -169,8 +220,9 @@ cleanup_create_handle (struct CreateContextHandle *handle)
169{ 220{
170 if (NULL != handle->ns_qe) 221 if (NULL != handle->ns_qe)
171 GNUNET_NAMESTORE_cancel (handle->ns_qe); 222 GNUNET_NAMESTORE_cancel (handle->ns_qe);
172 if (NULL != handle->name) 223 GNUNET_free_non_null (handle->name);
173 GNUNET_free (handle->name); 224 GNUNET_free_non_null (handle->name);
225 GNUNET_free_non_null (handle->attrs);
174 GNUNET_free (handle); 226 GNUNET_free (handle);
175} 227}
176 228
@@ -190,7 +242,9 @@ send_result (int32_t status,
190 GNUNET_MQ_send (cch->client->mq, 242 GNUNET_MQ_send (cch->client->mq,
191 env); 243 env);
192 cleanup_create_handle (cch); 244 cleanup_create_handle (cch);
193 245 GNUNET_CONTAINER_DLL_remove (cch->client->create_op_head,
246 cch->client->create_op_tail,
247 cch);
194} 248}
195 249
196static void 250static void
@@ -201,15 +255,10 @@ context_store_cont (void *cls,
201 struct CreateContextHandle *cch = cls; 255 struct CreateContextHandle *cch = cls;
202 256
203 cch->ns_qe = NULL; 257 cch->ns_qe = NULL;
204 GNUNET_CONTAINER_DLL_remove (cch->client->create_op_head,
205 cch->client->create_op_tail,
206 cch);
207
208 if (GNUNET_SYSERR == success) 258 if (GNUNET_SYSERR == success)
209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
210 "Failed to create context %s\n", 260 "Failed to create context %s\n",
211 emsg); 261 emsg);
212
213 send_result (success, cch); 262 send_result (success, cch);
214} 263}
215 264
@@ -297,7 +346,7 @@ handle_create_context_message (void *cls,
297 { 346 {
298 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 347 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
299 "Trusted Setup failed.\n"); 348 "Trusted Setup failed.\n");
300 send_result(GNUNET_SYSERR, cch); 349 send_result (GNUNET_SYSERR, cch);
301 zklaim_ctx_free (ctx); 350 zklaim_ctx_free (ctx);
302 return; 351 return;
303 } 352 }
@@ -317,16 +366,135 @@ handle_create_context_message (void *cls,
317 ctx_record.record_type = GNUNET_GNSRECORD_TYPE_ZKLAIM_CTX; 366 ctx_record.record_type = GNUNET_GNSRECORD_TYPE_ZKLAIM_CTX;
318 ctx_record.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 367 ctx_record.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
319 cch->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle, 368 cch->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle,
320 &cch->private_key, 369 &cch->private_key,
321 cch->name, 370 cch->name,
322 1, 371 1,
323 &ctx_record, 372 &ctx_record,
324 &context_store_cont, 373 &context_store_cont,
325 cch); 374 cch);
326 GNUNET_free (rdata); 375 GNUNET_free (rdata);
327 GNUNET_free (data); 376 GNUNET_free (data);
328} 377}
329 378
379/**
380 * Cleanup attribute store handle
381 *
382 * @param handle handle to clean up
383 */
384static void
385cleanup_lookup_handle (struct LookupHandle *handle)
386{
387 if (NULL != handle->ns_qe)
388 GNUNET_NAMESTORE_cancel (handle->ns_qe);
389 GNUNET_free_non_null (handle->name);
390 GNUNET_free (handle);
391}
392
393
394static void
395send_ctx_result (struct LookupHandle *lh,
396 const char* ctx,
397 size_t len)
398{
399 struct GNUNET_MQ_Envelope *env;
400 struct ContextMessage *r_msg;
401
402
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404 "Sending RESULT_CODE message\n");
405 env = GNUNET_MQ_msg_extra (r_msg,
406 len,
407 GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CTX);
408 r_msg->ctx_len = htonl (len);
409 memcpy ((char*)&r_msg[1],
410 ctx,
411 len);
412 GNUNET_MQ_send (lh->client->mq,
413 env);
414 cleanup_lookup_handle (lh);
415 GNUNET_CONTAINER_DLL_remove (lh->client->lookup_op_head,
416 lh->client->lookup_op_tail,
417 lh);
418}
419
420
421static void
422ctx_not_found_cb (void* cls)
423{
424 struct LookupHandle *lh = cls;
425
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
427 "Context %s not found!\n",
428 lh->name);
429
430 send_ctx_result (lh, NULL, 0);
431}
432
433
434static void
435ctx_found_cb (void *cls,
436 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
437 const char *label,
438 unsigned int rd_count,
439 const struct GNUNET_GNSRECORD_Data *rd)
440{
441 struct LookupHandle *lh = cls;
442
443 send_ctx_result (lh, (char*) rd->data, rd->data_size);
444}
445
446
447
448static int
449check_lookup_message(void *cls,
450 const struct LookupMessage *lm)
451{
452 uint16_t size;
453
454 size = ntohs (lm->header.size);
455 if (size <= sizeof (struct LookupMessage))
456 {
457 GNUNET_break (0);
458 return GNUNET_SYSERR;
459 }
460 return GNUNET_OK;
461}
462
463
464static void
465handle_lookup_message (void *cls,
466 const struct LookupMessage *lm)
467{
468 struct LookupHandle *lh;
469 struct ZkClient *zkc = cls;
470 size_t str_len;
471
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
473 "Received CREATE_REQUEST message\n");
474
475 str_len = ntohs (lm->name_len);
476
477 lh = GNUNET_new (struct LookupHandle);
478 lh->name = GNUNET_strndup ((char*)&lm[1], str_len-1);
479 lh->private_key = lm->private_key;
480 GNUNET_CRYPTO_ecdsa_key_get_public (&lm->private_key,
481 &lh->public_key);
482
483 GNUNET_SERVICE_client_continue (zkc->client);
484 lh->client = zkc;
485 GNUNET_CONTAINER_DLL_insert (zkc->lookup_op_head,
486 zkc->lookup_op_tail,
487 lh);
488
489 lh->ns_qe = GNUNET_NAMESTORE_records_lookup (ns_handle,
490 &lh->private_key,
491 lh->name,
492 &ctx_not_found_cb,
493 lh,
494 &ctx_found_cb,
495 lh);
496}
497
330 498
331 499
332/** 500/**
@@ -431,5 +599,9 @@ GNUNET_SERVICE_MAIN
431 GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE, 599 GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE,
432 struct CreateRequestMessage, 600 struct CreateRequestMessage,
433 NULL), 601 NULL),
602 GNUNET_MQ_hd_var_size (lookup_message,
603 GNUNET_MESSAGE_TYPE_ZKLAIM_LOOKUP_CTX,
604 struct LookupMessage,
605 NULL),
434 GNUNET_MQ_handler_end()); 606 GNUNET_MQ_handler_end());
435/* end of gnunet-service-zklaim.c */ 607/* end of gnunet-service-zklaim.c */
diff --git a/src/zklaim/zklaim_api.c b/src/zklaim/zklaim_api.c
index f54ede342..73998925b 100644
--- a/src/zklaim/zklaim_api.c
+++ b/src/zklaim/zklaim_api.c
@@ -28,36 +28,10 @@
28#include "gnunet_zklaim_service.h" 28#include "gnunet_zklaim_service.h"
29#include "zklaim/zklaim.h" 29#include "zklaim/zklaim.h"
30#include "zklaim_api.h" 30#include "zklaim_api.h"
31#include "zklaim_functions.h"
31 32
32#define LOG(kind,...) GNUNET_log_from (kind, "zklaim-api",__VA_ARGS__) 33#define LOG(kind,...) GNUNET_log_from (kind, "zklaim-api",__VA_ARGS__)
33 34
34/**
35 * Handle for an ego.
36 */
37struct GNUNET_ZKLAIM_Context
38{
39 /**
40 * ZKlaim context.
41 */
42 struct zklaim_ctx *zk_ctx;
43
44 /**
45 * Current name associated with this context.
46 */
47 char *name;
48
49 /**
50 * Attributes associated with context
51 */
52 char *attrs;
53
54 /**
55 * Client context associated with this ego.
56 */
57 void *ctx;
58
59};
60
61 35
62/** 36/**
63 * Handle for an operation with the service. 37 * Handle for an operation with the service.
@@ -93,6 +67,11 @@ struct GNUNET_ZKLAIM_Operation
93 GNUNET_ZKLAIM_ContinuationWithStatus cont; 67 GNUNET_ZKLAIM_ContinuationWithStatus cont;
94 68
95 /** 69 /**
70 * Context result
71 */
72 GNUNET_ZKLAIM_ContextResult ctx_cont;
73
74 /**
96 * Closure for @e cont or @e cb. 75 * Closure for @e cont or @e cb.
97 */ 76 */
98 void *cls; 77 void *cls;
@@ -273,6 +252,67 @@ handle_zklaim_result_code (void *cls,
273 GNUNET_free (op); 252 GNUNET_free (op);
274} 253}
275 254
255/**
256 * We received a result code from the service. Check the message
257 * is well-formed.
258 *
259 * @param cls closure
260 * @param rcm result message received
261 * @return #GNUNET_OK if the message is well-formed
262 */
263static int
264check_zklaim_result_ctx (void *cls,
265 const struct ContextMessage *cm)
266{
267 //TODO check for data sanity
268 return GNUNET_OK;
269}
270
271
272/**
273 * We received a context result from the service.
274 *
275 * @param cls closure
276 * @param rcm result message received
277 */
278static void
279handle_zklaim_result_ctx (void *cls,
280 const struct ContextMessage *cm)
281{
282 struct GNUNET_ZKLAIM_Handle *h = cls;
283 struct GNUNET_ZKLAIM_Operation *op;
284 struct GNUNET_ZKLAIM_Context ctx;
285 uint16_t ctx_len = ntohs (cm->ctx_len);
286
287 op = h->op_head;
288 if (NULL == op)
289 {
290 GNUNET_break (0);
291 reschedule_connect (h);
292 return;
293 }
294 GNUNET_CONTAINER_DLL_remove (h->op_head,
295 h->op_tail,
296 op);
297 ctx.attrs = (char*)&cm[1];
298 ctx.ctx = zklaim_context_new ();
299 zklaim_ctx_deserialize (ctx.ctx,
300 (unsigned char *) &cm[1]+ strlen (ctx.attrs) + 1,
301 ctx_len);
302 if (NULL != op->ctx_cont)
303 {
304 if (0 > ctx_len)
305 op->ctx_cont (op->cls,
306 &ctx);
307 else
308 op->ctx_cont (op->cls,
309 &ctx);
310 }
311 zklaim_ctx_free (ctx.ctx);
312 GNUNET_free (op);
313}
314
315
276 316
277/** 317/**
278 * Try again to connect to the zklaim service. 318 * Try again to connect to the zklaim service.
@@ -288,6 +328,10 @@ reconnect (void *cls)
288 GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CODE, 328 GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CODE,
289 struct ResultCodeMessage, 329 struct ResultCodeMessage,
290 h), 330 h),
331 GNUNET_MQ_hd_var_size (zklaim_result_ctx,
332 GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CTX,
333 struct ContextMessage,
334 h),
291 GNUNET_MQ_handler_end () 335 GNUNET_MQ_handler_end ()
292 }; 336 };
293 337
@@ -430,4 +474,60 @@ GNUNET_ZKLAIM_disconnect (struct GNUNET_ZKLAIM_Handle *h)
430 GNUNET_free (h); 474 GNUNET_free (h);
431} 475}
432 476
477/**
478 * Lookup context
479 */
480struct GNUNET_ZKLAIM_Operation*
481GNUNET_ZKLAIM_lookup_context (struct GNUNET_ZKLAIM_Handle *h,
482 const char *name,
483 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
484 GNUNET_ZKLAIM_ContextResult cont,
485 void* cont_cls)
486{
487 struct GNUNET_ZKLAIM_Operation *op;
488 struct GNUNET_MQ_Envelope *env;
489 struct LookupMessage *lm;
490 size_t slen;
491
492 if (NULL == h->mq)
493 return NULL;
494 slen = strlen (name) + 1;
495 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct LookupMessage))
496 {
497 GNUNET_break (0);
498 return NULL;
499 }
500 op = GNUNET_new (struct GNUNET_ZKLAIM_Operation);
501 op->h = h;
502 op->ctx_cont = cont;
503 op->cls = cont_cls;
504 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
505 h->op_tail,
506 op);
507 env = GNUNET_MQ_msg_extra (lm,
508 slen,
509 GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE);
510 lm->name_len = htons (slen);
511 lm->reserved = htons (0);
512 lm->private_key = *key;
513 GNUNET_memcpy (&lm[1],
514 name,
515 slen);
516 GNUNET_MQ_send (h->mq,
517 env);
518 return op;
519}
520
521void
522GNUNET_ZKLAIM_issue_from_context (struct GNUNET_ZKLAIM_Context *ctx,
523 struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
524 GNUNET_ZKLAIM_PayloadIterator iter,
525 void* iter_cls)
526{
527 ZKLAIM_context_issue (ctx,
528 key,
529 iter,
530 iter_cls);
531}
532
433/* end of zklaim_api.c */ 533/* end of zklaim_api.c */
diff --git a/src/zklaim/zklaim_api.h b/src/zklaim/zklaim_api.h
index 97c21b498..24197b06c 100644
--- a/src/zklaim/zklaim_api.h
+++ b/src/zklaim/zklaim_api.h
@@ -31,6 +31,28 @@
31 31
32GNUNET_NETWORK_STRUCT_BEGIN 32GNUNET_NETWORK_STRUCT_BEGIN
33 33
34/**
35 * Answer from service to client about last operation;
36 * GET_DEFAULT maybe answered with this message on failure;
37 * CREATE and RENAME will always be answered with this message.
38 */
39struct ContextMessage
40{
41 /**
42 * Type: #GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CTX
43 */
44 struct GNUNET_MessageHeader header;
45
46 /**
47 * Length if the serialized context.
48 */
49 uint32_t ctx_len GNUNET_PACKED;
50
51 /* followed by 0-terminated error message (on error) */
52
53};
54
55
34 56
35/** 57/**
36 * Answer from service to client about last operation; 58 * Answer from service to client about last operation;
@@ -54,6 +76,36 @@ struct ResultCodeMessage
54 76
55}; 77};
56 78
79/**
80 * Client requests issue of a credential. Service
81 * will respond with a context.
82 */
83struct LookupMessage
84{
85 /**
86 * Type: #GNUNET_MESSAGE_TYPE_ZKLAIM_LOOKUP_CTX
87 */
88 struct GNUNET_MessageHeader header;
89
90 /**
91 * Number of bytes in name string including 0-termination, in NBO.
92 */
93 uint16_t name_len GNUNET_PACKED;
94
95 /**
96 * Always zero.
97 */
98 uint16_t reserved GNUNET_PACKED;
99
100 /**
101 * The private key
102 */
103 struct GNUNET_CRYPTO_EcdsaPrivateKey private_key;
104
105 /* followed by 0-terminated identity name */
106
107};
108
57 109
58/** 110/**
59 * Client requests creation of an identity. Service 111 * Client requests creation of an identity. Service
diff --git a/src/zklaim/zklaim_functions.c b/src/zklaim/zklaim_functions.c
new file mode 100644
index 000000000..1c66b421c
--- /dev/null
+++ b/src/zklaim/zklaim_functions.c
@@ -0,0 +1,75 @@
1#include "platform.h"
2#include "zklaim/zklaim.h"
3#include "gcrypt.h"
4#include "gnunet_zklaim_service.h"
5#include "zklaim_functions.h"
6
7int
8ZKLAIM_context_sign (struct GNUNET_ZKLAIM_Context *ctx,
9 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key)
10{
11 int rc;
12 gcry_sexp_t priv;
13
14 //TODO how to ensure not hashed??
15 zklaim_hash_ctx (ctx->ctx);
16 rc = gcry_sexp_build (&priv, NULL,
17 "(private-key(ecc(curve \"Ed25519\")"
18 "(d %b)))",
19 (int) sizeof (key->d), key->d);
20 if (0 != rc)
21 {
22 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
23 "GCRY error...\n");
24 //send_issue_response (ih, NULL, 0);
25 return GNUNET_SYSERR;
26 }
27 return zklaim_ctx_sign (ctx->ctx, priv);
28}
29
30void
31ZKLAIM_context_attributes_iterate (const struct GNUNET_ZKLAIM_Context *ctx,
32 GNUNET_ZKLAIM_PayloadIterator iter,
33 void *iter_cls)
34{
35 int i;
36 int j;
37 uint64_t data;
38 char *attr_name;
39 char *tmp;
40 zklaim_wrap_payload_ctx *plw;
41
42 tmp = GNUNET_strdup (ctx->attrs);
43 attr_name = strtok (tmp, ",");
44 plw = ctx->ctx->pl_ctx_head;
45
46 for (i = 0; i < ctx->ctx->num_of_payloads; i++)
47 {
48 for (j = 0; j < ZKLAIM_MAX_PAYLOAD_ATTRIBUTES; j++)
49 {
50 GNUNET_assert (NULL != attr_name);
51 iter (iter_cls, attr_name, &data);
52 zklaim_set_attr (&plw->pl,
53 data,
54 j);
55 attr_name = strtok (NULL, ",");
56 }
57 plw = plw->next;
58 GNUNET_assert (NULL != plw);
59 }
60 GNUNET_free (tmp);
61
62}
63
64void
65ZKLAIM_context_issue (struct GNUNET_ZKLAIM_Context *ctx,
66 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
67 GNUNET_ZKLAIM_PayloadIterator iter,
68 void *iter_cls)
69{
70 ZKLAIM_context_attributes_iterate (ctx,
71 iter,
72 iter_cls);
73 ZKLAIM_context_sign (ctx,
74 key);
75}
diff --git a/src/zklaim/zklaim_functions.h b/src/zklaim/zklaim_functions.h
new file mode 100644
index 000000000..558485ed3
--- /dev/null
+++ b/src/zklaim/zklaim_functions.h
@@ -0,0 +1,46 @@
1#ifndef GNUNET_ZKLAIM_FUNCTIONS_H
2#define GNUNET_ZKLAIM_FUNCTIONS_H
3
4#include "gnunet_zklaim_service.h"
5
6/**
7 * Handle for an ego.
8 */
9struct GNUNET_ZKLAIM_Context
10{
11 /**
12 * ZKlaim context.
13 */
14 struct zklaim_ctx *ctx;
15
16 /**
17 * Current name associated with this context.
18 */
19 char *name;
20
21 /**
22 * Attributes associated with context
23 */
24 char *attrs;
25
26};
27
28
29
30int
31ZKLAIM_context_sign (struct GNUNET_ZKLAIM_Context *ctx,
32 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key);
33
34
35void
36ZKLAIM_context_attributes_iterate (const struct GNUNET_ZKLAIM_Context *ctx,
37 GNUNET_ZKLAIM_PayloadIterator iter,
38 void *iter_cls);
39
40
41void
42ZKLAIM_context_issue (struct GNUNET_ZKLAIM_Context *ctx,
43 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
44 GNUNET_ZKLAIM_PayloadIterator iter,
45 void *iter_cls);
46#endif