aboutsummaryrefslogtreecommitdiff
path: root/src/zklaim/gnunet-zklaim.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zklaim/gnunet-zklaim.c')
-rw-r--r--src/zklaim/gnunet-zklaim.c91
1 files changed, 87 insertions, 4 deletions
diff --git a/src/zklaim/gnunet-zklaim.c b/src/zklaim/gnunet-zklaim.c
index 053482362..a97bca5d4 100644
--- a/src/zklaim/gnunet-zklaim.c
+++ b/src/zklaim/gnunet-zklaim.c
@@ -55,6 +55,11 @@ static char* context_name;
55static char* issue_attrs; 55static char* issue_attrs;
56 56
57/** 57/**
58 * Attribute names for issuer context data
59 */
60static char* create_attrs;
61
62/**
58 * Ego name 63 * Ego name
59 */ 64 */
60static char* ego_name; 65static char* ego_name;
@@ -119,25 +124,97 @@ context_create_cb (void *cls,
119 int32_t success, 124 int32_t success,
120 const char* emsg) 125 const char* emsg)
121{ 126{
127 if (GNUNET_OK == success)
128 fprintf (stdout,
129 "Created.\n");
130 else
131 fprintf(stderr,
132 "Failed.\n");
133 if (NULL == cleanup_task)
134 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
135 return;
136}
137
138static void
139issue_iter (void *cls,
140 const char* attr_name,
141 uint64_t *data)
142{
143 char *tmp;
144 char *key;
145 char *val;
146 tmp = GNUNET_strdup (issue_attrs);
147 key = strtok (tmp, "=");
148 while (NULL != key)
149 {
150 val = strtok (NULL, ";");
151 if (0 != strcmp (attr_name, key))
152 {
153 key = strtok (NULL, "=");
154 continue;
155 }
156 if (1 != sscanf (val, "%lu", data))
157 fprintf (stderr,
158 "Failed to fill %s with %s\n",
159 key, val);
160 key = strtok (NULL, "=");
161 }
162 GNUNET_free (tmp);
163 fprintf (stdout, "Setting %s=%lu\n", attr_name, *data);
164}
165
166static void
167context_cb (void *cls,
168 const struct GNUNET_ZKLAIM_Context *ctx)
169{
170 int ret;
171 if (NULL == ctx)
172 {
173 fprintf (stderr,
174 "Context does not exist!\n");
175 }
176 else
177 {
178 ret = GNUNET_ZKLAIM_issue_from_context ((struct GNUNET_ZKLAIM_Context*)ctx,
179 (struct GNUNET_CRYPTO_EcdsaPrivateKey*)pkey,
180 &issue_iter,
181 NULL);
182 fprintf (stdout,
183 "Issued (%d)\n", ret);
184 }
185 if (NULL == cleanup_task)
186 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
122 return; 187 return;
188
123} 189}
124 190
125static void 191static void
126handle_arguments () 192handle_arguments ()
127{ 193{
128 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), 194 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60),
129 &timeout_task, 195 &timeout_task,
130 NULL); 196 NULL);
131 if (create) 197 if (create)
132 { 198 {
199 fprintf (stdout,
200 "Creating context...\n");
133 zklaim_op = GNUNET_ZKLAIM_context_create (zklaim_handle, 201 zklaim_op = GNUNET_ZKLAIM_context_create (zklaim_handle,
134 pkey, 202 pkey,
135 context_name, 203 context_name,
136 issue_attrs, 204 create_attrs,
137 &context_create_cb, 205 &context_create_cb,
138 NULL); 206 NULL);
139 return; 207 return;
140 } 208 }
209 if (issue_attrs)
210 {
211 zklaim_op = GNUNET_ZKLAIM_lookup_context (zklaim_handle,
212 context_name,
213 pkey,
214 &context_cb,
215 NULL);
216 return;
217 }
141 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 218 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
142} 219}
143 220
@@ -182,7 +259,7 @@ run (void *cls,
182 _("Context name missing!\n")); 259 _("Context name missing!\n"));
183 return; 260 return;
184 } 261 }
185 if ( (create) && (NULL == issue_attrs) ) 262 if ( (create) && (NULL == create_attrs) )
186 { 263 {
187 ret = 1; 264 ret = 1;
188 fprintf (stderr, 265 fprintf (stderr,
@@ -192,6 +269,7 @@ run (void *cls,
192 269
193 zklaim_handle = GNUNET_ZKLAIM_connect (c); 270 zklaim_handle = GNUNET_ZKLAIM_connect (c);
194 //Get Ego 271 //Get Ego
272 init = GNUNET_YES;
195 identity_handle = GNUNET_IDENTITY_connect (c, 273 identity_handle = GNUNET_IDENTITY_connect (c,
196 &ego_cb, 274 &ego_cb,
197 NULL); 275 NULL);
@@ -215,7 +293,7 @@ main(int argc, char *const argv[])
215 "attributes", 293 "attributes",
216 NULL, 294 NULL,
217 gettext_noop ("Context attributes (comma separated)"), 295 gettext_noop ("Context attributes (comma separated)"),
218 &issue_attrs), 296 &create_attrs),
219 GNUNET_GETOPT_option_string ('e', 297 GNUNET_GETOPT_option_string ('e',
220 "ego", 298 "ego",
221 NULL, 299 NULL,
@@ -225,6 +303,11 @@ main(int argc, char *const argv[])
225 "create", 303 "create",
226 gettext_noop ("Create new issuer context"), 304 gettext_noop ("Create new issuer context"),
227 &create), 305 &create),
306 GNUNET_GETOPT_option_string ('I',
307 "issue",
308 gettext_noop ("Issue a credential with the given attributes and given zklaim context"),
309 NULL,
310 &issue_attrs),
228 GNUNET_GETOPT_OPTION_END 311 GNUNET_GETOPT_OPTION_END
229 }; 312 };
230 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct", 313 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",