aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim
diff options
context:
space:
mode:
Diffstat (limited to 'src/reclaim')
-rw-r--r--src/reclaim/plugin_rest_openid_connect.c241
-rw-r--r--src/reclaim/plugin_rest_reclaim.c293
2 files changed, 260 insertions, 274 deletions
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c
index eb602a08f..64782fb72 100644
--- a/src/reclaim/plugin_rest_openid_connect.c
+++ b/src/reclaim/plugin_rest_openid_connect.c
@@ -249,6 +249,36 @@ const struct GNUNET_CONFIGURATION_Handle *cfg;
249static char *allow_methods; 249static char *allow_methods;
250 250
251/** 251/**
252 * Ego list
253 */
254static struct EgoEntry *ego_head;
255
256/**
257 * Ego list
258 */
259static struct EgoEntry *ego_tail;
260
261/**
262 * The processing state
263 */
264static int state;
265
266/**
267 * Handle to Identity service.
268 */
269static struct GNUNET_IDENTITY_Handle *identity_handle;
270
271/**
272 * GNS handle
273 */
274static struct GNUNET_GNS_Handle *gns_handle;
275
276/**
277 * Identity Provider
278 */
279static struct GNUNET_RECLAIM_Handle *idp;
280
281/**
252 * @brief struct returned by the initialization function of the plugin 282 * @brief struct returned by the initialization function of the plugin
253 */ 283 */
254struct Plugin 284struct Plugin
@@ -361,15 +391,6 @@ struct EgoEntry
361 391
362struct RequestHandle 392struct RequestHandle
363{ 393{
364 /**
365 * Ego list
366 */
367 struct EgoEntry *ego_head;
368
369 /**
370 * Ego list
371 */
372 struct EgoEntry *ego_tail;
373 394
374 /** 395 /**
375 * Selected ego 396 * Selected ego
@@ -387,39 +408,14 @@ struct RequestHandle
387 struct OIDC_Variables *oidc; 408 struct OIDC_Variables *oidc;
388 409
389 /** 410 /**
390 * The processing state
391 */
392 int state;
393
394 /**
395 * Handle to Identity service.
396 */
397 struct GNUNET_IDENTITY_Handle *identity_handle;
398
399 /**
400 * Rest connection
401 */
402 struct GNUNET_REST_RequestHandle *rest_handle;
403
404 /**
405 * GNS handle
406 */
407 struct GNUNET_GNS_Handle *gns_handle;
408
409 /**
410 * GNS lookup op 411 * GNS lookup op
411 */ 412 */
412 struct GNUNET_GNS_LookupRequest *gns_op; 413 struct GNUNET_GNS_LookupRequest *gns_op;
413 414
414 /** 415 /**
415 * Handle to NAMESTORE 416 * Rest connection
416 */
417 struct GNUNET_NAMESTORE_Handle *namestore_handle;
418
419 /**
420 * Iterator for NAMESTORE
421 */ 417 */
422 struct GNUNET_NAMESTORE_ZoneIterator *namestore_handle_it; 418 struct GNUNET_REST_RequestHandle *rest_handle;
423 419
424 /** 420 /**
425 * Attribute claim list for id_token 421 * Attribute claim list for id_token
@@ -442,10 +438,6 @@ struct RequestHandle
442 */ 438 */
443 struct GNUNET_IDENTITY_Operation *op; 439 struct GNUNET_IDENTITY_Operation *op;
444 440
445 /**
446 * Identity Provider
447 */
448 struct GNUNET_RECLAIM_Handle *idp;
449 441
450 /** 442 /**
451 * Idp Operation 443 * Idp Operation
@@ -529,6 +521,7 @@ struct RequestHandle
529 int response_code; 521 int response_code;
530}; 522};
531 523
524
532/** 525/**
533 * Cleanup lookup handle 526 * Cleanup lookup handle
534 * @param handle Handle to clean up 527 * @param handle Handle to clean up
@@ -536,13 +529,10 @@ struct RequestHandle
536static void 529static void
537cleanup_handle (struct RequestHandle *handle) 530cleanup_handle (struct RequestHandle *handle)
538{ 531{
539 struct EgoEntry *ego_entry;
540 532
541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); 533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
542 if (NULL != handle->timeout_task) 534 if (NULL != handle->timeout_task)
543 GNUNET_SCHEDULER_cancel (handle->timeout_task); 535 GNUNET_SCHEDULER_cancel (handle->timeout_task);
544 if (NULL != handle->identity_handle)
545 GNUNET_IDENTITY_disconnect (handle->identity_handle);
546 if (NULL != handle->attr_it) 536 if (NULL != handle->attr_it)
547 GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); 537 GNUNET_RECLAIM_get_attributes_stop (handle->attr_it);
548 if (NULL != handle->attest_it) 538 if (NULL != handle->attest_it)
@@ -551,8 +541,6 @@ cleanup_handle (struct RequestHandle *handle)
551 GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); 541 GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it);
552 if (NULL != handle->idp_op) 542 if (NULL != handle->idp_op)
553 GNUNET_RECLAIM_cancel (handle->idp_op); 543 GNUNET_RECLAIM_cancel (handle->idp_op);
554 if (NULL != handle->idp)
555 GNUNET_RECLAIM_disconnect (handle->idp);
556 GNUNET_free (handle->url); 544 GNUNET_free (handle->url);
557 GNUNET_free (handle->tld); 545 GNUNET_free (handle->tld);
558 GNUNET_free (handle->redirect_prefix); 546 GNUNET_free (handle->redirect_prefix);
@@ -561,11 +549,6 @@ cleanup_handle (struct RequestHandle *handle)
561 GNUNET_free (handle->edesc); 549 GNUNET_free (handle->edesc);
562 if (NULL != handle->gns_op) 550 if (NULL != handle->gns_op)
563 GNUNET_GNS_lookup_cancel (handle->gns_op); 551 GNUNET_GNS_lookup_cancel (handle->gns_op);
564 if (NULL != handle->gns_handle)
565 GNUNET_GNS_disconnect (handle->gns_handle);
566
567 if (NULL != handle->namestore_handle)
568 GNUNET_NAMESTORE_disconnect (handle->namestore_handle);
569 if (NULL != handle->oidc) 552 if (NULL != handle->oidc)
570 { 553 {
571 GNUNET_free (handle->oidc->client_id); 554 GNUNET_free (handle->oidc->client_id);
@@ -585,15 +568,6 @@ cleanup_handle (struct RequestHandle *handle)
585 if (NULL!=handle->attests_list) 568 if (NULL!=handle->attests_list)
586 GNUNET_RECLAIM_attestation_list_destroy (handle->attests_list); 569 GNUNET_RECLAIM_attestation_list_destroy (handle->attests_list);
587 570
588 while (NULL != (ego_entry = handle->ego_head))
589 {
590 GNUNET_CONTAINER_DLL_remove (handle->ego_head,
591 handle->ego_tail,
592 ego_entry);
593 GNUNET_free (ego_entry->identifier);
594 GNUNET_free (ego_entry->keystring);
595 GNUNET_free (ego_entry);
596 }
597 GNUNET_free (handle); 571 GNUNET_free (handle);
598} 572}
599 573
@@ -993,7 +967,8 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
993 handle->redirect_prefix, 967 handle->redirect_prefix,
994 handle->tld, 968 handle->tld,
995 handle->redirect_suffix, 969 handle->redirect_suffix,
996 (NULL == strchr(handle->redirect_suffix, '?') ? "?" : "&"), 970 (NULL == strchr (handle->redirect_suffix, '?') ? "?" :
971 "&"),
997 handle->oidc->response_type, 972 handle->oidc->response_type,
998 code_string, 973 code_string,
999 handle->oidc->state); 974 handle->oidc->state);
@@ -1003,7 +978,8 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
1003 GNUNET_asprintf (&redirect_uri, 978 GNUNET_asprintf (&redirect_uri,
1004 "%s%s%s=%s&state=%s", 979 "%s%s%s=%s&state=%s",
1005 handle->oidc->redirect_uri, 980 handle->oidc->redirect_uri,
1006 (NULL == strchr(handle->oidc->redirect_uri, '?') ? "?" : "&"), 981 (NULL == strchr (handle->oidc->redirect_uri, '?') ? "?" :
982 "&"),
1007 handle->oidc->response_type, 983 handle->oidc->response_type,
1008 code_string, 984 code_string,
1009 handle->oidc->state); 985 handle->oidc->state);
@@ -1082,7 +1058,7 @@ oidc_attest_collect_finished_cb (void *cls)
1082 handle->attest_it = NULL; 1058 handle->attest_it = NULL;
1083 merged_list = attribute_list_merge (handle->attr_idtoken_list, 1059 merged_list = attribute_list_merge (handle->attr_idtoken_list,
1084 handle->attr_userinfo_list); 1060 handle->attr_userinfo_list);
1085 handle->idp_op = GNUNET_RECLAIM_ticket_issue (handle->idp, 1061 handle->idp_op = GNUNET_RECLAIM_ticket_issue (idp,
1086 &handle->priv_key, 1062 &handle->priv_key,
1087 &handle->oidc->client_pkey, 1063 &handle->oidc->client_pkey,
1088 merged_list, 1064 merged_list,
@@ -1149,7 +1125,7 @@ oidc_attr_collect_finished_cb (void *cls)
1149 } 1125 }
1150 handle->attests_list = GNUNET_new (struct GNUNET_RECLAIM_AttestationList); 1126 handle->attests_list = GNUNET_new (struct GNUNET_RECLAIM_AttestationList);
1151 handle->attest_it = 1127 handle->attest_it =
1152 GNUNET_RECLAIM_get_attestations_start (handle->idp, 1128 GNUNET_RECLAIM_get_attestations_start (idp,
1153 &handle->priv_key, 1129 &handle->priv_key,
1154 &oidc_iteration_error, 1130 &oidc_iteration_error,
1155 handle, 1131 handle,
@@ -1315,7 +1291,7 @@ code_redirect (void *cls)
1315 return; 1291 return;
1316 } 1292 }
1317 // iterate over egos and compare their public key 1293 // iterate over egos and compare their public key
1318 for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry; 1294 for (handle->ego_entry = ego_head; NULL != handle->ego_entry;
1319 handle->ego_entry = handle->ego_entry->next) 1295 handle->ego_entry = handle->ego_entry->next)
1320 { 1296 {
1321 GNUNET_IDENTITY_ego_get_public_key (handle->ego_entry->ego, &ego_pkey); 1297 GNUNET_IDENTITY_ego_get_public_key (handle->ego_entry->ego, &ego_pkey);
@@ -1323,13 +1299,12 @@ code_redirect (void *cls)
1323 { 1299 {
1324 handle->priv_key = 1300 handle->priv_key =
1325 *GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego); 1301 *GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego);
1326 handle->idp = GNUNET_RECLAIM_connect (cfg);
1327 handle->attr_idtoken_list = 1302 handle->attr_idtoken_list =
1328 GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 1303 GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
1329 handle->attr_userinfo_list = 1304 handle->attr_userinfo_list =
1330 GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 1305 GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
1331 handle->attr_it = 1306 handle->attr_it =
1332 GNUNET_RECLAIM_get_attributes_start (handle->idp, 1307 GNUNET_RECLAIM_get_attributes_start (idp,
1333 &handle->priv_key, 1308 &handle->priv_key,
1334 &oidc_iteration_error, 1309 &oidc_iteration_error,
1335 handle, 1310 handle,
@@ -1474,7 +1449,7 @@ client_redirect (void *cls)
1474 1449
1475 /* Lookup client redirect uri to verify request */ 1450 /* Lookup client redirect uri to verify request */
1476 handle->gns_op = 1451 handle->gns_op =
1477 GNUNET_GNS_lookup (handle->gns_handle, 1452 GNUNET_GNS_lookup (gns_handle,
1478 GNUNET_GNS_EMPTY_LABEL_AT, 1453 GNUNET_GNS_EMPTY_LABEL_AT,
1479 &handle->oidc->client_pkey, 1454 &handle->oidc->client_pkey,
1480 GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT, 1455 GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT,
@@ -1700,14 +1675,14 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1700 1675
1701 // If we know this identity, translated the corresponding TLD 1676 // If we know this identity, translated the corresponding TLD
1702 // TODO: We might want to have a reverse lookup functionality for TLDs? 1677 // TODO: We might want to have a reverse lookup functionality for TLDs?
1703 for (tmp_ego = handle->ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next) 1678 for (tmp_ego = ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next)
1704 { 1679 {
1705 priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego); 1680 priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego);
1706 GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &pkey); 1681 GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &pkey);
1707 if (0 == GNUNET_memcmp (&pkey, &handle->oidc->client_pkey)) 1682 if (0 == GNUNET_memcmp (&pkey, &handle->oidc->client_pkey))
1708 { 1683 {
1709 handle->tld = GNUNET_strdup (tmp_ego->identifier); 1684 handle->tld = GNUNET_strdup (tmp_ego->identifier);
1710 handle->ego_entry = handle->ego_tail; 1685 handle->ego_entry = ego_tail;
1711 } 1686 }
1712 } 1687 }
1713 handle->oidc->scope = get_url_parameter_copy (handle, OIDC_SCOPE_KEY); 1688 handle->oidc->scope = get_url_parameter_copy (handle, OIDC_SCOPE_KEY);
@@ -1790,6 +1765,7 @@ login_cont (struct GNUNET_REST_RequestHandle *con_handle,
1790 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 1765 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
1791} 1766}
1792 1767
1768
1793static int 1769static int
1794parse_credentials_basic_auth (struct RequestHandle *handle, 1770parse_credentials_basic_auth (struct RequestHandle *handle,
1795 char **client_id, 1771 char **client_id,
@@ -1847,8 +1823,8 @@ parse_credentials_basic_auth (struct RequestHandle *handle,
1847 1823
1848static int 1824static int
1849parse_credentials_post_body (struct RequestHandle *handle, 1825parse_credentials_post_body (struct RequestHandle *handle,
1850 char **client_id, 1826 char **client_id,
1851 char **client_secret) 1827 char **client_secret)
1852{ 1828{
1853 struct GNUNET_HashCode cache_key; 1829 struct GNUNET_HashCode cache_key;
1854 char *client_id_tmp; 1830 char *client_id_tmp;
@@ -1861,8 +1837,9 @@ parse_credentials_post_body (struct RequestHandle *handle,
1861 ->url_param_map, 1837 ->url_param_map,
1862 &cache_key)) 1838 &cache_key))
1863 return GNUNET_SYSERR; 1839 return GNUNET_SYSERR;
1864 client_id_tmp = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, 1840 client_id_tmp = GNUNET_CONTAINER_multihashmap_get (
1865 &cache_key); 1841 handle->rest_handle->url_param_map,
1842 &cache_key);
1866 if (NULL == client_id_tmp) 1843 if (NULL == client_id_tmp)
1867 return GNUNET_SYSERR; 1844 return GNUNET_SYSERR;
1868 *client_id = strdup (client_id_tmp); 1845 *client_id = strdup (client_id_tmp);
@@ -1896,13 +1873,16 @@ check_authorization (struct RequestHandle *handle,
1896 { 1873 {
1897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1898 "Received client credentials in HTTP AuthZ header\n"); 1875 "Received client credentials in HTTP AuthZ header\n");
1899 } else if (GNUNET_OK == parse_credentials_post_body (handle, 1876 }
1900 &received_cid, 1877 else if (GNUNET_OK == parse_credentials_post_body (handle,
1901 &received_cpw)) 1878 &received_cid,
1879 &received_cpw))
1902 { 1880 {
1903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1904 "Received client credentials in POST body\n"); 1882 "Received client credentials in POST body\n");
1905 } else { 1883 }
1884 else
1885 {
1906 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); 1886 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1907 handle->response_code = MHD_HTTP_UNAUTHORIZED; 1887 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1908 return GNUNET_SYSERR; 1888 return GNUNET_SYSERR;
@@ -1931,7 +1911,7 @@ check_authorization (struct RequestHandle *handle,
1931 return GNUNET_SYSERR; 1911 return GNUNET_SYSERR;
1932 } 1912 }
1933 // check client_id 1913 // check client_id
1934 for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry; 1914 for (handle->ego_entry = ego_head; NULL != handle->ego_entry;
1935 handle->ego_entry = handle->ego_entry->next) 1915 handle->ego_entry = handle->ego_entry->next)
1936 { 1916 {
1937 if (0 == strcmp (handle->ego_entry->keystring, received_cid)) 1917 if (0 == strcmp (handle->ego_entry->keystring, received_cid))
@@ -1963,7 +1943,7 @@ find_ego (struct RequestHandle *handle,
1963 struct EgoEntry *ego_entry; 1943 struct EgoEntry *ego_entry;
1964 struct GNUNET_CRYPTO_EcdsaPublicKey pub_key; 1944 struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
1965 1945
1966 for (ego_entry = handle->ego_head; NULL != ego_entry; 1946 for (ego_entry = ego_head; NULL != ego_entry;
1967 ego_entry = ego_entry->next) 1947 ego_entry = ego_entry->next)
1968 { 1948 {
1969 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &pub_key); 1949 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &pub_key);
@@ -2321,14 +2301,13 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2321 return; 2301 return;
2322 } 2302 }
2323 2303
2324 handle->idp = GNUNET_RECLAIM_connect (cfg);
2325 handle->oidc->response = json_object (); 2304 handle->oidc->response = json_object ();
2326 json_object_set_new (handle->oidc->response, 2305 json_object_set_new (handle->oidc->response,
2327 "sub", 2306 "sub",
2328 json_string (iss_ego->keystring)); 2307 json_string (iss_ego->keystring));
2329 privkey = GNUNET_IDENTITY_ego_get_private_key (aud_ego->ego); 2308 privkey = GNUNET_IDENTITY_ego_get_private_key (aud_ego->ego);
2330 2309
2331 handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp, 2310 handle->idp_op = GNUNET_RECLAIM_ticket_consume (idp,
2332 privkey, 2311 privkey,
2333 ticket, 2312 ticket,
2334 consume_ticket, 2313 consume_ticket,
@@ -2338,36 +2317,6 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2338 2317
2339 2318
2340/** 2319/**
2341 * Handle rest request
2342 *
2343 * @param handle the request handle
2344 */
2345static void
2346init_cont (struct RequestHandle *handle)
2347{
2348 struct GNUNET_REST_RequestHandlerError err;
2349 static const struct GNUNET_REST_RequestHandler handlers[] =
2350 { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint },
2351 { MHD_HTTP_METHOD_POST,
2352 GNUNET_REST_API_NS_AUTHORIZE,
2353 &authorize_endpoint }, // url-encoded
2354 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont },
2355 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint },
2356 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
2357 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
2358 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont },
2359 GNUNET_REST_HANDLER_END };
2360
2361 if (GNUNET_NO ==
2362 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
2363 {
2364 handle->response_code = err.error_code;
2365 GNUNET_SCHEDULER_add_now (&do_error, handle);
2366 }
2367}
2368
2369
2370/**
2371 * If listing is enabled, prints information about the egos. 2320 * If listing is enabled, prints information about the egos.
2372 * 2321 *
2373 * This function is initially called for all egos and then again 2322 * This function is initially called for all egos and then again
@@ -2406,18 +2355,16 @@ list_ego (void *cls,
2406 void **ctx, 2355 void **ctx,
2407 const char *identifier) 2356 const char *identifier)
2408{ 2357{
2409 struct RequestHandle *handle = cls;
2410 struct EgoEntry *ego_entry; 2358 struct EgoEntry *ego_entry;
2411 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 2359 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
2412 2360
2413 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) 2361 if ((NULL == ego) && (ID_REST_STATE_INIT == state))
2414 { 2362 {
2415 handle->state = ID_REST_STATE_POST_INIT; 2363 state = ID_REST_STATE_POST_INIT;
2416 init_cont (handle);
2417 return; 2364 return;
2418 } 2365 }
2419 GNUNET_assert (NULL != ego); 2366 GNUNET_assert (NULL != ego);
2420 if (ID_REST_STATE_INIT == handle->state) 2367 if (ID_REST_STATE_INIT == state)
2421 2368
2422 { 2369 {
2423 ego_entry = GNUNET_new (struct EgoEntry); 2370 ego_entry = GNUNET_new (struct EgoEntry);
@@ -2425,15 +2372,15 @@ list_ego (void *cls,
2425 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); 2372 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
2426 ego_entry->ego = ego; 2373 ego_entry->ego = ego;
2427 ego_entry->identifier = GNUNET_strdup (identifier); 2374 ego_entry->identifier = GNUNET_strdup (identifier);
2428 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, 2375 GNUNET_CONTAINER_DLL_insert_tail (ego_head,
2429 handle->ego_tail, 2376 ego_tail,
2430 ego_entry); 2377 ego_entry);
2431 return; 2378 return;
2432 } 2379 }
2433 /* Ego renamed or added */ 2380 /* Ego renamed or added */
2434 if (identifier != NULL) 2381 if (identifier != NULL)
2435 { 2382 {
2436 for (ego_entry = handle->ego_head; NULL != ego_entry; 2383 for (ego_entry = ego_head; NULL != ego_entry;
2437 ego_entry = ego_entry->next) 2384 ego_entry = ego_entry->next)
2438 { 2385 {
2439 if (ego_entry->ego == ego) 2386 if (ego_entry->ego == ego)
@@ -2452,15 +2399,15 @@ list_ego (void *cls,
2452 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); 2399 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
2453 ego_entry->ego = ego; 2400 ego_entry->ego = ego;
2454 ego_entry->identifier = GNUNET_strdup (identifier); 2401 ego_entry->identifier = GNUNET_strdup (identifier);
2455 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, 2402 GNUNET_CONTAINER_DLL_insert_tail (ego_head,
2456 handle->ego_tail, 2403 ego_tail,
2457 ego_entry); 2404 ego_entry);
2458 } 2405 }
2459 } 2406 }
2460 else 2407 else
2461 { 2408 {
2462 /* Delete */ 2409 /* Delete */
2463 for (ego_entry = handle->ego_head; NULL != ego_entry; 2410 for (ego_entry = ego_head; NULL != ego_entry;
2464 ego_entry = ego_entry->next) 2411 ego_entry = ego_entry->next)
2465 { 2412 {
2466 if (ego_entry->ego == ego) 2413 if (ego_entry->ego == ego)
@@ -2469,8 +2416,8 @@ list_ego (void *cls,
2469 if (NULL == ego_entry) 2416 if (NULL == ego_entry)
2470 return; /* Not found */ 2417 return; /* Not found */
2471 2418
2472 GNUNET_CONTAINER_DLL_remove (handle->ego_head, 2419 GNUNET_CONTAINER_DLL_remove (ego_head,
2473 handle->ego_tail, 2420 ego_tail,
2474 ego_entry); 2421 ego_entry);
2475 GNUNET_free (ego_entry->identifier); 2422 GNUNET_free (ego_entry->identifier);
2476 GNUNET_free (ego_entry->keystring); 2423 GNUNET_free (ego_entry->keystring);
@@ -2480,12 +2427,23 @@ list_ego (void *cls,
2480} 2427}
2481 2428
2482 2429
2483static void 2430static enum GNUNET_GenericReturnValue
2484rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, 2431rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
2485 GNUNET_REST_ResultProcessor proc, 2432 GNUNET_REST_ResultProcessor proc,
2486 void *proc_cls) 2433 void *proc_cls)
2487{ 2434{
2488 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 2435 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
2436 struct GNUNET_REST_RequestHandlerError err;
2437 static const struct GNUNET_REST_RequestHandler handlers[] =
2438 { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint },
2439 { MHD_HTTP_METHOD_POST,
2440 GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint }, // url-encoded
2441 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont },
2442 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint },
2443 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
2444 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
2445 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont },
2446 GNUNET_REST_HANDLER_END };
2489 2447
2490 handle->oidc = GNUNET_new (struct OIDC_Variables); 2448 handle->oidc = GNUNET_new (struct OIDC_Variables);
2491 if (NULL == OIDC_cookie_jar_map) 2449 if (NULL == OIDC_cookie_jar_map)
@@ -2495,19 +2453,17 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
2495 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 2453 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
2496 handle->proc_cls = proc_cls; 2454 handle->proc_cls = proc_cls;
2497 handle->proc = proc; 2455 handle->proc = proc;
2498 handle->state = ID_REST_STATE_INIT;
2499 handle->rest_handle = rest_handle; 2456 handle->rest_handle = rest_handle;
2500
2501 handle->url = GNUNET_strdup (rest_handle->url); 2457 handle->url = GNUNET_strdup (rest_handle->url);
2502 if (handle->url[strlen (handle->url) - 1] == '/') 2458 if (handle->url[strlen (handle->url) - 1] == '/')
2503 handle->url[strlen (handle->url) - 1] = '\0'; 2459 handle->url[strlen (handle->url) - 1] = '\0';
2504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 2460 if (GNUNET_NO ==
2505 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle); 2461 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
2506 handle->gns_handle = GNUNET_GNS_connect (cfg); 2462 return GNUNET_NO;
2507 handle->namestore_handle = GNUNET_NAMESTORE_connect (cfg); 2463
2508 handle->timeout_task = 2464 handle->timeout_task =
2509 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); 2465 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
2510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); 2466 return GNUNET_YES;
2511} 2467}
2512 2468
2513 2469
@@ -2532,6 +2488,11 @@ libgnunet_plugin_rest_openid_connect_init (void *cls)
2532 api->cls = &plugin; 2488 api->cls = &plugin;
2533 api->name = GNUNET_REST_API_NS_OIDC; 2489 api->name = GNUNET_REST_API_NS_OIDC;
2534 api->process_request = &rest_identity_process_request; 2490 api->process_request = &rest_identity_process_request;
2491 identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL);
2492 gns_handle = GNUNET_GNS_connect (cfg);
2493 idp = GNUNET_RECLAIM_connect (cfg);
2494
2495 state = ID_REST_STATE_INIT;
2535 GNUNET_asprintf (&allow_methods, 2496 GNUNET_asprintf (&allow_methods,
2536 "%s, %s, %s, %s, %s", 2497 "%s, %s, %s, %s, %s",
2537 MHD_HTTP_METHOD_GET, 2498 MHD_HTTP_METHOD_GET,
@@ -2557,6 +2518,7 @@ libgnunet_plugin_rest_openid_connect_done (void *cls)
2557{ 2518{
2558 struct GNUNET_REST_Plugin *api = cls; 2519 struct GNUNET_REST_Plugin *api = cls;
2559 struct Plugin *plugin = api->cls; 2520 struct Plugin *plugin = api->cls;
2521 struct EgoEntry *ego_entry;
2560 2522
2561 plugin->cfg = NULL; 2523 plugin->cfg = NULL;
2562 2524
@@ -2573,6 +2535,21 @@ libgnunet_plugin_rest_openid_connect_done (void *cls)
2573 2535
2574 GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it); 2536 GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it);
2575 GNUNET_free (allow_methods); 2537 GNUNET_free (allow_methods);
2538 if (NULL != gns_handle)
2539 GNUNET_GNS_disconnect (gns_handle);
2540 if (NULL != identity_handle)
2541 GNUNET_IDENTITY_disconnect (identity_handle);
2542 if (NULL != idp)
2543 GNUNET_RECLAIM_disconnect (idp);
2544 while (NULL != (ego_entry = ego_head))
2545 {
2546 GNUNET_CONTAINER_DLL_remove (ego_head,
2547 ego_tail,
2548 ego_entry);
2549 GNUNET_free (ego_entry->identifier);
2550 GNUNET_free (ego_entry->keystring);
2551 GNUNET_free (ego_entry);
2552 }
2576 GNUNET_free (api); 2553 GNUNET_free (api);
2577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2578 "OpenID Connect REST plugin is finished\n"); 2555 "OpenID Connect REST plugin is finished\n");
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index 10ee2f801..eb442bc3b 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -88,6 +88,31 @@ const struct GNUNET_CONFIGURATION_Handle *cfg;
88static char *allow_methods; 88static char *allow_methods;
89 89
90/** 90/**
91 * Ego list
92 */
93static struct EgoEntry *ego_head;
94
95/**
96 * Ego list
97 */
98static struct EgoEntry *ego_tail;
99
100/**
101 * The processing state
102 */
103static int state;
104
105/**
106 * Handle to Identity service.
107 */
108static struct GNUNET_IDENTITY_Handle *identity_handle;
109
110/**
111 * Identity Provider
112 */
113static struct GNUNET_RECLAIM_Handle *idp;
114
115/**
91 * @brief struct returned by the initialization function of the plugin 116 * @brief struct returned by the initialization function of the plugin
92 */ 117 */
93struct Plugin 118struct Plugin
@@ -129,15 +154,6 @@ struct EgoEntry
129 154
130struct RequestHandle 155struct RequestHandle
131{ 156{
132 /**
133 * Ego list
134 */
135 struct EgoEntry *ego_head;
136
137 /**
138 * Ego list
139 */
140 struct EgoEntry *ego_tail;
141 157
142 /** 158 /**
143 * Selected ego 159 * Selected ego
@@ -150,16 +166,6 @@ struct RequestHandle
150 struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key; 166 struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key;
151 167
152 /** 168 /**
153 * The processing state
154 */
155 int state;
156
157 /**
158 * Handle to Identity service.
159 */
160 struct GNUNET_IDENTITY_Handle *identity_handle;
161
162 /**
163 * Rest connection 169 * Rest connection
164 */ 170 */
165 struct GNUNET_REST_RequestHandle *rest_handle; 171 struct GNUNET_REST_RequestHandle *rest_handle;
@@ -175,11 +181,6 @@ struct RequestHandle
175 struct GNUNET_IDENTITY_Operation *op; 181 struct GNUNET_IDENTITY_Operation *op;
176 182
177 /** 183 /**
178 * Identity Provider
179 */
180 struct GNUNET_RECLAIM_Handle *idp;
181
182 /**
183 * Idp Operation 184 * Idp Operation
184 */ 185 */
185 struct GNUNET_RECLAIM_Operation *idp_op; 186 struct GNUNET_RECLAIM_Operation *idp_op;
@@ -194,7 +195,6 @@ struct RequestHandle
194 */ 195 */
195 struct GNUNET_RECLAIM_AttestationIterator *attest_it; 196 struct GNUNET_RECLAIM_AttestationIterator *attest_it;
196 197
197
198 /** 198 /**
199 * Ticket iterator 199 * Ticket iterator
200 */ 200 */
@@ -251,51 +251,31 @@ struct RequestHandle
251 * @param handle Handle to clean up 251 * @param handle Handle to clean up
252 */ 252 */
253static void 253static void
254cleanup_handle (struct RequestHandle *handle) 254cleanup_handle (void *cls)
255{ 255{
256 struct EgoEntry *ego_entry; 256 struct RequestHandle *handle = cls;
257 struct EgoEntry *ego_tmp;
258 257
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); 258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
260 if (NULL != handle->resp_object) 259 if (NULL != handle->resp_object)
261 json_decref (handle->resp_object); 260 json_decref (handle->resp_object);
262 if (NULL != handle->timeout_task) 261 if (NULL != handle->timeout_task)
263 GNUNET_SCHEDULER_cancel (handle->timeout_task); 262 GNUNET_SCHEDULER_cancel (handle->timeout_task);
264 if (NULL != handle->identity_handle)
265 GNUNET_IDENTITY_disconnect (handle->identity_handle);
266 if (NULL != handle->attr_it) 263 if (NULL != handle->attr_it)
267 GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); 264 GNUNET_RECLAIM_get_attributes_stop (handle->attr_it);
268 if (NULL != handle->attest_it) 265 if (NULL != handle->attest_it)
269 GNUNET_RECLAIM_get_attestations_stop (handle->attest_it); 266 GNUNET_RECLAIM_get_attestations_stop (handle->attest_it);
270 if (NULL != handle->ticket_it) 267 if (NULL != handle->ticket_it)
271 GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); 268 GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it);
272 if (NULL != handle->idp)
273 GNUNET_RECLAIM_disconnect (handle->idp);
274 if (NULL != handle->url) 269 if (NULL != handle->url)
275 GNUNET_free (handle->url); 270 GNUNET_free (handle->url);
276 if (NULL != handle->emsg) 271 if (NULL != handle->emsg)
277 GNUNET_free (handle->emsg); 272 GNUNET_free (handle->emsg);
278 if (NULL != handle->attr_list) 273 if (NULL != handle->attr_list)
279 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list); 274 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list);
280 for (ego_entry = handle->ego_head; NULL != ego_entry;)
281 {
282 ego_tmp = ego_entry;
283 ego_entry = ego_entry->next;
284 GNUNET_free (ego_tmp->identifier);
285 GNUNET_free (ego_tmp->keystring);
286 GNUNET_free (ego_tmp);
287 }
288 GNUNET_free (handle); 275 GNUNET_free (handle);
289} 276}
290 277
291 278
292static void
293cleanup_handle_delayed (void *cls)
294{
295 cleanup_handle (cls);
296}
297
298
299/** 279/**
300 * Task run on error, sends error message. Cleans up everything. 280 * Task run on error, sends error message. Cleans up everything.
301 * 281 *
@@ -316,7 +296,7 @@ do_error (void *cls)
316 resp = GNUNET_REST_create_response (json_error); 296 resp = GNUNET_REST_create_response (json_error);
317 MHD_add_response_header (resp, "Content-Type", "application/json"); 297 MHD_add_response_header (resp, "Content-Type", "application/json");
318 handle->proc (handle->proc_cls, resp, handle->response_code); 298 handle->proc (handle->proc_cls, resp, handle->response_code);
319 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 299 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
320 GNUNET_free (json_error); 300 GNUNET_free (json_error);
321} 301}
322 302
@@ -339,9 +319,7 @@ do_timeout (void *cls)
339static void 319static void
340collect_error_cb (void *cls) 320collect_error_cb (void *cls)
341{ 321{
342 struct RequestHandle *handle = cls; 322 do_error (cls);
343
344 do_error (handle);
345} 323}
346 324
347 325
@@ -359,7 +337,7 @@ finished_cont (void *cls, int32_t success, const char *emsg)
359 return; 337 return;
360 } 338 }
361 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 339 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
362 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 340 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
363} 341}
364 342
365 343
@@ -376,7 +354,7 @@ delete_finished_cb (void *cls, int32_t success, const char *emsg)
376 return; 354 return;
377 } 355 }
378 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 356 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
379 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 357 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
380} 358}
381 359
382 360
@@ -485,7 +463,7 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
485 identity = handle->url + strlen ( 463 identity = handle->url + strlen (
486 GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; 464 GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1;
487 465
488 for (ego_entry = handle->ego_head; NULL != ego_entry; 466 for (ego_entry = ego_head; NULL != ego_entry;
489 ego_entry = ego_entry->next) 467 ego_entry = ego_entry->next)
490 if (0 == strcmp (identity, ego_entry->identifier)) 468 if (0 == strcmp (identity, ego_entry->identifier))
491 break; 469 break;
@@ -523,9 +501,8 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
523 */ 501 */
524 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id)) 502 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
525 GNUNET_RECLAIM_id_generate (&attribute->id); 503 GNUNET_RECLAIM_id_generate (&attribute->id);
526 handle->idp = GNUNET_RECLAIM_connect (cfg);
527 exp = GNUNET_TIME_UNIT_HOURS; 504 exp = GNUNET_TIME_UNIT_HOURS;
528 handle->idp_op = GNUNET_RECLAIM_attestation_store (handle->idp, 505 handle->idp_op = GNUNET_RECLAIM_attestation_store (idp,
529 identity_priv, 506 identity_priv,
530 attribute, 507 attribute,
531 &exp, 508 &exp,
@@ -644,7 +621,7 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
644 identity = handle->url + strlen ( 621 identity = handle->url + strlen (
645 GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; 622 GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1;
646 623
647 for (ego_entry = handle->ego_head; NULL != ego_entry; 624 for (ego_entry = ego_head; NULL != ego_entry;
648 ego_entry = ego_entry->next) 625 ego_entry = ego_entry->next)
649 if (0 == strcmp (identity, ego_entry->identifier)) 626 if (0 == strcmp (identity, ego_entry->identifier))
650 break; 627 break;
@@ -659,8 +636,7 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
659 return; 636 return;
660 } 637 }
661 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 638 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
662 handle->idp = GNUNET_RECLAIM_connect (cfg); 639 handle->attest_it = GNUNET_RECLAIM_get_attestations_start (idp,
663 handle->attest_it = GNUNET_RECLAIM_get_attestations_start (handle->idp,
664 priv_key, 640 priv_key,
665 &collect_error_cb, 641 &collect_error_cb,
666 handle, 642 handle,
@@ -713,7 +689,7 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
713 return; 689 return;
714 } 690 }
715 691
716 for (ego_entry = handle->ego_head; NULL != ego_entry; 692 for (ego_entry = ego_head; NULL != ego_entry;
717 ego_entry = ego_entry->next) 693 ego_entry = ego_entry->next)
718 if (0 == strcmp (identity, ego_entry->identifier)) 694 if (0 == strcmp (identity, ego_entry->identifier))
719 break; 695 break;
@@ -727,11 +703,10 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
727 return; 703 return;
728 } 704 }
729 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 705 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
730 handle->idp = GNUNET_RECLAIM_connect (cfg);
731 memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attestation)); 706 memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attestation));
732 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); 707 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
733 attr.name = ""; 708 attr.name = "";
734 handle->idp_op = GNUNET_RECLAIM_attestation_delete (handle->idp, 709 handle->idp_op = GNUNET_RECLAIM_attestation_delete (idp,
735 priv_key, 710 priv_key,
736 &attr, 711 &attr,
737 &delete_finished_cb, 712 &delete_finished_cb,
@@ -768,7 +743,7 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle,
768 } 743 }
769 identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1; 744 identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1;
770 745
771 for (ego_entry = handle->ego_head; NULL != ego_entry; 746 for (ego_entry = ego_head; NULL != ego_entry;
772 ego_entry = ego_entry->next) 747 ego_entry = ego_entry->next)
773 if (0 == strcmp (identity, ego_entry->identifier)) 748 if (0 == strcmp (identity, ego_entry->identifier))
774 break; 749 break;
@@ -782,9 +757,8 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle,
782 return; 757 return;
783 } 758 }
784 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 759 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
785 handle->idp = GNUNET_RECLAIM_connect (cfg);
786 handle->ticket_it = 760 handle->ticket_it =
787 GNUNET_RECLAIM_ticket_iteration_start (handle->idp, 761 GNUNET_RECLAIM_ticket_iteration_start (idp,
788 priv_key, 762 priv_key,
789 &collect_error_cb, 763 &collect_error_cb,
790 handle, 764 handle,
@@ -823,7 +797,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
823 } 797 }
824 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; 798 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
825 799
826 for (ego_entry = handle->ego_head; NULL != ego_entry; 800 for (ego_entry = ego_head; NULL != ego_entry;
827 ego_entry = ego_entry->next) 801 ego_entry = ego_entry->next)
828 if (0 == strcmp (identity, ego_entry->identifier)) 802 if (0 == strcmp (identity, ego_entry->identifier))
829 break; 803 break;
@@ -862,9 +836,8 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
862 */ 836 */
863 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id)) 837 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
864 GNUNET_RECLAIM_id_generate (&attribute->id); 838 GNUNET_RECLAIM_id_generate (&attribute->id);
865 handle->idp = GNUNET_RECLAIM_connect (cfg);
866 exp = GNUNET_TIME_UNIT_HOURS; 839 exp = GNUNET_TIME_UNIT_HOURS;
867 handle->idp_op = GNUNET_RECLAIM_attribute_store (handle->idp, 840 handle->idp_op = GNUNET_RECLAIM_attribute_store (idp,
868 identity_priv, 841 identity_priv,
869 attribute, 842 attribute,
870 &exp, 843 &exp,
@@ -1012,7 +985,7 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
1012 } 985 }
1013 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; 986 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
1014 987
1015 for (ego_entry = handle->ego_head; NULL != ego_entry; 988 for (ego_entry = ego_head; NULL != ego_entry;
1016 ego_entry = ego_entry->next) 989 ego_entry = ego_entry->next)
1017 if (0 == strcmp (identity, ego_entry->identifier)) 990 if (0 == strcmp (identity, ego_entry->identifier))
1018 break; 991 break;
@@ -1027,8 +1000,7 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
1027 return; 1000 return;
1028 } 1001 }
1029 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 1002 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1030 handle->idp = GNUNET_RECLAIM_connect (cfg); 1003 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (idp,
1031 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp,
1032 priv_key, 1004 priv_key,
1033 &collect_error_cb, 1005 &collect_error_cb,
1034 handle, 1006 handle,
@@ -1078,7 +1050,7 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
1078 return; 1050 return;
1079 } 1051 }
1080 1052
1081 for (ego_entry = handle->ego_head; NULL != ego_entry; 1053 for (ego_entry = ego_head; NULL != ego_entry;
1082 ego_entry = ego_entry->next) 1054 ego_entry = ego_entry->next)
1083 if (0 == strcmp (identity, ego_entry->identifier)) 1055 if (0 == strcmp (identity, ego_entry->identifier))
1084 break; 1056 break;
@@ -1092,11 +1064,10 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
1092 return; 1064 return;
1093 } 1065 }
1094 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 1066 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1095 handle->idp = GNUNET_RECLAIM_connect (cfg);
1096 memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attribute)); 1067 memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attribute));
1097 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); 1068 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
1098 attr.name = ""; 1069 attr.name = "";
1099 handle->idp_op = GNUNET_RECLAIM_attribute_delete (handle->idp, 1070 handle->idp_op = GNUNET_RECLAIM_attribute_delete (idp,
1100 priv_key, 1071 priv_key,
1101 &attr, 1072 &attr,
1102 &delete_finished_cb, 1073 &delete_finished_cb,
@@ -1152,7 +1123,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
1152 return; 1123 return;
1153 } 1124 }
1154 1125
1155 for (ego_entry = handle->ego_head; NULL != ego_entry; 1126 for (ego_entry = ego_head; NULL != ego_entry;
1156 ego_entry = ego_entry->next) 1127 ego_entry = ego_entry->next)
1157 { 1128 {
1158 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); 1129 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
@@ -1169,8 +1140,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
1169 } 1140 }
1170 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 1141 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1171 1142
1172 handle->idp = GNUNET_RECLAIM_connect (cfg); 1143 handle->idp_op = GNUNET_RECLAIM_ticket_revoke (idp,
1173 handle->idp_op = GNUNET_RECLAIM_ticket_revoke (handle->idp,
1174 identity_priv, 1144 identity_priv,
1175 ticket, 1145 ticket,
1176 &finished_cont, 1146 &finished_cont,
@@ -1256,7 +1226,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
1256 json_decref (data_json); 1226 json_decref (data_json);
1257 return; 1227 return;
1258 } 1228 }
1259 for (ego_entry = handle->ego_head; NULL != ego_entry; 1229 for (ego_entry = ego_head; NULL != ego_entry;
1260 ego_entry = ego_entry->next) 1230 ego_entry = ego_entry->next)
1261 { 1231 {
1262 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); 1232 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
@@ -1273,8 +1243,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
1273 } 1243 }
1274 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 1244 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1275 handle->resp_object = json_object (); 1245 handle->resp_object = json_object ();
1276 handle->idp = GNUNET_RECLAIM_connect (cfg); 1246 handle->idp_op = GNUNET_RECLAIM_ticket_consume (idp,
1277 handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp,
1278 identity_priv, 1247 identity_priv,
1279 ticket, 1248 ticket,
1280 &consume_cont, 1249 &consume_cont,
@@ -1308,55 +1277,6 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
1308 1277
1309 1278
1310/** 1279/**
1311 * Handle rest request
1312 *
1313 * @param handle the request handle
1314 */
1315static void
1316init_cont (struct RequestHandle *handle)
1317{
1318 struct GNUNET_REST_RequestHandlerError err;
1319 static const struct GNUNET_REST_RequestHandler handlers[] =
1320 { { MHD_HTTP_METHOD_GET,
1321 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
1322 &list_attribute_cont },
1323 { MHD_HTTP_METHOD_POST,
1324 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
1325 &add_attribute_cont },
1326 { MHD_HTTP_METHOD_DELETE,
1327 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
1328 &delete_attribute_cont },
1329 { MHD_HTTP_METHOD_GET,
1330 GNUNET_REST_API_NS_RECLAIM_ATTESTATION,
1331 &list_attestation_cont },
1332 { MHD_HTTP_METHOD_POST,
1333 GNUNET_REST_API_NS_RECLAIM_ATTESTATION,
1334 &add_attestation_cont },
1335 { MHD_HTTP_METHOD_DELETE,
1336 GNUNET_REST_API_NS_RECLAIM_ATTESTATION,
1337 &delete_attestation_cont },
1338 { MHD_HTTP_METHOD_GET,
1339 GNUNET_REST_API_NS_IDENTITY_TICKETS,
1340 &list_tickets_cont },
1341 { MHD_HTTP_METHOD_POST,
1342 GNUNET_REST_API_NS_IDENTITY_REVOKE,
1343 &revoke_ticket_cont },
1344 { MHD_HTTP_METHOD_POST,
1345 GNUNET_REST_API_NS_IDENTITY_CONSUME,
1346 &consume_ticket_cont },
1347 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont },
1348 GNUNET_REST_HANDLER_END };
1349
1350 if (GNUNET_NO ==
1351 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1352 {
1353 handle->response_code = err.error_code;
1354 GNUNET_SCHEDULER_add_now (&do_error, handle);
1355 }
1356}
1357
1358
1359/**
1360 * If listing is enabled, prints information about the egos. 1280 * If listing is enabled, prints information about the egos.
1361 * 1281 *
1362 * This function is initially called for all egos and then again 1282 * This function is initially called for all egos and then again
@@ -1395,52 +1315,126 @@ list_ego (void *cls,
1395 void **ctx, 1315 void **ctx,
1396 const char *identifier) 1316 const char *identifier)
1397{ 1317{
1398 struct RequestHandle *handle = cls;
1399 struct EgoEntry *ego_entry; 1318 struct EgoEntry *ego_entry;
1400 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 1319 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
1401 1320
1402 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) 1321 if ((NULL == ego) && (ID_REST_STATE_INIT == state))
1403 { 1322 {
1404 handle->state = ID_REST_STATE_POST_INIT; 1323 state = ID_REST_STATE_POST_INIT;
1405 init_cont (handle);
1406 return; 1324 return;
1407 } 1325 }
1408 if (ID_REST_STATE_INIT == handle->state) 1326 if (ID_REST_STATE_INIT == state)
1409 { 1327 {
1410 ego_entry = GNUNET_new (struct EgoEntry); 1328 ego_entry = GNUNET_new (struct EgoEntry);
1411 GNUNET_IDENTITY_ego_get_public_key (ego, &pk); 1329 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
1412 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); 1330 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
1413 ego_entry->ego = ego; 1331 ego_entry->ego = ego;
1414 ego_entry->identifier = GNUNET_strdup (identifier); 1332 ego_entry->identifier = GNUNET_strdup (identifier);
1415 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, 1333 GNUNET_CONTAINER_DLL_insert_tail (ego_head,
1416 handle->ego_tail, 1334 ego_tail,
1417 ego_entry); 1335 ego_entry);
1418 } 1336 }
1337 /* Ego renamed or added */
1338 if (identifier != NULL)
1339 {
1340 for (ego_entry = ego_head; NULL != ego_entry;
1341 ego_entry = ego_entry->next)
1342 {
1343 if (ego_entry->ego == ego)
1344 {
1345 /* Rename */
1346 GNUNET_free (ego_entry->identifier);
1347 ego_entry->identifier = GNUNET_strdup (identifier);
1348 break;
1349 }
1350 }
1351 if (NULL == ego_entry)
1352 {
1353 /* Add */
1354 ego_entry = GNUNET_new (struct EgoEntry);
1355 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
1356 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
1357 ego_entry->ego = ego;
1358 ego_entry->identifier = GNUNET_strdup (identifier);
1359 GNUNET_CONTAINER_DLL_insert_tail (ego_head,
1360 ego_tail,
1361 ego_entry);
1362 }
1363 }
1364 else
1365 {
1366 /* Delete */
1367 for (ego_entry = ego_head; NULL != ego_entry;
1368 ego_entry = ego_entry->next)
1369 {
1370 if (ego_entry->ego == ego)
1371 break;
1372 }
1373 if (NULL == ego_entry)
1374 return; /* Not found */
1375
1376 GNUNET_CONTAINER_DLL_remove (ego_head,
1377 ego_tail,
1378 ego_entry);
1379 GNUNET_free (ego_entry->identifier);
1380 GNUNET_free (ego_entry->keystring);
1381 GNUNET_free (ego_entry);
1382 return;
1383 }
1384
1419} 1385}
1420 1386
1421 1387
1422static void 1388static enum GNUNET_GenericReturnValue
1423rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, 1389rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1424 GNUNET_REST_ResultProcessor proc, 1390 GNUNET_REST_ResultProcessor proc,
1425 void *proc_cls) 1391 void *proc_cls)
1426{ 1392{
1427 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 1393 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1394 struct GNUNET_REST_RequestHandlerError err;
1395 static const struct GNUNET_REST_RequestHandler handlers[] =
1396 { { MHD_HTTP_METHOD_GET,
1397 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &list_attribute_cont },
1398 { MHD_HTTP_METHOD_POST,
1399 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &add_attribute_cont },
1400 { MHD_HTTP_METHOD_DELETE,
1401 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &delete_attribute_cont },
1402 { MHD_HTTP_METHOD_GET,
1403 GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &list_attestation_cont },
1404 { MHD_HTTP_METHOD_POST,
1405 GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &add_attestation_cont },
1406 { MHD_HTTP_METHOD_DELETE,
1407 GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &delete_attestation_cont },
1408 { MHD_HTTP_METHOD_GET,
1409 GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont },
1410 { MHD_HTTP_METHOD_POST,
1411 GNUNET_REST_API_NS_IDENTITY_REVOKE, &revoke_ticket_cont },
1412 { MHD_HTTP_METHOD_POST,
1413 GNUNET_REST_API_NS_IDENTITY_CONSUME, &consume_ticket_cont },
1414 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont },
1415 GNUNET_REST_HANDLER_END
1416 };
1428 1417
1429 handle->response_code = 0; 1418 handle->response_code = 0;
1430 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1419 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1431 handle->proc_cls = proc_cls; 1420 handle->proc_cls = proc_cls;
1432 handle->proc = proc; 1421 handle->proc = proc;
1433 handle->state = ID_REST_STATE_INIT; 1422 state = ID_REST_STATE_INIT;
1434 handle->rest_handle = rest_handle; 1423 handle->rest_handle = rest_handle;
1435 1424
1436 handle->url = GNUNET_strdup (rest_handle->url); 1425 handle->url = GNUNET_strdup (rest_handle->url);
1437 if (handle->url[strlen (handle->url) - 1] == '/') 1426 if (handle->url[strlen (handle->url) - 1] == '/')
1438 handle->url[strlen (handle->url) - 1] = '\0'; 1427 handle->url[strlen (handle->url) - 1] = '\0';
1439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 1428 if (GNUNET_NO ==
1440 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle); 1429 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1430 {
1431 cleanup_handle (handle);
1432 return GNUNET_NO;
1433 }
1434
1441 handle->timeout_task = 1435 handle->timeout_task =
1442 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); 1436 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
1443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); 1437 return GNUNET_YES;
1444} 1438}
1445 1439
1446 1440
@@ -1472,7 +1466,8 @@ libgnunet_plugin_rest_reclaim_init (void *cls)
1472 MHD_HTTP_METHOD_PUT, 1466 MHD_HTTP_METHOD_PUT,
1473 MHD_HTTP_METHOD_DELETE, 1467 MHD_HTTP_METHOD_DELETE,
1474 MHD_HTTP_METHOD_OPTIONS); 1468 MHD_HTTP_METHOD_OPTIONS);
1475 1469 identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL);
1470 idp = GNUNET_RECLAIM_connect (cfg);
1476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1477 _ ("Identity Provider REST API initialized\n")); 1472 _ ("Identity Provider REST API initialized\n"));
1478 return api; 1473 return api;
@@ -1490,8 +1485,22 @@ libgnunet_plugin_rest_reclaim_done (void *cls)
1490{ 1485{
1491 struct GNUNET_REST_Plugin *api = cls; 1486 struct GNUNET_REST_Plugin *api = cls;
1492 struct Plugin *plugin = api->cls; 1487 struct Plugin *plugin = api->cls;
1488 struct EgoEntry *ego_entry;
1489 struct EgoEntry *ego_tmp;
1493 1490
1494 plugin->cfg = NULL; 1491 plugin->cfg = NULL;
1492 if (NULL != idp)
1493 GNUNET_RECLAIM_disconnect (idp);
1494 if (NULL != identity_handle)
1495 GNUNET_IDENTITY_disconnect (identity_handle);
1496 for (ego_entry = ego_head; NULL != ego_entry;)
1497 {
1498 ego_tmp = ego_entry;
1499 ego_entry = ego_entry->next;
1500 GNUNET_free (ego_tmp->identifier);
1501 GNUNET_free (ego_tmp->keystring);
1502 GNUNET_free (ego_tmp);
1503 }
1495 1504
1496 GNUNET_free (allow_methods); 1505 GNUNET_free (allow_methods);
1497 GNUNET_free (api); 1506 GNUNET_free (api);