obsolete due to alpine policy
[oweals/gnunet.git] / src / reclaim / plugin_rest_openid_connect.c
index bf1e950da7acb46fbe74748609a879a9af148da1..a4a368ab58154035e5811d6da87966e127d47d6a 100644 (file)
@@ -16,7 +16,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
    SPDX-License-Identifier: AGPL3.0-or-later
  */
+ */
 /**
  * @author Martin Schanzenbach
  * @author Philippe Buschmann
 /**
  * OIDC ignored parameter array
  */
-static char *OIDC_ignored_parameter_array[] = {"display",
-                                               "prompt",
-                                               "ui_locales",
-                                               "response_mode",
-                                               "id_token_hint",
-                                               "login_hint",
-                                               "acr_values"};
+static char *OIDC_ignored_parameter_array[] = { "display",
+                                                "prompt",
+                                                "ui_locales",
+                                                "response_mode",
+                                                "id_token_hint",
+                                                "login_hint",
+                                                "acr_values" };
 
 /**
  * OIDC Hash map that keeps track of issued cookies
@@ -517,6 +517,7 @@ cleanup_handle (struct RequestHandle *handle)
   struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp;
   struct EgoEntry *ego_entry;
   struct EgoEntry *ego_tmp;
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
   if (NULL != handle->timeout_task)
     GNUNET_SCHEDULER_cancel (handle->timeout_task);
@@ -651,6 +652,7 @@ do_redirect_error (void *cls)
   struct RequestHandle *handle = cls;
   struct MHD_Response *resp;
   char *redirect;
+
   GNUNET_asprintf (&redirect,
                    "%s?error=%s&error_description=%s%s%s",
                    handle->oidc->redirect_uri,
@@ -743,7 +745,7 @@ cookie_identity_interpretation (struct RequestHandle *handle)
                       strlen (OIDC_COOKIE_HEADER_KEY),
                       &cache_key);
   if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
-                                                             ->header_param_map,
+                                                           ->header_param_map,
                                                            &cache_key))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No cookie found\n");
@@ -845,7 +847,8 @@ login_redirect (void *cls)
                      OIDC_STATE_KEY,
                      (NULL != handle->oidc->state) ? handle->oidc->state : "",
                      OIDC_CODE_CHALLENGE_KEY,
-                     (NULL != handle->oidc->code_challenge) ? handle->oidc->code_challenge : "",
+                     (NULL != handle->oidc->code_challenge) ?
+                     handle->oidc->code_challenge : "",
                      OIDC_NONCE_KEY,
                      (NULL != handle->oidc->nonce) ? handle->oidc->nonce : "");
     resp = GNUNET_REST_create_response ("");
@@ -872,6 +875,7 @@ static void
 oidc_iteration_error (void *cls)
 {
   struct RequestHandle *handle = cls;
+
   handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
   handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
   GNUNET_SCHEDULER_add_now (&do_error, handle);
@@ -902,7 +906,7 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
   handle->ticket = *ticket;
   ticket_str =
     GNUNET_STRINGS_data_to_string_alloc (&handle->ticket,
-                                         sizeof (struct GNUNET_RECLAIM_Ticket));
+                                         sizeof(struct GNUNET_RECLAIM_Ticket));
   // TODO change if more attributes are needed (see max_age)
   code_string = OIDC_build_authz_code (&handle->priv_key,
                                        &handle->ticket,
@@ -912,7 +916,6 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
   if ((NULL != handle->redirect_prefix) && (NULL != handle->redirect_suffix) &&
       (NULL != handle->tld))
   {
-
     GNUNET_asprintf (&redirect_uri,
                      "%s.%s/%s?%s=%s&state=%s",
                      handle->redirect_prefix,
@@ -944,6 +947,7 @@ static void
 oidc_collect_finished_cb (void *cls)
 {
   struct RequestHandle *handle = cls;
+
   handle->attr_it = NULL;
   handle->ticket_it = NULL;
   if (NULL == handle->attr_list->list_head)
@@ -1043,10 +1047,10 @@ code_redirect (void *cls)
     {
       if (GNUNET_OK !=
           GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc
-                                                        ->login_identity,
+                                                      ->login_identity,
                                                       strlen (
                                                         handle->oidc
-                                                          ->login_identity),
+                                                        ->login_identity),
                                                       &pubkey))
       {
         handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_COOKIE);
@@ -1190,7 +1194,7 @@ lookup_redirect_uri_result (void *cls,
       GNUNET_STRINGS_string_to_data (tmp_key_str,
                                      strlen (tmp_key_str),
                                      &redirect_zone,
-                                     sizeof (redirect_zone));
+                                     sizeof(redirect_zone));
     }
     GNUNET_SCHEDULER_add_now (&build_redirect, handle);
     GNUNET_free (tmp);
@@ -1227,9 +1231,10 @@ get_url_parameter_copy (const struct RequestHandle *handle, const char *key)
 {
   struct GNUNET_HashCode hc;
   char *value;
+
   GNUNET_CRYPTO_hash (key, strlen (key), &hc);
   if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
-                                                              ->url_param_map,
+                                                            ->url_param_map,
                                                             &hc))
     return NULL;
   value =
@@ -1294,7 +1299,7 @@ build_authz_response (void *cls)
 
   // TODO check other values if needed
   number_of_ignored_parameter =
-    sizeof (OIDC_ignored_parameter_array) / sizeof (char *);
+    sizeof(OIDC_ignored_parameter_array) / sizeof(char *);
   for (iterator = 0; iterator < number_of_ignored_parameter; iterator++)
   {
     GNUNET_CRYPTO_hash (OIDC_ignored_parameter_array[iterator],
@@ -1302,7 +1307,7 @@ build_authz_response (void *cls)
                         &cache_key);
     if (GNUNET_YES ==
         GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
-                                                  ->url_param_map,
+                                                ->url_param_map,
                                                 &cache_key))
     {
       handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_ACCESS_DENIED);
@@ -1406,11 +1411,12 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
   }
 
   // OPTIONAL value: code_challenge
-  handle->oidc->code_challenge = get_url_parameter_copy (handle, OIDC_CODE_CHALLENGE_KEY);
+  handle->oidc->code_challenge = get_url_parameter_copy (handle,
+                                                         OIDC_CODE_CHALLENGE_KEY);
   if (NULL == handle->oidc->code_challenge)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-        "OAuth authorization request does not contain PKCE parameters!\n");
+                "OAuth authorization request does not contain PKCE parameters!\n");
   }
 
   if (GNUNET_OK !=
@@ -1469,6 +1475,7 @@ login_cont (struct GNUNET_REST_RequestHandle *con_handle,
   json_error_t error;
   json_t *identity;
   char term_data[handle->rest_handle->data_size + 1];
+
   term_data[handle->rest_handle->data_size] = '\0';
   GNUNET_memcpy (term_data,
                  handle->rest_handle->data,
@@ -1531,7 +1538,7 @@ check_authorization (struct RequestHandle *handle,
                       strlen (OIDC_AUTHORIZATION_HEADER_KEY),
                       &cache_key);
   if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
-                                                             ->header_param_map,
+                                                           ->header_param_map,
                                                            &cache_key))
   {
     handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
@@ -1627,7 +1634,7 @@ check_authorization (struct RequestHandle *handle,
   GNUNET_STRINGS_string_to_data (client_id,
                                  strlen (client_id),
                                  cid,
-                                 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
+                                 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
 
   GNUNET_free (basic_authorization);
   return GNUNET_OK;
@@ -1698,6 +1705,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
   char *jwt_secret;
   char *nonce;
   char *code_verifier;
+
   /*
    * Check Authorization
    */
@@ -1764,15 +1772,14 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
   code_verifier = get_url_parameter_copy (handle, OIDC_CODE_VERIFIER_KEY);
   if (NULL == code_verifier)
   {
-    handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
-    handle->edesc = GNUNET_strdup ("missing parameter code_verifier");
-    handle->response_code = MHD_HTTP_BAD_REQUEST;
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "OAuth authorization request does not contain PKCE parameters!\n");
+
   }
 
   // decode code
-  if (GNUNET_OK != OIDC_parse_authz_code (privkey, code, code_verifier, &ticket, &cl, &nonce))
+  if (GNUNET_OK != OIDC_parse_authz_code (privkey, code, code_verifier, &ticket,
+                                          &cl, &nonce))
   {
     handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
     handle->edesc = GNUNET_strdup ("invalid code");
@@ -1886,7 +1893,7 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
                       strlen (OIDC_AUTHORIZATION_HEADER_KEY),
                       &cache_key);
   if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
-                                                             ->header_param_map,
+                                                           ->header_param_map,
                                                            &cache_key))
   {
     handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
@@ -1976,16 +1983,16 @@ init_cont (struct RequestHandle *handle)
 {
   struct GNUNET_REST_RequestHandlerError err;
   static const struct GNUNET_REST_RequestHandler handlers[] =
-    {{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint},
-     {MHD_HTTP_METHOD_POST,
+  { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint },
+    MHD_HTTP_METHOD_POST,
       GNUNET_REST_API_NS_AUTHORIZE,
-      &authorize_endpoint}, // url-encoded
-     {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont},
-     {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint},
-     {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint},
-     {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint},
-     {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont},
-     GNUNET_REST_HANDLER_END};
+      &authorize_endpoint },   // url-encoded
+    { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont },
+    { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint },
+    { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
+    { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
+    { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont },
+    GNUNET_REST_HANDLER_END };
 
   if (GNUNET_NO ==
       GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
@@ -2107,6 +2114,7 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
                                void *proc_cls)
 {
   struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
+
   handle->oidc = GNUNET_new (struct OIDC_Variables);
   if (NULL == OIDC_cookie_jar_map)
     OIDC_cookie_jar_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
@@ -2147,7 +2155,7 @@ libgnunet_plugin_rest_openid_connect_init (void *cls)
   cfg = cls;
   if (NULL != plugin.cfg)
     return NULL; /* can only initialize once! */
-  memset (&plugin, 0, sizeof (struct Plugin));
+  memset (&plugin, 0, sizeof(struct Plugin));
   plugin.cfg = cfg;
   api = GNUNET_new (struct GNUNET_REST_Plugin);
   api->cls = &plugin;
@@ -2178,6 +2186,7 @@ libgnunet_plugin_rest_openid_connect_done (void *cls)
 {
   struct GNUNET_REST_Plugin *api = cls;
   struct Plugin *plugin = api->cls;
+
   plugin->cfg = NULL;
 
   struct GNUNET_CONTAINER_MultiHashMapIterator *hashmap_it;