diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-10-07 20:03:31 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-10-07 20:03:31 +0200 |
commit | be9becc6f217f93f433d3301ae10b0d05ff31096 (patch) | |
tree | ddb0f00e7e8bef26d4e97d54a675428241092334 /src | |
parent | 40fa67d024c8d7cc7d6f2af1a557e0ecc59e60f0 (diff) | |
download | gnunet-be9becc6f217f93f433d3301ae10b0d05ff31096.tar.gz gnunet-be9becc6f217f93f433d3301ae10b0d05ff31096.zip |
-add ticket listing for rest, bugfixes
Diffstat (limited to 'src')
-rw-r--r-- | src/identity-provider/Makefile.am | 3 | ||||
-rw-r--r-- | src/identity-provider/identity_provider_api.c | 11 | ||||
-rw-r--r-- | src/identity-provider/plugin_rest_identity_provider.c | 146 | ||||
-rwxr-xr-x | src/identity-provider/test_idp_consume.sh | 2 |
4 files changed, 145 insertions, 17 deletions
diff --git a/src/identity-provider/Makefile.am b/src/identity-provider/Makefile.am index 488954a44..098313f9a 100644 --- a/src/identity-provider/Makefile.am +++ b/src/identity-provider/Makefile.am | |||
@@ -83,7 +83,8 @@ libgnunetidentityprovider_la_LDFLAGS = \ | |||
83 | -version-info 0:0:0 | 83 | -version-info 0:0:0 |
84 | 84 | ||
85 | libgnunet_plugin_rest_identity_provider_la_SOURCES = \ | 85 | libgnunet_plugin_rest_identity_provider_la_SOURCES = \ |
86 | plugin_rest_identity_provider.c | 86 | plugin_rest_identity_provider.c \ |
87 | jwt.c | ||
87 | libgnunet_plugin_rest_identity_provider_la_LIBADD = \ | 88 | libgnunet_plugin_rest_identity_provider_la_LIBADD = \ |
88 | $(top_builddir)/src/identity/libgnunetidentity.la \ | 89 | $(top_builddir)/src/identity/libgnunetidentity.la \ |
89 | libgnunetidentityprovider.la \ | 90 | libgnunetidentityprovider.la \ |
diff --git a/src/identity-provider/identity_provider_api.c b/src/identity-provider/identity_provider_api.c index 1dec43b16..99faf0ecd 100644 --- a/src/identity-provider/identity_provider_api.c +++ b/src/identity-provider/identity_provider_api.c | |||
@@ -702,20 +702,19 @@ handle_ticket_result (void *cls, | |||
702 | GNUNET_free (op); | 702 | GNUNET_free (op); |
703 | return; | 703 | return; |
704 | } else if (NULL != it) { | 704 | } else if (NULL != it) { |
705 | GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, | ||
706 | handle->ticket_it_tail, | ||
707 | it); | ||
708 | if (msg_len == sizeof (struct TicketResultMessage)) | 705 | if (msg_len == sizeof (struct TicketResultMessage)) |
709 | { | 706 | { |
710 | if (NULL != it->tr_cb) | 707 | if (NULL != it->tr_cb) |
711 | it->finish_cb (it->finish_cb_cls); | 708 | GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, |
709 | handle->ticket_it_tail, | ||
710 | it); | ||
711 | it->finish_cb (it->finish_cb_cls); | ||
712 | GNUNET_free (it); | ||
712 | } else { | 713 | } else { |
713 | |||
714 | ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1]; | 714 | ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1]; |
715 | if (NULL != it->tr_cb) | 715 | if (NULL != it->tr_cb) |
716 | it->tr_cb (it->cls, ticket); | 716 | it->tr_cb (it->cls, ticket); |
717 | } | 717 | } |
718 | GNUNET_free (it); | ||
719 | return; | 718 | return; |
720 | } | 719 | } |
721 | GNUNET_break (0); | 720 | GNUNET_break (0); |
diff --git a/src/identity-provider/plugin_rest_identity_provider.c b/src/identity-provider/plugin_rest_identity_provider.c index b8fb3d1cb..43251d93d 100644 --- a/src/identity-provider/plugin_rest_identity_provider.c +++ b/src/identity-provider/plugin_rest_identity_provider.c | |||
@@ -50,11 +50,22 @@ | |||
50 | #define GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES "/idp/attributes" | 50 | #define GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES "/idp/attributes" |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Ticket namespace | ||
54 | */ | ||
55 | #define GNUNET_REST_API_NS_IDENTITY_TICKETS "/idp/tickets" | ||
56 | |||
57 | /** | ||
53 | * Attribute key | 58 | * Attribute key |
54 | */ | 59 | */ |
55 | #define GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE "attribute" | 60 | #define GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE "attribute" |
56 | 61 | ||
57 | /** | 62 | /** |
63 | * Ticket key | ||
64 | */ | ||
65 | #define GNUNET_REST_JSONAPI_IDENTITY_TICKET "ticket" | ||
66 | |||
67 | |||
68 | /** | ||
58 | * Value key | 69 | * Value key |
59 | */ | 70 | */ |
60 | #define GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE_VALUE "value" | 71 | #define GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE_VALUE "value" |
@@ -176,7 +187,12 @@ struct RequestHandle | |||
176 | * Attribute iterator | 187 | * Attribute iterator |
177 | */ | 188 | */ |
178 | struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *attr_it; | 189 | struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *attr_it; |
179 | 190 | ||
191 | /** | ||
192 | * Ticket iterator | ||
193 | */ | ||
194 | struct GNUNET_IDENTITY_PROVIDER_TicketIterator *ticket_it; | ||
195 | |||
180 | /** | 196 | /** |
181 | * Desired timeout for the lookup (default is no timeout). | 197 | * Desired timeout for the lookup (default is no timeout). |
182 | */ | 198 | */ |
@@ -243,10 +259,12 @@ cleanup_handle (struct RequestHandle *handle) | |||
243 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 259 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
244 | if (NULL != handle->identity_handle) | 260 | if (NULL != handle->identity_handle) |
245 | GNUNET_IDENTITY_disconnect (handle->identity_handle); | 261 | GNUNET_IDENTITY_disconnect (handle->identity_handle); |
246 | if (NULL != handle->idp) | ||
247 | GNUNET_IDENTITY_PROVIDER_disconnect (handle->idp); | ||
248 | if (NULL != handle->attr_it) | 262 | if (NULL != handle->attr_it) |
249 | GNUNET_IDENTITY_PROVIDER_get_attributes_stop (handle->attr_it); | 263 | GNUNET_IDENTITY_PROVIDER_get_attributes_stop (handle->attr_it); |
264 | if (NULL != handle->ticket_it) | ||
265 | GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (handle->ticket_it); | ||
266 | if (NULL != handle->idp) | ||
267 | GNUNET_IDENTITY_PROVIDER_disconnect (handle->idp); | ||
250 | if (NULL != handle->url) | 268 | if (NULL != handle->url) |
251 | GNUNET_free (handle->url); | 269 | GNUNET_free (handle->url); |
252 | if (NULL != handle->emsg) | 270 | if (NULL != handle->emsg) |
@@ -300,7 +318,7 @@ do_timeout (void *cls) | |||
300 | 318 | ||
301 | 319 | ||
302 | static void | 320 | static void |
303 | attr_collect_error_cb (void *cls) | 321 | collect_error_cb (void *cls) |
304 | { | 322 | { |
305 | struct RequestHandle *handle = cls; | 323 | struct RequestHandle *handle = cls; |
306 | 324 | ||
@@ -313,7 +331,7 @@ attr_collect_error_cb (void *cls) | |||
313 | * @param cls the request handle | 331 | * @param cls the request handle |
314 | */ | 332 | */ |
315 | static void | 333 | static void |
316 | return_attr_list (void *cls) | 334 | return_response (void *cls) |
317 | { | 335 | { |
318 | char* result_str; | 336 | char* result_str; |
319 | struct RequestHandle *handle = cls; | 337 | struct RequestHandle *handle = cls; |
@@ -329,14 +347,121 @@ return_attr_list (void *cls) | |||
329 | 347 | ||
330 | 348 | ||
331 | static void | 349 | static void |
332 | attr_collect_finished_cb (void *cls) | 350 | collect_finished_cb (void *cls) |
333 | { | 351 | { |
334 | struct RequestHandle *handle = cls; | 352 | struct RequestHandle *handle = cls; |
335 | //Done | 353 | //Done |
336 | handle->attr_it = NULL; | 354 | handle->attr_it = NULL; |
337 | GNUNET_SCHEDULER_add_now (&return_attr_list, handle); | 355 | handle->ticket_it = NULL; |
356 | GNUNET_SCHEDULER_add_now (&return_response, handle); | ||
357 | } | ||
358 | |||
359 | |||
360 | /** | ||
361 | * Collect all attributes for an ego | ||
362 | * | ||
363 | */ | ||
364 | static void | ||
365 | ticket_collect (void *cls, | ||
366 | const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket) | ||
367 | { | ||
368 | struct RequestHandle *handle = cls; | ||
369 | json_t *value; | ||
370 | char* tmp; | ||
371 | |||
372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n"); | ||
373 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, | ||
374 | sizeof (uint64_t)); | ||
375 | handle->json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_TICKET, | ||
376 | tmp); | ||
377 | GNUNET_free (tmp); | ||
378 | GNUNET_JSONAPI_document_resource_add (handle->resp_object, handle->json_resource); | ||
379 | |||
380 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->identity, | ||
381 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
382 | value = json_string (tmp); | ||
383 | GNUNET_JSONAPI_resource_add_attr (handle->json_resource, | ||
384 | "issuer", | ||
385 | value); | ||
386 | GNUNET_free (tmp); | ||
387 | json_decref (value); | ||
388 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, | ||
389 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
390 | value = json_string (tmp); | ||
391 | GNUNET_JSONAPI_resource_add_attr (handle->json_resource, | ||
392 | "audience", | ||
393 | value); | ||
394 | GNUNET_free (tmp); | ||
395 | json_decref (value); | ||
396 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, | ||
397 | sizeof (uint64_t)); | ||
398 | value = json_string (tmp); | ||
399 | GNUNET_JSONAPI_resource_add_attr (handle->json_resource, | ||
400 | "rnd", | ||
401 | value); | ||
402 | GNUNET_free (tmp); | ||
403 | json_decref (value); | ||
404 | GNUNET_IDENTITY_PROVIDER_ticket_iteration_next (handle->ticket_it); | ||
338 | } | 405 | } |
339 | 406 | ||
407 | |||
408 | |||
409 | /** | ||
410 | * List tickets for identity request | ||
411 | * | ||
412 | * @param con_handle the connection handle | ||
413 | * @param url the url | ||
414 | * @param cls the RequestHandle | ||
415 | */ | ||
416 | static void | ||
417 | list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle, | ||
418 | const char* url, | ||
419 | void *cls) | ||
420 | { | ||
421 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | ||
422 | struct RequestHandle *handle = cls; | ||
423 | struct EgoEntry *ego_entry; | ||
424 | char *identity; | ||
425 | |||
426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting tickets for %s.\n", | ||
427 | handle->url); | ||
428 | if ( strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) >= | ||
429 | strlen (handle->url)) | ||
430 | { | ||
431 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | ||
432 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
433 | return; | ||
434 | } | ||
435 | identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1; | ||
436 | |||
437 | for (ego_entry = handle->ego_head; | ||
438 | NULL != ego_entry; | ||
439 | ego_entry = ego_entry->next) | ||
440 | if (0 == strcmp (identity, ego_entry->identifier)) | ||
441 | break; | ||
442 | handle->resp_object = GNUNET_JSONAPI_document_new (); | ||
443 | |||
444 | if (NULL == ego_entry) | ||
445 | { | ||
446 | //Done | ||
447 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", | ||
448 | identity); | ||
449 | GNUNET_SCHEDULER_add_now (&return_response, handle); | ||
450 | return; | ||
451 | } | ||
452 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | ||
453 | handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); | ||
454 | handle->ticket_it = GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (handle->idp, | ||
455 | priv_key, | ||
456 | &collect_error_cb, | ||
457 | handle, | ||
458 | &ticket_collect, | ||
459 | handle, | ||
460 | &collect_finished_cb, | ||
461 | handle); | ||
462 | } | ||
463 | |||
464 | |||
340 | /** | 465 | /** |
341 | * Collect all attributes for an ego | 466 | * Collect all attributes for an ego |
342 | * | 467 | * |
@@ -405,18 +530,18 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
405 | //Done | 530 | //Done |
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", | 531 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", |
407 | identity); | 532 | identity); |
408 | GNUNET_SCHEDULER_add_now (&return_attr_list, handle); | 533 | GNUNET_SCHEDULER_add_now (&return_response, handle); |
409 | return; | 534 | return; |
410 | } | 535 | } |
411 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 536 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
412 | handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); | 537 | handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); |
413 | handle->attr_it = GNUNET_IDENTITY_PROVIDER_get_attributes_start (handle->idp, | 538 | handle->attr_it = GNUNET_IDENTITY_PROVIDER_get_attributes_start (handle->idp, |
414 | priv_key, | 539 | priv_key, |
415 | &attr_collect_error_cb, | 540 | &collect_error_cb, |
416 | handle, | 541 | handle, |
417 | &attr_collect, | 542 | &attr_collect, |
418 | handle, | 543 | handle, |
419 | &attr_collect_finished_cb, | 544 | &collect_finished_cb, |
420 | handle); | 545 | handle); |
421 | } | 546 | } |
422 | 547 | ||
@@ -457,6 +582,7 @@ init_cont (struct RequestHandle *handle) | |||
457 | struct GNUNET_REST_RequestHandlerError err; | 582 | struct GNUNET_REST_RequestHandlerError err; |
458 | static const struct GNUNET_REST_RequestHandler handlers[] = { | 583 | static const struct GNUNET_REST_RequestHandler handlers[] = { |
459 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES, &list_attribute_cont}, | 584 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES, &list_attribute_cont}, |
585 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont}, | ||
460 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY_PROVIDER, | 586 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY_PROVIDER, |
461 | &options_cont}, | 587 | &options_cont}, |
462 | GNUNET_REST_HANDLER_END | 588 | GNUNET_REST_HANDLER_END |
diff --git a/src/identity-provider/test_idp_consume.sh b/src/identity-provider/test_idp_consume.sh index 0d05145e0..81cd0b149 100755 --- a/src/identity-provider/test_idp_consume.sh +++ b/src/identity-provider/test_idp_consume.sh | |||
@@ -24,6 +24,7 @@ which timeout &> /dev/null && DO_TIMEOUT="timeout 30" | |||
24 | 24 | ||
25 | TEST_ATTR="test" | 25 | TEST_ATTR="test" |
26 | gnunet-arm -s -c test_idp.conf | 26 | gnunet-arm -s -c test_idp.conf |
27 | gnunet-arm -i rest -c test_idp.conf | ||
27 | gnunet-identity -C testego -c test_idp.conf | 28 | gnunet-identity -C testego -c test_idp.conf |
28 | gnunet-identity -C rpego -c test_idp.conf | 29 | gnunet-identity -C rpego -c test_idp.conf |
29 | SUBJECT_KEY=$(gnunet-identity -d -c test_idp.conf | grep rpego | awk '{print $3}') | 30 | SUBJECT_KEY=$(gnunet-identity -d -c test_idp.conf | grep rpego | awk '{print $3}') |
@@ -33,4 +34,5 @@ gnunet-idp -e testego -a name -V John -c test_idp.conf > /dev/null 2>&1 | |||
33 | TICKET=$(gnunet-idp -e testego -i "email,name" -r $SUBJECT_KEY -c test_idp.conf | awk '{print $1}') | 34 | TICKET=$(gnunet-idp -e testego -i "email,name" -r $SUBJECT_KEY -c test_idp.conf | awk '{print $1}') |
34 | echo "Consuming ticket $TICKET" | 35 | echo "Consuming ticket $TICKET" |
35 | gnunet-idp -e rpego -C $TICKET -c test_idp.conf | 36 | gnunet-idp -e rpego -C $TICKET -c test_idp.conf |
37 | curl http://localhost:7776/idp/tickets/testego | ||
36 | gnunet-arm -e -c test_idp.conf | 38 | gnunet-arm -e -c test_idp.conf |