JWT Plugin, Prepared Ticketing
authorMarkus Voggenreiter <Markus.Voggenreiter@tum.de>
Fri, 8 Nov 2019 11:06:54 +0000 (12:06 +0100)
committerMarkus Voggenreiter <Markus.Voggenreiter@tum.de>
Fri, 8 Nov 2019 11:06:54 +0000 (12:06 +0100)
src/reclaim-attribute/reclaim_attribute.c
src/reclaim/plugin_rest_openid_connect.c
src/reclaim/plugin_rest_reclaim.c

index 113ec7ef5418d961b21f8087c66a5dab95cc32e6..207bfb61752d4ff20b7cdc39b0fd50497dbd5811 100644 (file)
@@ -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;
 
index 000e9ca997ef222d8903c3a40dcdf2c9f42db25f..d6032517321c18e8c83bb46034b561a46a01eeb1 100644 (file)
@@ -967,7 +967,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,
@@ -982,39 +982,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);
 }
 
 
@@ -1447,6 +1503,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)
index 0beb9b366288ec4fb0687e07c157645955239f01..5572bf7c9ebedb9294c287b062ce5e0cea10c40c 100644 (file)
@@ -37,9 +37,6 @@
 #include "gnunet_rest_plugin.h"
 #include "gnunet_signatures.h"
 #include "json_reclaim.h"
-#include <openssl/bio.h>
-#include <openssl/evp.h>
-
 /**
  * REST root namespace
  */
@@ -1196,26 +1193,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";