aboutsummaryrefslogtreecommitdiff
path: root/src/identity-provider/plugin_rest_identity_provider.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-03-05 19:39:56 +0100
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-03-05 19:39:56 +0100
commitbb5a41d072ab7964006cb68a45e043d856cb630e (patch)
treefd2fbf5bd6fdace3892a1ba2bdb712c81a485232 /src/identity-provider/plugin_rest_identity_provider.c
parentd036b626b8eea15f99d91faf309843936289fde7 (diff)
downloadgnunet-bb5a41d072ab7964006cb68a45e043d856cb630e.tar.gz
gnunet-bb5a41d072ab7964006cb68a45e043d856cb630e.zip
start fixing gns
Diffstat (limited to 'src/identity-provider/plugin_rest_identity_provider.c')
-rw-r--r--src/identity-provider/plugin_rest_identity_provider.c76
1 files changed, 40 insertions, 36 deletions
diff --git a/src/identity-provider/plugin_rest_identity_provider.c b/src/identity-provider/plugin_rest_identity_provider.c
index 3f9279d5c..7b4ebf2fc 100644
--- a/src/identity-provider/plugin_rest_identity_provider.c
+++ b/src/identity-provider/plugin_rest_identity_provider.c
@@ -409,6 +409,11 @@ struct RequestHandle
409 char *url; 409 char *url;
410 410
411 /** 411 /**
412 * The tld for redirect
413 */
414 char *tld;
415
416 /**
412 * Error response message 417 * Error response message
413 */ 418 */
414 char *emsg; 419 char *emsg;
@@ -457,6 +462,8 @@ cleanup_handle (struct RequestHandle *handle)
457 GNUNET_IDENTITY_PROVIDER_disconnect (handle->idp); 462 GNUNET_IDENTITY_PROVIDER_disconnect (handle->idp);
458 if (NULL != handle->url) 463 if (NULL != handle->url)
459 GNUNET_free (handle->url); 464 GNUNET_free (handle->url);
465 if (NULL != handle->tld)
466 GNUNET_free (handle->tld);
460 if (NULL != handle->emsg) 467 if (NULL != handle->emsg)
461 GNUNET_free (handle->emsg); 468 GNUNET_free (handle->emsg);
462 if (NULL != handle->edesc) 469 if (NULL != handle->edesc)
@@ -1463,6 +1470,8 @@ static void get_client_name_result (void *cls,
1463 char *code_base64_final_string; 1470 char *code_base64_final_string;
1464 char *redirect_path; 1471 char *redirect_path;
1465 char *tmp; 1472 char *tmp;
1473 char *tmp_prefix;
1474 char *prefix;
1466 ticket_str = GNUNET_STRINGS_data_to_string_alloc (&handle->ticket, 1475 ticket_str = GNUNET_STRINGS_data_to_string_alloc (&handle->ticket,
1467 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket)); 1476 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
1468 //TODO change if more attributes are needed (see max_age) 1477 //TODO change if more attributes are needed (see max_age)
@@ -1476,8 +1485,13 @@ static void get_client_name_result (void *cls,
1476 redirect_path = strtok (tmp, "/"); 1485 redirect_path = strtok (tmp, "/");
1477 redirect_path = strtok (NULL, "/"); 1486 redirect_path = strtok (NULL, "/");
1478 redirect_path = strtok (NULL, "/"); 1487 redirect_path = strtok (NULL, "/");
1479 GNUNET_asprintf (&redirect_uri, "https://%s.gnu/%s?%s=%s&state=%s", 1488 tmp_prefix = GNUNET_strdup (handle->oidc->redirect_uri);
1480 label, 1489 prefix = strrchr (tmp_prefix,
1490 (unsigned char) '.');
1491 *prefix = '\0';
1492 GNUNET_asprintf (&redirect_uri, "%s.%s/%s?%s=%s&state=%s",
1493 tmp_prefix,
1494 handle->tld,
1481 redirect_path, 1495 redirect_path,
1482 handle->oidc->response_type, 1496 handle->oidc->response_type,
1483 code_base64_final_string, handle->oidc->state); 1497 code_base64_final_string, handle->oidc->state);
@@ -1486,6 +1500,7 @@ static void get_client_name_result (void *cls,
1486 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); 1500 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
1487 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 1501 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
1488 GNUNET_free (tmp); 1502 GNUNET_free (tmp);
1503 GNUNET_free (tmp_prefix);
1489 GNUNET_free (redirect_uri); 1504 GNUNET_free (redirect_uri);
1490 GNUNET_free (ticket_str); 1505 GNUNET_free (ticket_str);
1491 GNUNET_free (code_json_string); 1506 GNUNET_free (code_json_string);
@@ -1730,7 +1745,6 @@ static void namestore_iteration_finished (void *cls)
1730 struct RequestHandle *handle = cls; 1745 struct RequestHandle *handle = cls;
1731 struct GNUNET_HashCode cache_key; 1746 struct GNUNET_HashCode cache_key;
1732 1747
1733 char *expected_redirect_uri;
1734 char *expected_scope; 1748 char *expected_scope;
1735 char delimiter[]=" "; 1749 char delimiter[]=" ";
1736 int number_of_ignored_parameter, iterator; 1750 int number_of_ignored_parameter, iterator;
@@ -1766,23 +1780,9 @@ static void namestore_iteration_finished (void *cls)
1766 GNUNET_SCHEDULER_add_now (&do_error, handle); 1780 GNUNET_SCHEDULER_add_now (&do_error, handle);
1767 return; 1781 return;
1768 } 1782 }
1769 handle->oidc->redirect_uri = GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->url_param_map, 1783 handle->oidc->redirect_uri = GNUNET_strdup (GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->url_param_map,
1770 &cache_key); 1784 &cache_key));
1771 1785
1772 GNUNET_asprintf (&expected_redirect_uri, "https://%s.zkey", handle->oidc->client_id);
1773 // verify the redirect uri matches https://<client_id>.zkey[/xyz]
1774 if( 0 != strncmp( expected_redirect_uri, handle->oidc->redirect_uri, strlen(expected_redirect_uri)) )
1775 {
1776 handle->oidc->redirect_uri = NULL;
1777 handle->emsg=GNUNET_strdup("invalid_request");
1778 handle->edesc=GNUNET_strdup("Invalid redirect_uri");
1779 GNUNET_SCHEDULER_add_now (&do_error, handle);
1780 GNUNET_free(expected_redirect_uri);
1781 return;
1782 }
1783 handle->oidc->redirect_uri = GNUNET_strdup(handle->oidc->redirect_uri);
1784
1785 GNUNET_free(expected_redirect_uri);
1786 // REQUIRED value: response_type 1786 // REQUIRED value: response_type
1787 GNUNET_CRYPTO_hash (OIDC_RESPONSE_TYPE_KEY, strlen (OIDC_RESPONSE_TYPE_KEY), 1787 GNUNET_CRYPTO_hash (OIDC_RESPONSE_TYPE_KEY, strlen (OIDC_RESPONSE_TYPE_KEY),
1788 &cache_key); 1788 &cache_key);
@@ -1897,6 +1897,9 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1897{ 1897{
1898 struct RequestHandle *handle = cls; 1898 struct RequestHandle *handle = cls;
1899 struct GNUNET_HashCode cache_key; 1899 struct GNUNET_HashCode cache_key;
1900 struct EgoEntry *tmp_ego;
1901 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1902 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
1900 1903
1901 cookie_identity_interpretation(handle); 1904 cookie_identity_interpretation(handle);
1902 1905
@@ -1922,9 +1925,8 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1922 GNUNET_SCHEDULER_add_now (&do_error, handle); 1925 GNUNET_SCHEDULER_add_now (&do_error, handle);
1923 return; 1926 return;
1924 } 1927 }
1925 handle->oidc->client_id = GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->url_param_map, 1928 handle->oidc->client_id = GNUNET_strdup (GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->url_param_map,
1926 &cache_key); 1929 &cache_key));
1927 handle->oidc->client_id = GNUNET_strdup (handle->oidc->client_id);
1928 1930
1929 if ( GNUNET_OK 1931 if ( GNUNET_OK
1930 != GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc->client_id, 1932 != GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc->client_id,
@@ -1952,6 +1954,22 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1952 handle->ego_entry = handle->ego_head; 1954 handle->ego_entry = handle->ego_head;
1953 handle->priv_key = *GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego); 1955 handle->priv_key = *GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego);
1954 handle->oidc->is_client_trusted = GNUNET_NO; 1956 handle->oidc->is_client_trusted = GNUNET_NO;
1957
1958 //First check if client_id is one of our egos; TODO: handle other TLD cases: Delegation, from config
1959 for (tmp_ego = handle->ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next)
1960 {
1961 priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego);
1962 GNUNET_CRYPTO_ecdsa_key_get_public (priv_key,
1963 &pkey);
1964 if ( 0 == memcmp (&pkey, &handle->oidc->client_pkey,
1965 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) )
1966 {
1967 handle->tld = GNUNET_strdup (tmp_ego->identifier);
1968 handle->oidc->is_client_trusted = GNUNET_YES;
1969 handle->ego_entry = handle->ego_tail;
1970 }
1971 }
1972
1955 1973
1956 // Checks if client_id is valid: 1974 // Checks if client_id is valid:
1957 handle->namestore_handle_it = GNUNET_NAMESTORE_zone_iteration_start ( 1975 handle->namestore_handle_it = GNUNET_NAMESTORE_zone_iteration_start (
@@ -2217,20 +2235,6 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2217 GNUNET_SCHEDULER_add_now (&do_error, handle); 2235 GNUNET_SCHEDULER_add_now (&do_error, handle);
2218 return; 2236 return;
2219 } 2237 }
2220 // check redirect_uri
2221 GNUNET_asprintf (&expected_redirect_uri, "https://%s.zkey", client_id);
2222 // verify the redirect uri matches https://<client_id>.zkey[/xyz]
2223 if( 0 != strncmp( expected_redirect_uri, redirect_uri, strlen(expected_redirect_uri)) )
2224 {
2225 GNUNET_free_non_null(user_psw);
2226 handle->emsg=GNUNET_strdup("invalid_request");
2227 handle->edesc=GNUNET_strdup("Invalid redirect_uri");
2228 handle->response_code = MHD_HTTP_BAD_REQUEST;
2229 GNUNET_SCHEDULER_add_now (&do_error, handle);
2230 GNUNET_free(expected_redirect_uri);
2231 return;
2232 }
2233 GNUNET_free(expected_redirect_uri);
2234 GNUNET_CRYPTO_hash (code, strlen (code), &cache_key); 2238 GNUNET_CRYPTO_hash (code, strlen (code), &cache_key);
2235 int i = 1; 2239 int i = 1;
2236 if ( GNUNET_SYSERR 2240 if ( GNUNET_SYSERR