diff options
Diffstat (limited to 'src/credential/gnunet-credential.c')
-rw-r--r-- | src/credential/gnunet-credential.c | 655 |
1 files changed, 328 insertions, 327 deletions
diff --git a/src/credential/gnunet-credential.c b/src/credential/gnunet-credential.c index 7873e4230..415525e9a 100644 --- a/src/credential/gnunet-credential.c +++ b/src/credential/gnunet-credential.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gnunet-credential.c | 21 | * @file gnunet-credential.c |
22 | * @brief command line tool to access command line Credential service | 22 | * @brief command line tool to access command line Credential service |
@@ -126,23 +126,23 @@ static int collect; | |||
126 | * @param cls unused | 126 | * @param cls unused |
127 | */ | 127 | */ |
128 | static void | 128 | static void |
129 | do_shutdown (void *cls) | 129 | do_shutdown(void *cls) |
130 | { | 130 | { |
131 | if (NULL != verify_request) | 131 | if (NULL != verify_request) |
132 | { | 132 | { |
133 | GNUNET_CREDENTIAL_request_cancel (verify_request); | 133 | GNUNET_CREDENTIAL_request_cancel(verify_request); |
134 | verify_request = NULL; | 134 | verify_request = NULL; |
135 | } | 135 | } |
136 | if (NULL != credential) | 136 | if (NULL != credential) |
137 | { | 137 | { |
138 | GNUNET_CREDENTIAL_disconnect (credential); | 138 | GNUNET_CREDENTIAL_disconnect(credential); |
139 | credential = NULL; | 139 | credential = NULL; |
140 | } | 140 | } |
141 | if (NULL != tt) | 141 | if (NULL != tt) |
142 | { | 142 | { |
143 | GNUNET_SCHEDULER_cancel (tt); | 143 | GNUNET_SCHEDULER_cancel(tt); |
144 | tt = NULL; | 144 | tt = NULL; |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | 148 | ||
@@ -152,14 +152,14 @@ do_shutdown (void *cls) | |||
152 | * @param cls unused | 152 | * @param cls unused |
153 | */ | 153 | */ |
154 | static void | 154 | static void |
155 | do_timeout (void *cls) | 155 | do_timeout(void *cls) |
156 | { | 156 | { |
157 | tt = NULL; | 157 | tt = NULL; |
158 | GNUNET_SCHEDULER_shutdown (); | 158 | GNUNET_SCHEDULER_shutdown(); |
159 | } | 159 | } |
160 | 160 | ||
161 | static void | 161 | static void |
162 | handle_collect_result (void *cls, | 162 | handle_collect_result(void *cls, |
163 | unsigned int d_count, | 163 | unsigned int d_count, |
164 | struct GNUNET_CREDENTIAL_Delegation *dc, | 164 | struct GNUNET_CREDENTIAL_Delegation *dc, |
165 | unsigned int c_count, | 165 | unsigned int c_count, |
@@ -170,27 +170,27 @@ handle_collect_result (void *cls, | |||
170 | 170 | ||
171 | verify_request = NULL; | 171 | verify_request = NULL; |
172 | if (NULL != cred) | 172 | if (NULL != cred) |
173 | { | ||
174 | for (i=0;i<c_count;i++) | ||
175 | { | 173 | { |
176 | line = GNUNET_CREDENTIAL_credential_to_string (&cred[i]); | 174 | for (i = 0; i < c_count; i++) |
177 | printf ("%s\n", | 175 | { |
178 | line); | 176 | line = GNUNET_CREDENTIAL_credential_to_string(&cred[i]); |
179 | GNUNET_free (line); | 177 | printf("%s\n", |
178 | line); | ||
179 | GNUNET_free(line); | ||
180 | } | ||
180 | } | 181 | } |
181 | } | ||
182 | 182 | ||
183 | 183 | ||
184 | GNUNET_SCHEDULER_shutdown (); | 184 | GNUNET_SCHEDULER_shutdown(); |
185 | } | 185 | } |
186 | 186 | ||
187 | 187 | ||
188 | static void | 188 | static void |
189 | handle_verify_result (void *cls, | 189 | handle_verify_result(void *cls, |
190 | unsigned int d_count, | 190 | unsigned int d_count, |
191 | struct GNUNET_CREDENTIAL_Delegation *dc, | 191 | struct GNUNET_CREDENTIAL_Delegation *dc, |
192 | unsigned int c_count, | 192 | unsigned int c_count, |
193 | struct GNUNET_CREDENTIAL_Credential *cred) | 193 | struct GNUNET_CREDENTIAL_Credential *cred) |
194 | { | 194 | { |
195 | int i; | 195 | int i; |
196 | char* iss_key; | 196 | char* iss_key; |
@@ -198,44 +198,45 @@ handle_verify_result (void *cls, | |||
198 | 198 | ||
199 | verify_request = NULL; | 199 | verify_request = NULL; |
200 | if (NULL == cred) | 200 | if (NULL == cred) |
201 | printf ("Failed.\n"); | 201 | printf("Failed.\n"); |
202 | else | 202 | else |
203 | { | ||
204 | printf("Delegation Chain:\n"); | ||
205 | for (i=0;i<d_count;i++) | ||
206 | { | 203 | { |
207 | iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&dc[i].issuer_key); | 204 | printf("Delegation Chain:\n"); |
208 | sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&dc[i].subject_key); | 205 | for (i = 0; i < d_count; i++) |
209 | if (0 != dc[i].subject_attribute_len) | 206 | { |
210 | { | 207 | iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string(&dc[i].issuer_key); |
211 | printf ("(%d) %s.%s <- %s.%s\n", i, | 208 | sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string(&dc[i].subject_key); |
212 | iss_key, dc[i].issuer_attribute, | 209 | if (0 != dc[i].subject_attribute_len) |
213 | sub_key, dc[i].subject_attribute); | 210 | { |
214 | } else { | 211 | printf("(%d) %s.%s <- %s.%s\n", i, |
215 | printf ("(%d) %s.%s <- %s\n", i, | 212 | iss_key, dc[i].issuer_attribute, |
216 | iss_key, dc[i].issuer_attribute, | 213 | sub_key, dc[i].subject_attribute); |
217 | sub_key); | 214 | } |
218 | } | 215 | else |
219 | GNUNET_free (iss_key); | 216 | { |
220 | GNUNET_free (sub_key); | 217 | printf("(%d) %s.%s <- %s\n", i, |
218 | iss_key, dc[i].issuer_attribute, | ||
219 | sub_key); | ||
220 | } | ||
221 | GNUNET_free(iss_key); | ||
222 | GNUNET_free(sub_key); | ||
223 | } | ||
224 | printf("\nCredentials:\n"); | ||
225 | for (i = 0; i < c_count; i++) | ||
226 | { | ||
227 | iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred[i].issuer_key); | ||
228 | sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred[i].subject_key); | ||
229 | printf("%s.%s <- %s\n", | ||
230 | iss_key, cred[i].issuer_attribute, | ||
231 | sub_key); | ||
232 | GNUNET_free(iss_key); | ||
233 | GNUNET_free(sub_key); | ||
234 | } | ||
235 | printf("Successful.\n"); | ||
221 | } | 236 | } |
222 | printf("\nCredentials:\n"); | ||
223 | for (i=0;i<c_count;i++) | ||
224 | { | ||
225 | iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred[i].issuer_key); | ||
226 | sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred[i].subject_key); | ||
227 | printf ("%s.%s <- %s\n", | ||
228 | iss_key, cred[i].issuer_attribute, | ||
229 | sub_key); | ||
230 | GNUNET_free (iss_key); | ||
231 | GNUNET_free (sub_key); | ||
232 | 237 | ||
233 | } | ||
234 | printf ("Successful.\n"); | ||
235 | } | ||
236 | 238 | ||
237 | 239 | GNUNET_SCHEDULER_shutdown(); | |
238 | GNUNET_SCHEDULER_shutdown (); | ||
239 | } | 240 | } |
240 | 241 | ||
241 | /** | 242 | /** |
@@ -246,8 +247,8 @@ handle_verify_result (void *cls, | |||
246 | * @param ego an ego known to identity service, or NULL | 247 | * @param ego an ego known to identity service, or NULL |
247 | */ | 248 | */ |
248 | static void | 249 | static void |
249 | identity_cb (void *cls, | 250 | identity_cb(void *cls, |
250 | const struct GNUNET_IDENTITY_Ego *ego) | 251 | const struct GNUNET_IDENTITY_Ego *ego) |
251 | { | 252 | { |
252 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 253 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
253 | struct GNUNET_CREDENTIAL_Credential *crd; | 254 | struct GNUNET_CREDENTIAL_Credential *crd; |
@@ -257,76 +258,77 @@ identity_cb (void *cls, | |||
257 | 258 | ||
258 | el = NULL; | 259 | el = NULL; |
259 | if (NULL == ego) | 260 | if (NULL == ego) |
260 | { | ||
261 | if (NULL != ego_name) | ||
262 | { | 261 | { |
263 | fprintf (stderr, | 262 | if (NULL != ego_name) |
264 | _("Ego `%s' not known to identity service\n"), | 263 | { |
265 | ego_name); | 264 | fprintf(stderr, |
265 | _("Ego `%s' not known to identity service\n"), | ||
266 | ego_name); | ||
267 | } | ||
268 | GNUNET_SCHEDULER_shutdown(); | ||
269 | return; | ||
266 | } | 270 | } |
267 | GNUNET_SCHEDULER_shutdown (); | ||
268 | return; | ||
269 | } | ||
270 | 271 | ||
271 | if (GNUNET_YES == collect) | 272 | if (GNUNET_YES == collect) |
272 | { | ||
273 | |||
274 | if (GNUNET_OK != | ||
275 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_key, | ||
276 | strlen (issuer_key), | ||
277 | &issuer_pkey)) | ||
278 | { | 273 | { |
279 | fprintf (stderr, | 274 | if (GNUNET_OK != |
280 | _("Issuer public key `%s' is not well-formed\n"), | 275 | GNUNET_CRYPTO_ecdsa_public_key_from_string(issuer_key, |
281 | issuer_key); | 276 | strlen(issuer_key), |
282 | GNUNET_SCHEDULER_shutdown (); | 277 | &issuer_pkey)) |
278 | { | ||
279 | fprintf(stderr, | ||
280 | _("Issuer public key `%s' is not well-formed\n"), | ||
281 | issuer_key); | ||
282 | GNUNET_SCHEDULER_shutdown(); | ||
283 | } | ||
284 | privkey = GNUNET_IDENTITY_ego_get_private_key(ego); | ||
285 | |||
286 | collect_request = GNUNET_CREDENTIAL_collect(credential, | ||
287 | &issuer_pkey, | ||
288 | issuer_attr, //TODO argument | ||
289 | privkey, | ||
290 | &handle_collect_result, | ||
291 | NULL); | ||
292 | return; | ||
283 | } | 293 | } |
284 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
285 | |||
286 | collect_request = GNUNET_CREDENTIAL_collect(credential, | ||
287 | &issuer_pkey, | ||
288 | issuer_attr, //TODO argument | ||
289 | privkey, | ||
290 | &handle_collect_result, | ||
291 | NULL); | ||
292 | return; | ||
293 | } | ||
294 | 294 | ||
295 | //Else issue | 295 | //Else issue |
296 | 296 | ||
297 | if (NULL == expiration) | 297 | if (NULL == expiration) |
298 | { | 298 | { |
299 | fprintf (stderr, | 299 | fprintf(stderr, |
300 | "Please specify a TTL\n"); | 300 | "Please specify a TTL\n"); |
301 | GNUNET_SCHEDULER_shutdown (); | 301 | GNUNET_SCHEDULER_shutdown(); |
302 | return; | 302 | return; |
303 | } else if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative (expiration, | 303 | } |
304 | &etime_rel)) | 304 | else if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative(expiration, |
305 | { | 305 | &etime_rel)) |
306 | etime_abs = GNUNET_TIME_relative_to_absolute (etime_rel); | 306 | { |
307 | } else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (expiration, | 307 | etime_abs = GNUNET_TIME_relative_to_absolute(etime_rel); |
308 | &etime_abs)) | 308 | } |
309 | { | 309 | else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute(expiration, |
310 | fprintf (stderr, | 310 | &etime_abs)) |
311 | "%s is not a valid ttl!\n", | 311 | { |
312 | expiration); | 312 | fprintf(stderr, |
313 | GNUNET_SCHEDULER_shutdown (); | 313 | "%s is not a valid ttl!\n", |
314 | return; | 314 | expiration); |
315 | } | 315 | GNUNET_SCHEDULER_shutdown(); |
316 | 316 | return; | |
317 | 317 | } | |
318 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); | 318 | |
319 | GNUNET_free_non_null (ego_name); | 319 | |
320 | privkey = GNUNET_IDENTITY_ego_get_private_key(ego); | ||
321 | GNUNET_free_non_null(ego_name); | ||
320 | ego_name = NULL; | 322 | ego_name = NULL; |
321 | crd = GNUNET_CREDENTIAL_credential_issue (privkey, | 323 | crd = GNUNET_CREDENTIAL_credential_issue(privkey, |
322 | &subject_pkey, | 324 | &subject_pkey, |
323 | issuer_attr, | 325 | issuer_attr, |
324 | &etime_abs); | 326 | &etime_abs); |
325 | 327 | ||
326 | res = GNUNET_CREDENTIAL_credential_to_string (crd); | 328 | res = GNUNET_CREDENTIAL_credential_to_string(crd); |
327 | GNUNET_free (crd); | 329 | GNUNET_free(crd); |
328 | printf ("%s\n", res); | 330 | printf("%s\n", res); |
329 | GNUNET_SCHEDULER_shutdown (); | 331 | GNUNET_SCHEDULER_shutdown(); |
330 | } | 332 | } |
331 | 333 | ||
332 | 334 | ||
@@ -341,181 +343,180 @@ identity_cb (void *cls, | |||
341 | * @param c configuration | 343 | * @param c configuration |
342 | */ | 344 | */ |
343 | static void | 345 | static void |
344 | run (void *cls, | 346 | run(void *cls, |
345 | char *const *args, | 347 | char *const *args, |
346 | const char *cfgfile, | 348 | const char *cfgfile, |
347 | const struct GNUNET_CONFIGURATION_Handle *c) | 349 | const struct GNUNET_CONFIGURATION_Handle *c) |
348 | { | 350 | { |
349 | |||
350 | cfg = c; | 351 | cfg = c; |
351 | 352 | ||
352 | 353 | ||
353 | tt = GNUNET_SCHEDULER_add_delayed (timeout, | 354 | tt = GNUNET_SCHEDULER_add_delayed(timeout, |
354 | &do_timeout, NULL); | 355 | &do_timeout, NULL); |
355 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 356 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
356 | |||
357 | if (GNUNET_YES == collect) { | ||
358 | if (NULL == issuer_key) | ||
359 | { | ||
360 | fprintf (stderr, | ||
361 | _("Issuer public key not well-formed\n")); | ||
362 | GNUNET_SCHEDULER_shutdown (); | ||
363 | return; | ||
364 | 357 | ||
365 | } | 358 | if (GNUNET_YES == collect) |
366 | |||
367 | credential = GNUNET_CREDENTIAL_connect (cfg); | ||
368 | |||
369 | if (NULL == credential) | ||
370 | { | ||
371 | fprintf (stderr, | ||
372 | _("Failed to connect to CREDENTIAL\n")); | ||
373 | GNUNET_SCHEDULER_shutdown (); | ||
374 | return; | ||
375 | } | ||
376 | if (NULL == issuer_attr) | ||
377 | { | ||
378 | fprintf (stderr, | ||
379 | _("You must provide issuer the attribute\n")); | ||
380 | GNUNET_SCHEDULER_shutdown (); | ||
381 | return; | ||
382 | } | ||
383 | |||
384 | if (NULL == ego_name) | ||
385 | { | 359 | { |
386 | fprintf (stderr, | 360 | if (NULL == issuer_key) |
387 | _("ego required\n")); | 361 | { |
388 | GNUNET_SCHEDULER_shutdown (); | 362 | fprintf(stderr, |
363 | _("Issuer public key not well-formed\n")); | ||
364 | GNUNET_SCHEDULER_shutdown(); | ||
365 | return; | ||
366 | } | ||
367 | |||
368 | credential = GNUNET_CREDENTIAL_connect(cfg); | ||
369 | |||
370 | if (NULL == credential) | ||
371 | { | ||
372 | fprintf(stderr, | ||
373 | _("Failed to connect to CREDENTIAL\n")); | ||
374 | GNUNET_SCHEDULER_shutdown(); | ||
375 | return; | ||
376 | } | ||
377 | if (NULL == issuer_attr) | ||
378 | { | ||
379 | fprintf(stderr, | ||
380 | _("You must provide issuer the attribute\n")); | ||
381 | GNUNET_SCHEDULER_shutdown(); | ||
382 | return; | ||
383 | } | ||
384 | |||
385 | if (NULL == ego_name) | ||
386 | { | ||
387 | fprintf(stderr, | ||
388 | _("ego required\n")); | ||
389 | GNUNET_SCHEDULER_shutdown(); | ||
390 | return; | ||
391 | } | ||
392 | el = GNUNET_IDENTITY_ego_lookup(cfg, | ||
393 | ego_name, | ||
394 | &identity_cb, | ||
395 | (void *)cfg); | ||
389 | return; | 396 | return; |
390 | |||
391 | } | 397 | } |
392 | el = GNUNET_IDENTITY_ego_lookup (cfg, | ||
393 | ego_name, | ||
394 | &identity_cb, | ||
395 | (void *) cfg); | ||
396 | return; | ||
397 | |||
398 | } | ||
399 | 398 | ||
400 | if (NULL == subject_key) | 399 | if (NULL == subject_key) |
401 | { | ||
402 | fprintf (stderr, | ||
403 | _("Subject public key needed\n")); | ||
404 | GNUNET_SCHEDULER_shutdown (); | ||
405 | return; | ||
406 | |||
407 | } | ||
408 | if (GNUNET_OK != | ||
409 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_key, | ||
410 | strlen (subject_key), | ||
411 | &subject_pkey)) | ||
412 | { | ||
413 | fprintf (stderr, | ||
414 | _("Subject public key `%s' is not well-formed\n"), | ||
415 | subject_key); | ||
416 | GNUNET_SCHEDULER_shutdown (); | ||
417 | return; | ||
418 | } | ||
419 | if (GNUNET_YES == verify) { | ||
420 | if (NULL == issuer_key) | ||
421 | { | ||
422 | fprintf (stderr, | ||
423 | _("Issuer public key not well-formed\n")); | ||
424 | GNUNET_SCHEDULER_shutdown (); | ||
425 | return; | ||
426 | |||
427 | } | ||
428 | if (GNUNET_OK != | ||
429 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_key, | ||
430 | strlen (issuer_key), | ||
431 | &issuer_pkey)) | ||
432 | { | 400 | { |
433 | fprintf (stderr, | 401 | fprintf(stderr, |
434 | _("Issuer public key `%s' is not well-formed\n"), | 402 | _("Subject public key needed\n")); |
435 | issuer_key); | 403 | GNUNET_SCHEDULER_shutdown(); |
436 | GNUNET_SCHEDULER_shutdown (); | ||
437 | return; | 404 | return; |
438 | } | 405 | } |
439 | credential = GNUNET_CREDENTIAL_connect (cfg); | 406 | if (GNUNET_OK != |
440 | 407 | GNUNET_CRYPTO_ecdsa_public_key_from_string(subject_key, | |
441 | if (NULL == credential) | 408 | strlen(subject_key), |
409 | &subject_pkey)) | ||
442 | { | 410 | { |
443 | fprintf (stderr, | 411 | fprintf(stderr, |
444 | _("Failed to connect to CREDENTIAL\n")); | 412 | _("Subject public key `%s' is not well-formed\n"), |
445 | GNUNET_SCHEDULER_shutdown (); | 413 | subject_key); |
414 | GNUNET_SCHEDULER_shutdown(); | ||
446 | return; | 415 | return; |
447 | } | 416 | } |
448 | if (NULL == issuer_attr || NULL == subject_credential) | 417 | if (GNUNET_YES == verify) |
449 | { | 418 | { |
450 | fprintf (stderr, | 419 | if (NULL == issuer_key) |
451 | _("You must provide issuer and subject attributes\n")); | 420 | { |
452 | GNUNET_SCHEDULER_shutdown (); | 421 | fprintf(stderr, |
453 | return; | 422 | _("Issuer public key not well-formed\n")); |
423 | GNUNET_SCHEDULER_shutdown(); | ||
424 | return; | ||
425 | } | ||
426 | if (GNUNET_OK != | ||
427 | GNUNET_CRYPTO_ecdsa_public_key_from_string(issuer_key, | ||
428 | strlen(issuer_key), | ||
429 | &issuer_pkey)) | ||
430 | { | ||
431 | fprintf(stderr, | ||
432 | _("Issuer public key `%s' is not well-formed\n"), | ||
433 | issuer_key); | ||
434 | GNUNET_SCHEDULER_shutdown(); | ||
435 | return; | ||
436 | } | ||
437 | credential = GNUNET_CREDENTIAL_connect(cfg); | ||
438 | |||
439 | if (NULL == credential) | ||
440 | { | ||
441 | fprintf(stderr, | ||
442 | _("Failed to connect to CREDENTIAL\n")); | ||
443 | GNUNET_SCHEDULER_shutdown(); | ||
444 | return; | ||
445 | } | ||
446 | if (NULL == issuer_attr || NULL == subject_credential) | ||
447 | { | ||
448 | fprintf(stderr, | ||
449 | _("You must provide issuer and subject attributes\n")); | ||
450 | GNUNET_SCHEDULER_shutdown(); | ||
451 | return; | ||
452 | } | ||
453 | |||
454 | //Subject credentials are comma separated | ||
455 | char *tmp = GNUNET_strdup(subject_credential); | ||
456 | char *tok = strtok(tmp, ","); | ||
457 | if (NULL == tok) | ||
458 | { | ||
459 | fprintf(stderr, | ||
460 | "Invalid subject credentials\n"); | ||
461 | GNUNET_free(tmp); | ||
462 | GNUNET_SCHEDULER_shutdown(); | ||
463 | return; | ||
464 | } | ||
465 | int count = 1; | ||
466 | int i; | ||
467 | while (NULL != (tok = strtok(NULL, ","))) | ||
468 | count++; | ||
469 | struct GNUNET_CREDENTIAL_Credential credentials[count]; | ||
470 | struct GNUNET_CREDENTIAL_Credential *cred; | ||
471 | GNUNET_free(tmp); | ||
472 | tmp = GNUNET_strdup(subject_credential); | ||
473 | tok = strtok(tmp, ","); | ||
474 | for (i = 0; i < count; i++) | ||
475 | { | ||
476 | cred = GNUNET_CREDENTIAL_credential_from_string(tok); | ||
477 | GNUNET_memcpy(&credentials[i], | ||
478 | cred, | ||
479 | sizeof(struct GNUNET_CREDENTIAL_Credential)); | ||
480 | credentials[i].issuer_attribute = GNUNET_strdup(cred->issuer_attribute); | ||
481 | tok = strtok(NULL, ","); | ||
482 | GNUNET_free(cred); | ||
483 | } | ||
484 | |||
485 | verify_request = GNUNET_CREDENTIAL_verify(credential, | ||
486 | &issuer_pkey, | ||
487 | issuer_attr, //TODO argument | ||
488 | &subject_pkey, | ||
489 | count, | ||
490 | credentials, | ||
491 | &handle_verify_result, | ||
492 | NULL); | ||
493 | for (i = 0; i < count; i++) | ||
494 | { | ||
495 | GNUNET_free((char*)credentials[i].issuer_attribute); | ||
496 | } | ||
497 | GNUNET_free(tmp); | ||
454 | } | 498 | } |
455 | 499 | else if (GNUNET_YES == create_cred) | |
456 | //Subject credentials are comma separated | ||
457 | char *tmp = GNUNET_strdup (subject_credential); | ||
458 | char *tok = strtok (tmp, ","); | ||
459 | if (NULL == tok) | ||
460 | { | 500 | { |
461 | fprintf (stderr, | 501 | if (NULL == ego_name) |
462 | "Invalid subject credentials\n"); | 502 | { |
463 | GNUNET_free (tmp); | 503 | fprintf(stderr, |
464 | GNUNET_SCHEDULER_shutdown (); | 504 | _("Issuer ego required\n")); |
505 | GNUNET_SCHEDULER_shutdown(); | ||
506 | return; | ||
507 | } | ||
508 | el = GNUNET_IDENTITY_ego_lookup(cfg, | ||
509 | ego_name, | ||
510 | &identity_cb, | ||
511 | (void *)cfg); | ||
465 | return; | 512 | return; |
466 | } | 513 | } |
467 | int count = 1; | 514 | else |
468 | int i; | ||
469 | while (NULL != (tok = strtok(NULL, ","))) | ||
470 | count++; | ||
471 | struct GNUNET_CREDENTIAL_Credential credentials[count]; | ||
472 | struct GNUNET_CREDENTIAL_Credential *cred; | ||
473 | GNUNET_free (tmp); | ||
474 | tmp = GNUNET_strdup (subject_credential); | ||
475 | tok = strtok (tmp, ","); | ||
476 | for (i=0;i<count;i++) | ||
477 | { | ||
478 | cred = GNUNET_CREDENTIAL_credential_from_string (tok); | ||
479 | GNUNET_memcpy (&credentials[i], | ||
480 | cred, | ||
481 | sizeof (struct GNUNET_CREDENTIAL_Credential)); | ||
482 | credentials[i].issuer_attribute = GNUNET_strdup (cred->issuer_attribute); | ||
483 | tok = strtok(NULL, ","); | ||
484 | GNUNET_free (cred); | ||
485 | } | ||
486 | |||
487 | verify_request = GNUNET_CREDENTIAL_verify(credential, | ||
488 | &issuer_pkey, | ||
489 | issuer_attr, //TODO argument | ||
490 | &subject_pkey, | ||
491 | count, | ||
492 | credentials, | ||
493 | &handle_verify_result, | ||
494 | NULL); | ||
495 | for (i=0;i<count;i++) | ||
496 | { | ||
497 | GNUNET_free ((char*)credentials[i].issuer_attribute); | ||
498 | } | ||
499 | GNUNET_free (tmp); | ||
500 | } else if (GNUNET_YES == create_cred) { | ||
501 | if (NULL == ego_name) | ||
502 | { | 515 | { |
503 | fprintf (stderr, | 516 | fprintf(stderr, |
504 | _("Issuer ego required\n")); | 517 | _("Please specify name to lookup, subject key and issuer key!\n")); |
505 | GNUNET_SCHEDULER_shutdown (); | 518 | GNUNET_SCHEDULER_shutdown(); |
506 | return; | ||
507 | |||
508 | } | 519 | } |
509 | el = GNUNET_IDENTITY_ego_lookup (cfg, | ||
510 | ego_name, | ||
511 | &identity_cb, | ||
512 | (void *) cfg); | ||
513 | return; | ||
514 | } else { | ||
515 | fprintf (stderr, | ||
516 | _("Please specify name to lookup, subject key and issuer key!\n")); | ||
517 | GNUNET_SCHEDULER_shutdown (); | ||
518 | } | ||
519 | return; | 520 | return; |
520 | } | 521 | } |
521 | 522 | ||
@@ -528,67 +529,67 @@ run (void *cls, | |||
528 | * @return 0 ok, 1 on error | 529 | * @return 0 ok, 1 on error |
529 | */ | 530 | */ |
530 | int | 531 | int |
531 | main (int argc, char *const *argv) | 532 | main(int argc, char *const *argv) |
532 | { | 533 | { |
533 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 534 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
534 | GNUNET_GETOPT_option_flag ('I', | 535 | GNUNET_GETOPT_option_flag('I', |
535 | "issue", | 536 | "issue", |
536 | gettext_noop ("create credential"), | 537 | gettext_noop("create credential"), |
537 | &create_cred), | 538 | &create_cred), |
538 | GNUNET_GETOPT_option_flag ('V', | 539 | GNUNET_GETOPT_option_flag('V', |
539 | "verify", | 540 | "verify", |
540 | gettext_noop ("verify credential against attribute"), | 541 | gettext_noop("verify credential against attribute"), |
541 | &verify), | 542 | &verify), |
542 | GNUNET_GETOPT_option_string ('s', | 543 | GNUNET_GETOPT_option_string('s', |
543 | "subject", | 544 | "subject", |
544 | "PKEY", | 545 | "PKEY", |
545 | gettext_noop ("The public key of the subject to lookup the credential for"), | 546 | gettext_noop("The public key of the subject to lookup the credential for"), |
546 | &subject_key), | 547 | &subject_key), |
547 | GNUNET_GETOPT_option_string ('b', | 548 | GNUNET_GETOPT_option_string('b', |
548 | "credential", | 549 | "credential", |
549 | "CRED", | 550 | "CRED", |
550 | gettext_noop ("The name of the credential presented by the subject"), | 551 | gettext_noop("The name of the credential presented by the subject"), |
551 | &subject_credential), | 552 | &subject_credential), |
552 | GNUNET_GETOPT_option_string ('i', | 553 | GNUNET_GETOPT_option_string('i', |
553 | "issuer", | 554 | "issuer", |
554 | "PKEY", | 555 | "PKEY", |
555 | gettext_noop ("The public key of the authority to verify the credential against"), | 556 | gettext_noop("The public key of the authority to verify the credential against"), |
556 | &issuer_key), | 557 | &issuer_key), |
557 | GNUNET_GETOPT_option_string ('e', | 558 | GNUNET_GETOPT_option_string('e', |
558 | "ego", | 559 | "ego", |
559 | "EGO", | 560 | "EGO", |
560 | gettext_noop ("The ego to use"), | 561 | gettext_noop("The ego to use"), |
561 | &ego_name), | 562 | &ego_name), |
562 | GNUNET_GETOPT_option_string ('a', | 563 | GNUNET_GETOPT_option_string('a', |
563 | "attribute", | 564 | "attribute", |
564 | "ATTR", | 565 | "ATTR", |
565 | gettext_noop ("The issuer attribute to verify against or to issue"), | 566 | gettext_noop("The issuer attribute to verify against or to issue"), |
566 | &issuer_attr), | 567 | &issuer_attr), |
567 | GNUNET_GETOPT_option_string ('T', | 568 | GNUNET_GETOPT_option_string('T', |
568 | "ttl", | 569 | "ttl", |
569 | "EXP", | 570 | "EXP", |
570 | gettext_noop ("The time to live for the credential"), | 571 | gettext_noop("The time to live for the credential"), |
571 | &expiration), | 572 | &expiration), |
572 | GNUNET_GETOPT_option_flag ('g', | 573 | GNUNET_GETOPT_option_flag('g', |
573 | "collect", | 574 | "collect", |
574 | gettext_noop ("collect credentials"), | 575 | gettext_noop("collect credentials"), |
575 | &collect), | 576 | &collect), |
576 | GNUNET_GETOPT_OPTION_END | 577 | GNUNET_GETOPT_OPTION_END |
577 | }; | 578 | }; |
578 | int ret; | 579 | int ret; |
579 | 580 | ||
580 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 581 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
581 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 582 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
582 | return 2; | 583 | return 2; |
583 | 584 | ||
584 | GNUNET_log_setup ("gnunet-credential", "WARNING", NULL); | 585 | GNUNET_log_setup("gnunet-credential", "WARNING", NULL); |
585 | ret = | 586 | ret = |
586 | (GNUNET_OK == | 587 | (GNUNET_OK == |
587 | GNUNET_PROGRAM_run (argc, argv, "gnunet-credential", | 588 | GNUNET_PROGRAM_run(argc, argv, "gnunet-credential", |
588 | _("GNUnet credential resolver tool"), | 589 | _("GNUnet credential resolver tool"), |
589 | options, | 590 | options, |
590 | &run, NULL)) ? 0 : 1; | 591 | &run, NULL)) ? 0 : 1; |
591 | GNUNET_free ((void*) argv); | 592 | GNUNET_free((void*)argv); |
592 | return ret; | 593 | return ret; |
593 | } | 594 | } |
594 | 595 | ||