gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r36800 - gnunet/src/identity-provider


From: gnunet
Subject: [GNUnet-SVN] r36800 - gnunet/src/identity-provider
Date: Sun, 10 Jan 2016 00:06:05 +0100

Author: schanzen
Date: 2016-01-10 00:06:05 +0100 (Sun, 10 Jan 2016)
New Revision: 36800

Modified:
   gnunet/src/identity-provider/gnunet-service-identity-provider.c
   gnunet/src/identity-provider/identity_token.c
   gnunet/src/identity-provider/identity_token.h
Log:
- refactor


Modified: gnunet/src/identity-provider/gnunet-service-identity-provider.c
===================================================================
--- gnunet/src/identity-provider/gnunet-service-identity-provider.c     
2016-01-09 17:45:50 UTC (rev 36799)
+++ gnunet/src/identity-provider/gnunet-service-identity-provider.c     
2016-01-09 23:06:05 UTC (rev 36800)
@@ -32,7 +32,6 @@
 #include "gnunet_namestore_service.h"
 #include "gnunet_statistics_service.h"
 #include "gnunet_gns_service.h"
-#include <jansson.h>
 #include "gnunet_signatures.h"
 #include "identity_provider.h"
 #include "identity_token.h"
@@ -328,7 +327,7 @@
   char *token_metadata;
   char *write_ptr;
   char *enc_token_str;
-  const char *key;
+  char *val_str;
   const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
   struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
   struct GNUNET_CRYPTO_EcdhePrivateKey *new_ecdhe_privkey;
@@ -343,11 +342,8 @@
   struct GNUNET_TIME_Absolute new_iat;
   struct GNUNET_TIME_Absolute new_nbf;
   struct IdentityToken *new_token;
-  json_t *payload_json;
-  json_t *value;
-  json_t *cur_value;
-  json_t *token_nbf_json;
-  json_t *token_exp_json;
+  struct TokenAttr *cur_value;
+  struct TokenAttr *attr;
   size_t token_metadata_len;
 
   priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
@@ -363,12 +359,19 @@
   //but this service will reissue new tokens that can be retrieved from GNS
   //automatically.
 
-  payload_json = token->payload;
-
-  token_exp_json = json_object_get (payload_json, "exp");
-  token_nbf_json = json_object_get (payload_json, "nbf");
-  token_exp.abs_value_us = json_integer_value(token_exp_json);
-  token_nbf.abs_value_us = json_integer_value(token_nbf_json);
+  for (attr = token->attr_head; NULL != attr; attr = attr->next)
+  {
+    if (0 == strcmp (attr->name, "exp"))
+    {
+      sscanf (attr->val_head->value,
+              "%lu",
+              &token_exp.abs_value_us);
+    } else if (0 == strcmp (attr->name, "nbf")) {
+      sscanf (attr->val_head->value,
+              "%lu",
+              &token_nbf.abs_value_us);
+    }
+  }
   token_rel_exp = GNUNET_TIME_absolute_get_difference (token_nbf, token_exp);
 
   token_ttl = GNUNET_TIME_absolute_get_remaining (token_exp);
@@ -379,7 +382,6 @@
     {
       min_rel_exp = token_ttl;
     }
-    json_decref (payload_json);
     GNUNET_free (token);
     token = NULL;
     GNUNET_free (label);
@@ -396,41 +398,52 @@
   new_exp = GNUNET_TIME_relative_to_absolute (token_rel_exp);
   new_nbf = GNUNET_TIME_absolute_get ();
   new_iat = new_nbf;
-
-  json_object_foreach(payload_json, key, value) {
-    if (0 == strcmp (key, "exp"))
+  for (attr = token->attr_head; NULL != attr; attr = attr->next)
+  {
+    if (0 == strcmp (attr->name, "exp"))
     {
-      token_add_json (new_token, key, json_integer (new_exp.abs_value_us));
+      GNUNET_asprintf (&val_str, "%ul", new_exp.abs_value_us);
+      token_add_attr (new_token, attr->name, val_str);
+      GNUNET_free (val_str);
     }
-    else if (0 == strcmp (key, "nbf"))
+    else if (0 == strcmp (attr->name, "nbf"))
     {
-      token_add_json (new_token, key, json_integer (new_nbf.abs_value_us));
+      GNUNET_asprintf (&val_str, "%ul", new_nbf.abs_value_us);
+      token_add_attr (new_token, attr->name, val_str);
+      GNUNET_free (val_str);
     }
-    else if (0 == strcmp (key, "iat"))
+    else if (0 == strcmp (attr->name, "iat"))
     {
-      token_add_json (new_token, key, json_integer (new_iat.abs_value_us));
+      GNUNET_asprintf (&val_str, "%ul", new_iat.abs_value_us);
+      token_add_attr (new_token, attr->name, val_str);
+      GNUNET_free (val_str);
     }
-    else if ((0 == strcmp (key, "iss"))
-             || (0 == strcmp (key, "aud")))
+    else if ((0 == strcmp (attr->name, "iss"))
+             || (0 == strcmp (attr->name, "aud")))
     {
       //Omit
     }
-    else if ((0 == strcmp (key, "sub"))
-             || (0 == strcmp (key, "rnl")))
+    else if (0 == strcmp (attr->name, "sub"))
     {
-      token_add_json (new_token, key, value);
+      token_add_attr (new_token,
+                      attr->name,
+                      attr->val_head->value);
     }
-    else {
-      GNUNET_CRYPTO_hash (key,
-                          strlen (key),
+    else 
+    {
+      GNUNET_CRYPTO_hash (attr->name,
+                          strlen (attr->name),
                           &key_hash);
       //Check if attr still exists. omit of not
-      if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains 
(ego_entry->attr_map,
-                                                               &key_hash))
+      if (GNUNET_NO != 
+          GNUNET_CONTAINER_multihashmap_contains (ego_entry->attr_map,
+                                                  &key_hash))
       {
         cur_value = GNUNET_CONTAINER_multihashmap_get (ego_entry->attr_map,
                                                        &key_hash);
-        token_add_json (new_token, key, cur_value);
+        GNUNET_CONTAINER_DLL_insert (new_token->attr_head,
+                                     new_token->attr_tail,
+                                     cur_value);
       }
     }
   }
@@ -441,8 +454,6 @@
                                   &new_ecdhe_privkey,
                                   &enc_token_str));
 
-  json_decref (payload_json);
-
   token_record[0].data = enc_token_str;
   token_record[0].data_size = strlen (enc_token_str) + 1;
   token_record[0].expiration_time = rd_exp; //Old expiration time
@@ -504,10 +515,22 @@
                  const struct GNUNET_HashCode *key,
                  void *value)
 {
-  json_t *attr_value = value;
+  struct TokenAttr *attr = value;
+  struct TokenAttrValue *val;
+  struct TokenAttrValue *tmp_val;
+  for (val = attr->val_head; NULL != val;)
+  {
+    tmp_val = val->next;
+    GNUNET_CONTAINER_DLL_remove (attr->val_head,
+                                 attr->val_tail,
+                                 val);
+    GNUNET_free (val->value);
+    GNUNET_free (val);
+    val = tmp_val;
+  }
+  GNUNET_free (attr->name);
+  GNUNET_free (attr);
 
-  json_decref (attr_value);
-
   return GNUNET_YES;
 }
 
@@ -612,9 +635,10 @@
                    const struct GNUNET_GNSRECORD_Data *rd)
 {
   struct EgoEntry *ego_entry = cls;
-  json_t *attr_value;
   struct GNUNET_HashCode key;
-  char* attr;
+  struct TokenAttr *attr;
+  struct TokenAttrValue *val;
+  char *val_str;
   int i;
 
   if (NULL == lbl)
@@ -639,15 +663,20 @@
   {
     if (rd->record_type == GNUNET_GNSRECORD_TYPE_ID_ATTR)
     {
-      attr = GNUNET_GNSRECORD_value_to_string (rd->record_type,
-                                               rd->data,
-                                               rd->data_size);
-      attr_value = json_string (attr);
+      val_str = GNUNET_GNSRECORD_value_to_string (rd->record_type,
+                                              rd->data,
+                                              rd->data_size);
+      attr = GNUNET_malloc (sizeof (struct TokenAttr));
+      attr->name = GNUNET_strdup (lbl);
+      val = GNUNET_malloc (sizeof (struct TokenAttrValue));
+      val->value = val_str;
+      GNUNET_CONTAINER_DLL_insert (attr->val_head,
+                                   attr->val_tail,
+                                   val);
       GNUNET_CONTAINER_multihashmap_put (ego_entry->attr_map,
                                          &key,
-                                         attr_value,
+                                         attr,
                                          
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
-      GNUNET_free (attr);
     }
 
     GNUNET_NAMESTORE_zone_iterator_next (ns_it);
@@ -654,22 +683,25 @@
     return;
   }
 
-  attr_value = json_array();
+  attr = GNUNET_malloc (sizeof (struct TokenAttr));
+  attr->name = GNUNET_strdup (lbl);
   for (i = 0; i < rd_count; i++)
   {
     if (rd[i].record_type == GNUNET_GNSRECORD_TYPE_ID_ATTR)
     {
-      attr = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
-                                               rd[i].data,
-                                               rd[i].data_size);
-      json_array_append_new (attr_value, json_string (attr));
-      GNUNET_free (attr);
+      val_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
+                                                  rd[i].data,
+                                                  rd[i].data_size);
+      val = GNUNET_malloc (sizeof (struct TokenAttrValue));
+      val->value = val_str;
+      GNUNET_CONTAINER_DLL_insert (attr->val_head,
+                                   attr->val_tail,
+                                   val);
     }
-
   }
   GNUNET_CONTAINER_multihashmap_put (ego_entry->attr_map,
                                      &key,
-                                     attr_value,
+                                     attr,
                                      
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
   GNUNET_NAMESTORE_zone_iterator_next (ns_it);
   return;
@@ -947,6 +979,7 @@
   char *enc_token_str;
   char *token_metadata;
   char* write_ptr;
+  char* attr_val;
   uint64_t time;
   uint64_t exp_time;
   uint64_t rnd_key;
@@ -973,9 +1006,13 @@
   time = GNUNET_TIME_absolute_get().abs_value_us;
   exp_time = time + token_expiration_interval.rel_value_us;
 
-  token_add_json (handle->token, "nbf", json_integer (time));
-  token_add_json (handle->token, "iat", json_integer (time));
-  token_add_json (handle->token, "exp", json_integer (exp_time));
+  GNUNET_asprintf (&attr_val, "%ul", time);
+  token_add_attr (handle->token, "nbf", attr_val);
+  token_add_attr (handle->token, "iat", attr_val);
+  GNUNET_free (attr_val);
+  GNUNET_asprintf (&attr_val, "%ul", exp_time);
+  token_add_attr (handle->token, "exp", attr_val);
+  GNUNET_free (attr_val);
   token_add_attr (handle->token, "nonce", nonce_str);
 
   //Token in a serialized encrypted format 
@@ -1036,7 +1073,6 @@
 {
   int i;
   char* data;
-  json_t *attr_arr;
   struct IssueHandle *handle = cls;
   struct GNUNET_HashCode key;
 
@@ -1073,9 +1109,9 @@
                                                rd->data,
                                                rd->data_size);
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding value: %s\n", data);
-      token_add_json (handle->token,
+      token_add_attr (handle->token,
                       label,
-                      json_string (data));
+                      data);
       GNUNET_free (data);
     }
     GNUNET_NAMESTORE_zone_iterator_next (handle->ns_it);
@@ -1083,7 +1119,6 @@
   }
 
   i = 0;
-  attr_arr = json_array();
   for (; i < rd_count; i++)
   {
     if (rd->record_type == GNUNET_GNSRECORD_TYPE_ID_ATTR)
@@ -1092,16 +1127,11 @@
                                                rd[i].data,
                                                rd[i].data_size);
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding value: %s\n", data);
-      json_array_append_new (attr_arr, json_string (data));
+      token_add_attr (handle->token, label, data);
       GNUNET_free (data);
     }
   }
 
-  if (0 < json_array_size (attr_arr))
-  {
-    token_add_json (handle->token, label, attr_arr);
-  }
-  json_decref (attr_arr);
   GNUNET_NAMESTORE_zone_iterator_next (handle->ns_it);
 }
 
@@ -1342,17 +1372,17 @@
   identity_handle = GNUNET_IDENTITY_connect (cfg,
                                              &list_ego,
                                              NULL);
-  
+
   if (GNUNET_OK == 
       GNUNET_CONFIGURATION_get_value_time (cfg,
-                                             "identity-provider",
-                                            "TOKEN_EXPIRATION_INTERVAL",
-                                            &token_expiration_interval))
+                                           "identity-provider",
+                                           "TOKEN_EXPIRATION_INTERVAL",
+                                           &token_expiration_interval))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Time window for zone iteration: %s\n",
                 GNUNET_STRINGS_relative_time_to_string 
(token_expiration_interval,
-                                                                     
GNUNET_YES));
+                                                        GNUNET_YES));
   } else {
     token_expiration_interval = DEFAULT_TOKEN_EXPIRATION_INTERVAL;
   }

Modified: gnunet/src/identity-provider/identity_token.c
===================================================================
--- gnunet/src/identity-provider/identity_token.c       2016-01-09 17:45:50 UTC 
(rev 36799)
+++ gnunet/src/identity-provider/identity_token.c       2016-01-09 23:06:05 UTC 
(rev 36800)
@@ -29,7 +29,14 @@
 #include "identity_token.h"
 #include <jansson.h>
 
+#define JWT_ALG "alg"
 
+#define JWT_ALG_VALUE "ED512"
+
+#define JWT_TYP "typ"
+
+#define JWT_TYP_VALUE "jwt"
+
 /**
  * Crypto helper functions
  */
@@ -176,8 +183,6 @@
 }
 
 
-
-
 /**
  * Identity Token API
  */
@@ -203,20 +208,10 @@
   audience = GNUNET_STRINGS_data_to_string_alloc (aud,
                                                   sizeof (struct 
GNUNET_CRYPTO_EcdsaPublicKey));
 
-
-
   token = GNUNET_malloc (sizeof (struct IdentityToken));
-
-  token->header = json_object();
-  token->payload = json_object();
-
-  json_object_set_new (token->header, "alg", json_string ("ED512"));
-  json_object_set_new (token->header, "typ", json_string ("JWT"));
-
-  json_object_set_new (token->payload, "iss", json_string (issuer));
-  json_object_set_new (token->payload, "aud", json_string (audience));
-  json_object_set_new (token->payload, "sub", json_string (issuer));
-
+  token_add_attr (token, "iss", issuer);
+  token_add_attr (token, "aud", audience);
+  token_add_attr (token, "sub", issuer);
   token->aud_key = *aud;
   GNUNET_free (issuer);
   GNUNET_free (audience);
@@ -226,50 +221,115 @@
 void
 token_destroy (struct IdentityToken *token)
 {
-  json_decref (token->header);
-  json_decref (token->payload);
+  struct TokenAttr *attr;
+  struct TokenAttr *tmp_attr;
+  struct TokenAttrValue *val;
+  struct TokenAttrValue *tmp_val;
+
+  for (attr = token->attr_head; NULL != attr;)
+  {
+    tmp_attr = attr->next;
+    GNUNET_CONTAINER_DLL_remove (token->attr_head,
+                                 token->attr_tail,
+                                 attr);
+    for (val = attr->val_head; NULL != val;)
+    {
+      tmp_val = val->next;
+      GNUNET_CONTAINER_DLL_remove (attr->val_head,
+                                   attr->val_tail,
+                                   val);
+      GNUNET_free (val->value);
+      GNUNET_free (val);
+      val = tmp_val;
+    }
+    GNUNET_free (attr->name);
+    GNUNET_free (attr);
+    attr = tmp_attr;
+  }
+
+  
   GNUNET_free (token);
 }
 
 void
-token_add_attr (const struct IdentityToken *token,
-                                         const char* key,
-                                         const char* value)
+token_add_attr (struct IdentityToken *token,
+                const char* key,
+                const char* value)
 {
+  struct TokenAttr *attr;
+  struct TokenAttrValue *new_val;
   GNUNET_assert (NULL != token);
-  GNUNET_assert (NULL != token->payload);
 
-  json_object_set_new (token->payload, key, json_string (value));
+  new_val = GNUNET_malloc (sizeof (struct TokenAttrValue));
+  new_val->value = GNUNET_strdup (value);
+  for (attr = token->attr_head; NULL != attr; attr = attr->next)
+  {
+    if (0 == strcmp (key, attr->name))
+      break;
+  }
+
+  if (NULL == attr)
+  {
+    attr = GNUNET_malloc (sizeof (struct TokenAttr));
+    attr->name = GNUNET_strdup (key);
+    GNUNET_CONTAINER_DLL_insert (token->attr_head,
+                                 token->attr_tail,
+                                 attr);
+  }
+
+  GNUNET_CONTAINER_DLL_insert (attr->val_head,
+                               attr->val_tail,
+                               new_val);
 }
 
-void
-token_add_json (const struct IdentityToken *token,
-                                         const char* key,
-                                         json_t* value)
+static void
+parse_json_payload(const char* payload_base64,
+                   struct IdentityToken *token) 
 {
-  GNUNET_assert (NULL != token);
-  GNUNET_assert (NULL != token->payload);
+  const char *key;
+  const json_t *value;
+  const json_t *arr_value;
+  char *payload;
+  int idx;
+  json_t *payload_json;
+  json_error_t err_json;
 
-  json_object_set_new (token->payload, key, value);
+  GNUNET_STRINGS_base64_decode (payload_base64,
+                                strlen (payload_base64),
+                                &payload);
+  //TODO signature and aud key
+  payload_json = json_loads (payload, JSON_DECODE_ANY, &err_json);
+
+  json_object_foreach (payload_json, key, value)
+  {
+    if (json_is_array (value))
+    {
+      json_array_foreach (value, idx, arr_value)
+      {
+        token_add_attr (token,
+                        key,
+                        json_string_value (arr_value));
+      }
+    } else {
+      token_add_attr (token, key, json_string_value (value));
+    }
+  }
+
+  GNUNET_free (payload);
 }
 
-
 int
 token_parse2 (const char* raw_data,
-                                       const struct 
GNUNET_CRYPTO_EcdhePrivateKey *priv_key,
-                                       const struct 
GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
-                                       struct IdentityToken **result)
+              const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_key,
+              const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
+              struct IdentityToken **result)
 {
   char *enc_token_str;
   char *tmp_buf;
   char *token_str;
   char *enc_token;
-  char *header;
-  char *header_base64;
-  char *payload;
   char *payload_base64;
   size_t enc_token_len;
-  json_error_t err_json;
 
   GNUNET_asprintf (&tmp_buf, "%s", raw_data);
   strtok (tmp_buf, ",");
@@ -289,34 +349,23 @@
     return GNUNET_SYSERR;
   }
 
-  header_base64 = strtok (token_str, ".");
+  GNUNET_assert (NULL != strtok (token_str, "."));
   payload_base64 = strtok (NULL, ".");
 
-  GNUNET_STRINGS_base64_decode (header_base64,
-                                strlen (header_base64),
-                                &header);
-  GNUNET_STRINGS_base64_decode (payload_base64,
-                                strlen (payload_base64),
-                                &payload);
-  //TODO signature
+  *result = GNUNET_malloc (sizeof (struct IdentityToken));
+  parse_json_payload (payload_base64, *result);
 
-
-  *result = GNUNET_malloc (sizeof (struct IdentityToken));
   (*result)->aud_key =  *aud_key;
-  (*result)->header = json_loads (header, JSON_DECODE_ANY, &err_json);
-  (*result)->payload = json_loads (payload, JSON_DECODE_ANY, &err_json);
   GNUNET_free (enc_token);
   GNUNET_free (token_str);
   GNUNET_free (tmp_buf);
-  GNUNET_free (payload);
-  GNUNET_free (header);
   return GNUNET_OK;
 }
 
 int
 token_parse (const char* raw_data,
-                                      const struct 
GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
-                                      struct IdentityToken **result)
+             const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
+             struct IdentityToken **result)
 {
   char *ecdh_pubkey_str;
   char *enc_token_str;
@@ -323,12 +372,8 @@
   char *tmp_buf;
   char *token_str;
   char *enc_token;
-  char *header;
-  char *header_base64;
-  char *payload;
   char *payload_base64;
   size_t enc_token_len;
-  json_error_t err_json;
   struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey;
 
   GNUNET_asprintf (&tmp_buf, "%s", raw_data);
@@ -353,33 +398,60 @@
     return GNUNET_SYSERR;
   }
 
-  header_base64 = strtok (token_str, ".");
+  GNUNET_assert (NULL != strtok (token_str, "."));
   payload_base64 = strtok (NULL, ".");
 
-  GNUNET_STRINGS_base64_decode (header_base64,
-                                strlen (header_base64),
-                                &header);
-  GNUNET_STRINGS_base64_decode (payload_base64,
-                                strlen (payload_base64),
-                                &payload);
-  //TODO signature and aud key
+  *result = GNUNET_malloc (sizeof (struct IdentityToken));
+  parse_json_payload (payload_base64, *result);
 
-
-  *result = GNUNET_malloc (sizeof (struct IdentityToken));
-  (*result)->header = json_loads (header, JSON_DECODE_ANY, &err_json);
-  (*result)->payload = json_loads (payload, JSON_DECODE_ANY, &err_json);
   GNUNET_free (enc_token);
   GNUNET_free (token_str);
   GNUNET_free (tmp_buf);
-  GNUNET_free (payload);
-  GNUNET_free (header);
   return GNUNET_OK;
 }
 
+static char*
+create_json_payload (const struct IdentityToken *token)
+{
+  struct TokenAttr *attr;
+  struct TokenAttrValue *val;
+  json_t *root;
+  char *json_str;
+
+  root = json_object();
+  for (attr = token->attr_head; NULL != attr; attr = attr->next)
+  {
+    for (val = attr->val_head; NULL != val; val = val->next)
+    {
+      json_object_set_new (root,
+                           attr->name,
+                           json_string (val->value)); 
+    }
+  }
+  json_str = json_dumps (root, JSON_INDENT(1));
+  json_decref (root);
+  return json_str;
+}
+
+static char*
+create_json_header(void)
+{
+  json_t *root;
+  char *json_str;
+
+  root = json_object ();
+  json_object_set_new (root, JWT_ALG, json_string (JWT_ALG_VALUE));
+  json_object_set_new (root, JWT_TYP, json_string (JWT_TYP_VALUE));
+
+  json_str = json_dumps (root, JSON_INDENT(1));
+  json_decref (root);
+  return json_str;
+}
+
 int
 token_to_string (const struct IdentityToken *token,
-                                          const struct 
GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
-                                          char **result)
+                 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
+                 char **result)
 {
   char *payload_str;
   char *header_str;
@@ -389,7 +461,7 @@
   char *signature_target;
   char *signature_str;
   struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
-  header_str = json_dumps (token->header, JSON_COMPACT);
+  header_str = create_json_header();
   GNUNET_STRINGS_base64_encode (header_str,
                                 strlen (header_str),
                                 &header_base64);
@@ -398,7 +470,7 @@
   while (NULL != padding)
     padding = strtok(NULL, "=");
 
-  payload_str = json_dumps (token->payload, JSON_COMPACT);
+  payload_str = create_json_payload (token);
   GNUNET_STRINGS_base64_encode (payload_str,
                                 strlen (payload_str),
                                 &payload_base64);
@@ -422,9 +494,7 @@
   {
     GNUNET_free (signature_target);
     GNUNET_free (payload_str);
-    GNUNET_free (header_str);
     GNUNET_free (payload_base64);
-    GNUNET_free (header_base64);
     GNUNET_free (purpose);
     return GNUNET_SYSERR;
   }
@@ -446,9 +516,9 @@
 
 int
 token_serialize (const struct IdentityToken *token,
-                                          const struct 
GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
-                                          struct GNUNET_CRYPTO_EcdhePrivateKey 
**ecdh_privkey,
-                                          char **result)
+                 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
+                 struct GNUNET_CRYPTO_EcdhePrivateKey **ecdh_privkey,
+                 char **result)
 {
   char *token_str;
   char *enc_token;
@@ -457,8 +527,8 @@
   struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey;
 
   GNUNET_assert (GNUNET_OK == token_to_string (token,
-                                                                        
priv_key,
-                                                                        
&token_str));
+                                               priv_key,
+                                               &token_str));
 
   GNUNET_assert (GNUNET_OK == encrypt_str_ecdhe (token_str,
                                                  &token->aud_key,
@@ -480,8 +550,8 @@
 
 struct TokenTicketPayload*
 ticket_payload_create (const char* nonce,
-                                                const struct 
GNUNET_CRYPTO_EcdsaPublicKey* identity_pkey,
-                                                const char* lbl_str)
+                       const struct GNUNET_CRYPTO_EcdsaPublicKey* 
identity_pkey,
+                       const char* lbl_str)
 {
   struct TokenTicketPayload* payload;
 

Modified: gnunet/src/identity-provider/identity_token.h
===================================================================
--- gnunet/src/identity-provider/identity_token.h       2016-01-09 17:45:50 UTC 
(rev 36799)
+++ gnunet/src/identity-provider/identity_token.h       2016-01-09 23:06:05 UTC 
(rev 36800)
@@ -32,14 +32,14 @@
 struct IdentityToken
 {
   /**
-   * JSON header
+   * DLL
    */
-  json_t *header;
+  struct TokenAttr *attr_head;
 
   /**
-   * JSON Payload
+   * DLL
    */
-  json_t *payload;
+  struct TokenAttr *attr_tail;
 
   /**
    * Token Signature
@@ -52,6 +52,53 @@
   struct GNUNET_CRYPTO_EcdsaPublicKey aud_key;
 };
 
+struct TokenAttr
+{
+  /**
+   * DLL
+   */
+  struct TokenAttr *next;
+
+  /**
+   * DLL
+   */
+  struct TokenAttr *prev;
+
+  /**
+   * Attribute name
+   */
+  char *name;
+
+  /**
+   * Attribute value DLL
+   */
+  struct TokenAttrValue *val_head;
+
+  /**
+   * Attribute value DLL
+   */
+  struct TokenAttrValue *val_tail;
+
+};
+
+struct TokenAttrValue
+{
+  /**
+   * DLL
+   */
+  struct TokenAttrValue *next;
+
+  /**
+   * DLL
+   */
+  struct TokenAttrValue *prev;
+
+  /**
+   * Attribute value
+   */
+  char *value;
+};
+
 struct TokenTicketPayload
 {
   /**
@@ -124,11 +171,21 @@
  * @param value the value
  */
 void
-token_add_attr (const struct IdentityToken *token,
-                                         const char* key,
-                                         const char* value);
+token_add_attr (struct IdentityToken *token,
+                const char* key,
+                const char* value);
 
 /**
+ * Add a value to a TokenAttribute
+ *
+ * @param attr the token attribute
+ * @param value value to add
+ */
+  void
+  token_attr_add_value (const struct TokenAttr *attr,
+                        const char *value);
+
+/**
  * Add a new key value pair to the token with the value as json
  *
  * @param the token to modify
@@ -138,8 +195,8 @@
  */
 void
 token_add_json (const struct IdentityToken *token,
-                         const char* key,
-                         json_t* value);
+                const char* key,
+                json_t* value);
 
 /**
  * Serialize a token. The token will be signed and base64 according to the
@@ -159,9 +216,9 @@
  */
 int 
 token_serialize (const struct IdentityToken*token,
-                          const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
-                          struct GNUNET_CRYPTO_EcdhePrivateKey **ecdhe_privkey,
-                          char **result);
+                 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
+                 struct GNUNET_CRYPTO_EcdhePrivateKey **ecdhe_privkey,
+                 char **result);
 
 /**
  * Parses the serialized token and returns a token
@@ -172,10 +229,10 @@
  *
  * @return GNUNET_OK on success
  */
-int
-token_parse (const char* data,
-             const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
-             struct IdentityToken **result);
+  int
+  token_parse (const char* data,
+               const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
+               struct IdentityToken **result);
 
 /**
  * Parses the serialized token and returns a token
@@ -189,11 +246,11 @@
  *
  * @return GNUNET_OK on success
  */
-  int
-  token_parse2 (const char* data,
-                const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_key,
-                const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
-                struct IdentityToken **result);
+int
+token_parse2 (const char* data,
+              const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_key,
+              const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
+              struct IdentityToken **result);
 
 
 /**
@@ -206,10 +263,10 @@
  *
  * @return GNUNET_OK on success
  */
-  int
-  token_to_string (const struct IdentityToken *token,
-                   const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
-                   char **result);
+int
+token_to_string (const struct IdentityToken *token,
+                 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
+                 char **result);
 
 /**
  *
@@ -261,9 +318,9 @@
  *
  * @return GNUNET_OK on success
  */
-  int
-  ticket_parse (const char* raw_data,
-                const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
-                struct TokenTicket **ticket);
+int
+ticket_parse (const char* raw_data,
+              const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
+              struct TokenTicket **ticket);
 
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]