diff options
Diffstat (limited to 'src/zklaim/gnunet-zklaim.c')
-rw-r--r-- | src/zklaim/gnunet-zklaim.c | 236 |
1 files changed, 236 insertions, 0 deletions
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 | */ | ||
35 | static int init; | ||
36 | |||
37 | /** | ||
38 | * return value | ||
39 | */ | ||
40 | static int ret; | ||
41 | |||
42 | /** | ||
43 | * Create new ZKlaim issuer context flag | ||
44 | */ | ||
45 | static int create; | ||
46 | |||
47 | /** | ||
48 | * Name of new context | ||
49 | */ | ||
50 | static char* context_name; | ||
51 | |||
52 | /** | ||
53 | * Attribute names for issuer context data | ||
54 | */ | ||
55 | static char* issue_attrs; | ||
56 | |||
57 | /** | ||
58 | * Ego name | ||
59 | */ | ||
60 | static char* ego_name; | ||
61 | |||
62 | /** | ||
63 | * ZKLAIM handle | ||
64 | */ | ||
65 | static struct GNUNET_ZKLAIM_Handle *zklaim_handle; | ||
66 | |||
67 | /** | ||
68 | * ZKLAIM Operation | ||
69 | */ | ||
70 | static struct GNUNET_ZKLAIM_Operation *zklaim_op; | ||
71 | |||
72 | /** | ||
73 | * IDENTITY handle | ||
74 | */ | ||
75 | static struct GNUNET_IDENTITY_Handle *identity_handle; | ||
76 | |||
77 | /** | ||
78 | * ego private key | ||
79 | */ | ||
80 | static const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey; | ||
81 | |||
82 | /** | ||
83 | * Timeout task | ||
84 | */ | ||
85 | static struct GNUNET_SCHEDULER_Task *timeout; | ||
86 | |||
87 | /** | ||
88 | * Cleanup task | ||
89 | */ | ||
90 | static struct GNUNET_SCHEDULER_Task *cleanup_task; | ||
91 | |||
92 | static void | ||
93 | do_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 | |||
106 | static void | ||
107 | timeout_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 | |||
117 | static void | ||
118 | context_create_cb (void *cls, | ||
119 | int32_t success, | ||
120 | const char* emsg) | ||
121 | { | ||
122 | return; | ||
123 | } | ||
124 | |||
125 | static void | ||
126 | handle_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 | |||
144 | static void | ||
145 | ego_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 | |||
163 | static void | ||
164 | run (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 | |||
203 | int | ||
204 | main(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 | } | ||