aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/zklaim/Makefile.am26
-rw-r--r--src/zklaim/gnunet-service-zklaim.c417
-rw-r--r--src/zklaim/gnunet-zklaim.c236
-rw-r--r--src/zklaim/zklaim_api.h7
4 files changed, 685 insertions, 1 deletions
diff --git a/src/zklaim/Makefile.am b/src/zklaim/Makefile.am
index 1b25ac1a3..c718ae28f 100644
--- a/src/zklaim/Makefile.am
+++ b/src/zklaim/Makefile.am
@@ -18,6 +18,9 @@ plugin_LTLIBRARIES = \
18lib_LTLIBRARIES = \ 18lib_LTLIBRARIES = \
19 libgnunetzklaim.la 19 libgnunetzklaim.la
20 20
21libexec_PROGRAMS = \
22 gnunet-service-zklaim
23
21libgnunetzklaim_la_SOURCES = \ 24libgnunetzklaim_la_SOURCES = \
22 zklaim_api.c \ 25 zklaim_api.c \
23 zklaim_api.h 26 zklaim_api.h
@@ -28,6 +31,29 @@ libgnunetzklaim_la_LDFLAGS = \
28 $(GN_LIB_LDFLAGS) $(WINFLAGS) \ 31 $(GN_LIB_LDFLAGS) $(WINFLAGS) \
29 -version-info 0:0:0 32 -version-info 0:0:0
30 33
34gnunet_service_zklaim_SOURCES = \
35 gnunet-service-zklaim.c
36gnunet_service_zklaim_LDADD = \
37 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
38 $(top_builddir)/src/util/libgnunetutil.la \
39 $(top_builddir)/src/namestore/libgnunetnamestore.la \
40 $(top_builddir)/src/statistics/libgnunetstatistics.la \
41 $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \
42 $(top_builddir)/src/reclaim/libgnunetreclaim.la \
43 $(top_builddir)/src/gns/libgnunetgns.la \
44 $(GCLIBADD)\
45 $(LIBGCRYPT_LIBS) \
46 -lzklaim \
47 -lgcrypt \
48 -lgmp \
49 -lgmpxx \
50 -lcrypto \
51 -lprocps \
52 -lstdc++ \
53 -lm
54 $(GN_LIBINTL)
55
56
31 57
32libgnunet_plugin_reclaim_attribute_zklaim_la_SOURCES = \ 58libgnunet_plugin_reclaim_attribute_zklaim_la_SOURCES = \
33 plugin_reclaim_attribute_zklaim.c 59 plugin_reclaim_attribute_zklaim.c
diff --git a/src/zklaim/gnunet-service-zklaim.c b/src/zklaim/gnunet-service-zklaim.c
new file mode 100644
index 000000000..ac8455364
--- /dev/null
+++ b/src/zklaim/gnunet-service-zklaim.c
@@ -0,0 +1,417 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 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 * @author Martin Schanzenbach
20 * @file src/reclaim/gnunet-service-reclaim.c
21 * @brief reclaim Service
22 *
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_constants.h"
27#include "gnunet_protocols.h"
28#include "gnunet_gnsrecord_lib.h"
29#include "gnunet_gns_service.h"
30#include "gnunet_statistics_service.h"
31#include "gnunet_namestore_service.h"
32#include "zklaim_api.h"
33#include "zklaim/zklaim.h"
34
35/**
36 * Namestore handle
37 */
38static struct GNUNET_NAMESTORE_Handle *ns_handle;
39
40/**
41 * GNS handle
42 */
43static struct GNUNET_GNS_Handle *gns_handle;
44
45/**
46 * Handle to the statistics service.
47 */
48static struct GNUNET_STATISTICS_Handle *stats;
49
50/**
51 * Our configuration.
52 */
53static const struct GNUNET_CONFIGURATION_Handle *cfg;
54
55/**
56 * An idp client
57 */
58struct ZkClient
59{
60
61 /**
62 * The client
63 */
64 struct GNUNET_SERVICE_Client *client;
65
66 /**
67 * Message queue for transmission to @e client
68 */
69 struct GNUNET_MQ_Handle *mq;
70
71 /**
72 * Head of DLL of context create ops
73 */
74 struct CreateContextHandle *create_op_head;
75
76 /**
77 * Tail of DLL of attribute store ops
78 */
79 struct CreateContextHandle *create_op_tail;
80
81};
82
83struct CreateContextHandle
84{
85 /**
86 * DLL
87 */
88 struct CreateContextHandle *next;
89
90 /**
91 * DLL
92 */
93 struct CreateContextHandle *prev;
94
95 /**
96 * Client connection
97 */
98 struct ZkClient *client;
99
100 /**
101 * Issuer private key
102 */
103 struct GNUNET_CRYPTO_EcdsaPrivateKey private_key;
104
105 /**
106 * Issuer public key
107 */
108 struct GNUNET_CRYPTO_EcdsaPublicKey public_key;
109
110 /**
111 * QueueEntry
112 */
113 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
114
115 /**
116 * The context name
117 */
118 char *name;
119
120 /**
121 * The attributes to support
122 */
123 char *attrs;
124
125};
126
127/**
128 * Cleanup task
129 */
130static void
131cleanup()
132{
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
134 "Cleaning up\n");
135
136 if (NULL != stats)
137 {
138 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
139 stats = NULL;
140 }
141 if (NULL != gns_handle)
142 GNUNET_GNS_disconnect (gns_handle);
143 if (NULL != ns_handle)
144 GNUNET_NAMESTORE_disconnect (ns_handle);
145}
146
147/**
148 * Shutdown task
149 *
150 * @param cls NULL
151 */
152static void
153do_shutdown (void *cls)
154{
155 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
156 "Shutting down...\n");
157 cleanup();
158}
159
160
161
162/**
163 * Cleanup attribute store handle
164 *
165 * @param handle handle to clean up
166 */
167static void
168cleanup_create_handle (struct CreateContextHandle *handle)
169{
170 if (NULL != handle->ns_qe)
171 GNUNET_NAMESTORE_cancel (handle->ns_qe);
172 if (NULL != handle->name)
173 GNUNET_free (handle->name);
174 GNUNET_free (handle);
175}
176
177static void
178send_result (int32_t status,
179 struct CreateContextHandle *cch)
180{
181 struct GNUNET_MQ_Envelope *env;
182 struct ResultCodeMessage *r_msg;
183
184
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
186 "Sending RESULT_CODE message\n");
187 env = GNUNET_MQ_msg (r_msg,
188 GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CODE);
189 r_msg->result_code = htonl (status);
190 GNUNET_MQ_send (cch->client->mq,
191 env);
192 cleanup_create_handle (cch);
193
194}
195
196static void
197context_store_cont (void *cls,
198 int32_t success,
199 const char *emsg)
200{
201 struct CreateContextHandle *cch = cls;
202
203 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)
209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
210 "Failed to create context %s\n",
211 emsg);
212
213 send_result (success, cch);
214}
215
216
217
218static int
219check_create_context_message(void *cls,
220 const struct CreateRequestMessage *crm)
221{
222 uint16_t size;
223
224 size = ntohs (crm->header.size);
225 if (size <= sizeof (struct CreateRequestMessage))
226 {
227 GNUNET_break (0);
228 return GNUNET_SYSERR;
229 }
230 return GNUNET_OK;
231}
232
233
234static void
235handle_create_context_message (void *cls,
236 const struct CreateRequestMessage *crm)
237{
238 struct CreateContextHandle *cch;
239 struct ZkClient *zkc = cls;
240 size_t data_len;
241 char *tmp;
242 char *pos;
243 unsigned char *data;
244 int num_attrs;
245 int num_pl;
246 int i;
247 zklaim_ctx *ctx;
248
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
250 "Received CREATE_REQUEST message\n");
251
252 data_len = ntohs (crm->name_len);
253
254 cch = GNUNET_new (struct CreateContextHandle);
255 cch->name = GNUNET_strndup ((char*)&crm[1], data_len-1);
256 data_len = ntohs(crm->attrs_len);
257 cch->attrs = GNUNET_strndup (((char*)&crm[1]) + strlen (cch->name) + 1,
258 data_len-1);
259 cch->private_key = crm->private_key;
260 GNUNET_CRYPTO_ecdsa_key_get_public (&crm->private_key,
261 &cch->public_key);
262
263 GNUNET_SERVICE_client_continue (zkc->client);
264 cch->client = zkc;
265 GNUNET_CONTAINER_DLL_insert (zkc->create_op_head,
266 zkc->create_op_tail,
267 cch);
268
269 tmp = GNUNET_strdup (cch->attrs);
270 pos = strtok(tmp, ",");
271 num_attrs = 0;
272 if (NULL == pos)
273 {
274 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
275 "No attributes given.\n");
276 send_result(GNUNET_SYSERR, cch);
277 GNUNET_free (tmp);
278 return;
279 }
280 while (NULL != pos)
281 {
282 num_attrs++;
283 pos = strtok(NULL, ",");
284 }
285 GNUNET_free (tmp);
286 num_pl = num_attrs / 5;
287 zklaim_payload pl[num_pl];
288 ctx = zklaim_context_new ();
289 for (i = 0; i < num_pl; i++)
290 zklaim_add_pl (ctx, pl[i]);
291 zklaim_hash_ctx (ctx);
292 if (0 != zklaim_trusted_setup (ctx))
293 {
294 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
295 "Trusted Setup failed.\n");
296 send_result(GNUNET_SYSERR, cch);
297 zklaim_ctx_free (ctx);
298 return;
299 }
300 if (0 != zklaim_ctx_serialize (ctx, &data))
301 {
302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
303 "Context serialization failed.\n");
304 send_result(GNUNET_SYSERR, cch);
305 zklaim_ctx_free (ctx);
306 return;
307 }
308 zklaim_ctx_free (ctx);
309 // store ctx,attrs as GNS record
310}
311
312
313
314/**
315 * Main function that will be run
316 *
317 * @param cls closure
318 * @param c the configuration used
319 * @param server the service handle
320 */
321static void
322run (void *cls,
323 const struct GNUNET_CONFIGURATION_Handle *c,
324 struct GNUNET_SERVICE_Handle *server)
325{
326 cfg = c;
327
328 stats = GNUNET_STATISTICS_create ("zklaim", cfg);
329
330 //Connect to services
331 ns_handle = GNUNET_NAMESTORE_connect (cfg);
332 if (NULL == ns_handle)
333 {
334 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to namestore");
335 }
336
337 gns_handle = GNUNET_GNS_connect (cfg);
338 if (NULL == gns_handle)
339 {
340 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to gns");
341 }
342 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
343}
344
345
346/**
347 * Called whenever a client is disconnected.
348 *
349 * @param cls closure
350 * @param client identification of the client
351 * @param app_ctx @a client
352 */
353static void
354client_disconnect_cb (void *cls,
355 struct GNUNET_SERVICE_Client *client,
356 void *app_ctx)
357{
358 struct ZkClient *zkc = app_ctx;
359 struct CreateContextHandle *cch;
360
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
362 "Client %p disconnected\n",
363 client);
364
365 while (NULL != (cch = zkc->create_op_head))
366 {
367 GNUNET_CONTAINER_DLL_remove (zkc->create_op_head,
368 zkc->create_op_tail,
369 cch);
370 cleanup_create_handle (cch);
371 }
372 GNUNET_free (zkc);
373}
374
375
376
377/**
378 * Add a client to our list of active clients.
379 *
380 * @param cls NULL
381 * @param client client to add
382 * @param mq message queue for @a client
383 * @return internal namestore client structure for this client
384 */
385static void *
386client_connect_cb (void *cls,
387 struct GNUNET_SERVICE_Client *client,
388 struct GNUNET_MQ_Handle *mq)
389{
390 struct ZkClient *zkc;
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "Client %p connected\n",
393 client);
394 zkc = GNUNET_new (struct ZkClient);
395 zkc->client = client;
396 zkc->mq = mq;
397 return zkc;
398}
399
400
401
402/**
403 * Define "main" method using service macro.
404 */
405GNUNET_SERVICE_MAIN
406("zklaim",
407 GNUNET_SERVICE_OPTION_NONE,
408 &run,
409 &client_connect_cb,
410 &client_disconnect_cb,
411 NULL,
412 GNUNET_MQ_hd_var_size (create_context_message,
413 GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE,
414 struct CreateRequestMessage,
415 NULL),
416 GNUNET_MQ_handler_end());
417/* end of gnunet-service-zklaim.c */
diff --git a/src/zklaim/gnunet-zklaim.c b/src/zklaim/gnunet-zklaim.c
new file mode 100644
index 000000000..053482362
--- /dev/null
+++ b/src/zklaim/gnunet-zklaim.c
@@ -0,0 +1,236 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 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 * @author Martin Schanzenbach
20 * @file src/zklaim/gnunet-zklaim.c
21 * @brief ZKlaim CLI
22 *
23 */
24
25#include "platform.h"
26#include "gnunet_util_lib.h"
27#include "gnunet_namestore_service.h"
28#include "gnunet_zklaim_service.h"
29#include "gnunet_identity_service.h"
30#include "gnunet_signatures.h"
31
32/**
33 * state
34 */
35static int init;
36
37/**
38 * return value
39 */
40static int ret;
41
42/**
43 * Create new ZKlaim issuer context flag
44 */
45static int create;
46
47/**
48 * Name of new context
49 */
50static char* context_name;
51
52/**
53 * Attribute names for issuer context data
54 */
55static char* issue_attrs;
56
57/**
58 * Ego name
59 */
60static char* ego_name;
61
62/**
63 * ZKLAIM handle
64 */
65static struct GNUNET_ZKLAIM_Handle *zklaim_handle;
66
67/**
68 * ZKLAIM Operation
69 */
70static struct GNUNET_ZKLAIM_Operation *zklaim_op;
71
72/**
73 * IDENTITY handle
74 */
75static struct GNUNET_IDENTITY_Handle *identity_handle;
76
77/**
78 * ego private key
79 */
80static const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
81
82/**
83 * Timeout task
84 */
85static struct GNUNET_SCHEDULER_Task *timeout;
86
87/**
88 * Cleanup task
89 */
90static struct GNUNET_SCHEDULER_Task *cleanup_task;
91
92static void
93do_cleanup(void *cls)
94{
95 cleanup_task = NULL;
96 if (NULL != timeout)
97 GNUNET_SCHEDULER_cancel (timeout);
98 if (NULL != zklaim_op)
99 GNUNET_ZKLAIM_cancel (zklaim_op);
100 if (NULL != zklaim_handle)
101 GNUNET_ZKLAIM_disconnect (zklaim_handle);
102 if (NULL != identity_handle)
103 GNUNET_IDENTITY_disconnect (identity_handle);
104}
105
106static void
107timeout_task (void *cls)
108{
109 timeout = NULL;
110 ret = 1;
111 fprintf (stderr,
112 "Timeout\n");
113 if (NULL == cleanup_task)
114 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
115}
116
117static void
118context_create_cb (void *cls,
119 int32_t success,
120 const char* emsg)
121{
122 return;
123}
124
125static void
126handle_arguments ()
127{
128 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
129 &timeout_task,
130 NULL);
131 if (create)
132 {
133 zklaim_op = GNUNET_ZKLAIM_context_create (zklaim_handle,
134 pkey,
135 context_name,
136 issue_attrs,
137 &context_create_cb,
138 NULL);
139 return;
140 }
141 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
142}
143
144static void
145ego_cb (void *cls,
146 struct GNUNET_IDENTITY_Ego *ego,
147 void **ctx,
148 const char *name)
149{
150 if (NULL == name) {
151 if (GNUNET_YES == init) {
152 init = GNUNET_NO;
153 handle_arguments();
154 }
155 return;
156 }
157 if (0 != strcmp (name, ego_name))
158 return;
159 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
160}
161
162
163static void
164run (void *cls,
165 char *const *args,
166 const char *cfgfile,
167 const struct GNUNET_CONFIGURATION_Handle *c)
168{
169 ret = 0;
170 if (NULL == ego_name)
171 {
172 ret = 1;
173 fprintf (stderr,
174 _("Ego is required\n"));
175 return;
176 }
177
178 if ( (create) && (NULL == context_name) )
179 {
180 ret = 1;
181 fprintf (stderr,
182 _("Context name missing!\n"));
183 return;
184 }
185 if ( (create) && (NULL == issue_attrs) )
186 {
187 ret = 1;
188 fprintf (stderr,
189 _("Context attributes missing!\n"));
190 return;
191 }
192
193 zklaim_handle = GNUNET_ZKLAIM_connect (c);
194 //Get Ego
195 identity_handle = GNUNET_IDENTITY_connect (c,
196 &ego_cb,
197 NULL);
198
199
200}
201
202
203int
204main(int argc, char *const argv[])
205{
206 struct GNUNET_GETOPT_CommandLineOption options[] = {
207
208 GNUNET_GETOPT_option_string ('n',
209 "name",
210 NULL,
211 gettext_noop ("Context name"),
212 &context_name),
213
214 GNUNET_GETOPT_option_string ('A',
215 "attributes",
216 NULL,
217 gettext_noop ("Context attributes (comma separated)"),
218 &issue_attrs),
219 GNUNET_GETOPT_option_string ('e',
220 "ego",
221 NULL,
222 gettext_noop ("Ego"),
223 &ego_name),
224 GNUNET_GETOPT_option_flag ('C',
225 "create",
226 gettext_noop ("Create new issuer context"),
227 &create),
228 GNUNET_GETOPT_OPTION_END
229 };
230 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",
231 "ct", options,
232 &run, NULL))
233 return 1;
234 else
235 return ret;
236}
diff --git a/src/zklaim/zklaim_api.h b/src/zklaim/zklaim_api.h
index 77053c667..97c21b498 100644
--- a/src/zklaim/zklaim_api.h
+++ b/src/zklaim/zklaim_api.h
@@ -67,11 +67,16 @@ struct CreateRequestMessage
67 struct GNUNET_MessageHeader header; 67 struct GNUNET_MessageHeader header;
68 68
69 /** 69 /**
70 * Number of bytes in identity name string including 0-termination, in NBO. 70 * Number of bytes in name string including 0-termination, in NBO.
71 */ 71 */
72 uint16_t name_len GNUNET_PACKED; 72 uint16_t name_len GNUNET_PACKED;
73 73
74 /** 74 /**
75 * Number of bytes in attributes string including 0-termination, in NBO.
76 */
77 uint16_t attrs_len GNUNET_PACKED;
78
79 /**
75 * Always zero. 80 * Always zero.
76 */ 81 */
77 uint16_t reserved GNUNET_PACKED; 82 uint16_t reserved GNUNET_PACKED;