2 This file is part of GNUnet.
3 Copyright (C) 2012-2018 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @author Martin Schanzenbach
22 * @author Philippe Buschmann
23 * @file identity/plugin_rest_openid_connect.c
24 * @brief GNUnet Namestore REST plugin
31 #include "gnunet_gns_service.h"
32 #include "gnunet_gnsrecord_lib.h"
33 #include "gnunet_identity_service.h"
34 #include "gnunet_namestore_service.h"
35 #include "gnunet_reclaim_lib.h"
36 #include "gnunet_reclaim_service.h"
37 #include "gnunet_rest_lib.h"
38 #include "gnunet_rest_plugin.h"
39 #include "gnunet_signatures.h"
40 #include "microhttpd.h"
41 #include "oidc_helper.h"
45 #define GNUNET_REST_API_NS_OIDC "/openid"
50 #define GNUNET_REST_API_NS_AUTHORIZE "/openid/authorize"
55 #define GNUNET_REST_API_NS_TOKEN "/openid/token"
60 #define GNUNET_REST_API_NS_USERINFO "/openid/userinfo"
65 #define GNUNET_REST_API_NS_LOGIN "/openid/login"
68 * State while collecting all egos
70 #define ID_REST_STATE_INIT 0
73 * Done collecting egos
75 #define ID_REST_STATE_POST_INIT 1
80 #define OIDC_GRANT_TYPE_KEY "grant_type"
85 #define OIDC_GRANT_TYPE_VALUE "authorization_code"
90 #define OIDC_CODE_KEY "code"
93 * OIDC response_type key
95 #define OIDC_RESPONSE_TYPE_KEY "response_type"
100 #define OIDC_CLIENT_ID_KEY "client_id"
105 #define OIDC_SCOPE_KEY "scope"
108 * OIDC redirect_uri key
110 #define OIDC_REDIRECT_URI_KEY "redirect_uri"
115 #define OIDC_STATE_KEY "state"
120 #define OIDC_NONCE_KEY "nonce"
125 #define OIDC_CLAIMS_KEY "claims"
128 * OIDC PKCE code challenge
130 #define OIDC_CODE_CHALLENGE_KEY "code_challenge"
133 * OIDC PKCE code verifier
135 #define OIDC_CODE_VERIFIER_KEY "code_verifier"
138 * OIDC cookie expiration (in seconds)
140 #define OIDC_COOKIE_EXPIRATION 3
143 * OIDC cookie header key
145 #define OIDC_COOKIE_HEADER_KEY "cookie"
148 * OIDC cookie header information key
150 #define OIDC_AUTHORIZATION_HEADER_KEY "authorization"
153 * OIDC cookie header information key
155 #define OIDC_COOKIE_HEADER_INFORMATION_KEY "Identity="
158 * OIDC cookie header if user cancelled
160 #define OIDC_COOKIE_HEADER_ACCESS_DENIED "Identity=Denied"
163 * OIDC expected response_type while authorizing
165 #define OIDC_EXPECTED_AUTHORIZATION_RESPONSE_TYPE "code"
168 * OIDC expected scope part while authorizing
170 #define OIDC_EXPECTED_AUTHORIZATION_SCOPE "openid"
173 * OIDC error key for invalid client
175 #define OIDC_ERROR_KEY_INVALID_CLIENT "invalid_client"
178 * OIDC error key for invalid scopes
180 #define OIDC_ERROR_KEY_INVALID_SCOPE "invalid_scope"
183 * OIDC error key for invalid requests
185 #define OIDC_ERROR_KEY_INVALID_REQUEST "invalid_request"
188 * OIDC error key for invalid tokens
190 #define OIDC_ERROR_KEY_INVALID_TOKEN "invalid_token"
193 * OIDC error key for invalid cookies
195 #define OIDC_ERROR_KEY_INVALID_COOKIE "invalid_cookie"
198 * OIDC error key for generic server errors
200 #define OIDC_ERROR_KEY_SERVER_ERROR "server_error"
203 * OIDC error key for unsupported grants
205 #define OIDC_ERROR_KEY_UNSUPPORTED_GRANT_TYPE "unsupported_grant_type"
208 * OIDC error key for unsupported response types
210 #define OIDC_ERROR_KEY_UNSUPPORTED_RESPONSE_TYPE "unsupported_response_type"
213 * OIDC error key for unauthorized clients
215 #define OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT "unauthorized_client"
218 * OIDC error key for denied access
220 #define OIDC_ERROR_KEY_ACCESS_DENIED "access_denied"
224 * OIDC ignored parameter array
226 static char *OIDC_ignored_parameter_array[] = { "display",
235 * OIDC Hash map that keeps track of issued cookies
237 struct GNUNET_CONTAINER_MultiHashMap *OIDC_cookie_jar_map;
240 * Hash map that links the issued access token to the corresponding ticket and
243 struct GNUNET_CONTAINER_MultiHashMap *OIDC_access_token_map;
246 * The configuration handle
248 const struct GNUNET_CONFIGURATION_Handle *cfg;
251 * HTTP methods allows for this plugin
253 static char *allow_methods;
256 * @brief struct returned by the initialization function of the plugin
260 const struct GNUNET_CONFIGURATION_Handle *cfg;
264 * OIDC needed variables
266 struct OIDC_Variables
269 * The RP client public key
271 struct GNUNET_CRYPTO_EcdsaPublicKey client_pkey;
274 * The OIDC client id of the RP
279 * The OIDC redirect uri
284 * The list of oidc scopes
304 * The OIDC response type
309 * The identity chosen by the user to login
311 char *login_identity;
314 * User cancelled authorization/login
319 * The PKCE code_challenge
321 char *code_challenge;
324 * The PKCE code_verifier
342 struct EgoEntry *next;
347 struct EgoEntry *prev;
362 struct GNUNET_IDENTITY_Ego *ego;
371 struct EgoEntry *ego_head;
376 struct EgoEntry *ego_tail;
381 struct EgoEntry *ego_entry;
384 * Pointer to ego private key
386 struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key;
391 struct OIDC_Variables *oidc;
394 * The processing state
399 * Handle to Identity service.
401 struct GNUNET_IDENTITY_Handle *identity_handle;
406 struct GNUNET_REST_RequestHandle *rest_handle;
411 struct GNUNET_GNS_Handle *gns_handle;
416 struct GNUNET_GNS_LookupRequest *gns_op;
419 * Handle to NAMESTORE
421 struct GNUNET_NAMESTORE_Handle *namestore_handle;
424 * Iterator for NAMESTORE
426 struct GNUNET_NAMESTORE_ZoneIterator *namestore_handle_it;
429 * Attribute claim list for id_token
431 struct GNUNET_RECLAIM_AttributeList *attr_idtoken_list;
434 * Attribute claim list for userinfo
436 struct GNUNET_RECLAIM_AttributeList *attr_userinfo_list;
441 struct GNUNET_RECLAIM_AttestationList *attests_list;
447 struct GNUNET_IDENTITY_Operation *op;
452 struct GNUNET_RECLAIM_Handle *idp;
457 struct GNUNET_RECLAIM_Operation *idp_op;
462 struct GNUNET_RECLAIM_AttributeIterator *attr_it;
465 * Attestation iterator
467 struct GNUNET_RECLAIM_AttestationIterator *attest_it;
473 struct GNUNET_RECLAIM_TicketIterator *ticket_it;
478 struct GNUNET_RECLAIM_Ticket ticket;
481 * Desired timeout for the lookup (default is no timeout).
483 struct GNUNET_TIME_Relative timeout;
486 * ID of a task associated with the resolution process.
488 struct GNUNET_SCHEDULER_Task *timeout_task;
491 * The plugin result processor
493 GNUNET_REST_ResultProcessor proc;
496 * The closure of the result processor
506 * The tld for redirect
511 * The redirect prefix
513 char *redirect_prefix;
516 * The redirect suffix
518 char *redirect_suffix;
521 * Error response message
526 * Error response description
537 * Cleanup lookup handle
538 * @param handle Handle to clean up
541 cleanup_handle (struct RequestHandle *handle)
543 struct EgoEntry *ego_entry;
545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
546 if (NULL != handle->timeout_task)
547 GNUNET_SCHEDULER_cancel (handle->timeout_task);
548 if (NULL != handle->identity_handle)
549 GNUNET_IDENTITY_disconnect (handle->identity_handle);
550 if (NULL != handle->attr_it)
551 GNUNET_RECLAIM_get_attributes_stop (handle->attr_it);
552 if (NULL != handle->attest_it)
553 GNUNET_RECLAIM_get_attestations_stop (handle->attest_it);
554 if (NULL != handle->ticket_it)
555 GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it);
556 if (NULL != handle->idp_op)
557 GNUNET_RECLAIM_cancel (handle->idp_op);
558 if (NULL != handle->idp)
559 GNUNET_RECLAIM_disconnect (handle->idp);
560 GNUNET_free_non_null (handle->url);
561 GNUNET_free_non_null (handle->tld);
562 GNUNET_free_non_null (handle->redirect_prefix);
563 GNUNET_free_non_null (handle->redirect_suffix);
564 GNUNET_free_non_null (handle->emsg);
565 GNUNET_free_non_null (handle->edesc);
566 if (NULL != handle->gns_op)
567 GNUNET_GNS_lookup_cancel (handle->gns_op);
568 if (NULL != handle->gns_handle)
569 GNUNET_GNS_disconnect (handle->gns_handle);
571 if (NULL != handle->namestore_handle)
572 GNUNET_NAMESTORE_disconnect (handle->namestore_handle);
573 if (NULL != handle->oidc)
575 GNUNET_free_non_null (handle->oidc->client_id);
576 GNUNET_free_non_null (handle->oidc->login_identity);
577 GNUNET_free_non_null (handle->oidc->nonce);
578 GNUNET_free_non_null (handle->oidc->redirect_uri);
579 GNUNET_free_non_null (handle->oidc->response_type);
580 GNUNET_free_non_null (handle->oidc->scope);
581 GNUNET_free_non_null (handle->oidc->state);
582 json_decref (handle->oidc->response);
583 GNUNET_free (handle->oidc);
585 if (NULL!=handle->attr_idtoken_list)
586 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_idtoken_list);
587 if (NULL!=handle->attr_userinfo_list)
588 GNUNET_RECLAIM_attribute_list_destroy (handle->attr_userinfo_list);
589 if (NULL!=handle->attests_list)
590 GNUNET_RECLAIM_attestation_list_destroy (handle->attests_list);
592 while (NULL != (ego_entry = handle->ego_head))
594 GNUNET_CONTAINER_DLL_remove (handle->ego_head,
597 GNUNET_free_non_null (ego_entry->identifier);
598 GNUNET_free_non_null (ego_entry->keystring);
599 GNUNET_free (ego_entry);
601 GNUNET_free (handle);
606 cleanup_handle_delayed (void *cls)
608 cleanup_handle (cls);
613 * Task run on error, sends error message. Cleans up everything.
615 * @param cls the `struct RequestHandle`
620 struct RequestHandle *handle = cls;
621 struct MHD_Response *resp;
624 GNUNET_asprintf (&json_error,
625 "{ \"error\" : \"%s\", \"error_description\" : \"%s\"%s%s%s}",
627 (NULL != handle->edesc) ? handle->edesc : "",
628 (NULL != handle->oidc->state) ? ", \"state\":\"" : "",
629 (NULL != handle->oidc->state) ? handle->oidc->state : "",
630 (NULL != handle->oidc->state) ? "\"" : "");
631 if (0 == handle->response_code)
632 handle->response_code = MHD_HTTP_BAD_REQUEST;
633 resp = GNUNET_REST_create_response (json_error);
634 if (MHD_HTTP_UNAUTHORIZED == handle->response_code)
635 MHD_add_response_header (resp, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Basic");
636 MHD_add_response_header (resp,
637 MHD_HTTP_HEADER_CONTENT_TYPE,
639 handle->proc (handle->proc_cls, resp, handle->response_code);
640 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
641 GNUNET_free (json_error);
646 * Task run on error in userinfo endpoint, sends error header. Cleans up
649 * @param cls the `struct RequestHandle`
652 do_userinfo_error (void *cls)
654 struct RequestHandle *handle = cls;
655 struct MHD_Response *resp;
658 GNUNET_asprintf (&error,
659 "error=\"%s\", error_description=\"%s\"",
661 (NULL != handle->edesc) ? handle->edesc : "");
662 resp = GNUNET_REST_create_response ("");
663 MHD_add_response_header (resp, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Bearer");
664 handle->proc (handle->proc_cls, resp, handle->response_code);
665 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
671 * Task run on error, sends error message and redirects. Cleans up everything.
673 * @param cls the `struct RequestHandle`
676 do_redirect_error (void *cls)
678 struct RequestHandle *handle = cls;
679 struct MHD_Response *resp;
682 GNUNET_asprintf (&redirect,
683 "%s?error=%s&error_description=%s%s%s",
684 handle->oidc->redirect_uri,
687 (NULL != handle->oidc->state) ? "&state=" : "",
688 (NULL != handle->oidc->state) ? handle->oidc->state : "");
689 resp = GNUNET_REST_create_response ("");
690 MHD_add_response_header (resp, "Location", redirect);
691 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
692 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
693 GNUNET_free (redirect);
698 * Task run on timeout, sends error message. Cleans up everything.
700 * @param cls the `struct RequestHandle`
703 do_timeout (void *cls)
705 struct RequestHandle *handle = cls;
707 handle->timeout_task = NULL;
713 * Return attributes for claim
715 * @param cls the request handle
718 return_userinfo_response (void *cls)
721 struct RequestHandle *handle = cls;
722 struct MHD_Response *resp;
724 result_str = json_dumps (handle->oidc->response, 0);
725 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"ID-Token: %s\n",result_str);
726 resp = GNUNET_REST_create_response (result_str);
727 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
728 GNUNET_free (result_str);
729 cleanup_handle (handle);
734 * Respond to OPTIONS request
736 * @param con_handle the connection handle
738 * @param cls the RequestHandle
741 options_cont (struct GNUNET_REST_RequestHandle *con_handle,
745 struct MHD_Response *resp;
746 struct RequestHandle *handle = cls;
748 // For now, independent of path return all options
749 resp = GNUNET_REST_create_response (NULL);
750 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
751 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
752 cleanup_handle (handle);
758 * Interprets cookie header and pass its identity keystring to handle
761 cookie_identity_interpretation (struct RequestHandle *handle)
763 struct GNUNET_HashCode cache_key;
765 struct GNUNET_TIME_Absolute current_time, *relog_time;
766 char delimiter[] = "; ";
771 // gets identity of login try with cookie
772 GNUNET_CRYPTO_hash (OIDC_COOKIE_HEADER_KEY,
773 strlen (OIDC_COOKIE_HEADER_KEY),
775 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No cookie found\n");
782 // splits cookies and find 'Identity' cookie
784 GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->header_param_map,
786 cookies = GNUNET_strdup (tmp_cookies);
787 token = strtok (cookies, delimiter);
788 handle->oidc->user_cancelled = GNUNET_NO;
789 handle->oidc->login_identity = NULL;
792 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
793 "Unable to parse cookie: %s\n",
795 GNUNET_free (cookies);
799 while (NULL != token)
801 if (0 == strcmp (token, OIDC_COOKIE_HEADER_ACCESS_DENIED))
803 handle->oidc->user_cancelled = GNUNET_YES;
804 GNUNET_free (cookies);
807 if (NULL != strstr (token, OIDC_COOKIE_HEADER_INFORMATION_KEY))
809 token = strtok (NULL, delimiter);
813 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
814 "No cookie value to process: %s\n",
816 GNUNET_free (cookies);
819 GNUNET_CRYPTO_hash (token, strlen (token), &cache_key);
821 GNUNET_CONTAINER_multihashmap_contains (OIDC_cookie_jar_map, &cache_key))
824 GNUNET_ERROR_TYPE_WARNING,
825 "Found cookie `%s', but no corresponding expiration entry present...\n",
827 GNUNET_free (cookies);
831 GNUNET_CONTAINER_multihashmap_get (OIDC_cookie_jar_map, &cache_key);
832 current_time = GNUNET_TIME_absolute_get ();
833 // 30 min after old login -> redirect to login
834 if (current_time.abs_value_us > relog_time->abs_value_us)
836 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
837 "Found cookie `%s', but it is expired.\n",
839 GNUNET_free (cookies);
842 value = strtok (token, OIDC_COOKIE_HEADER_INFORMATION_KEY);
843 GNUNET_assert (NULL != value);
844 handle->oidc->login_identity = GNUNET_strdup (value);
845 GNUNET_free (cookies);
850 * Redirects to login page stored in configuration file
853 login_redirect (void *cls)
855 char *login_base_url;
857 struct MHD_Response *resp;
858 struct RequestHandle *handle = cls;
860 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
861 "reclaim-rest-plugin",
865 GNUNET_asprintf (&new_redirect,
866 "%s?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s",
868 OIDC_RESPONSE_TYPE_KEY,
869 handle->oidc->response_type,
871 handle->oidc->client_id,
872 OIDC_REDIRECT_URI_KEY,
873 handle->oidc->redirect_uri,
877 (NULL != handle->oidc->state) ? handle->oidc->state : "",
878 OIDC_CODE_CHALLENGE_KEY,
879 (NULL != handle->oidc->code_challenge) ?
880 handle->oidc->code_challenge : "",
882 (NULL != handle->oidc->nonce) ? handle->oidc->nonce : "",
884 (NULL != handle->oidc->claims) ? handle->oidc->claims :
886 resp = GNUNET_REST_create_response ("");
887 MHD_add_response_header (resp, "Location", new_redirect);
888 GNUNET_free (login_base_url);
892 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
893 handle->edesc = GNUNET_strdup ("gnunet configuration failed");
894 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
895 GNUNET_SCHEDULER_add_now (&do_error, handle);
898 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
899 GNUNET_free (new_redirect);
900 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
905 * Does internal server error when iteration failed.
908 oidc_iteration_error (void *cls)
910 struct RequestHandle *handle = cls;
912 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
913 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
914 GNUNET_SCHEDULER_add_now (&do_error, handle);
919 * Issues ticket and redirects to relying party with the authorization code as
920 * parameter. Otherwise redirects with error
923 oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
925 struct RequestHandle *handle = cls;
926 struct MHD_Response *resp;
931 handle->idp_op = NULL;
934 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
935 handle->edesc = GNUNET_strdup ("Server cannot generate ticket.");
936 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
939 handle->ticket = *ticket;
941 GNUNET_STRINGS_data_to_string_alloc (&handle->ticket,
942 sizeof(struct GNUNET_RECLAIM_Ticket));
943 code_string = OIDC_build_authz_code (&handle->priv_key,
945 handle->attr_idtoken_list,
946 handle->attests_list,
948 handle->oidc->code_challenge);
949 if ((NULL != handle->redirect_prefix) && (NULL != handle->redirect_suffix) &&
950 (NULL != handle->tld))
952 GNUNET_asprintf (&redirect_uri,
953 "%s.%s/%s?%s=%s&state=%s",
954 handle->redirect_prefix,
956 handle->redirect_suffix,
957 handle->oidc->response_type,
959 handle->oidc->state);
963 GNUNET_asprintf (&redirect_uri,
965 handle->oidc->redirect_uri,
966 handle->oidc->response_type,
968 handle->oidc->state);
970 resp = GNUNET_REST_create_response ("");
971 MHD_add_response_header (resp, "Location", redirect_uri);
972 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
973 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
974 GNUNET_free (redirect_uri);
975 GNUNET_free (ticket_str);
976 GNUNET_free (code_string);
980 static struct GNUNET_RECLAIM_AttributeList*
981 attribute_list_merge (struct GNUNET_RECLAIM_AttributeList *list_a,
982 struct GNUNET_RECLAIM_AttributeList *list_b)
984 struct GNUNET_RECLAIM_AttributeList *merged_list;
985 struct GNUNET_RECLAIM_AttributeListEntry *le_a;
986 struct GNUNET_RECLAIM_AttributeListEntry *le_b;
987 struct GNUNET_RECLAIM_AttributeListEntry *le_m;
989 merged_list = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
990 for (le_a = list_a->list_head; NULL != le_a; le_a = le_a->next)
992 le_m = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
993 le_m->attribute = GNUNET_RECLAIM_attribute_new (le_a->attribute->name,
996 le_a->attribute->type,
997 le_a->attribute->data,
998 le_a->attribute->data_size);
999 le_m->attribute->id = le_a->attribute->id;
1000 le_m->attribute->flag = le_a->attribute->flag;
1001 le_m->attribute->attestation = le_a->attribute->attestation;
1002 GNUNET_CONTAINER_DLL_insert (merged_list->list_head,
1003 merged_list->list_tail,
1007 for (le_b = list_b->list_head; NULL != le_b; le_b = le_b->next)
1009 for (le_m = merged_list->list_head; NULL != le_m; le_m = le_m->next)
1011 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (&le_m->attribute->id,
1012 &le_b->attribute->id))
1013 break; /** Attribute already in list **/
1016 continue; /** Attribute already in list **/
1017 le_m = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
1018 le_m->attribute = GNUNET_RECLAIM_attribute_new (le_b->attribute->name,
1021 le_b->attribute->type,
1022 le_b->attribute->data,
1023 le_b->attribute->data_size);
1024 le_m->attribute->id = le_b->attribute->id;
1025 le_m->attribute->flag = le_b->attribute->flag;
1026 le_m->attribute->attestation = le_b->attribute->attestation;
1027 GNUNET_CONTAINER_DLL_insert (merged_list->list_head,
1028 merged_list->list_tail,
1036 oidc_attest_collect_finished_cb (void *cls)
1038 struct RequestHandle *handle = cls;
1039 struct GNUNET_RECLAIM_AttributeList *merged_list;
1041 handle->attest_it = NULL;
1042 merged_list = attribute_list_merge (handle->attr_idtoken_list,
1043 handle->attr_userinfo_list);
1044 handle->idp_op = GNUNET_RECLAIM_ticket_issue (handle->idp,
1046 &handle->oidc->client_pkey,
1048 &oidc_ticket_issue_cb,
1050 GNUNET_RECLAIM_attribute_list_destroy (merged_list);
1055 * Collects all attributes for an ego if in scope parameter
1058 oidc_attest_collect (void *cls,
1059 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
1060 const struct GNUNET_RECLAIM_Attestation *attest)
1062 struct RequestHandle *handle = cls;
1063 struct GNUNET_RECLAIM_AttributeListEntry *le;
1064 struct GNUNET_RECLAIM_AttestationListEntry *ale;
1066 for (ale = handle->attests_list->list_head; NULL != ale; ale = ale->next)
1068 if (GNUNET_NO == GNUNET_RECLAIM_id_is_equal (&ale->attestation->id,
1071 /** Attestation already in list **/
1072 GNUNET_RECLAIM_get_attestations_next (handle->attest_it);
1076 for (le = handle->attr_idtoken_list->list_head; NULL != le; le = le->next)
1078 if (GNUNET_NO == GNUNET_RECLAIM_id_is_equal (&le->attribute->attestation,
1081 /** Attestation matches for attribute, add **/
1082 ale = GNUNET_new (struct GNUNET_RECLAIM_AttestationListEntry);
1083 ale->attestation = GNUNET_RECLAIM_attestation_new (attest->name,
1087 GNUNET_CONTAINER_DLL_insert (handle->attests_list->list_head,
1088 handle->attests_list->list_tail,
1091 GNUNET_RECLAIM_get_attestations_next (handle->attest_it);
1096 oidc_attr_collect_finished_cb (void *cls)
1098 struct RequestHandle *handle = cls;
1100 handle->attr_it = NULL;
1101 handle->ticket_it = NULL;
1102 if (NULL == handle->attr_idtoken_list->list_head)
1104 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_SCOPE);
1105 handle->edesc = GNUNET_strdup ("The requested scope is not available.");
1106 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1109 handle->attests_list = GNUNET_new (struct GNUNET_RECLAIM_AttestationList);
1111 GNUNET_RECLAIM_get_attestations_start (handle->idp,
1113 &oidc_iteration_error,
1115 &oidc_attest_collect,
1117 &oidc_attest_collect_finished_cb,
1124 attr_in_claims_request (struct RequestHandle *handle,
1125 const char *attr_name,
1126 const char *claims_parameter)
1128 char *scope_variables;
1129 char *scope_variable;
1130 char delimiter[] = " ";
1131 int ret = GNUNET_NO;
1138 scope_variables = GNUNET_strdup (handle->oidc->scope);
1139 scope_variable = strtok (scope_variables, delimiter);
1140 while (NULL != scope_variable)
1142 if (0 == strcmp (attr_name, scope_variable))
1144 scope_variable = strtok (NULL, delimiter);
1146 if (NULL != scope_variable)
1148 GNUNET_free (scope_variables);
1150 /** Try claims parameter if no in scope */
1151 if ((NULL != handle->oidc->claims) &&
1152 (GNUNET_YES != ret))
1154 root = json_loads (handle->oidc->claims, JSON_DECODE_ANY, &error);
1155 claims_j = json_object_get (root, claims_parameter);
1156 /* obj is a JSON object */
1157 if (NULL != claims_j)
1159 json_object_foreach (claims_j, key, value) {
1160 if (0 != strcmp (attr_name, key))
1173 attr_in_idtoken_request (struct RequestHandle *handle,
1174 const char *attr_name)
1176 return attr_in_claims_request (handle, attr_name, "id_token");
1181 attr_in_userinfo_request (struct RequestHandle *handle,
1182 const char *attr_name)
1184 return attr_in_claims_request (handle, attr_name, "userinfo");
1189 * Collects all attributes for an ego if in scope parameter
1192 oidc_attr_collect (void *cls,
1193 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
1194 const struct GNUNET_RECLAIM_Attribute *attr)
1196 struct RequestHandle *handle = cls;
1197 struct GNUNET_RECLAIM_AttributeListEntry *le;
1198 if (GNUNET_YES == attr_in_idtoken_request (handle, attr->name))
1200 le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
1201 le->attribute = GNUNET_RECLAIM_attribute_new (attr->name,
1206 le->attribute->id = attr->id;
1207 le->attribute->flag = attr->flag;
1208 le->attribute->attestation = attr->attestation;
1209 GNUNET_CONTAINER_DLL_insert (handle->attr_idtoken_list->list_head,
1210 handle->attr_idtoken_list->list_tail,
1213 if (GNUNET_YES == attr_in_userinfo_request (handle, attr->name))
1215 le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
1216 le->attribute = GNUNET_RECLAIM_attribute_new (attr->name,
1221 le->attribute->id = attr->id;
1222 le->attribute->flag = attr->flag;
1223 le->attribute->attestation = attr->attestation;
1224 GNUNET_CONTAINER_DLL_insert (handle->attr_userinfo_list->list_head,
1225 handle->attr_userinfo_list->list_tail,
1229 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
1234 * Checks time and cookie and redirects accordingly
1237 code_redirect (void *cls)
1239 struct RequestHandle *handle = cls;
1240 struct GNUNET_TIME_Absolute current_time;
1241 struct GNUNET_TIME_Absolute *relog_time;
1242 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
1243 struct GNUNET_CRYPTO_EcdsaPublicKey ego_pkey;
1244 struct GNUNET_HashCode cache_key;
1245 char *identity_cookie;
1247 GNUNET_asprintf (&identity_cookie,
1249 handle->oidc->login_identity);
1250 GNUNET_CRYPTO_hash (identity_cookie, strlen (identity_cookie), &cache_key);
1251 GNUNET_free (identity_cookie);
1252 // No login time for identity -> redirect to login
1254 GNUNET_CONTAINER_multihashmap_contains (OIDC_cookie_jar_map, &cache_key))
1257 GNUNET_CONTAINER_multihashmap_get (OIDC_cookie_jar_map, &cache_key);
1258 current_time = GNUNET_TIME_absolute_get ();
1259 // 30 min after old login -> redirect to login
1260 if (current_time.abs_value_us <= relog_time->abs_value_us)
1263 GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc
1270 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_COOKIE);
1272 GNUNET_strdup ("The cookie of a login identity is not valid");
1273 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1276 // iterate over egos and compare their public key
1277 for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry;
1278 handle->ego_entry = handle->ego_entry->next)
1280 GNUNET_IDENTITY_ego_get_public_key (handle->ego_entry->ego, &ego_pkey);
1281 if (0 == GNUNET_memcmp (&ego_pkey, &pubkey))
1284 *GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego);
1285 handle->idp = GNUNET_RECLAIM_connect (cfg);
1286 handle->attr_idtoken_list =
1287 GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
1288 handle->attr_userinfo_list =
1289 GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
1291 GNUNET_RECLAIM_get_attributes_start (handle->idp,
1293 &oidc_iteration_error,
1297 &oidc_attr_collect_finished_cb,
1302 GNUNET_SCHEDULER_add_now (&login_redirect, handle);
1310 build_redirect (void *cls)
1312 struct RequestHandle *handle = cls;
1313 struct MHD_Response *resp;
1316 if (GNUNET_YES == handle->oidc->user_cancelled)
1318 if ((NULL != handle->redirect_prefix) &&
1319 (NULL != handle->redirect_suffix) && (NULL != handle->tld))
1321 GNUNET_asprintf (&redirect_uri,
1322 "%s.%s/%s?error=%s&error_description=%s&state=%s",
1323 handle->redirect_prefix,
1325 handle->redirect_suffix,
1327 "User denied access",
1328 handle->oidc->state);
1332 GNUNET_asprintf (&redirect_uri,
1333 "%s?error=%s&error_description=%s&state=%s",
1334 handle->oidc->redirect_uri,
1336 "User denied access",
1337 handle->oidc->state);
1339 resp = GNUNET_REST_create_response ("");
1340 MHD_add_response_header (resp, "Location", redirect_uri);
1341 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
1342 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
1343 GNUNET_free (redirect_uri);
1346 GNUNET_SCHEDULER_add_now (&code_redirect, handle);
1351 lookup_redirect_uri_result (void *cls,
1353 const struct GNUNET_GNSRECORD_Data *rd)
1355 struct RequestHandle *handle = cls;
1359 struct GNUNET_CRYPTO_EcdsaPublicKey redirect_zone;
1361 handle->gns_op = NULL;
1364 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
1366 GNUNET_strdup ("Server cannot generate ticket, redirect uri not found.");
1367 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1370 for (int i = 0; i < rd_count; i++)
1372 if (GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT != rd[i].record_type)
1374 if (0 != strncmp (rd[i].data, handle->oidc->redirect_uri, rd[i].data_size))
1376 tmp = GNUNET_strndup (rd[i].data, rd[i].data_size);
1377 if (NULL == strstr (tmp, handle->oidc->client_id))
1379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1380 "Redirect uri %s does not contain client_id %s\n",
1382 handle->oidc->client_id);
1386 pos = strrchr (tmp, (unsigned char) '.');
1389 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1390 "Redirect uri %s contains client_id but is malformed\n",
1396 handle->redirect_prefix = GNUNET_strdup (tmp);
1397 tmp_key_str = pos + 1;
1398 pos = strchr (tmp_key_str, (unsigned char) '/');
1401 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1402 "Redirect uri %s contains client_id but is malformed\n",
1408 handle->redirect_suffix = GNUNET_strdup (pos + 1);
1410 GNUNET_STRINGS_string_to_data (tmp_key_str,
1411 strlen (tmp_key_str),
1413 sizeof(redirect_zone));
1415 GNUNET_SCHEDULER_add_now (&build_redirect, handle);
1419 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
1421 GNUNET_strdup ("Server cannot generate ticket, redirect uri not found.");
1422 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1427 * Initiate redirect back to client.
1430 client_redirect (void *cls)
1432 struct RequestHandle *handle = cls;
1434 /* Lookup client redirect uri to verify request */
1436 GNUNET_GNS_lookup (handle->gns_handle,
1437 GNUNET_GNS_EMPTY_LABEL_AT,
1438 &handle->oidc->client_pkey,
1439 GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT,
1440 GNUNET_GNS_LO_DEFAULT,
1441 &lookup_redirect_uri_result,
1447 get_url_parameter_copy (const struct RequestHandle *handle, const char *key)
1449 struct GNUNET_HashCode hc;
1452 GNUNET_CRYPTO_hash (key, strlen (key), &hc);
1453 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
1458 GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, &hc);
1461 return GNUNET_strdup (value);
1466 * Iteration over all results finished, build final
1469 * @param cls the `struct RequestHandle`
1472 build_authz_response (void *cls)
1474 struct RequestHandle *handle = cls;
1475 struct GNUNET_HashCode cache_key;
1477 char *expected_scope;
1478 char delimiter[] = " ";
1479 int number_of_ignored_parameter, iterator;
1482 // REQUIRED value: redirect_uri
1483 handle->oidc->redirect_uri =
1484 get_url_parameter_copy (handle, OIDC_REDIRECT_URI_KEY);
1485 if (NULL == handle->oidc->redirect_uri)
1487 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1488 handle->edesc = GNUNET_strdup ("missing parameter redirect_uri");
1489 GNUNET_SCHEDULER_add_now (&do_error, handle);
1493 // REQUIRED value: response_type
1494 handle->oidc->response_type =
1495 get_url_parameter_copy (handle, OIDC_RESPONSE_TYPE_KEY);
1496 if (NULL == handle->oidc->response_type)
1498 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1499 handle->edesc = GNUNET_strdup ("missing parameter response_type");
1500 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1504 // REQUIRED value: scope
1505 handle->oidc->scope = get_url_parameter_copy (handle, OIDC_SCOPE_KEY);
1506 if (NULL == handle->oidc->scope)
1508 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_SCOPE);
1509 handle->edesc = GNUNET_strdup ("missing parameter scope");
1510 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1514 // OPTIONAL value: nonce
1515 handle->oidc->nonce = get_url_parameter_copy (handle, OIDC_NONCE_KEY);
1517 // OPTIONAL value: claims
1518 handle->oidc->claims = get_url_parameter_copy (handle, OIDC_CLAIMS_KEY);
1520 // TODO check other values if needed
1521 number_of_ignored_parameter =
1522 sizeof(OIDC_ignored_parameter_array) / sizeof(char *);
1523 for (iterator = 0; iterator < number_of_ignored_parameter; iterator++)
1525 GNUNET_CRYPTO_hash (OIDC_ignored_parameter_array[iterator],
1526 strlen (OIDC_ignored_parameter_array[iterator]),
1529 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
1533 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_ACCESS_DENIED);
1534 GNUNET_asprintf (&handle->edesc,
1535 "Server will not handle parameter: %s",
1536 OIDC_ignored_parameter_array[iterator]);
1537 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1542 // We only support authorization code flows.
1543 if (0 != strcmp (handle->oidc->response_type,
1544 OIDC_EXPECTED_AUTHORIZATION_RESPONSE_TYPE))
1546 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNSUPPORTED_RESPONSE_TYPE);
1547 handle->edesc = GNUNET_strdup ("The authorization server does not support "
1548 "obtaining this authorization code.");
1549 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1553 // Checks if scope contains 'openid'
1554 expected_scope = GNUNET_strdup (handle->oidc->scope);
1556 test = strtok (expected_scope, delimiter);
1557 while (NULL != test)
1559 if (0 == strcmp (OIDC_EXPECTED_AUTHORIZATION_SCOPE, expected_scope))
1561 test = strtok (NULL, delimiter);
1565 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_SCOPE);
1567 GNUNET_strdup ("The requested scope is invalid, unknown, or malformed.");
1568 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1569 GNUNET_free (expected_scope);
1573 GNUNET_free (expected_scope);
1574 if ((NULL == handle->oidc->login_identity) &&
1575 (GNUNET_NO == handle->oidc->user_cancelled))
1576 GNUNET_SCHEDULER_add_now (&login_redirect, handle);
1578 GNUNET_SCHEDULER_add_now (&client_redirect, handle);
1583 * Iterate over tlds in config
1586 tld_iter (void *cls, const char *section, const char *option, const char *value)
1588 struct RequestHandle *handle = cls;
1589 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1592 GNUNET_CRYPTO_ecdsa_public_key_from_string (value, strlen (value), &pkey))
1594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping non key %s\n", value);
1597 if (0 == GNUNET_memcmp (&pkey, &handle->oidc->client_pkey))
1598 handle->tld = GNUNET_strdup (option + 1);
1603 * Responds to authorization GET and url-encoded POST request
1605 * @param con_handle the connection handle
1606 * @param url the url
1607 * @param cls the RequestHandle
1610 authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1614 struct RequestHandle *handle = cls;
1615 struct EgoEntry *tmp_ego;
1616 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
1617 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1619 cookie_identity_interpretation (handle);
1621 // RECOMMENDED value: state - REQUIRED for answers
1622 handle->oidc->state = get_url_parameter_copy (handle, OIDC_STATE_KEY);
1624 // REQUIRED value: client_id
1625 handle->oidc->client_id = get_url_parameter_copy (handle, OIDC_CLIENT_ID_KEY);
1626 if (NULL == handle->oidc->client_id)
1628 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1629 handle->edesc = GNUNET_strdup ("missing parameter client_id");
1630 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
1631 GNUNET_SCHEDULER_add_now (&do_error, handle);
1635 // OPTIONAL value: code_challenge
1636 handle->oidc->code_challenge = get_url_parameter_copy (handle,
1637 OIDC_CODE_CHALLENGE_KEY);
1638 if (NULL == handle->oidc->code_challenge)
1640 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1641 "OAuth authorization request does not contain PKCE parameters!\n");
1645 GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc->client_id,
1647 handle->oidc->client_id),
1648 &handle->oidc->client_pkey))
1650 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT);
1651 handle->edesc = GNUNET_strdup ("The client is not authorized to request an "
1652 "authorization code using this method.");
1653 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
1654 GNUNET_SCHEDULER_add_now (&do_error, handle);
1658 // If we know this identity, translated the corresponding TLD
1659 // TODO: We might want to have a reverse lookup functionality for TLDs?
1660 for (tmp_ego = handle->ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next)
1662 priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego);
1663 GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &pkey);
1664 if (0 == GNUNET_memcmp (&pkey, &handle->oidc->client_pkey))
1666 handle->tld = GNUNET_strdup (tmp_ego->identifier);
1667 handle->ego_entry = handle->ego_tail;
1670 handle->oidc->scope = get_url_parameter_copy (handle, OIDC_SCOPE_KEY);
1671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scope: %s\n", handle->oidc->scope);
1672 if (NULL == handle->tld)
1673 GNUNET_CONFIGURATION_iterate_section_values (cfg, "gns", tld_iter, handle);
1674 if (NULL == handle->tld)
1675 handle->tld = GNUNET_strdup (handle->oidc->client_id);
1676 GNUNET_SCHEDULER_add_now (&build_authz_response, handle);
1681 * Combines an identity with a login time and responds OK to login request
1683 * @param con_handle the connection handle
1684 * @param url the url
1685 * @param cls the RequestHandle
1688 login_cont (struct GNUNET_REST_RequestHandle *con_handle,
1692 struct MHD_Response *resp = GNUNET_REST_create_response ("");
1693 struct RequestHandle *handle = cls;
1694 struct GNUNET_HashCode cache_key;
1695 struct GNUNET_TIME_Absolute *current_time;
1696 struct GNUNET_TIME_Absolute *last_time;
1702 char term_data[handle->rest_handle->data_size + 1];
1704 term_data[handle->rest_handle->data_size] = '\0';
1705 GNUNET_memcpy (term_data,
1706 handle->rest_handle->data,
1707 handle->rest_handle->data_size);
1708 root = json_loads (term_data, JSON_DECODE_ANY, &error);
1709 identity = json_object_get (root, "identity");
1710 if (! json_is_string (identity))
1712 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1713 "Error parsing json string from %s\n",
1715 handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
1717 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
1720 GNUNET_asprintf (&cookie, "Identity=%s", json_string_value (identity));
1721 GNUNET_asprintf (&header_val,
1724 OIDC_COOKIE_EXPIRATION);
1725 MHD_add_response_header (resp, "Set-Cookie", header_val);
1726 MHD_add_response_header (resp, "Access-Control-Allow-Methods", "POST");
1727 GNUNET_CRYPTO_hash (cookie, strlen (cookie), &cache_key);
1729 if (0 != strcmp (json_string_value (identity), "Denied"))
1731 current_time = GNUNET_new (struct GNUNET_TIME_Absolute);
1732 *current_time = GNUNET_TIME_relative_to_absolute (
1733 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_second_ (),
1734 OIDC_COOKIE_EXPIRATION));
1736 GNUNET_CONTAINER_multihashmap_get (OIDC_cookie_jar_map, &cache_key);
1737 GNUNET_free_non_null (last_time);
1738 GNUNET_CONTAINER_multihashmap_put (OIDC_cookie_jar_map,
1741 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1743 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1744 GNUNET_free (cookie);
1745 GNUNET_free (header_val);
1747 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
1752 check_authorization (struct RequestHandle *handle,
1753 struct GNUNET_CRYPTO_EcdsaPublicKey *cid)
1755 struct GNUNET_HashCode cache_key;
1756 char *authorization;
1758 char *basic_authorization;
1761 char *expected_pass;
1763 GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY,
1764 strlen (OIDC_AUTHORIZATION_HEADER_KEY),
1766 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
1770 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1771 handle->edesc = GNUNET_strdup ("missing authorization");
1772 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1773 return GNUNET_SYSERR;
1776 GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->header_param_map,
1779 // split header in "Basic" and [content]
1780 credentials = strtok (authorization, " ");
1781 if ((NULL == credentials) || (0 != strcmp ("Basic", credentials)))
1783 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1784 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1785 return GNUNET_SYSERR;
1787 credentials = strtok (NULL, " ");
1788 if (NULL == credentials)
1790 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1791 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1792 return GNUNET_SYSERR;
1794 GNUNET_STRINGS_base64_decode (credentials,
1795 strlen (credentials),
1796 (void **) &basic_authorization);
1798 if (NULL == basic_authorization)
1800 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1801 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1802 return GNUNET_SYSERR;
1804 client_id = strtok (basic_authorization, ":");
1805 if (NULL == client_id)
1807 GNUNET_free_non_null (basic_authorization);
1808 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1809 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1810 return GNUNET_SYSERR;
1812 pass = strtok (NULL, ":");
1815 GNUNET_free_non_null (basic_authorization);
1816 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1817 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1818 return GNUNET_SYSERR;
1821 // check client password
1822 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
1823 "reclaim-rest-plugin",
1824 "OIDC_CLIENT_SECRET",
1827 if (0 != strcmp (expected_pass, pass))
1829 GNUNET_free_non_null (basic_authorization);
1830 GNUNET_free (expected_pass);
1831 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1832 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1833 return GNUNET_SYSERR;
1835 GNUNET_free (expected_pass);
1839 GNUNET_free_non_null (basic_authorization);
1840 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
1841 handle->edesc = GNUNET_strdup ("gnunet configuration failed");
1842 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
1843 return GNUNET_SYSERR;
1847 for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry;
1848 handle->ego_entry = handle->ego_entry->next)
1850 if (0 == strcmp (handle->ego_entry->keystring, client_id))
1853 if (NULL == handle->ego_entry)
1855 GNUNET_free_non_null (basic_authorization);
1856 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1857 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1858 return GNUNET_SYSERR;
1860 GNUNET_STRINGS_string_to_data (client_id,
1863 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
1865 GNUNET_free (basic_authorization);
1870 const struct EgoEntry *
1871 find_ego (struct RequestHandle *handle,
1872 struct GNUNET_CRYPTO_EcdsaPublicKey *test_key)
1874 struct EgoEntry *ego_entry;
1875 struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
1877 for (ego_entry = handle->ego_head; NULL != ego_entry;
1878 ego_entry = ego_entry->next)
1880 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &pub_key);
1881 if (0 == GNUNET_memcmp (&pub_key, test_key))
1889 persist_access_token (const struct RequestHandle *handle,
1890 const char *access_token,
1891 const struct GNUNET_RECLAIM_Ticket *ticket)
1893 struct GNUNET_HashCode hc;
1894 struct GNUNET_RECLAIM_Ticket *ticketbuf;
1896 GNUNET_CRYPTO_hash (access_token, strlen (access_token), &hc);
1897 ticketbuf = GNUNET_new (struct GNUNET_RECLAIM_Ticket);
1898 *ticketbuf = *ticket;
1899 GNUNET_assert (GNUNET_SYSERR !=
1900 GNUNET_CONTAINER_multihashmap_put (
1901 OIDC_access_token_map,
1904 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1909 * Responds to token url-encoded POST request
1911 * @param con_handle the connection handle
1912 * @param url the url
1913 * @param cls the RequestHandle
1916 token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1920 struct RequestHandle *handle = cls;
1921 const struct EgoEntry *ego_entry;
1922 struct GNUNET_TIME_Relative expiration_time;
1923 struct GNUNET_RECLAIM_AttributeList *cl = NULL;
1924 struct GNUNET_RECLAIM_AttestationList *al = NULL;
1925 struct GNUNET_RECLAIM_Ticket ticket;
1926 struct GNUNET_CRYPTO_EcdsaPublicKey cid;
1927 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
1928 struct GNUNET_HashCode cache_key;
1929 struct MHD_Response *resp;
1932 char *json_response;
1937 char *code_verifier;
1940 * Check Authorization
1942 if (GNUNET_SYSERR == check_authorization (handle, &cid))
1944 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1945 "OIDC authorization for token endpoint failed\n");
1946 GNUNET_SCHEDULER_add_now (&do_error, handle);
1954 // TODO Do not allow multiple equal parameter names
1955 // REQUIRED grant_type
1956 GNUNET_CRYPTO_hash (OIDC_GRANT_TYPE_KEY,
1957 strlen (OIDC_GRANT_TYPE_KEY),
1959 grant_type = get_url_parameter_copy (handle, OIDC_GRANT_TYPE_KEY);
1960 if (NULL == grant_type)
1962 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1963 handle->edesc = GNUNET_strdup ("missing parameter grant_type");
1964 handle->response_code = MHD_HTTP_BAD_REQUEST;
1965 GNUNET_SCHEDULER_add_now (&do_error, handle);
1969 // Check parameter grant_type == "authorization_code"
1970 if (0 != strcmp (OIDC_GRANT_TYPE_VALUE, grant_type))
1972 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNSUPPORTED_GRANT_TYPE);
1973 handle->response_code = MHD_HTTP_BAD_REQUEST;
1974 GNUNET_free (grant_type);
1975 GNUNET_SCHEDULER_add_now (&do_error, handle);
1978 GNUNET_free (grant_type);
1980 code = get_url_parameter_copy (handle, OIDC_CODE_KEY);
1983 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1984 handle->edesc = GNUNET_strdup ("missing parameter code");
1985 handle->response_code = MHD_HTTP_BAD_REQUEST;
1986 GNUNET_SCHEDULER_add_now (&do_error, handle);
1989 ego_entry = find_ego (handle, &cid);
1990 if (NULL == ego_entry)
1992 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1993 handle->edesc = GNUNET_strdup ("Unknown client");
1994 handle->response_code = MHD_HTTP_BAD_REQUEST;
1996 GNUNET_SCHEDULER_add_now (&do_error, handle);
1999 privkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
2001 // REQUIRED code verifier
2002 code_verifier = get_url_parameter_copy (handle, OIDC_CODE_VERIFIER_KEY);
2003 if (NULL == code_verifier)
2005 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2006 "OAuth authorization request does not contain PKCE parameters!\n");
2011 if (GNUNET_OK != OIDC_parse_authz_code (privkey, code, code_verifier, &ticket,
2014 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
2015 handle->edesc = GNUNET_strdup ("invalid code");
2016 handle->response_code = MHD_HTTP_BAD_REQUEST;
2018 GNUNET_SCHEDULER_add_now (&do_error, handle);
2024 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg,
2025 "reclaim-rest-plugin",
2029 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
2030 handle->edesc = GNUNET_strdup ("gnunet configuration failed");
2031 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
2032 GNUNET_SCHEDULER_add_now (&do_error, handle);
2037 // TODO OPTIONAL acr,amr,azp
2038 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
2039 "reclaim-rest-plugin",
2043 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
2044 handle->edesc = GNUNET_strdup ("No signing secret configured!");
2045 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
2046 GNUNET_SCHEDULER_add_now (&do_error, handle);
2049 id_token = OIDC_id_token_new (&ticket.audience,
2054 (NULL != nonce) ? nonce : NULL,
2056 access_token = OIDC_access_token_new ();
2057 OIDC_build_token_response (access_token,
2062 persist_access_token (handle, access_token, &ticket);
2063 resp = GNUNET_REST_create_response (json_response);
2064 MHD_add_response_header (resp, "Cache-Control", "no-store");
2065 MHD_add_response_header (resp, "Pragma", "no-cache");
2066 MHD_add_response_header (resp, "Content-Type", "application/json");
2067 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
2068 GNUNET_RECLAIM_attribute_list_destroy (cl);
2069 GNUNET_RECLAIM_attestation_list_destroy (al);
2070 GNUNET_free (access_token);
2071 GNUNET_free (json_response);
2072 GNUNET_free (id_token);
2073 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
2078 * Collects claims and stores them in handle
2081 consume_ticket (void *cls,
2082 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
2083 const struct GNUNET_RECLAIM_Attribute *attr,
2084 const struct GNUNET_RECLAIM_Attestation *attest)
2086 struct RequestHandle *handle = cls;
2087 handle->idp_op = NULL;
2089 if (NULL == identity)
2091 GNUNET_SCHEDULER_add_now (&return_userinfo_response, handle);
2094 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attr->attestation))
2098 tmp_value = GNUNET_RECLAIM_attribute_value_to_string (attr->type,
2101 value = json_string (tmp_value);
2102 json_object_set_new (handle->oidc->response, attr->name, value);
2103 GNUNET_free (tmp_value);
2106 json_t *claim_sources;
2107 json_t *claim_sources_jwt;
2108 json_t *claim_names;
2109 char *attest_val_str;
2110 claim_sources = json_object_get (handle->oidc->response,"_claim_sources");
2111 claim_names = json_object_get (handle->oidc->response,"_claim_names");
2113 GNUNET_RECLAIM_attestation_value_to_string (attest->type,
2116 if ((NULL == claim_sources) && (NULL == claim_names) )
2118 claim_sources = json_object ();
2119 claim_names = json_object ();
2123 GNUNET_asprintf (&source_name, "src%d", i);
2124 while (NULL != (claim_sources_jwt = json_object_get (claim_sources,
2127 if (0 == strcmp (json_string_value (json_object_get (claim_sources_jwt,
2131 // Adapt only the claim names
2132 json_object_set_new (claim_names, attr->data,
2133 json_string (source_name));
2134 json_object_set (handle->oidc->response,
2135 "_claim_names", claim_names);
2139 GNUNET_free (source_name);
2140 GNUNET_asprintf (&source_name, "src%d", i);
2144 if (NULL == claim_sources_jwt)
2146 claim_sources_jwt = json_object ();
2147 // Set the JWT for names
2148 json_object_set_new (claim_names, attr->data,
2149 json_string (source_name));
2150 // Set the JWT for the inner source
2151 json_object_set_new (claim_sources_jwt, "JWT",
2152 json_string (attest_val_str));
2153 // Set the JWT for the source
2154 json_object_set_new (claim_sources, source_name, claim_sources_jwt);
2156 json_object_set (handle->oidc->response, "_claim_names", claim_names);
2157 json_object_set (handle->oidc->response, "_claim_sources",claim_sources);
2160 json_decref (claim_sources);
2161 json_decref (claim_names);
2162 json_decref (claim_sources_jwt);
2163 GNUNET_free (attest_val_str);
2168 * Responds to userinfo GET and url-encoded POST request
2170 * @param con_handle the connection handle
2171 * @param url the url
2172 * @param cls the RequestHandle
2175 userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2179 // TODO expiration time
2180 struct RequestHandle *handle = cls;
2181 char delimiter[] = " ";
2182 struct GNUNET_HashCode cache_key;
2183 char *authorization;
2184 char *authorization_type;
2185 char *authorization_access_token;
2186 struct GNUNET_RECLAIM_Ticket *ticket;
2187 const struct EgoEntry *ego_entry;
2188 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
2190 GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY,
2191 strlen (OIDC_AUTHORIZATION_HEADER_KEY),
2193 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
2197 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
2198 handle->edesc = GNUNET_strdup ("No Access Token");
2199 handle->response_code = MHD_HTTP_UNAUTHORIZED;
2200 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
2204 GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->header_param_map,
2207 // split header in "Bearer" and access_token
2208 authorization = GNUNET_strdup (authorization);
2209 authorization_type = strtok (authorization, delimiter);
2210 if ((NULL == authorization_type) ||
2211 (0 != strcmp ("Bearer", authorization_type)))
2213 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
2214 handle->edesc = GNUNET_strdup ("No Access Token");
2215 handle->response_code = MHD_HTTP_UNAUTHORIZED;
2216 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
2217 GNUNET_free (authorization);
2220 authorization_access_token = strtok (NULL, delimiter);
2221 if (NULL == authorization_access_token)
2223 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
2224 handle->edesc = GNUNET_strdup ("Access token missing");
2225 handle->response_code = MHD_HTTP_UNAUTHORIZED;
2226 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
2227 GNUNET_free (authorization);
2231 GNUNET_CRYPTO_hash (authorization_access_token,
2232 strlen (authorization_access_token),
2235 GNUNET_CONTAINER_multihashmap_contains (OIDC_access_token_map,
2238 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
2239 handle->edesc = GNUNET_strdup ("The access token expired");
2240 handle->response_code = MHD_HTTP_UNAUTHORIZED;
2241 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
2242 GNUNET_free (authorization);
2246 GNUNET_CONTAINER_multihashmap_get (OIDC_access_token_map, &cache_key);
2247 GNUNET_assert (NULL != ticket);
2248 ego_entry = find_ego (handle, &ticket->audience);
2249 if (NULL == ego_entry)
2251 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
2252 handle->edesc = GNUNET_strdup ("The access token expired");
2253 handle->response_code = MHD_HTTP_UNAUTHORIZED;
2254 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
2255 GNUNET_free (authorization);
2259 handle->idp = GNUNET_RECLAIM_connect (cfg);
2260 handle->oidc->response = json_object ();
2261 json_object_set_new (handle->oidc->response,
2263 json_string (ego_entry->keystring));
2264 privkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
2265 handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp,
2270 GNUNET_free (authorization);
2275 * Handle rest request
2277 * @param handle the request handle
2280 init_cont (struct RequestHandle *handle)
2282 struct GNUNET_REST_RequestHandlerError err;
2283 static const struct GNUNET_REST_RequestHandler handlers[] =
2284 { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint },
2285 { MHD_HTTP_METHOD_POST,
2286 GNUNET_REST_API_NS_AUTHORIZE,
2287 &authorize_endpoint }, // url-encoded
2288 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont },
2289 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint },
2290 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
2291 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
2292 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont },
2293 GNUNET_REST_HANDLER_END };
2296 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
2298 handle->response_code = err.error_code;
2299 GNUNET_SCHEDULER_add_now (&do_error, handle);
2305 * If listing is enabled, prints information about the egos.
2307 * This function is initially called for all egos and then again
2308 * whenever a ego's identifier changes or if it is deleted. At the
2309 * end of the initial pass over all egos, the function is once called
2310 * with 'NULL' for 'ego'. That does NOT mean that the callback won't
2311 * be invoked in the future or that there was an error.
2313 * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get',
2314 * this function is only called ONCE, and 'NULL' being passed in
2315 * 'ego' does indicate an error (i.e. name is taken or no default
2316 * value is known). If 'ego' is non-NULL and if '*ctx'
2317 * is set in those callbacks, the value WILL be passed to a subsequent
2318 * call to the identity callback of 'GNUNET_IDENTITY_connect' (if
2319 * that one was not NULL).
2321 * When an identity is renamed, this function is called with the
2322 * (known) ego but the NEW identifier.
2324 * When an identity is deleted, this function is called with the
2325 * (known) ego and "NULL" for the 'identifier'. In this case,
2326 * the 'ego' is henceforth invalid (and the 'ctx' should also be
2329 * @param cls closure
2330 * @param ego ego handle
2331 * @param ctx context for application to store data for this ego
2332 * (during the lifetime of this process, initially NULL)
2333 * @param identifier identifier assigned by the user for this ego,
2334 * NULL if the user just deleted the ego and it
2335 * must thus no longer be used
2338 list_ego (void *cls,
2339 struct GNUNET_IDENTITY_Ego *ego,
2341 const char *identifier)
2343 struct RequestHandle *handle = cls;
2344 struct EgoEntry *ego_entry;
2345 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
2347 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
2349 handle->state = ID_REST_STATE_POST_INIT;
2353 GNUNET_assert (NULL != ego);
2354 if (ID_REST_STATE_INIT == handle->state)
2357 ego_entry = GNUNET_new (struct EgoEntry);
2358 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
2359 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
2360 ego_entry->ego = ego;
2361 ego_entry->identifier = GNUNET_strdup (identifier);
2362 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head,
2367 /* Ego renamed or added */
2368 if (identifier != NULL)
2370 for (ego_entry = handle->ego_head; NULL != ego_entry;
2371 ego_entry = ego_entry->next)
2373 if (ego_entry->ego == ego)
2376 GNUNET_free (ego_entry->identifier);
2377 ego_entry->identifier = GNUNET_strdup (identifier);
2381 if (NULL == ego_entry)
2384 ego_entry = GNUNET_new (struct EgoEntry);
2385 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
2386 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
2387 ego_entry->ego = ego;
2388 ego_entry->identifier = GNUNET_strdup (identifier);
2389 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head,
2397 for (ego_entry = handle->ego_head; NULL != ego_entry;
2398 ego_entry = ego_entry->next)
2400 if (ego_entry->ego == ego)
2403 if (NULL == ego_entry)
2404 return; /* Not found */
2406 GNUNET_CONTAINER_DLL_remove (handle->ego_head,
2409 GNUNET_free (ego_entry->identifier);
2410 GNUNET_free (ego_entry->keystring);
2411 GNUNET_free (ego_entry);
2418 rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
2419 GNUNET_REST_ResultProcessor proc,
2422 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
2424 handle->oidc = GNUNET_new (struct OIDC_Variables);
2425 if (NULL == OIDC_cookie_jar_map)
2426 OIDC_cookie_jar_map = GNUNET_CONTAINER_multihashmap_create (10,
2428 if (NULL == OIDC_access_token_map)
2429 OIDC_access_token_map =
2430 GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
2431 handle->response_code = 0;
2432 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
2433 handle->proc_cls = proc_cls;
2434 handle->proc = proc;
2435 handle->state = ID_REST_STATE_INIT;
2436 handle->rest_handle = rest_handle;
2438 handle->url = GNUNET_strdup (rest_handle->url);
2439 if (handle->url[strlen (handle->url) - 1] == '/')
2440 handle->url[strlen (handle->url) - 1] = '\0';
2441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
2442 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle);
2443 handle->gns_handle = GNUNET_GNS_connect (cfg);
2444 handle->namestore_handle = GNUNET_NAMESTORE_connect (cfg);
2445 handle->timeout_task =
2446 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
2447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
2452 * Entry point for the plugin.
2454 * @param cls Config info
2455 * @return NULL on error, otherwise the plugin context
2458 libgnunet_plugin_rest_openid_connect_init (void *cls)
2460 static struct Plugin plugin;
2461 struct GNUNET_REST_Plugin *api;
2464 if (NULL != plugin.cfg)
2465 return NULL; /* can only initialize once! */
2466 memset (&plugin, 0, sizeof(struct Plugin));
2468 api = GNUNET_new (struct GNUNET_REST_Plugin);
2470 api->name = GNUNET_REST_API_NS_OIDC;
2471 api->process_request = &rest_identity_process_request;
2472 GNUNET_asprintf (&allow_methods,
2473 "%s, %s, %s, %s, %s",
2474 MHD_HTTP_METHOD_GET,
2475 MHD_HTTP_METHOD_POST,
2476 MHD_HTTP_METHOD_PUT,
2477 MHD_HTTP_METHOD_DELETE,
2478 MHD_HTTP_METHOD_OPTIONS);
2480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2481 _ ("OpenID Connect REST API initialized\n"));
2487 * Exit point from the plugin.
2489 * @param cls the plugin context (as returned by "init")
2490 * @return always NULL
2493 libgnunet_plugin_rest_openid_connect_done (void *cls)
2495 struct GNUNET_REST_Plugin *api = cls;
2496 struct Plugin *plugin = api->cls;
2500 struct GNUNET_CONTAINER_MultiHashMapIterator *hashmap_it;
2503 GNUNET_CONTAINER_multihashmap_iterator_create (OIDC_cookie_jar_map);
2504 while (GNUNET_YES ==
2505 GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL,
2507 GNUNET_free_non_null (value);
2508 GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it);
2509 GNUNET_CONTAINER_multihashmap_destroy (OIDC_cookie_jar_map);
2512 GNUNET_CONTAINER_multihashmap_iterator_create (OIDC_access_token_map);
2513 while (GNUNET_YES ==
2514 GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL,
2516 GNUNET_free_non_null (value);
2517 GNUNET_CONTAINER_multihashmap_destroy (OIDC_access_token_map);
2518 GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it);
2519 GNUNET_free_non_null (allow_methods);
2521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2522 "OpenID Connect REST plugin is finished\n");
2527 /* end of plugin_rest_openid_connect.c */