aboutsummaryrefslogtreecommitdiff
path: root/src/identity-provider/plugin_rest_identity_provider.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity-provider/plugin_rest_identity_provider.c')
-rw-r--r--src/identity-provider/plugin_rest_identity_provider.c146
1 files changed, 136 insertions, 10 deletions
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
302static void 320static void
303attr_collect_error_cb (void *cls) 321collect_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 */
315static void 333static void
316return_attr_list (void *cls) 334return_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
331static void 349static void
332attr_collect_finished_cb (void *cls) 350collect_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 */
364static void
365ticket_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 */
416static void
417list_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