aboutsummaryrefslogtreecommitdiff
path: root/src/zklaim
diff options
context:
space:
mode:
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-08-17 19:09:44 +0200
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-08-17 19:09:44 +0200
commit9e3072d8c80e1ccf2efe851acd046782cc574dbd (patch)
tree18fbf3c3b7aad88844fc05295bd6c7810f128ac9 /src/zklaim
parent31487d74b36541f0d97caf6d844da52a7667cd97 (diff)
downloadgnunet-9e3072d8c80e1ccf2efe851acd046782cc574dbd.tar.gz
gnunet-9e3072d8c80e1ccf2efe851acd046782cc574dbd.zip
proving key still missing
Diffstat (limited to 'src/zklaim')
-rw-r--r--src/zklaim/gnunet-zklaim.c131
-rw-r--r--src/zklaim/zklaim_api.c56
-rw-r--r--src/zklaim/zklaim_functions.c37
-rw-r--r--src/zklaim/zklaim_functions.h6
4 files changed, 217 insertions, 13 deletions
diff --git a/src/zklaim/gnunet-zklaim.c b/src/zklaim/gnunet-zklaim.c
index a97bca5d4..fb6695574 100644
--- a/src/zklaim/gnunet-zklaim.c
+++ b/src/zklaim/gnunet-zklaim.c
@@ -57,6 +57,16 @@ static char* issue_attrs;
57/** 57/**
58 * Attribute names for issuer context data 58 * Attribute names for issuer context data
59 */ 59 */
60static char* credential;
61
62/**
63 * Attribute names for issuer context data
64 */
65static char* prove_predicate;
66
67/**
68 * Attribute names for issuer context data
69 */
60static char* create_attrs; 70static char* create_attrs;
61 71
62/** 72/**
@@ -168,6 +178,10 @@ context_cb (void *cls,
168 const struct GNUNET_ZKLAIM_Context *ctx) 178 const struct GNUNET_ZKLAIM_Context *ctx)
169{ 179{
170 int ret; 180 int ret;
181 size_t len;
182 char* data;
183 char *str;
184
171 if (NULL == ctx) 185 if (NULL == ctx)
172 { 186 {
173 fprintf (stderr, 187 fprintf (stderr,
@@ -179,8 +193,22 @@ context_cb (void *cls,
179 (struct GNUNET_CRYPTO_EcdsaPrivateKey*)pkey, 193 (struct GNUNET_CRYPTO_EcdsaPrivateKey*)pkey,
180 &issue_iter, 194 &issue_iter,
181 NULL); 195 NULL);
182 fprintf (stdout, 196 if (0 != ret)
183 "Issued (%d)\n", ret); 197 {
198 fprintf (stderr,
199 "Failed (%d)\n", ret);
200 }
201 else
202 {
203 len = GNUNET_ZKLAIM_context_serialize (ctx,
204 &data);
205 GNUNET_STRINGS_base64_encode (data,
206 len,
207 &str);
208 fprintf (stdout,
209 "%s\n", str);
210 GNUNET_free (str);
211 }
184 } 212 }
185 if (NULL == cleanup_task) 213 if (NULL == cleanup_task)
186 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 214 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
@@ -188,9 +216,75 @@ context_cb (void *cls,
188 216
189} 217}
190 218
219enum zklaim_op
220op_str_to_enum (const char* op_str)
221{
222
223 if (0 == strcmp ("<", op_str))
224 return zklaim_less;
225 else if (0 == strcmp ("<=", op_str))
226 return zklaim_less_or_eq;
227 else if (0 == strcmp ("==", op_str))
228 return zklaim_eq;
229 else if (0 == strcmp ("<=", op_str))
230 return zklaim_greater_or_eq;
231 else if (0 == strcmp ("<", op_str))
232 return zklaim_greater;
233 else if (0 == strcmp ("!=", op_str))
234 return zklaim_not_eq;
235 return zklaim_noop;
236}
237
238void
239prove_iter (void *cls,
240 const char* name,
241 enum zklaim_op *zop,
242 uint64_t *ref)
243{
244 char *tmp;
245 char *attr;
246 char *val;
247 char *op;
248 tmp = GNUNET_strdup (prove_predicate);
249 fprintf (stderr,
250 "%s\n",
251 prove_predicate);
252 attr = strtok (tmp, " ");
253 while (NULL != attr)
254 {
255 fprintf (stderr,
256 "Got %s\n", attr);
257 op = strtok (NULL, " ");
258 if (NULL == op)
259 break;
260 val = strtok (NULL, ";");
261 if (NULL == val)
262 break;
263 if (0 != strcmp (name, attr))
264 {
265 attr = strtok (NULL, " ");
266 continue;
267 }
268 *zop = op_str_to_enum (op);
269 if (1 != sscanf (val, "%lu", ref))
270 fprintf (stderr,
271 "Failed parse %s %s %s\n",
272 attr, op, val);
273 fprintf (stdout, "Setting %s %s %lu\n", name, op, *ref);
274 attr = strtok (NULL, " ");
275 }
276 GNUNET_free (tmp);
277
278}
279
191static void 280static void
192handle_arguments () 281handle_arguments ()
193{ 282{
283 struct GNUNET_ZKLAIM_Context *ctx;
284 size_t len;
285 char *data;
286 int ret;
287
194 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), 288 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60),
195 &timeout_task, 289 &timeout_task,
196 NULL); 290 NULL);
@@ -206,7 +300,7 @@ handle_arguments ()
206 NULL); 300 NULL);
207 return; 301 return;
208 } 302 }
209 if (issue_attrs) 303 else if (issue_attrs)
210 { 304 {
211 zklaim_op = GNUNET_ZKLAIM_lookup_context (zklaim_handle, 305 zklaim_op = GNUNET_ZKLAIM_lookup_context (zklaim_handle,
212 context_name, 306 context_name,
@@ -215,6 +309,24 @@ handle_arguments ()
215 NULL); 309 NULL);
216 return; 310 return;
217 } 311 }
312 else if (prove_predicate)
313 {
314 len = GNUNET_STRINGS_base64_decode (credential,
315 strlen (credential),
316 (void**)&data);
317
318 ctx = GNUNET_ZKLAIM_context_deserialize (data,
319 len);
320 fprintf (stderr,
321 "%s\n",
322 prove_predicate);
323
324 ret = GNUNET_ZKLAIM_context_prove (ctx,
325 &prove_iter,
326 NULL);
327 fprintf (stdout,
328 "Prove result: %d\n", ret);
329 }
218 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 330 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
219} 331}
220 332
@@ -288,7 +400,6 @@ main(int argc, char *const argv[])
288 NULL, 400 NULL,
289 gettext_noop ("Context name"), 401 gettext_noop ("Context name"),
290 &context_name), 402 &context_name),
291
292 GNUNET_GETOPT_option_string ('A', 403 GNUNET_GETOPT_option_string ('A',
293 "attributes", 404 "attributes",
294 NULL, 405 NULL,
@@ -305,9 +416,19 @@ main(int argc, char *const argv[])
305 &create), 416 &create),
306 GNUNET_GETOPT_option_string ('I', 417 GNUNET_GETOPT_option_string ('I',
307 "issue", 418 "issue",
308 gettext_noop ("Issue a credential with the given attributes and given zklaim context"),
309 NULL, 419 NULL,
420 gettext_noop ("Issue a credential with the given attributes and given zklaim context"),
310 &issue_attrs), 421 &issue_attrs),
422 GNUNET_GETOPT_option_string ('P',
423 "predicate",
424 NULL,
425 gettext_noop ("Predicate to prove"),
426 &prove_predicate),
427 GNUNET_GETOPT_option_string ('R',
428 "credential",
429 NULL,
430 gettext_noop ("A credential"),
431 &credential),
311 GNUNET_GETOPT_OPTION_END 432 GNUNET_GETOPT_OPTION_END
312 }; 433 };
313 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct", 434 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",
diff --git a/src/zklaim/zklaim_api.c b/src/zklaim/zklaim_api.c
index 6e9da67f3..6ca94fda5 100644
--- a/src/zklaim/zklaim_api.c
+++ b/src/zklaim/zklaim_api.c
@@ -536,4 +536,60 @@ GNUNET_ZKLAIM_issue_from_context (struct GNUNET_ZKLAIM_Context *ctx,
536 iter_cls); 536 iter_cls);
537} 537}
538 538
539size_t
540GNUNET_ZKLAIM_context_serialize (const struct GNUNET_ZKLAIM_Context *ctx,
541 char **buf)
542{
543 char *pos;
544 char *tmp;
545 size_t len;
546 size_t len_w;
547 size_t ret_len = 0;
548 len = zklaim_ctx_serialize (ctx->ctx,
549 (unsigned char**) &tmp);
550 ret_len += strlen (ctx->attrs) + 1 + sizeof (size_t) + len;
551 *buf = GNUNET_malloc (ret_len);
552 pos = *buf;
553 memcpy (pos, ctx->attrs, strlen (ctx->attrs) + 1);
554 pos += strlen (ctx->attrs) + 1;
555 len_w = htonl (len);
556 memcpy (pos, &len_w, sizeof (size_t));
557 pos += sizeof (size_t);
558 memcpy (pos, tmp, len);
559 GNUNET_free (tmp);
560 return ret_len;
561}
562
563
564struct GNUNET_ZKLAIM_Context *
565GNUNET_ZKLAIM_context_deserialize (char *data,
566 size_t data_len)
567{
568 struct GNUNET_ZKLAIM_Context *ctx;
569 char *pos;
570 size_t len;
571
572 ctx = GNUNET_new (struct GNUNET_ZKLAIM_Context);
573 ctx->attrs = GNUNET_strdup (data);
574 pos = data + strlen (ctx->attrs) + 1;
575 len = ntohl (*((size_t*)pos));
576 ctx->ctx = zklaim_context_new ();
577 pos += sizeof (size_t);
578 if (0 != zklaim_ctx_deserialize (ctx->ctx,
579 (unsigned char*) pos,
580 len))
581 return NULL;
582 return ctx;
583}
584
585int
586GNUNET_ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx,
587 GNUNET_ZKLAIM_PredicateIterator iter,
588 void* iter_cls)
589{
590 return ZKLAIM_context_prove (ctx,
591 iter,
592 iter_cls);
593}
594
539/* end of zklaim_api.c */ 595/* end of zklaim_api.c */
diff --git a/src/zklaim/zklaim_functions.c b/src/zklaim/zklaim_functions.c
index 7f83ecb22..e9e911623 100644
--- a/src/zklaim/zklaim_functions.c
+++ b/src/zklaim/zklaim_functions.c
@@ -101,7 +101,7 @@ ZKLAIM_context_issue (struct GNUNET_ZKLAIM_Context *ctx,
101 key); 101 key);
102} 102}
103 103
104void 104int
105ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx, 105ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx,
106 GNUNET_ZKLAIM_PredicateIterator iter, 106 GNUNET_ZKLAIM_PredicateIterator iter,
107 void *iter_cls) 107 void *iter_cls)
@@ -115,23 +115,44 @@ ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx,
115 tmp = GNUNET_strdup (ctx->attrs); 115 tmp = GNUNET_strdup (ctx->attrs);
116 attr_name = strtok (tmp, ","); 116 attr_name = strtok (tmp, ",");
117 plw = ctx->ctx->pl_ctx_head; 117 plw = ctx->ctx->pl_ctx_head;
118 118 fprintf (stderr,
119 "Num payloads: %lu, attrs: %s\n",
120 ctx->ctx->num_of_payloads,
121 ctx->attrs);
119 for (i = 0; i < ctx->ctx->num_of_payloads; i++) 122 for (i = 0; i < ctx->ctx->num_of_payloads; i++)
120 { 123 {
121 for (j = 0; j < ZKLAIM_MAX_PAYLOAD_ATTRIBUTES; j++) 124 for (j = 0; j < ZKLAIM_MAX_PAYLOAD_ATTRIBUTES; j++)
122 { 125 {
123 GNUNET_assert (NULL != attr_name); 126 plw->pl.data_op[j] = zklaim_noop;
127 }
128 plw = plw->next;
129 }
130 plw = ctx->ctx->pl_ctx_head;
131 for (i = 0; i < ctx->ctx->num_of_payloads; i++)
132 {
133 fprintf (stderr,
134 "Payload #%d\n",
135 i);
136
137 for (j = 0; j < ZKLAIM_MAX_PAYLOAD_ATTRIBUTES; j++)
138 {
139
140 if (NULL == attr_name)
141 break;
124 iter (iter_cls, 142 iter (iter_cls,
125 attr_name, 143 attr_name,
126 &plw->pl.data_op[i], 144 &plw->pl.data_op[j],
127 &plw->pl.data_ref[i]); 145 &plw->pl.data_ref[j]);
128 attr_name = strtok (NULL, ","); 146 attr_name = strtok (attr_name + strlen (attr_name) + 1, ",");
129 } 147 }
148 if (NULL == attr_name)
149 break;
130 plw = plw->next; 150 plw = plw->next;
131 GNUNET_assert (NULL != plw); 151 GNUNET_assert (NULL != plw);
132 } 152 }
133 GNUNET_free (tmp); 153 GNUNET_free (tmp);
134 154 zklaim_print (ctx->ctx);
155 return zklaim_proof_generate (ctx->ctx);
135} 156}
136 157
137int 158int
diff --git a/src/zklaim/zklaim_functions.h b/src/zklaim/zklaim_functions.h
index 8542023db..6fda611fa 100644
--- a/src/zklaim/zklaim_functions.h
+++ b/src/zklaim/zklaim_functions.h
@@ -68,4 +68,10 @@ ZKLAIM_context_issue (struct GNUNET_ZKLAIM_Context *ctx,
68 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 68 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
69 GNUNET_ZKLAIM_PayloadIterator iter, 69 GNUNET_ZKLAIM_PayloadIterator iter,
70 void *iter_cls); 70 void *iter_cls);
71
72int
73ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx,
74 GNUNET_ZKLAIM_PredicateIterator iter,
75 void *iter_cls);
76
71#endif 77#endif