aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-02-12 14:57:28 +0100
committerPhil <phil.buschmann@tum.de>2018-02-12 14:57:28 +0100
commitfaf1fef1ed824ca5f7692ac8a6a50f5f35352b0e (patch)
treef0e6b6293ec0fc798ada56ab2382ca1ebbf55c45 /src
parent0166171bb810849613164867bc3450bf5bf73a5a (diff)
downloadgnunet-faf1fef1ed824ca5f7692ac8a6a50f5f35352b0e.tar.gz
gnunet-faf1fef1ed824ca5f7692ac8a6a50f5f35352b0e.zip
-wip token endpoint refactor
Diffstat (limited to 'src')
-rw-r--r--src/identity-provider/jwt.c2
-rw-r--r--src/identity-provider/plugin_rest_identity_provider.c57
-rw-r--r--src/rest/gnunet-rest-server.c12
3 files changed, 40 insertions, 31 deletions
diff --git a/src/identity-provider/jwt.c b/src/identity-provider/jwt.c
index ede5424c8..ff3676cb6 100644
--- a/src/identity-provider/jwt.c
+++ b/src/identity-provider/jwt.c
@@ -33,7 +33,7 @@
33#define JWT_ALG "alg" 33#define JWT_ALG "alg"
34 34
35/*TODO is this the correct way to define new algs? */ 35/*TODO is this the correct way to define new algs? */
36#define JWT_ALG_VALUE "ED512" 36#define JWT_ALG_VALUE "urn:org:gnunet:jwt:alg:ecdsa:ed25519"
37 37
38#define JWT_TYP "typ" 38#define JWT_TYP "typ"
39 39
diff --git a/src/identity-provider/plugin_rest_identity_provider.c b/src/identity-provider/plugin_rest_identity_provider.c
index 8011d8da5..326313a13 100644
--- a/src/identity-provider/plugin_rest_identity_provider.c
+++ b/src/identity-provider/plugin_rest_identity_provider.c
@@ -607,6 +607,17 @@ return_response (void *cls)
607 cleanup_handle (handle); 607 cleanup_handle (handle);
608} 608}
609 609
610static void
611base_64_encode(char *string, char *output)
612{
613 GNUNET_STRINGS_base64_encode(string,strlen(string),&output);
614 char delimiter[] = "=";
615 output = strtok (output, delimiter);
616 while (NULL != output)
617 {
618 output = strtok (NULL, delimiter);
619 }
620}
610 621
611static void 622static void
612collect_finished_cb (void *cls) 623collect_finished_cb (void *cls)
@@ -1378,13 +1389,16 @@ oidc_ticket_issue_cb (void* cls,
1378// { 1389// {
1379// json_object_set_new(object,"nonce",json_string(handle->oidc->nonce)); 1390// json_object_set_new(object,"nonce",json_string(handle->oidc->nonce));
1380// } 1391// }
1392 //TODO change
1381 GNUNET_asprintf (&code_json_string, "{\"ticket\":\"%s\"%s%s%s}", 1393 GNUNET_asprintf (&code_json_string, "{\"ticket\":\"%s\"%s%s%s}",
1382 ticket_str, 1394 ticket_str,
1383 (NULL != handle->oidc->nonce) ? ", \"nonce\":\"" : "", 1395 (NULL != handle->oidc->nonce) ? ", \"nonce\":\"" : "",
1384 (NULL != handle->oidc->nonce) ? handle->oidc->nonce : "", 1396 (NULL != handle->oidc->nonce) ? handle->oidc->nonce : "",
1385 (NULL != handle->oidc->nonce) ? "\"" : ""); 1397 (NULL != handle->oidc->nonce) ? "\"" : "");
1386 GNUNET_STRINGS_base64_encode(code_json_string,strlen(code_json_string),&code_base64_final_string); 1398 GNUNET_STRINGS_base64_encode(code_json_string,strlen(code_json_string),&code_base64_final_string);
1387 1399 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", code_base64_final_string);
1400 base_64_encode(code_json_string, code_base64_final_string);
1401 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", code_base64_final_string);
1388 GNUNET_asprintf (&redirect_uri, "%s?%s=%s&state=%s", 1402 GNUNET_asprintf (&redirect_uri, "%s?%s=%s&state=%s",
1389 handle->oidc->redirect_uri, 1403 handle->oidc->redirect_uri,
1390 handle->oidc->response_type, 1404 handle->oidc->response_type,
@@ -1894,21 +1908,22 @@ consume_ticket (void *cls,
1894 1908
1895 if (NULL == identity) 1909 if (NULL == identity)
1896 { 1910 {
1897 GNUNET_SCHEDULER_add_now (&return_response, handle); 1911 GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle);
1912// GNUNET_SCHEDULER_add_now (&return_response, handle);
1898 return; 1913 return;
1899 } 1914 }
1900 1915
1901 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding attribute: %s\n", 1916 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding attribute: %s\n",
1902 attr->name); 1917 attr->name);
1903 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE, 1918// json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE,
1904 attr->name); 1919// attr->name);
1905 GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource); 1920// GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource);
1906 1921//
1907 value = json_string (attr->data); 1922// value = json_string (attr->data);
1908 GNUNET_JSONAPI_resource_add_attr (json_resource, 1923// GNUNET_JSONAPI_resource_add_attr (json_resource,
1909 "value", 1924// "value",
1910 value); 1925// value);
1911 json_decref (value); 1926// json_decref (value);
1912} 1927}
1913 1928
1914static void 1929static void
@@ -1946,9 +1961,9 @@ token_cont(struct GNUNET_REST_RequestHandle *con_handle,
1946 } 1961 }
1947 authorization = GNUNET_CONTAINER_multihashmap_get ( handle->rest_handle->header_param_map, &cache_key); 1962 authorization = GNUNET_CONTAINER_multihashmap_get ( handle->rest_handle->header_param_map, &cache_key);
1948 1963
1964 //TODO authorization pointer will be moved as well
1949 //split header in "Basic" and [content] 1965 //split header in "Basic" and [content]
1950 credentials = GNUNET_strdup(authorization); 1966 credentials = strtok (authorization, delimiter);
1951 credentials = strtok (credentials, delimiter);
1952 if( NULL != credentials) 1967 if( NULL != credentials)
1953 { 1968 {
1954 credentials = strtok(NULL, delimiter); 1969 credentials = strtok(NULL, delimiter);
@@ -2232,27 +2247,27 @@ token_cont(struct GNUNET_REST_RequestHandle *con_handle,
2232 id_token); 2247 id_token);
2233 2248
2234 resp = GNUNET_REST_create_response (json_error); 2249 resp = GNUNET_REST_create_response (json_error);
2235
2236 MHD_add_response_header (resp, "Cache-Control", "no-store"); 2250 MHD_add_response_header (resp, "Cache-Control", "no-store");
2237 MHD_add_response_header (resp, "Pragma", "no-cache"); 2251 MHD_add_response_header (resp, "Pragma", "no-cache");
2238 MHD_add_response_header (resp, "Content-Type", "application/json"); 2252 MHD_add_response_header (resp, "Content-Type", "application/json");
2239 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 2253 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
2240 2254
2241 //necessary? should be
2242// handle->idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume(handle->idp,GNUNET_IDENTITY_ego_get_private_key(handle->ego_entry->ego),ticket,consume_cont, handle);
2243 GNUNET_IDENTITY_ATTRIBUTE_list_destroy(cl); 2255 GNUNET_IDENTITY_ATTRIBUTE_list_destroy(cl);
2244 //TODO write method 2256 //TODO write method
2245 handle->resp_object = GNUNET_JSONAPI_document_new ();
2246 handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); 2257 handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg);
2247 handle->idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume(handle->idp,GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego),ticket,consume_ticket,handle); 2258 handle->idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume (handle->idp,
2259 GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego),
2260 ticket,
2261 consume_ticket,
2262 handle);
2248 GNUNET_free(access_token_number); 2263 GNUNET_free(access_token_number);
2249// GNUNET_free(credentials);
2250 GNUNET_free(access_token); 2264 GNUNET_free(access_token);
2251 GNUNET_free(user_psw); 2265 GNUNET_free(user_psw);
2252// GNUNET_free(code); 2266 GNUNET_free(json_error);
2267 GNUNET_free(ticket);
2268 GNUNET_free(output);
2253 GNUNET_free(id_token); 2269 GNUNET_free(id_token);
2254 json_decref(root); 2270 json_decref(root);
2255// GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
2256} 2271}
2257 2272
2258/** 2273/**
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c
index 8e6688b5a..4313f07a2 100644
--- a/src/rest/gnunet-rest-server.c
+++ b/src/rest/gnunet-rest-server.c
@@ -410,14 +410,8 @@ create_response (void *cls,
410 { 410 {
411 MHD_post_process(con_handle->pp, upload_data, *upload_data_size); 411 MHD_post_process(con_handle->pp, upload_data, *upload_data_size);
412 } 412 }
413 else 413 MHD_destroy_post_processor(con_handle->pp);
414 { 414
415 MHD_destroy_post_processor(con_handle->pp);
416 }
417 MHD_get_connection_values (con,
418 MHD_HEADER_KIND,
419 &header_iterator,
420 rest_conndata_handle);
421 con_handle->state = GN_REST_STATE_PROCESSING; 415 con_handle->state = GN_REST_STATE_PROCESSING;
422 con_handle->plugin->process_request (rest_conndata_handle, 416 con_handle->plugin->process_request (rest_conndata_handle,
423 &plugin_callback, 417 &plugin_callback,
@@ -648,7 +642,7 @@ do_accept (void *cls)
648 _("Failed to pass client to MHD\n")); 642 _("Failed to pass client to MHD\n"));
649 return; 643 return;
650 } 644 }
651 645 GNUNET_free(s);
652 schedule_httpd (); 646 schedule_httpd ();
653} 647}
654 648