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_attribute_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"
123 * OIDC cookie expiration (in seconds)
125 #define OIDC_COOKIE_EXPIRATION 3
128 * OIDC cookie header key
130 #define OIDC_COOKIE_HEADER_KEY "cookie"
133 * OIDC cookie header information key
135 #define OIDC_AUTHORIZATION_HEADER_KEY "authorization"
138 * OIDC cookie header information key
140 #define OIDC_COOKIE_HEADER_INFORMATION_KEY "Identity="
143 * OIDC cookie header if user cancelled
145 #define OIDC_COOKIE_HEADER_ACCESS_DENIED "Identity=Denied"
148 * OIDC expected response_type while authorizing
150 #define OIDC_EXPECTED_AUTHORIZATION_RESPONSE_TYPE "code"
153 * OIDC expected scope part while authorizing
155 #define OIDC_EXPECTED_AUTHORIZATION_SCOPE "openid"
158 * OIDC error key for invalid client
160 #define OIDC_ERROR_KEY_INVALID_CLIENT "invalid_client"
163 * OIDC error key for invalid scopes
165 #define OIDC_ERROR_KEY_INVALID_SCOPE "invalid_scope"
168 * OIDC error key for invalid requests
170 #define OIDC_ERROR_KEY_INVALID_REQUEST "invalid_request"
173 * OIDC error key for invalid tokens
175 #define OIDC_ERROR_KEY_INVALID_TOKEN "invalid_token"
178 * OIDC error key for invalid cookies
180 #define OIDC_ERROR_KEY_INVALID_COOKIE "invalid_cookie"
183 * OIDC error key for generic server errors
185 #define OIDC_ERROR_KEY_SERVER_ERROR "server_error"
188 * OIDC error key for unsupported grants
190 #define OIDC_ERROR_KEY_UNSUPPORTED_GRANT_TYPE "unsupported_grant_type"
193 * OIDC error key for unsupported response types
195 #define OIDC_ERROR_KEY_UNSUPPORTED_RESPONSE_TYPE "unsupported_response_type"
198 * OIDC error key for unauthorized clients
200 #define OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT "unauthorized_client"
203 * OIDC error key for denied access
205 #define OIDC_ERROR_KEY_ACCESS_DENIED "access_denied"
209 * OIDC ignored parameter array
211 static char *OIDC_ignored_parameter_array[] = {
212 "display", "prompt", "ui_locales", "response_mode",
213 "id_token_hint", "login_hint", "acr_values"};
216 * OIDC Hash map that keeps track of issued cookies
218 struct GNUNET_CONTAINER_MultiHashMap *OIDC_cookie_jar_map;
221 * OIDC authorized identities and times hashmap
223 struct GNUNET_CONTAINER_MultiHashMap *OIDC_identity_grants;
226 * OIDC Hash map that keeps track of used authorization code(s)
228 struct GNUNET_CONTAINER_MultiHashMap *OIDC_used_ticket_map;
231 * Hash map that links the issued access token to the corresponding ticket and
234 struct GNUNET_CONTAINER_MultiHashMap *OIDC_access_token_map;
237 * The configuration handle
239 const struct GNUNET_CONFIGURATION_Handle *cfg;
242 * HTTP methods allows for this plugin
244 static char *allow_methods;
247 * @brief struct returned by the initialization function of the plugin
251 const struct GNUNET_CONFIGURATION_Handle *cfg;
255 * OIDC needed variables
257 struct OIDC_Variables
260 * The RP client public key
262 struct GNUNET_CRYPTO_EcdsaPublicKey client_pkey;
265 * The OIDC client id of the RP
270 * The OIDC redirect uri
275 * The list of oidc scopes
290 * The OIDC response type
295 * The identity chosen by the user to login
297 char *login_identity;
300 * User cancelled authorization/login
318 struct EgoEntry *next;
323 struct EgoEntry *prev;
338 struct GNUNET_IDENTITY_Ego *ego;
347 struct EgoEntry *ego_head;
352 struct EgoEntry *ego_tail;
357 struct EgoEntry *ego_entry;
360 * Pointer to ego private key
362 struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key;
367 struct OIDC_Variables *oidc;
370 * The processing state
375 * Handle to Identity service.
377 struct GNUNET_IDENTITY_Handle *identity_handle;
382 struct GNUNET_REST_RequestHandle *rest_handle;
387 struct GNUNET_GNS_Handle *gns_handle;
392 struct GNUNET_GNS_LookupRequest *gns_op;
395 * Handle to NAMESTORE
397 struct GNUNET_NAMESTORE_Handle *namestore_handle;
400 * Iterator for NAMESTORE
402 struct GNUNET_NAMESTORE_ZoneIterator *namestore_handle_it;
405 * Attribute claim list
407 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list;
412 struct GNUNET_IDENTITY_Operation *op;
417 struct GNUNET_RECLAIM_Handle *idp;
422 struct GNUNET_RECLAIM_Operation *idp_op;
427 struct GNUNET_RECLAIM_AttributeIterator *attr_it;
432 struct GNUNET_RECLAIM_TicketIterator *ticket_it;
437 struct GNUNET_RECLAIM_Ticket ticket;
440 * Desired timeout for the lookup (default is no timeout).
442 struct GNUNET_TIME_Relative timeout;
445 * ID of a task associated with the resolution process.
447 struct GNUNET_SCHEDULER_Task *timeout_task;
450 * The plugin result processor
452 GNUNET_REST_ResultProcessor proc;
455 * The closure of the result processor
465 * The tld for redirect
470 * The redirect prefix
472 char *redirect_prefix;
475 * The redirect suffix
477 char *redirect_suffix;
480 * Error response message
485 * Error response description
496 * Cleanup lookup handle
497 * @param handle Handle to clean up
500 cleanup_handle (struct RequestHandle *handle)
502 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_entry;
503 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp;
504 struct EgoEntry *ego_entry;
505 struct EgoEntry *ego_tmp;
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
507 if (NULL != handle->timeout_task)
508 GNUNET_SCHEDULER_cancel (handle->timeout_task);
509 if (NULL != handle->identity_handle)
510 GNUNET_IDENTITY_disconnect (handle->identity_handle);
511 if (NULL != handle->attr_it)
512 GNUNET_RECLAIM_get_attributes_stop (handle->attr_it);
513 if (NULL != handle->ticket_it)
514 GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it);
515 if (NULL != handle->idp)
516 GNUNET_RECLAIM_disconnect (handle->idp);
517 GNUNET_free_non_null (handle->url);
518 GNUNET_free_non_null (handle->tld);
519 GNUNET_free_non_null (handle->redirect_prefix);
520 GNUNET_free_non_null (handle->redirect_suffix);
521 GNUNET_free_non_null (handle->emsg);
522 GNUNET_free_non_null (handle->edesc);
523 if (NULL != handle->gns_op)
524 GNUNET_GNS_lookup_cancel (handle->gns_op);
525 if (NULL != handle->gns_handle)
526 GNUNET_GNS_disconnect (handle->gns_handle);
528 if (NULL != handle->namestore_handle)
529 GNUNET_NAMESTORE_disconnect (handle->namestore_handle);
530 if (NULL != handle->oidc) {
531 GNUNET_free_non_null (handle->oidc->client_id);
532 GNUNET_free_non_null (handle->oidc->login_identity);
533 GNUNET_free_non_null (handle->oidc->nonce);
534 GNUNET_free_non_null (handle->oidc->redirect_uri);
535 GNUNET_free_non_null (handle->oidc->response_type);
536 GNUNET_free_non_null (handle->oidc->scope);
537 GNUNET_free_non_null (handle->oidc->state);
538 json_decref (handle->oidc->response);
539 GNUNET_free (handle->oidc);
541 if (NULL != handle->attr_list) {
542 for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;) {
543 claim_tmp = claim_entry;
544 claim_entry = claim_entry->next;
545 GNUNET_free (claim_tmp->claim);
546 GNUNET_free (claim_tmp);
548 GNUNET_free (handle->attr_list);
550 for (ego_entry = handle->ego_head; NULL != ego_entry;) {
552 ego_entry = ego_entry->next;
553 GNUNET_free (ego_tmp->identifier);
554 GNUNET_free (ego_tmp->keystring);
555 GNUNET_free (ego_tmp);
557 GNUNET_free_non_null (handle->attr_it);
558 GNUNET_free (handle);
562 cleanup_handle_delayed (void *cls)
564 cleanup_handle (cls);
569 * Task run on error, sends error message. Cleans up everything.
571 * @param cls the `struct RequestHandle`
576 struct RequestHandle *handle = cls;
577 struct MHD_Response *resp;
582 "{ \"error\" : \"%s\", \"error_description\" : \"%s\"%s%s%s}",
583 handle->emsg, (NULL != handle->edesc) ? handle->edesc : "",
584 (NULL != handle->oidc->state) ? ", \"state\":\"" : "",
585 (NULL != handle->oidc->state) ? handle->oidc->state : "",
586 (NULL != handle->oidc->state) ? "\"" : "");
587 if (0 == handle->response_code)
588 handle->response_code = MHD_HTTP_BAD_REQUEST;
589 resp = GNUNET_REST_create_response (json_error);
590 if (MHD_HTTP_UNAUTHORIZED == handle->response_code)
591 MHD_add_response_header (resp, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Basic");
592 MHD_add_response_header (resp, MHD_HTTP_HEADER_CONTENT_TYPE,
594 handle->proc (handle->proc_cls, resp, handle->response_code);
595 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
596 GNUNET_free (json_error);
601 * Task run on error in userinfo endpoint, sends error header. Cleans up
604 * @param cls the `struct RequestHandle`
607 do_userinfo_error (void *cls)
609 struct RequestHandle *handle = cls;
610 struct MHD_Response *resp;
613 GNUNET_asprintf (&error, "error=\"%s\", error_description=\"%s\"",
614 handle->emsg, (NULL != handle->edesc) ? handle->edesc : "");
615 resp = GNUNET_REST_create_response ("");
616 MHD_add_response_header (resp, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Bearer");
617 handle->proc (handle->proc_cls, resp, handle->response_code);
618 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
624 * Task run on error, sends error message and redirects. Cleans up everything.
626 * @param cls the `struct RequestHandle`
629 do_redirect_error (void *cls)
631 struct RequestHandle *handle = cls;
632 struct MHD_Response *resp;
634 GNUNET_asprintf (&redirect, "%s?error=%s&error_description=%s%s%s",
635 handle->oidc->redirect_uri, handle->emsg, handle->edesc,
636 (NULL != handle->oidc->state) ? "&state=" : "",
637 (NULL != handle->oidc->state) ? handle->oidc->state : "");
638 resp = GNUNET_REST_create_response ("");
639 MHD_add_response_header (resp, "Location", redirect);
640 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
641 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
642 GNUNET_free (redirect);
646 * Task run on timeout, sends error message. Cleans up everything.
648 * @param cls the `struct RequestHandle`
651 do_timeout (void *cls)
653 struct RequestHandle *handle = cls;
655 handle->timeout_task = NULL;
660 * Return attributes for claim
662 * @param cls the request handle
665 return_userinfo_response (void *cls)
668 struct RequestHandle *handle = cls;
669 struct MHD_Response *resp;
671 result_str = json_dumps (handle->oidc->response, 0);
673 resp = GNUNET_REST_create_response (result_str);
674 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
675 GNUNET_free (result_str);
676 cleanup_handle (handle);
680 * Returns base64 encoded string urlencoded
682 * @param string the string to encode
683 * @return base64 encoded string
686 base64_encode (const char *s)
694 GNUNET_STRINGS_base64_encode (s, strlen (s), &enc);
695 tmp = strchr (enc, '=');
696 num_pads = strlen (enc) - (tmp - enc);
697 GNUNET_assert ((3 > num_pads) && (0 <= num_pads));
700 enc_urlencode = GNUNET_malloc (strlen (enc) + num_pads * 2);
701 strcpy (enc_urlencode, enc);
703 tmp = strchr (enc_urlencode, '=');
704 for (i = 0; i < num_pads; i++) {
705 strcpy (tmp, "%3D"); // replace '=' with '%3D'
708 return enc_urlencode;
712 * Respond to OPTIONS request
714 * @param con_handle the connection handle
716 * @param cls the RequestHandle
719 options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url,
722 struct MHD_Response *resp;
723 struct RequestHandle *handle = cls;
725 // For now, independent of path return all options
726 resp = GNUNET_REST_create_response (NULL);
727 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
728 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
729 cleanup_handle (handle);
735 * Interprets cookie header and pass its identity keystring to handle
738 cookie_identity_interpretation (struct RequestHandle *handle)
740 struct GNUNET_HashCode cache_key;
742 struct GNUNET_TIME_Absolute current_time, *relog_time;
743 char delimiter[] = "; ";
748 // gets identity of login try with cookie
749 GNUNET_CRYPTO_hash (OIDC_COOKIE_HEADER_KEY, strlen (OIDC_COOKIE_HEADER_KEY),
751 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (
752 handle->rest_handle->header_param_map, &cache_key)) {
753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No cookie found\n");
756 // splits cookies and find 'Identity' cookie
757 tmp_cookies = GNUNET_CONTAINER_multihashmap_get (
758 handle->rest_handle->header_param_map, &cache_key);
759 cookies = GNUNET_strdup (tmp_cookies);
760 token = strtok (cookies, delimiter);
761 handle->oidc->user_cancelled = GNUNET_NO;
762 handle->oidc->login_identity = NULL;
764 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to parse cookie: %s\n",
766 GNUNET_free (cookies);
770 while (NULL != token) {
771 if (0 == strcmp (token, OIDC_COOKIE_HEADER_ACCESS_DENIED)) {
772 handle->oidc->user_cancelled = GNUNET_YES;
773 GNUNET_free (cookies);
776 if (NULL != strstr (token, OIDC_COOKIE_HEADER_INFORMATION_KEY))
778 token = strtok (NULL, delimiter);
781 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No cookie value to process: %s\n",
783 GNUNET_free (cookies);
786 GNUNET_CRYPTO_hash (token, strlen (token), &cache_key);
787 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (OIDC_cookie_jar_map,
790 GNUNET_ERROR_TYPE_WARNING,
791 "Found cookie `%s', but no corresponding expiration entry present...\n",
793 GNUNET_free (cookies);
797 GNUNET_CONTAINER_multihashmap_get (OIDC_cookie_jar_map, &cache_key);
798 current_time = GNUNET_TIME_absolute_get ();
799 // 30 min after old login -> redirect to login
800 if (current_time.abs_value_us > relog_time->abs_value_us) {
801 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
802 "Found cookie `%s', but it is expired.\n", token);
803 GNUNET_free (cookies);
806 value = strtok (token, OIDC_COOKIE_HEADER_INFORMATION_KEY);
807 GNUNET_assert (NULL != value);
808 handle->oidc->login_identity = GNUNET_strdup (value);
812 * Redirects to login page stored in configuration file
815 login_redirect (void *cls)
817 char *login_base_url;
819 struct MHD_Response *resp;
820 struct RequestHandle *handle = cls;
823 GNUNET_CONFIGURATION_get_value_string (cfg, "reclaim-rest-plugin",
824 "address", &login_base_url)) {
825 GNUNET_asprintf (&new_redirect, "%s?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s",
826 login_base_url, OIDC_RESPONSE_TYPE_KEY,
827 handle->oidc->response_type, OIDC_CLIENT_ID_KEY,
828 handle->oidc->client_id, OIDC_REDIRECT_URI_KEY,
829 handle->oidc->redirect_uri, OIDC_SCOPE_KEY,
830 handle->oidc->scope, OIDC_STATE_KEY,
831 (NULL != handle->oidc->state) ? handle->oidc->state : "",
833 (NULL != handle->oidc->nonce) ? handle->oidc->nonce : "");
834 resp = GNUNET_REST_create_response ("");
835 MHD_add_response_header (resp, "Location", new_redirect);
836 GNUNET_free (login_base_url);
838 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
839 handle->edesc = GNUNET_strdup ("gnunet configuration failed");
840 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
841 GNUNET_SCHEDULER_add_now (&do_error, handle);
844 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
845 GNUNET_free (new_redirect);
846 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
850 * Does internal server error when iteration failed.
853 oidc_iteration_error (void *cls)
855 struct RequestHandle *handle = cls;
856 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
857 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
858 GNUNET_SCHEDULER_add_now (&do_error, handle);
863 * Issues ticket and redirects to relying party with the authorization code as
864 * parameter. Otherwise redirects with error
867 oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
869 struct RequestHandle *handle = cls;
870 struct MHD_Response *resp;
873 char *code_json_string;
874 char *code_base64_final_string;
876 handle->idp_op = NULL;
877 handle->ticket = *ticket;
878 if (NULL == ticket) {
879 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
880 handle->edesc = GNUNET_strdup ("Server cannot generate ticket.");
881 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
884 ticket_str = GNUNET_STRINGS_data_to_string_alloc (
885 &handle->ticket, sizeof (struct GNUNET_RECLAIM_Ticket));
886 // TODO change if more attributes are needed (see max_age)
887 code_json_string = OIDC_build_authz_code (&handle->priv_key, &handle->ticket,
888 handle->oidc->nonce);
889 code_base64_final_string = base64_encode (code_json_string);
890 if ((NULL != handle->redirect_prefix) && (NULL != handle->redirect_suffix) &&
891 (NULL != handle->tld)) {
893 GNUNET_asprintf (&redirect_uri, "%s.%s/%s?%s=%s&state=%s",
894 handle->redirect_prefix, handle->tld,
895 handle->redirect_suffix, handle->oidc->response_type,
896 code_base64_final_string, handle->oidc->state);
898 GNUNET_asprintf (&redirect_uri, "%s?%s=%s&state=%s",
899 handle->oidc->redirect_uri, handle->oidc->response_type,
900 code_base64_final_string, handle->oidc->state);
902 resp = GNUNET_REST_create_response ("");
903 MHD_add_response_header (resp, "Location", redirect_uri);
904 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
905 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
906 GNUNET_free (redirect_uri);
907 GNUNET_free (ticket_str);
908 GNUNET_free (code_json_string);
909 GNUNET_free (code_base64_final_string);
913 oidc_collect_finished_cb (void *cls)
915 struct RequestHandle *handle = cls;
916 handle->attr_it = NULL;
917 handle->ticket_it = NULL;
918 if (NULL == handle->attr_list->list_head) {
919 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_SCOPE);
920 handle->edesc = GNUNET_strdup ("The requested scope is not available.");
921 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
924 handle->idp_op = GNUNET_RECLAIM_ticket_issue (
925 handle->idp, &handle->priv_key, &handle->oidc->client_pkey,
926 handle->attr_list, &oidc_ticket_issue_cb, handle);
931 * Collects all attributes for an ego if in scope parameter
934 oidc_attr_collect (void *cls,
935 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
936 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
938 struct RequestHandle *handle = cls;
939 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
940 char *scope_variables;
941 char *scope_variable;
942 char delimiter[] = " ";
944 if ((NULL == attr->name) || (NULL == attr->data)) {
945 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
949 scope_variables = GNUNET_strdup (handle->oidc->scope);
950 scope_variable = strtok (scope_variables, delimiter);
951 while (NULL != scope_variable) {
952 if (0 == strcmp (attr->name, scope_variable)) {
955 scope_variable = strtok (NULL, delimiter);
957 if (NULL == scope_variable) {
958 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
959 GNUNET_free (scope_variables);
962 GNUNET_free (scope_variables);
964 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
965 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, attr->type,
966 attr->data, attr->data_size);
967 GNUNET_CONTAINER_DLL_insert (handle->attr_list->list_head,
968 handle->attr_list->list_tail, le);
969 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
974 * Checks time and cookie and redirects accordingly
977 code_redirect (void *cls)
979 struct RequestHandle *handle = cls;
980 struct GNUNET_TIME_Absolute current_time, *relog_time;
981 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey, ego_pkey;
982 struct GNUNET_HashCode cache_key;
983 char *identity_cookie;
985 GNUNET_asprintf (&identity_cookie, "Identity=%s",
986 handle->oidc->login_identity);
987 GNUNET_CRYPTO_hash (identity_cookie, strlen (identity_cookie), &cache_key);
988 GNUNET_free (identity_cookie);
989 // No login time for identity -> redirect to login
990 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (OIDC_cookie_jar_map,
993 GNUNET_CONTAINER_multihashmap_get (OIDC_cookie_jar_map, &cache_key);
994 current_time = GNUNET_TIME_absolute_get ();
995 // 30 min after old login -> redirect to login
996 if (current_time.abs_value_us <= relog_time->abs_value_us) {
997 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (
998 handle->oidc->login_identity,
999 strlen (handle->oidc->login_identity), &pubkey)) {
1000 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_COOKIE);
1002 GNUNET_strdup ("The cookie of a login identity is not valid");
1003 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1006 // iterate over egos and compare their public key
1007 for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry;
1008 handle->ego_entry = handle->ego_entry->next) {
1009 GNUNET_IDENTITY_ego_get_public_key (handle->ego_entry->ego, &ego_pkey);
1010 if (0 == memcmp (&ego_pkey, &pubkey,
1011 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) {
1013 *GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego);
1014 handle->idp = GNUNET_RECLAIM_connect (cfg);
1016 GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
1017 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (
1018 handle->idp, &handle->priv_key, &oidc_iteration_error, handle,
1019 &oidc_attr_collect, handle, &oidc_collect_finished_cb, handle);
1023 GNUNET_SCHEDULER_add_now (&login_redirect, handle);
1031 build_redirect (void *cls)
1033 struct RequestHandle *handle = cls;
1034 struct MHD_Response *resp;
1037 if (GNUNET_YES == handle->oidc->user_cancelled) {
1038 if ((NULL != handle->redirect_prefix) &&
1039 (NULL != handle->redirect_suffix) && (NULL != handle->tld)) {
1041 &redirect_uri, "%s.%s/%s?error=%s&error_description=%s&state=%s",
1042 handle->redirect_prefix, handle->tld, handle->redirect_suffix,
1043 "access_denied", "User denied access", handle->oidc->state);
1045 GNUNET_asprintf (&redirect_uri,
1046 "%s?error=%s&error_description=%s&state=%s",
1047 handle->oidc->redirect_uri, "access_denied",
1048 "User denied access", handle->oidc->state);
1050 resp = GNUNET_REST_create_response ("");
1051 MHD_add_response_header (resp, "Location", redirect_uri);
1052 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
1053 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
1054 GNUNET_free (redirect_uri);
1057 GNUNET_SCHEDULER_add_now (&code_redirect, handle);
1062 lookup_redirect_uri_result (void *cls, uint32_t rd_count,
1063 const struct GNUNET_GNSRECORD_Data *rd)
1065 struct RequestHandle *handle = cls;
1069 struct GNUNET_CRYPTO_EcdsaPublicKey redirect_zone;
1071 handle->gns_op = NULL;
1072 if (0 == rd_count) {
1073 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
1074 handle->edesc = GNUNET_strdup (
1075 "Server cannot generate ticket, redirect uri not found.");
1076 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1079 for (int i = 0; i < rd_count; i++) {
1080 if (GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT != rd[i].record_type)
1082 if (0 != strncmp (rd[i].data, handle->oidc->redirect_uri, rd[i].data_size))
1084 tmp = GNUNET_strndup (rd[i].data, rd[i].data_size);
1085 if (NULL == strstr (tmp, handle->oidc->client_id)) {
1086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1087 "Redirect uri %s does not contain client_id %s", tmp,
1088 handle->oidc->client_id);
1091 pos = strrchr (tmp, (unsigned char)'.');
1093 handle->redirect_prefix = GNUNET_strdup (tmp);
1094 tmp_key_str = pos + 1;
1095 pos = strchr (tmp_key_str, (unsigned char)'/');
1097 handle->redirect_suffix = GNUNET_strdup (pos + 1);
1099 GNUNET_STRINGS_string_to_data (tmp_key_str, strlen (tmp_key_str),
1100 &redirect_zone, sizeof (redirect_zone));
1102 GNUNET_SCHEDULER_add_now (&build_redirect, handle);
1106 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
1108 GNUNET_strdup ("Server cannot generate ticket, redirect uri not found.");
1109 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1114 * Initiate redirect back to client.
1117 client_redirect (void *cls)
1119 struct RequestHandle *handle = cls;
1121 /* Lookup client redirect uri to verify request */
1122 handle->gns_op = GNUNET_GNS_lookup (
1123 handle->gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &handle->oidc->client_pkey,
1124 GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT, GNUNET_GNS_LO_DEFAULT,
1125 &lookup_redirect_uri_result, handle);
1130 * Iteration over all results finished, build final
1133 * @param cls the `struct RequestHandle`
1136 build_authz_response (void *cls)
1138 struct RequestHandle *handle = cls;
1139 struct GNUNET_HashCode cache_key;
1141 char *expected_scope;
1142 char delimiter[] = " ";
1143 int number_of_ignored_parameter, iterator;
1146 // REQUIRED value: redirect_uri
1147 GNUNET_CRYPTO_hash (OIDC_REDIRECT_URI_KEY, strlen (OIDC_REDIRECT_URI_KEY),
1149 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (
1150 handle->rest_handle->url_param_map, &cache_key)) {
1151 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1152 handle->edesc = GNUNET_strdup ("missing parameter redirect_uri");
1153 GNUNET_SCHEDULER_add_now (&do_error, handle);
1156 handle->oidc->redirect_uri =
1157 GNUNET_strdup (GNUNET_CONTAINER_multihashmap_get (
1158 handle->rest_handle->url_param_map, &cache_key));
1160 // REQUIRED value: response_type
1161 GNUNET_CRYPTO_hash (OIDC_RESPONSE_TYPE_KEY, strlen (OIDC_RESPONSE_TYPE_KEY),
1163 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (
1164 handle->rest_handle->url_param_map, &cache_key)) {
1165 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1166 handle->edesc = GNUNET_strdup ("missing parameter response_type");
1167 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1170 handle->oidc->response_type = GNUNET_CONTAINER_multihashmap_get (
1171 handle->rest_handle->url_param_map, &cache_key);
1172 handle->oidc->response_type = GNUNET_strdup (handle->oidc->response_type);
1174 // REQUIRED value: scope
1175 GNUNET_CRYPTO_hash (OIDC_SCOPE_KEY, strlen (OIDC_SCOPE_KEY), &cache_key);
1176 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (
1177 handle->rest_handle->url_param_map, &cache_key)) {
1178 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_SCOPE);
1179 handle->edesc = GNUNET_strdup ("missing parameter scope");
1180 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1183 handle->oidc->scope = GNUNET_CONTAINER_multihashmap_get (
1184 handle->rest_handle->url_param_map, &cache_key);
1185 handle->oidc->scope = GNUNET_strdup (handle->oidc->scope);
1187 // OPTIONAL value: nonce
1188 GNUNET_CRYPTO_hash (OIDC_NONCE_KEY, strlen (OIDC_NONCE_KEY), &cache_key);
1189 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (
1190 handle->rest_handle->url_param_map, &cache_key)) {
1191 handle->oidc->nonce = GNUNET_CONTAINER_multihashmap_get (
1192 handle->rest_handle->url_param_map, &cache_key);
1193 handle->oidc->nonce = GNUNET_strdup (handle->oidc->nonce);
1196 // TODO check other values if needed
1197 number_of_ignored_parameter =
1198 sizeof (OIDC_ignored_parameter_array) / sizeof (char *);
1199 for (iterator = 0; iterator < number_of_ignored_parameter; iterator++) {
1200 GNUNET_CRYPTO_hash (OIDC_ignored_parameter_array[iterator],
1201 strlen (OIDC_ignored_parameter_array[iterator]),
1203 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (
1204 handle->rest_handle->url_param_map, &cache_key)) {
1205 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_ACCESS_DENIED);
1206 GNUNET_asprintf (&handle->edesc, "Server will not handle parameter: %s",
1207 OIDC_ignored_parameter_array[iterator]);
1208 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1213 // Checks if response_type is 'code'
1214 if (0 != strcmp (handle->oidc->response_type,
1215 OIDC_EXPECTED_AUTHORIZATION_RESPONSE_TYPE)) {
1216 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNSUPPORTED_RESPONSE_TYPE);
1217 handle->edesc = GNUNET_strdup ("The authorization server does not support "
1218 "obtaining this authorization code.");
1219 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1223 // Checks if scope contains 'openid'
1224 expected_scope = GNUNET_strdup (handle->oidc->scope);
1226 test = strtok (expected_scope, delimiter);
1227 while (NULL != test) {
1228 if (0 == strcmp (OIDC_EXPECTED_AUTHORIZATION_SCOPE, expected_scope))
1230 test = strtok (NULL, delimiter);
1233 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_SCOPE);
1235 GNUNET_strdup ("The requested scope is invalid, unknown, or "
1237 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1238 GNUNET_free (expected_scope);
1242 GNUNET_free (expected_scope);
1243 if ((NULL == handle->oidc->login_identity) &&
1244 (GNUNET_NO == handle->oidc->user_cancelled))
1245 GNUNET_SCHEDULER_add_now (&login_redirect, handle);
1247 GNUNET_SCHEDULER_add_now (&client_redirect, handle);
1251 * Iterate over tlds in config
1254 tld_iter (void *cls, const char *section, const char *option, const char *value)
1256 struct RequestHandle *handle = cls;
1257 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1259 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (
1260 value, strlen (value), &pkey)) {
1261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping non key %s\n", value);
1264 if (0 == memcmp (&pkey, &handle->oidc->client_pkey,
1265 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
1266 handle->tld = GNUNET_strdup (option + 1);
1270 * Responds to authorization GET and url-encoded POST request
1272 * @param con_handle the connection handle
1273 * @param url the url
1274 * @param cls the RequestHandle
1277 authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1278 const char *url, void *cls)
1280 struct RequestHandle *handle = cls;
1281 struct GNUNET_HashCode cache_key;
1282 struct EgoEntry *tmp_ego;
1283 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
1284 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1286 cookie_identity_interpretation (handle);
1288 // RECOMMENDED value: state - REQUIRED for answers
1289 GNUNET_CRYPTO_hash (OIDC_STATE_KEY, strlen (OIDC_STATE_KEY), &cache_key);
1290 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (
1291 handle->rest_handle->url_param_map, &cache_key)) {
1292 handle->oidc->state = GNUNET_CONTAINER_multihashmap_get (
1293 handle->rest_handle->url_param_map, &cache_key);
1294 handle->oidc->state = GNUNET_strdup (handle->oidc->state);
1297 // REQUIRED value: client_id
1298 GNUNET_CRYPTO_hash (OIDC_CLIENT_ID_KEY, strlen (OIDC_CLIENT_ID_KEY),
1300 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (
1301 handle->rest_handle->url_param_map, &cache_key)) {
1302 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1303 handle->edesc = GNUNET_strdup ("missing parameter client_id");
1304 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
1305 GNUNET_SCHEDULER_add_now (&do_error, handle);
1308 handle->oidc->client_id = GNUNET_strdup (GNUNET_CONTAINER_multihashmap_get (
1309 handle->rest_handle->url_param_map, &cache_key));
1311 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (
1312 handle->oidc->client_id,
1313 strlen (handle->oidc->client_id),
1314 &handle->oidc->client_pkey)) {
1315 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT);
1316 handle->edesc = GNUNET_strdup ("The client is not authorized to request an "
1317 "authorization code using this method.");
1318 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
1319 GNUNET_SCHEDULER_add_now (&do_error, handle);
1324 if (NULL == handle->ego_head) {
1325 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
1326 handle->edesc = GNUNET_strdup ("Egos are missing");
1327 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
1328 GNUNET_SCHEDULER_add_now (&do_error, handle);
1332 handle->ego_entry = handle->ego_head;
1334 *GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego);
1335 // If we know this identity, translated the corresponding TLD
1336 // TODO: We might want to have a reverse lookup functionality for TLDs?
1337 for (tmp_ego = handle->ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next) {
1338 priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego);
1339 GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &pkey);
1340 if (0 == memcmp (&pkey, &handle->oidc->client_pkey,
1341 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) {
1342 handle->tld = GNUNET_strdup (tmp_ego->identifier);
1343 handle->ego_entry = handle->ego_tail;
1346 if (NULL == handle->tld)
1347 GNUNET_CONFIGURATION_iterate_section_values (cfg, "gns", tld_iter, handle);
1348 if (NULL == handle->tld)
1349 handle->tld = GNUNET_strdup (handle->oidc->client_id);
1350 GNUNET_SCHEDULER_add_now (&build_authz_response, handle);
1354 * Combines an identity with a login time and responds OK to login request
1356 * @param con_handle the connection handle
1357 * @param url the url
1358 * @param cls the RequestHandle
1361 login_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url,
1364 struct MHD_Response *resp = GNUNET_REST_create_response ("");
1365 struct RequestHandle *handle = cls;
1366 struct GNUNET_HashCode cache_key;
1367 struct GNUNET_TIME_Absolute *current_time;
1368 struct GNUNET_TIME_Absolute *last_time;
1374 char term_data[handle->rest_handle->data_size + 1];
1375 term_data[handle->rest_handle->data_size] = '\0';
1376 GNUNET_memcpy (term_data, handle->rest_handle->data,
1377 handle->rest_handle->data_size);
1378 root = json_loads (term_data, JSON_DECODE_ANY, &error);
1379 identity = json_object_get (root, "identity");
1380 if (!json_is_string (identity)) {
1381 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing json string from %s\n",
1383 handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
1385 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
1388 GNUNET_asprintf (&cookie, "Identity=%s", json_string_value (identity));
1389 GNUNET_asprintf (&header_val, "%s;Max-Age=%d", cookie,
1390 OIDC_COOKIE_EXPIRATION);
1391 MHD_add_response_header (resp, "Set-Cookie", header_val);
1392 MHD_add_response_header (resp, "Access-Control-Allow-Methods", "POST");
1393 GNUNET_CRYPTO_hash (cookie, strlen (cookie), &cache_key);
1395 if (0 != strcmp (json_string_value (identity), "Denied")) {
1396 current_time = GNUNET_new (struct GNUNET_TIME_Absolute);
1398 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (
1399 GNUNET_TIME_relative_get_second_ (), OIDC_COOKIE_EXPIRATION));
1401 GNUNET_CONTAINER_multihashmap_get (OIDC_cookie_jar_map, &cache_key);
1402 GNUNET_free_non_null (last_time);
1403 GNUNET_CONTAINER_multihashmap_put (
1404 OIDC_cookie_jar_map, &cache_key, current_time,
1405 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1407 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1408 GNUNET_free (cookie);
1409 GNUNET_free (header_val);
1411 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
1415 check_authorization (struct RequestHandle *handle,
1416 struct GNUNET_CRYPTO_EcdsaPublicKey *cid)
1418 struct GNUNET_HashCode cache_key;
1419 char *authorization;
1421 char *basic_authorization;
1424 char *expected_pass;
1425 int client_exists = GNUNET_NO;
1427 GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY,
1428 strlen (OIDC_AUTHORIZATION_HEADER_KEY), &cache_key);
1429 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (
1430 handle->rest_handle->header_param_map, &cache_key)) {
1431 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1432 handle->edesc = GNUNET_strdup ("missing authorization");
1433 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1434 return GNUNET_SYSERR;
1436 authorization = GNUNET_CONTAINER_multihashmap_get (
1437 handle->rest_handle->header_param_map, &cache_key);
1439 // split header in "Basic" and [content]
1440 credentials = strtok (authorization, " ");
1441 if (0 != strcmp ("Basic", credentials)) {
1442 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1443 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1444 return GNUNET_SYSERR;
1446 credentials = strtok (NULL, " ");
1447 if (NULL == credentials) {
1448 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1449 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1450 return GNUNET_SYSERR;
1452 GNUNET_STRINGS_base64_decode (credentials, strlen (credentials),
1453 (void **)&basic_authorization);
1455 if (NULL == basic_authorization) {
1456 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1457 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1458 return GNUNET_SYSERR;
1460 client_id = strtok (basic_authorization, ":");
1461 if (NULL == client_id) {
1462 GNUNET_free_non_null (basic_authorization);
1463 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1464 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1465 return GNUNET_SYSERR;
1467 pass = strtok (NULL, ":");
1469 GNUNET_free_non_null (basic_authorization);
1470 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1471 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1472 return GNUNET_SYSERR;
1475 // check client password
1476 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (
1477 cfg, "reclaim-rest-plugin", "psw", &expected_pass)) {
1478 if (0 != strcmp (expected_pass, pass)) {
1479 GNUNET_free_non_null (basic_authorization);
1480 GNUNET_free (expected_pass);
1481 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1482 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1483 return GNUNET_SYSERR;
1485 GNUNET_free (expected_pass);
1487 GNUNET_free_non_null (basic_authorization);
1488 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
1489 handle->edesc = GNUNET_strdup ("gnunet configuration failed");
1490 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
1491 return GNUNET_SYSERR;
1495 for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry;) {
1496 if (0 == strcmp (handle->ego_entry->keystring, client_id)) {
1497 client_exists = GNUNET_YES;
1500 handle->ego_entry = handle->ego_entry->next;
1502 if (GNUNET_NO == client_exists) {
1503 GNUNET_free_non_null (basic_authorization);
1504 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
1505 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1506 return GNUNET_SYSERR;
1508 GNUNET_STRINGS_string_to_data (client_id, strlen (client_id), cid,
1509 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
1511 GNUNET_free (basic_authorization);
1516 ego_exists (struct RequestHandle *handle,
1517 struct GNUNET_CRYPTO_EcdsaPublicKey *test_key)
1519 struct EgoEntry *ego_entry;
1520 struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
1522 for (ego_entry = handle->ego_head; NULL != ego_entry;
1523 ego_entry = ego_entry->next) {
1524 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &pub_key);
1525 if (0 == memcmp (&pub_key, test_key,
1526 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) {
1530 if (NULL == ego_entry)
1536 store_ticket_reference (const struct RequestHandle *handle,
1537 const char *access_token,
1538 const struct GNUNET_RECLAIM_Ticket *ticket,
1539 const struct GNUNET_CRYPTO_EcdsaPublicKey *cid)
1541 struct GNUNET_HashCode cache_key;
1542 char *id_ticket_combination;
1543 char *ticket_string;
1546 GNUNET_CRYPTO_hash (access_token, strlen (access_token), &cache_key);
1547 client_id = GNUNET_STRINGS_data_to_string_alloc (
1548 cid, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
1549 ticket_string = GNUNET_STRINGS_data_to_string_alloc (
1550 ticket, sizeof (struct GNUNET_RECLAIM_Ticket));
1551 GNUNET_asprintf (&id_ticket_combination, "%s;%s", client_id, ticket_string);
1552 GNUNET_CONTAINER_multihashmap_put (
1553 OIDC_access_token_map, &cache_key, id_ticket_combination,
1554 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1556 GNUNET_free (client_id);
1557 GNUNET_free (ticket_string);
1561 * Responds to token url-encoded POST request
1563 * @param con_handle the connection handle
1564 * @param url the url
1565 * @param cls the RequestHandle
1568 token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, const char *url,
1571 struct RequestHandle *handle = cls;
1572 struct GNUNET_TIME_Relative expiration_time;
1573 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *cl;
1574 struct GNUNET_RECLAIM_Ticket *ticket;
1575 struct GNUNET_CRYPTO_EcdsaPublicKey cid;
1576 struct GNUNET_HashCode cache_key;
1577 struct MHD_Response *resp;
1580 char *json_response;
1588 * Check Authorization
1590 if (GNUNET_SYSERR == check_authorization (handle, &cid)) {
1591 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1592 "OIDC authorization for token endpoint failed\n");
1593 GNUNET_SCHEDULER_add_now (&do_error, handle);
1601 // TODO Do not allow multiple equal parameter names
1602 // REQUIRED grant_type
1603 GNUNET_CRYPTO_hash (OIDC_GRANT_TYPE_KEY, strlen (OIDC_GRANT_TYPE_KEY),
1605 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (
1606 handle->rest_handle->url_param_map, &cache_key)) {
1607 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1608 handle->edesc = GNUNET_strdup ("missing parameter grant_type");
1609 handle->response_code = MHD_HTTP_BAD_REQUEST;
1610 GNUNET_SCHEDULER_add_now (&do_error, handle);
1613 grant_type = GNUNET_CONTAINER_multihashmap_get (
1614 handle->rest_handle->url_param_map, &cache_key);
1617 GNUNET_CRYPTO_hash (OIDC_CODE_KEY, strlen (OIDC_CODE_KEY), &cache_key);
1618 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (
1619 handle->rest_handle->url_param_map, &cache_key)) {
1620 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1621 handle->edesc = GNUNET_strdup ("missing parameter code");
1622 handle->response_code = MHD_HTTP_BAD_REQUEST;
1623 GNUNET_SCHEDULER_add_now (&do_error, handle);
1626 code = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map,
1629 // REQUIRED redirect_uri
1630 GNUNET_CRYPTO_hash (OIDC_REDIRECT_URI_KEY, strlen (OIDC_REDIRECT_URI_KEY),
1632 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (
1633 handle->rest_handle->url_param_map, &cache_key)) {
1634 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1635 handle->edesc = GNUNET_strdup ("missing parameter redirect_uri");
1636 handle->response_code = MHD_HTTP_BAD_REQUEST;
1637 GNUNET_SCHEDULER_add_now (&do_error, handle);
1641 // Check parameter grant_type == "authorization_code"
1642 if (0 != strcmp (OIDC_GRANT_TYPE_VALUE, grant_type)) {
1643 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNSUPPORTED_GRANT_TYPE);
1644 handle->response_code = MHD_HTTP_BAD_REQUEST;
1645 GNUNET_SCHEDULER_add_now (&do_error, handle);
1648 GNUNET_CRYPTO_hash (code, strlen (code), &cache_key);
1649 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1650 OIDC_used_ticket_map, &cache_key, &i,
1651 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) {
1652 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1653 handle->edesc = GNUNET_strdup ("Cannot use the same code more than once");
1654 handle->response_code = MHD_HTTP_BAD_REQUEST;
1655 GNUNET_SCHEDULER_add_now (&do_error, handle);
1660 if (GNUNET_OK != OIDC_parse_authz_code (&cid, code, &ticket, &nonce)) {
1661 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1662 handle->edesc = GNUNET_strdup ("invalid code");
1663 handle->response_code = MHD_HTTP_BAD_REQUEST;
1664 GNUNET_SCHEDULER_add_now (&do_error, handle);
1670 GNUNET_CONFIGURATION_get_value_time (
1671 cfg, "reclaim-rest-plugin", "expiration_time", &expiration_time)) {
1672 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
1673 handle->edesc = GNUNET_strdup ("gnunet configuration failed");
1674 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
1675 GNUNET_SCHEDULER_add_now (&do_error, handle);
1676 GNUNET_free (ticket);
1681 // TODO OPTIONAL acr,amr,azp
1682 if (GNUNET_NO == ego_exists (handle, &ticket->audience)) {
1683 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1684 handle->edesc = GNUNET_strdup ("invalid code...");
1685 handle->response_code = MHD_HTTP_BAD_REQUEST;
1686 GNUNET_SCHEDULER_add_now (&do_error, handle);
1687 GNUNET_free (ticket);
1689 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (
1690 cfg, "reclaim-rest-plugin", "jwt_secret", &jwt_secret)) {
1691 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
1692 handle->edesc = GNUNET_strdup ("No signing secret configured!");
1693 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
1694 GNUNET_SCHEDULER_add_now (&do_error, handle);
1695 GNUNET_free (ticket);
1698 // TODO We should collect the attributes here. cl always empty
1699 cl = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
1700 id_token = OIDC_id_token_new (&ticket->audience, &ticket->identity, cl,
1702 (NULL != nonce) ? nonce : NULL, jwt_secret);
1703 access_token = OIDC_access_token_new ();
1704 OIDC_build_token_response (access_token, id_token, &expiration_time,
1707 store_ticket_reference (handle, access_token, ticket, &cid);
1708 resp = GNUNET_REST_create_response (json_response);
1709 MHD_add_response_header (resp, "Cache-Control", "no-store");
1710 MHD_add_response_header (resp, "Pragma", "no-cache");
1711 MHD_add_response_header (resp, "Content-Type", "application/json");
1712 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1713 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (cl);
1714 GNUNET_free (access_token);
1715 GNUNET_free (json_response);
1716 GNUNET_free (ticket);
1717 GNUNET_free (id_token);
1718 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
1722 * Collects claims and stores them in handle
1725 consume_ticket (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
1726 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
1728 struct RequestHandle *handle = cls;
1732 if (NULL == identity) {
1733 GNUNET_SCHEDULER_add_now (&return_userinfo_response, handle);
1736 tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, attr->data,
1738 value = json_string (tmp_value);
1739 json_object_set_new (handle->oidc->response, attr->name, value);
1740 GNUNET_free (tmp_value);
1744 * Responds to userinfo GET and url-encoded POST request
1746 * @param con_handle the connection handle
1747 * @param url the url
1748 * @param cls the RequestHandle
1751 userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1752 const char *url, void *cls)
1754 // TODO expiration time
1755 struct RequestHandle *handle = cls;
1756 char delimiter[] = " ";
1757 char delimiter_db[] = ";";
1758 struct GNUNET_HashCode cache_key;
1759 char *authorization, *authorization_type, *authorization_access_token;
1760 char *client_ticket, *client, *ticket_str;
1761 struct GNUNET_RECLAIM_Ticket *ticket;
1763 GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY,
1764 strlen (OIDC_AUTHORIZATION_HEADER_KEY), &cache_key);
1765 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (
1766 handle->rest_handle->header_param_map, &cache_key)) {
1767 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
1768 handle->edesc = GNUNET_strdup ("No Access Token");
1769 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1770 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
1773 authorization = GNUNET_CONTAINER_multihashmap_get (
1774 handle->rest_handle->header_param_map, &cache_key);
1776 // split header in "Bearer" and access_token
1777 authorization = GNUNET_strdup (authorization);
1778 authorization_type = strtok (authorization, delimiter);
1779 if (0 != strcmp ("Bearer", authorization_type)) {
1780 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
1781 handle->edesc = GNUNET_strdup ("No Access Token");
1782 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1783 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
1784 GNUNET_free (authorization);
1787 authorization_access_token = strtok (NULL, delimiter);
1788 if (NULL == authorization_access_token) {
1789 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
1790 handle->edesc = GNUNET_strdup ("No Access Token");
1791 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1792 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
1793 GNUNET_free (authorization);
1797 GNUNET_CRYPTO_hash (authorization_access_token,
1798 strlen (authorization_access_token), &cache_key);
1799 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (
1800 OIDC_access_token_map, &cache_key)) {
1801 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
1802 handle->edesc = GNUNET_strdup ("The Access Token expired");
1803 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1804 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
1805 GNUNET_free (authorization);
1810 GNUNET_CONTAINER_multihashmap_get (OIDC_access_token_map, &cache_key);
1811 client_ticket = GNUNET_strdup (client_ticket);
1812 client = strtok (client_ticket, delimiter_db);
1813 if (NULL == client) {
1814 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
1815 handle->edesc = GNUNET_strdup ("The Access Token expired");
1816 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1817 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
1818 GNUNET_free (authorization);
1819 GNUNET_free (client_ticket);
1822 handle->ego_entry = handle->ego_head;
1823 for (; NULL != handle->ego_entry;
1824 handle->ego_entry = handle->ego_entry->next) {
1825 if (0 == strcmp (handle->ego_entry->keystring, client))
1828 if (NULL == handle->ego_entry) {
1829 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
1830 handle->edesc = GNUNET_strdup ("The Access Token expired");
1831 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1832 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
1833 GNUNET_free (authorization);
1834 GNUNET_free (client_ticket);
1837 ticket_str = strtok (NULL, delimiter_db);
1838 if (NULL == ticket_str) {
1839 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
1840 handle->edesc = GNUNET_strdup ("The Access Token expired");
1841 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1842 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
1843 GNUNET_free (authorization);
1844 GNUNET_free (client_ticket);
1847 ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket);
1849 GNUNET_STRINGS_string_to_data (ticket_str, strlen (ticket_str), ticket,
1850 sizeof (struct GNUNET_RECLAIM_Ticket))) {
1851 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
1852 handle->edesc = GNUNET_strdup ("The Access Token expired");
1853 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1854 GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
1855 GNUNET_free (ticket);
1856 GNUNET_free (authorization);
1857 GNUNET_free (client_ticket);
1861 handle->idp = GNUNET_RECLAIM_connect (cfg);
1862 handle->oidc->response = json_object ();
1863 json_object_set_new (handle->oidc->response, "sub",
1864 json_string (handle->ego_entry->keystring));
1865 handle->idp_op = GNUNET_RECLAIM_ticket_consume (
1866 handle->idp, GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego),
1867 ticket, consume_ticket, handle);
1868 GNUNET_free (ticket);
1869 GNUNET_free (authorization);
1870 GNUNET_free (client_ticket);
1875 * Handle rest request
1877 * @param handle the request handle
1880 init_cont (struct RequestHandle *handle)
1882 struct GNUNET_REST_RequestHandlerError err;
1883 static const struct GNUNET_REST_RequestHandler handlers[] = {
1884 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint},
1885 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_AUTHORIZE,
1886 &authorize_endpoint}, // url-encoded
1887 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont},
1888 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint},
1889 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint},
1890 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint},
1891 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont},
1892 GNUNET_REST_HANDLER_END};
1894 if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, handlers,
1896 handle->response_code = err.error_code;
1897 GNUNET_SCHEDULER_add_now (&do_error, handle);
1902 * If listing is enabled, prints information about the egos.
1904 * This function is initially called for all egos and then again
1905 * whenever a ego's identifier changes or if it is deleted. At the
1906 * end of the initial pass over all egos, the function is once called
1907 * with 'NULL' for 'ego'. That does NOT mean that the callback won't
1908 * be invoked in the future or that there was an error.
1910 * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get',
1911 * this function is only called ONCE, and 'NULL' being passed in
1912 * 'ego' does indicate an error (i.e. name is taken or no default
1913 * value is known). If 'ego' is non-NULL and if '*ctx'
1914 * is set in those callbacks, the value WILL be passed to a subsequent
1915 * call to the identity callback of 'GNUNET_IDENTITY_connect' (if
1916 * that one was not NULL).
1918 * When an identity is renamed, this function is called with the
1919 * (known) ego but the NEW identifier.
1921 * When an identity is deleted, this function is called with the
1922 * (known) ego and "NULL" for the 'identifier'. In this case,
1923 * the 'ego' is henceforth invalid (and the 'ctx' should also be
1926 * @param cls closure
1927 * @param ego ego handle
1928 * @param ctx context for application to store data for this ego
1929 * (during the lifetime of this process, initially NULL)
1930 * @param identifier identifier assigned by the user for this ego,
1931 * NULL if the user just deleted the ego and it
1932 * must thus no longer be used
1935 list_ego (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx,
1936 const char *identifier)
1938 struct RequestHandle *handle = cls;
1939 struct EgoEntry *ego_entry;
1940 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
1942 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) {
1943 handle->state = ID_REST_STATE_POST_INIT;
1947 if (ID_REST_STATE_INIT == handle->state) {
1948 ego_entry = GNUNET_new (struct EgoEntry);
1949 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
1950 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
1951 ego_entry->ego = ego;
1952 ego_entry->identifier = GNUNET_strdup (identifier);
1953 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, handle->ego_tail,
1957 /* Ego renamed or added */
1958 if (identifier != NULL) {
1959 for (ego_entry = handle->ego_head; NULL != ego_entry;
1960 ego_entry = ego_entry->next) {
1961 if (ego_entry->ego == ego) {
1963 GNUNET_free (ego_entry->identifier);
1964 ego_entry->identifier = GNUNET_strdup (identifier);
1968 if (NULL == ego_entry) {
1970 ego_entry = GNUNET_new (struct EgoEntry);
1971 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
1972 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
1973 ego_entry->ego = ego;
1974 ego_entry->identifier = GNUNET_strdup (identifier);
1975 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, handle->ego_tail,
1980 for (ego_entry = handle->ego_head; NULL != ego_entry;
1981 ego_entry = ego_entry->next) {
1982 if (ego_entry->ego == ego)
1985 if (NULL != ego_entry)
1986 GNUNET_CONTAINER_DLL_remove (handle->ego_head, handle->ego_tail,
1992 rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1993 GNUNET_REST_ResultProcessor proc, void *proc_cls)
1995 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1996 handle->oidc = GNUNET_new (struct OIDC_Variables);
1997 if (NULL == OIDC_cookie_jar_map)
1998 OIDC_cookie_jar_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
1999 if (NULL == OIDC_identity_grants)
2000 OIDC_identity_grants = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
2001 if (NULL == OIDC_used_ticket_map)
2002 OIDC_used_ticket_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
2003 if (NULL == OIDC_access_token_map)
2004 OIDC_access_token_map =
2005 GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
2006 handle->response_code = 0;
2007 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
2008 handle->proc_cls = proc_cls;
2009 handle->proc = proc;
2010 handle->state = ID_REST_STATE_INIT;
2011 handle->rest_handle = rest_handle;
2013 handle->url = GNUNET_strdup (rest_handle->url);
2014 if (handle->url[strlen (handle->url) - 1] == '/')
2015 handle->url[strlen (handle->url) - 1] = '\0';
2016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
2017 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle);
2018 handle->gns_handle = GNUNET_GNS_connect (cfg);
2019 handle->namestore_handle = GNUNET_NAMESTORE_connect (cfg);
2020 handle->timeout_task =
2021 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
2022 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
2026 * Entry point for the plugin.
2028 * @param cls Config info
2029 * @return NULL on error, otherwise the plugin context
2032 libgnunet_plugin_rest_openid_connect_init (void *cls)
2034 static struct Plugin plugin;
2035 struct GNUNET_REST_Plugin *api;
2038 if (NULL != plugin.cfg)
2039 return NULL; /* can only initialize once! */
2040 memset (&plugin, 0, sizeof (struct Plugin));
2042 api = GNUNET_new (struct GNUNET_REST_Plugin);
2044 api->name = GNUNET_REST_API_NS_OIDC;
2045 api->process_request = &rest_identity_process_request;
2046 GNUNET_asprintf (&allow_methods, "%s, %s, %s, %s, %s", MHD_HTTP_METHOD_GET,
2047 MHD_HTTP_METHOD_POST, MHD_HTTP_METHOD_PUT,
2048 MHD_HTTP_METHOD_DELETE, MHD_HTTP_METHOD_OPTIONS);
2050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2051 _ ("Identity Provider REST API initialized\n"));
2057 * Exit point from the plugin.
2059 * @param cls the plugin context (as returned by "init")
2060 * @return always NULL
2063 libgnunet_plugin_rest_openid_connect_done (void *cls)
2065 struct GNUNET_REST_Plugin *api = cls;
2066 struct Plugin *plugin = api->cls;
2069 struct GNUNET_CONTAINER_MultiHashMapIterator *hashmap_it;
2072 GNUNET_CONTAINER_multihashmap_iterator_create (OIDC_cookie_jar_map);
2073 while (GNUNET_YES ==
2074 GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL, value))
2075 GNUNET_free_non_null (value);
2076 GNUNET_CONTAINER_multihashmap_destroy (OIDC_cookie_jar_map);
2079 GNUNET_CONTAINER_multihashmap_iterator_create (OIDC_identity_grants);
2080 while (GNUNET_YES ==
2081 GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL, value))
2082 GNUNET_free_non_null (value);
2083 GNUNET_CONTAINER_multihashmap_destroy (OIDC_identity_grants);
2086 GNUNET_CONTAINER_multihashmap_iterator_create (OIDC_used_ticket_map);
2087 while (GNUNET_YES ==
2088 GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL, value))
2089 GNUNET_free_non_null (value);
2090 GNUNET_CONTAINER_multihashmap_destroy (OIDC_used_ticket_map);
2093 GNUNET_CONTAINER_multihashmap_iterator_create (OIDC_access_token_map);
2094 while (GNUNET_YES ==
2095 GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL, value))
2096 GNUNET_free_non_null (value);
2097 GNUNET_CONTAINER_multihashmap_destroy (OIDC_access_token_map);
2098 GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it);
2099 GNUNET_free_non_null (allow_methods);
2101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2102 "Identity Provider REST plugin is finished\n");
2106 /* end of plugin_rest_identity_provider.c */