From c0fce9ca75973a646f80372fcc08c059818ba548 Mon Sep 17 00:00:00 2001 From: Markus Voggenreiter Date: Fri, 8 Nov 2019 12:06:54 +0100 Subject: [PATCH] JWT Plugin, Prepared Ticketing --- src/reclaim-attribute/reclaim_attribute.c | 2 +- src/reclaim/plugin_rest_openid_connect.c | 109 +++++++++++++++++----- src/reclaim/plugin_rest_reclaim.c | 23 ----- 3 files changed, 85 insertions(+), 49 deletions(-) diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c index 113ec7ef5..207bfb617 100644 --- a/src/reclaim-attribute/reclaim_attribute.c +++ b/src/reclaim-attribute/reclaim_attribute.c @@ -426,7 +426,7 @@ GNUNET_RECLAIM_ATTESTATION_reference_new (const char *attr_name, GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1); attr->name = write_ptr; - write_ptr += strlen (attr_name) +1; + write_ptr += strlen (attr_name) + 1; GNUNET_memcpy (write_ptr, ref_value_tmp, strlen (ref_value_tmp) + 1); attr->reference_value = write_ptr; diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c index 435cc3bf3..2c4b75c3f 100644 --- a/src/reclaim/plugin_rest_openid_connect.c +++ b/src/reclaim/plugin_rest_openid_connect.c @@ -973,7 +973,7 @@ oidc_collect_finished_cb (void *cls) /** - * Collects all attributes for an ego if in scope parameter + * Collects all attributes/references for an ego if in scope parameter */ static void oidc_attr_collect (void *cls, @@ -988,39 +988,95 @@ oidc_attr_collect (void *cls, char *scope_variable; char delimiter[] = " "; - if ((NULL == attr->name) || (NULL == attr->data)) + if ((NULL == attr) && (NULL == reference)) { GNUNET_RECLAIM_get_attributes_next (handle->attr_it); return; } - - scope_variables = GNUNET_strdup (handle->oidc->scope); - scope_variable = strtok (scope_variables, delimiter); - while (NULL != scope_variable) + if (NULL == attr) { - if (0 == strcmp (attr->name, scope_variable)) - break; - scope_variable = strtok (NULL, delimiter); + if ((NULL == reference->name) || (NULL == reference->reference_value)) + { + return; + } + scope_variables = GNUNET_strdup (handle->oidc->scope); + scope_variable = strtok (scope_variables, delimiter); + while (NULL != scope_variable) + { + if (0 == strcmp (reference->name, scope_variable)) + break; + scope_variable = strtok (NULL, delimiter); + } + if (NULL == scope_variable) + { + GNUNET_free (scope_variables); + return; + } + GNUNET_free (scope_variables); + // Store references as attributes as they only use the ID later + const char *type_str = NULL; + char *data; + size_t data_size; + uint32_t type; + le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); + type_str = "String"; + type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); + if (GNUNET_SYSERR ==(GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, + reference-> + reference_value, + (void **) & + data, + &data_size))) + { + return; + } + le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (reference->name, + type, + data, + data_size); + le->claim->id = reference->id; + le->claim->flag = 1; + + GNUNET_CONTAINER_DLL_insert (handle->attr_list->list_head, + handle->attr_list->list_tail, + le); } - if (NULL == scope_variable) + else { - GNUNET_RECLAIM_get_attributes_next (handle->attr_it); + if ((NULL == attr->name) || (NULL == attr->data)) + { + GNUNET_RECLAIM_get_attributes_next (handle->attr_it); + return; + } + scope_variables = GNUNET_strdup (handle->oidc->scope); + scope_variable = strtok (scope_variables, delimiter); + while (NULL != scope_variable) + { + if (0 == strcmp (attr->name, scope_variable)) + break; + scope_variable = strtok (NULL, delimiter); + } + if (NULL == scope_variable) + { + GNUNET_RECLAIM_get_attributes_next (handle->attr_it); + GNUNET_free (scope_variables); + return; + } GNUNET_free (scope_variables); - return; + + le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); + le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, + attr->type, + attr->data, + attr->data_size); + le->claim->id = attr->id; + le->claim->flag = attr->flag; + + GNUNET_CONTAINER_DLL_insert (handle->attr_list->list_head, + handle->attr_list->list_tail, + le); + GNUNET_RECLAIM_get_attributes_next (handle->attr_it); } - GNUNET_free (scope_variables); - - le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, - attr->type, - attr->data, - attr->data_size); - le->claim->id = attr->id; - le->claim->flag = attr->flag; - GNUNET_CONTAINER_DLL_insert (handle->attr_list->list_head, - handle->attr_list->list_tail, - le); - GNUNET_RECLAIM_get_attributes_next (handle->attr_it); } @@ -1456,6 +1512,9 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle, handle->ego_entry = handle->ego_tail; } } + handle->oidc->scope = get_url_parameter_copy (handle, OIDC_SCOPE_KEY); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scope: %s\n",GNUNET_strdup ( + handle->oidc->scope)); if (NULL == handle->tld) GNUNET_CONFIGURATION_iterate_section_values (cfg, "gns", tld_iter, handle); if (NULL == handle->tld) diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 3b3674112..16286444a 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c @@ -37,9 +37,6 @@ #include "gnunet_rest_plugin.h" #include "gnunet_signatures.h" #include "json_reclaim.h" -#include -#include - /** * REST root namespace */ @@ -1199,26 +1196,6 @@ parse_jwt (const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, jwt_body = strtok (NULL, delim); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "JWT Body: %s\n", jwt_body); - /*const char* jwt_base64 = jwt_body; - //No padding assumed - int jwt_len = (strlen(jwt_base64)*3)/4; - BIO *bio, *b64; - decoded_jwt = (char *) malloc(jwt_len + 1); - - decoded_jwt[jwt_len] = '\0'; - - bio = BIO_new_mem_buf(jwt_base64, -1); - b64 = BIO_new(BIO_f_base64()); - bio = BIO_push(b64, bio); - BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); - /**length = BIO_read(bio, *buffer, strlen(jwt_base64)); - assert(*length == jwt_len); //length should equal jwt_len, else something went horribly wrong - - BIO_free_all(bio); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsed JWT Body: %s\n", - decoded_jwt); -*/ - val_str = "String from JWT, which is stored under claim"; type_str = "String"; -- 2.25.1