-wip token endpoint refactor
authorPhil <phil.buschmann@tum.de>
Mon, 12 Feb 2018 13:57:28 +0000 (14:57 +0100)
committerPhil <phil.buschmann@tum.de>
Mon, 12 Feb 2018 13:57:28 +0000 (14:57 +0100)
src/identity-provider/jwt.c
src/identity-provider/plugin_rest_identity_provider.c
src/rest/gnunet-rest-server.c

index ede5424c8e06de45ff99c40789d0c65dadadf369..ff3676cb6a755764999f53f6fdcbb4e2807ebe58 100644 (file)
@@ -33,7 +33,7 @@
 #define JWT_ALG "alg"
 
 /*TODO is this the correct way to define new algs? */
-#define JWT_ALG_VALUE "ED512"
+#define JWT_ALG_VALUE "urn:org:gnunet:jwt:alg:ecdsa:ed25519"
 
 #define JWT_TYP "typ"
 
index 8011d8da5e5a576e87a312de37a84d9a7e0d3c4c..326313a13d88bf8deda423cc472c2723819860e6 100644 (file)
@@ -607,6 +607,17 @@ return_response (void *cls)
   cleanup_handle (handle);
 }
 
+static void
+base_64_encode(char *string, char *output)
+{
+  GNUNET_STRINGS_base64_encode(string,strlen(string),&output);
+  char delimiter[] = "=";
+  output = strtok (output, delimiter);
+  while (NULL != output)
+  {
+    output = strtok (NULL, delimiter);
+  }
+}
 
 static void
 collect_finished_cb (void *cls)
@@ -1378,13 +1389,16 @@ oidc_ticket_issue_cb (void* cls,
 //    {
 //      json_object_set_new(object,"nonce",json_string(handle->oidc->nonce));
 //    }
+    //TODO change
     GNUNET_asprintf (&code_json_string, "{\"ticket\":\"%s\"%s%s%s}",
                     ticket_str,
                     (NULL != handle->oidc->nonce) ? ", \"nonce\":\"" : "",
                     (NULL != handle->oidc->nonce) ? handle->oidc->nonce : "",
                     (NULL != handle->oidc->nonce) ? "\"" : "");
     GNUNET_STRINGS_base64_encode(code_json_string,strlen(code_json_string),&code_base64_final_string);
-
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", code_base64_final_string);
+    base_64_encode(code_json_string, code_base64_final_string);
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", code_base64_final_string);
     GNUNET_asprintf (&redirect_uri, "%s?%s=%s&state=%s",
                     handle->oidc->redirect_uri,
                     handle->oidc->response_type,
@@ -1894,21 +1908,22 @@ consume_ticket (void *cls,
 
   if (NULL == identity)
   {
-    GNUNET_SCHEDULER_add_now (&return_response, handle);
+    GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle);
+//    GNUNET_SCHEDULER_add_now (&return_response, handle);
     return;
   }
 
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding attribute: %s\n",
               attr->name);
-  json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE,
-                                               attr->name);
-  GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource);
-
-  value = json_string (attr->data);
-  GNUNET_JSONAPI_resource_add_attr (json_resource,
-                                    "value",
-                                    value);
-  json_decref (value);
+//  json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE,
+//                                               attr->name);
+//  GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource);
+//
+//  value = json_string (attr->data);
+//  GNUNET_JSONAPI_resource_add_attr (json_resource,
+//                                    "value",
+//                                    value);
+//  json_decref (value);
 }
 
 static void
@@ -1946,9 +1961,9 @@ token_cont(struct GNUNET_REST_RequestHandle *con_handle,
   }
   authorization = GNUNET_CONTAINER_multihashmap_get ( handle->rest_handle->header_param_map, &cache_key);
 
+  //TODO authorization pointer will be moved as well
   //split header in "Basic" and [content]
-  credentials = GNUNET_strdup(authorization);
-  credentials = strtok (credentials, delimiter);
+  credentials = strtok (authorization, delimiter);
   if( NULL != credentials)
   {
     credentials = strtok(NULL, delimiter);
@@ -2232,27 +2247,27 @@ token_cont(struct GNUNET_REST_RequestHandle *con_handle,
                   id_token);
 
   resp = GNUNET_REST_create_response (json_error);
-
   MHD_add_response_header (resp, "Cache-Control", "no-store");
   MHD_add_response_header (resp, "Pragma", "no-cache");
   MHD_add_response_header (resp, "Content-Type", "application/json");
   handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
 
-  //necessary? should be
-//  handle->idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume(handle->idp,GNUNET_IDENTITY_ego_get_private_key(handle->ego_entry->ego),ticket,consume_cont, handle);
   GNUNET_IDENTITY_ATTRIBUTE_list_destroy(cl);
   //TODO write method
-  handle->resp_object = GNUNET_JSONAPI_document_new ();
   handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg);
-  handle->idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume(handle->idp,GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego),ticket,consume_ticket,handle);
+  handle->idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume (handle->idp,
+                                                           GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego),
+                                                           ticket,
+                                                           consume_ticket,
+                                                           handle);
   GNUNET_free(access_token_number);
-//  GNUNET_free(credentials);
   GNUNET_free(access_token);
   GNUNET_free(user_psw);
-//  GNUNET_free(code);
+  GNUNET_free(json_error);
+  GNUNET_free(ticket);
+  GNUNET_free(output);
   GNUNET_free(id_token);
   json_decref(root);
-//  GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
 }
 
 /**
index 8e6688b5ae39475d7b8f8799e1e4cf72f03195dd..4313f07a25750c38ef424a6b26bbafdcb05baf36 100644 (file)
@@ -410,14 +410,8 @@ create_response (void *cls,
     {
       MHD_post_process(con_handle->pp, upload_data, *upload_data_size);
     }
-    else
-    {
-      MHD_destroy_post_processor(con_handle->pp);
-    }
-    MHD_get_connection_values (con,
-                               MHD_HEADER_KIND,
-                               &header_iterator,
-                               rest_conndata_handle);
+    MHD_destroy_post_processor(con_handle->pp);
+
     con_handle->state = GN_REST_STATE_PROCESSING;
     con_handle->plugin->process_request (rest_conndata_handle,
                                          &plugin_callback,
@@ -648,7 +642,7 @@ do_accept (void *cls)
                 _("Failed to pass client to MHD\n"));
     return;
   }
-
+  GNUNET_free(s);
   schedule_httpd ();
 }