aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_reclaim_attribute_lib.h9
-rw-r--r--src/include/gnunet_reclaim_plugin.h18
-rw-r--r--src/include/gnunet_reclaim_service.h6
-rw-r--r--src/reclaim-attribute/Makefile.am2
-rw-r--r--src/reclaim-attribute/plugin_reclaim_attestation_jwt.c53
-rw-r--r--src/reclaim-attribute/reclaim_attestation.c18
-rw-r--r--src/reclaim/gnunet-reclaim.c31
-rw-r--r--src/reclaim/gnunet-service-reclaim.c13
-rw-r--r--src/reclaim/plugin_rest_openid_connect.c3
-rw-r--r--src/reclaim/plugin_rest_reclaim.c3
-rw-r--r--src/reclaim/reclaim.h5
-rw-r--r--src/reclaim/reclaim_api.c12
12 files changed, 156 insertions, 17 deletions
diff --git a/src/include/gnunet_reclaim_attribute_lib.h b/src/include/gnunet_reclaim_attribute_lib.h
index 937a4d8f4..6d3503950 100644
--- a/src/include/gnunet_reclaim_attribute_lib.h
+++ b/src/include/gnunet_reclaim_attribute_lib.h
@@ -586,6 +586,15 @@ GNUNET_RECLAIM_attestation_number_to_typename (uint32_t type);
586uint32_t 586uint32_t
587GNUNET_RECLAIM_attestation_typename_to_number (const char *typename); 587GNUNET_RECLAIM_attestation_typename_to_number (const char *typename);
588 588
589/**
590 * Convert an attestation type name to the corresponding number
591 *
592 * @param typename name to convert
593 * @return corresponding number, UINT32_MAX on error
594 */
595struct GNUNET_RECLAIM_AttributeList*
596GNUNET_RECLAIM_attestation_get_attributes (const struct GNUNET_RECLAIM_Attestation *attest);
597
589 598
590#if 0 /* keep Emacsens' auto-indent happy */ 599#if 0 /* keep Emacsens' auto-indent happy */
591{ 600{
diff --git a/src/include/gnunet_reclaim_plugin.h b/src/include/gnunet_reclaim_plugin.h
index 4dd5252d2..ed62adf6c 100644
--- a/src/include/gnunet_reclaim_plugin.h
+++ b/src/include/gnunet_reclaim_plugin.h
@@ -165,6 +165,18 @@ typedef const char *(*GNUNET_RECLAIM_AttestationNumberToTypenameFunction) (
165 void *cls, 165 void *cls,
166 uint32_t type); 166 uint32_t type);
167 167
168/**
169 * Function called to convert a type number (i.e. 1) to the
170 * corresponding type string
171 *
172 * @param cls closure
173 * @param type number of a type to convert
174 * @return corresponding typestring, NULL on error
175 */
176typedef struct GNUNET_RECLAIM_AttributeList *(*GNUNET_RECLAIM_AttestationGetAttributesFunction) (
177 void *cls,
178 const struct GNUNET_RECLAIM_Attestation *attest);
179
168 180
169 181
170/** 182/**
@@ -231,6 +243,12 @@ struct GNUNET_RECLAIM_AttestationPluginFunctions
231 */ 243 */
232 GNUNET_RECLAIM_AttestationNumberToTypenameFunction number_to_typename; 244 GNUNET_RECLAIM_AttestationNumberToTypenameFunction number_to_typename;
233 245
246 /**
247 * Attesation attributes.
248 */
249 GNUNET_RECLAIM_AttestationGetAttributesFunction get_attributes;
250
251
234}; 252};
235 253
236 254
diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h
index c9c4fa5d1..ef9899dde 100644
--- a/src/include/gnunet_reclaim_service.h
+++ b/src/include/gnunet_reclaim_service.h
@@ -138,11 +138,13 @@ typedef void (*GNUNET_RECLAIM_AttributeTicketResult) (
138 * 138 *
139 * @param cls The callback closure 139 * @param cls The callback closure
140 * @param identity The identity authoritative over the attributes 140 * @param identity The identity authoritative over the attributes
141 * @param attr The attribute 141 * @param attestation The attestation
142 * @param attributes the parsed attributes
142 */ 143 */
143typedef void (*GNUNET_RECLAIM_AttestationResult) ( 144typedef void (*GNUNET_RECLAIM_AttestationResult) (
144 void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 145 void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
145 const struct GNUNET_RECLAIM_Attestation *attestation); 146 const struct GNUNET_RECLAIM_Attestation *attestation,
147 const struct GNUNET_RECLAIM_AttributeList *attributes);
146 148
147 149
148/** 150/**
diff --git a/src/reclaim-attribute/Makefile.am b/src/reclaim-attribute/Makefile.am
index a1c220340..9617672ee 100644
--- a/src/reclaim-attribute/Makefile.am
+++ b/src/reclaim-attribute/Makefile.am
@@ -44,6 +44,8 @@ libgnunet_plugin_reclaim_attestation_jwt_la_SOURCES = \
44 plugin_reclaim_attestation_jwt.c 44 plugin_reclaim_attestation_jwt.c
45libgnunet_plugin_reclaim_attestation_jwt_la_LIBADD = \ 45libgnunet_plugin_reclaim_attestation_jwt_la_LIBADD = \
46 $(top_builddir)/src/util/libgnunetutil.la \ 46 $(top_builddir)/src/util/libgnunetutil.la \
47 libgnunetreclaimattribute.la \
48 -ljansson\
47 $(LTLIBINTL) 49 $(LTLIBINTL)
48libgnunet_plugin_reclaim_attestation_jwt_la_LDFLAGS = \ 50libgnunet_plugin_reclaim_attestation_jwt_la_LDFLAGS = \
49 $(GN_PLUGIN_LDFLAGS) 51 $(GN_PLUGIN_LDFLAGS)
diff --git a/src/reclaim-attribute/plugin_reclaim_attestation_jwt.c b/src/reclaim-attribute/plugin_reclaim_attestation_jwt.c
index eb6043a66..8a67b18cd 100644
--- a/src/reclaim-attribute/plugin_reclaim_attestation_jwt.c
+++ b/src/reclaim-attribute/plugin_reclaim_attestation_jwt.c
@@ -30,7 +30,7 @@
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_reclaim_plugin.h" 31#include "gnunet_reclaim_plugin.h"
32#include <inttypes.h> 32#include <inttypes.h>
33 33#include <jansson.h>
34 34
35/** 35/**
36 * Convert the 'value' of an attestation to a string. 36 * Convert the 'value' of an attestation to a string.
@@ -142,6 +142,56 @@ jwt_number_to_typename (void *cls, uint32_t type)
142 return jwt_attest_name_map[i].name; 142 return jwt_attest_name_map[i].name;
143} 143}
144 144
145/**
146 * Parse a JWT and return the respective claim value as Attribute
147 *
148 * @param attest the jwt attestation
149 * @param claim the name of the claim in the JWT
150 *
151 * @return a GNUNET_RECLAIM_Attribute, containing the new value
152 */
153struct GNUNET_RECLAIM_AttributeList *
154jwt_parse_attributes (void *cls,
155 const struct GNUNET_RECLAIM_Attestation *attest)
156{
157 char *jwt_string;
158 struct GNUNET_RECLAIM_AttributeList *attrs;
159 char delim[] = ".";
160 char *val_str = NULL;
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
162 char *decoded_jwt;
163 json_t *json_val;
164 json_error_t *json_err = NULL;
165
166 if (GNUNET_RECLAIM_ATTESTATION_TYPE_JWT != attest->type)
167 return NULL;
168 attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
169
170 jwt_string = GNUNET_strdup (attest->data);
171 const char *jwt_body = strtok (jwt_string, delim);
172 jwt_body = strtok (NULL, delim);
173 GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body),
174 (void **) &decoded_jwt);
175 json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
176 const char *key;
177 json_t *value;
178 json_object_foreach (json_val, key, value) {
179 val_str = json_dumps (value, JSON_ENCODE_ANY);
180 GNUNET_RECLAIM_attribute_list_add (attrs,
181 key,
182 NULL,
183 GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,//FIXME
184 val_str,
185 strlen (val_str));
186 GNUNET_free (val_str);
187 }
188 GNUNET_free (jwt_string);
189 //FIXME needed??
190 return attrs;
191}
192
193
194
145 195
146/** 196/**
147 * Entry point for the plugin. 197 * Entry point for the plugin.
@@ -159,6 +209,7 @@ libgnunet_plugin_reclaim_attestation_jwt_init (void *cls)
159 api->string_to_value = &jwt_string_to_value; 209 api->string_to_value = &jwt_string_to_value;
160 api->typename_to_number = &jwt_typename_to_number; 210 api->typename_to_number = &jwt_typename_to_number;
161 api->number_to_typename = &jwt_number_to_typename; 211 api->number_to_typename = &jwt_number_to_typename;
212 api->get_attributes = &jwt_parse_attributes;
162 return api; 213 return api;
163} 214}
164 215
diff --git a/src/reclaim-attribute/reclaim_attestation.c b/src/reclaim-attribute/reclaim_attestation.c
index 1a7776719..fd08b9b12 100644
--- a/src/reclaim-attribute/reclaim_attestation.c
+++ b/src/reclaim-attribute/reclaim_attestation.c
@@ -500,3 +500,21 @@ GNUNET_RECLAIM_attestation_deserialize (const char *data, size_t data_size)
500 attestation->data = write_ptr; 500 attestation->data = write_ptr;
501 return attestation; 501 return attestation;
502} 502}
503
504struct GNUNET_RECLAIM_AttributeList*
505GNUNET_RECLAIM_attestation_get_attributes (const struct GNUNET_RECLAIM_Attestation *attest)
506{
507 unsigned int i;
508 struct Plugin *plugin;
509 struct GNUNET_RECLAIM_AttributeList *ret;
510 init ();
511 for (i = 0; i < num_plugins; i++)
512 {
513 plugin = attest_plugins[i];
514 if (NULL !=
515 (ret = plugin->api->get_attributes (plugin->api->cls,
516 attest)))
517 return ret;
518 }
519 return NULL;
520}
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c
index 3e31fef4c..0170ceff2 100644
--- a/src/reclaim/gnunet-reclaim.c
+++ b/src/reclaim/gnunet-reclaim.c
@@ -553,13 +553,27 @@ iter_cb (void *cls,
553 attr->data_size); 553 attr->data_size);
554 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type); 554 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type);
555 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id)); 555 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id));
556 fprintf (stdout, 556 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attr->attestation))
557 "Name: %s; Value: %s (%s); Flag %u; ID: %s\n", 557 {
558 attr->name, 558 fprintf (stdout,
559 attr_str, 559 "Name: %s; Value: %s (%s); Flag %u; ID: %s\n",
560 attr_type, 560 attr->name,
561 attr->flag, 561 attr_str,
562 id); 562 attr_type,
563 attr->flag,
564 id);
565 }
566 else
567 {
568 fprintf (stdout,
569 "Name: %s; Value: %s (%s); Flag %u; ID: %s\n",
570 attr->name,
571 attr_str,
572 attr_type,
573 attr->flag,
574 id);
575
576 }
563 GNUNET_free (id); 577 GNUNET_free (id);
564 } 578 }
565 GNUNET_RECLAIM_get_attributes_next (attr_iterator); 579 GNUNET_RECLAIM_get_attributes_next (attr_iterator);
@@ -609,7 +623,8 @@ attest_iter_finished (void *cls)
609static void 623static void
610attest_iter_cb (void *cls, 624attest_iter_cb (void *cls,
611 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 625 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
612 const struct GNUNET_RECLAIM_Attestation *attest) 626 const struct GNUNET_RECLAIM_Attestation *attest,
627 const struct GNUNET_RECLAIM_AttributeList *attrs)
613{ 628{
614 char *attest_str; 629 char *attest_str;
615 char *id; 630 char *id;
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index 61d029665..99831172b 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -1900,7 +1900,10 @@ attest_iter_cb (void *cls,
1900{ 1900{
1901 struct Iterator *ai = cls; 1901 struct Iterator *ai = cls;
1902 struct GNUNET_MQ_Envelope *env; 1902 struct GNUNET_MQ_Envelope *env;
1903 struct GNUNET_RECLAIM_AttributeList *attrs;
1904 struct GNUNET_RECLAIM_Attestation *att;
1903 char *data_tmp; 1905 char *data_tmp;
1906 char *attrs_size;
1904 1907
1905 if ((rd_count != 1) || 1908 if ((rd_count != 1) ||
1906 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION != rd->record_type)) 1909 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION != rd->record_type))
@@ -1908,6 +1911,10 @@ attest_iter_cb (void *cls,
1908 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); 1911 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1);
1909 return; 1912 return;
1910 } 1913 }
1914 att = GNUNET_RECLAIM_attestation_deserialize (rd->data,
1915 rd->data_size);
1916 attrs = GNUNET_RECLAIM_attestation_get_attributes (att);
1917 attrs_size = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs);
1911 1918
1912 struct AttestationResultMessage *arm; 1919 struct AttestationResultMessage *arm;
1913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attestation under: %s\n", 1920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attestation under: %s\n",
@@ -1915,13 +1922,17 @@ attest_iter_cb (void *cls,
1915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1922 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1916 "Sending ATTESTATION_RESULT message\n"); 1923 "Sending ATTESTATION_RESULT message\n");
1917 env = GNUNET_MQ_msg_extra (arm, 1924 env = GNUNET_MQ_msg_extra (arm,
1918 rd->data_size, 1925 rd->data_size + attrs_size,
1919 GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT); 1926 GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT);
1920 arm->id = htonl (ai->request_id); 1927 arm->id = htonl (ai->request_id);
1921 arm->attestation_len = htons (rd->data_size); 1928 arm->attestation_len = htons (rd->data_size);
1922 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); 1929 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity);
1923 data_tmp = (char *) &arm[1]; 1930 data_tmp = (char *) &arm[1];
1924 GNUNET_memcpy (data_tmp, rd->data, rd->data_size); 1931 GNUNET_memcpy (data_tmp, rd->data, rd->data_size);
1932 data_tmp += rd->data_size;
1933 GNUNET_RECLAIM_attribute_list_serialize (attrs,
1934 data_tmp);
1935
1925 GNUNET_MQ_send (ai->client->mq, env); 1936 GNUNET_MQ_send (ai->client->mq, env);
1926} 1937}
1927 1938
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c
index 345dbeed6..b296f6d15 100644
--- a/src/reclaim/plugin_rest_openid_connect.c
+++ b/src/reclaim/plugin_rest_openid_connect.c
@@ -988,7 +988,8 @@ oidc_attest_collect_finished_cb (void *cls)
988static void 988static void
989oidc_attest_collect (void *cls, 989oidc_attest_collect (void *cls,
990 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 990 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
991 const struct GNUNET_RECLAIM_Attestation *attest) 991 const struct GNUNET_RECLAIM_Attestation *attest,
992 const struct GNUNET_RECLAIM_AttributeList *attrs)
992{ 993{
993 struct RequestHandle *handle = cls; 994 struct RequestHandle *handle = cls;
994 struct GNUNET_RECLAIM_AttributeListEntry *le; 995 struct GNUNET_RECLAIM_AttributeListEntry *le;
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index 6f7a5987b..cddee9b54 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -619,7 +619,8 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
619static void 619static void
620attest_collect (void *cls, 620attest_collect (void *cls,
621 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 621 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
622 const struct GNUNET_RECLAIM_Attestation *attest) 622 const struct GNUNET_RECLAIM_Attestation *attest,
623 const struct GNUNET_RECLAIM_AttributeList *attrs)
623{ 624{
624 struct RequestHandle *handle = cls; 625 struct RequestHandle *handle = cls;
625 json_t *attr_obj; 626 json_t *attr_obj;
diff --git a/src/reclaim/reclaim.h b/src/reclaim/reclaim.h
index 7b5d7ab19..2cd07e861 100644
--- a/src/reclaim/reclaim.h
+++ b/src/reclaim/reclaim.h
@@ -179,6 +179,11 @@ struct AttestationResultMessage
179 uint16_t attestation_len GNUNET_PACKED; 179 uint16_t attestation_len GNUNET_PACKED;
180 180
181 /** 181 /**
182 * Length of serialized attribute data
183 */
184 uint16_t attributes_len GNUNET_PACKED;
185
186 /**
182 * always zero (for alignment) 187 * always zero (for alignment)
183 */ 188 */
184 uint16_t reserved GNUNET_PACKED; 189 uint16_t reserved GNUNET_PACKED;
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index 3820550c9..afab33320 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -801,11 +801,14 @@ handle_attestation_result (void *cls, const struct
801 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; 801 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
802 struct GNUNET_RECLAIM_Handle *h = cls; 802 struct GNUNET_RECLAIM_Handle *h = cls;
803 struct GNUNET_RECLAIM_AttestationIterator *it; 803 struct GNUNET_RECLAIM_AttestationIterator *it;
804 struct GNUNET_RECLAIM_AttributeList *attrs;
804 struct GNUNET_RECLAIM_Operation *op; 805 struct GNUNET_RECLAIM_Operation *op;
805 size_t att_len; 806 size_t att_len;
807 size_t attrs_len;
806 uint32_t r_id = ntohl (msg->id); 808 uint32_t r_id = ntohl (msg->id);
807 809
808 att_len = ntohs (msg->attestation_len); 810 att_len = ntohs (msg->attestation_len);
811 attrs_len = ntohs (msg->attributes_len);
809 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attestation result.\n"); 812 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attestation result.\n");
810 813
811 814
@@ -836,7 +839,7 @@ handle_attestation_result (void *cls, const struct
836 if (NULL != op) 839 if (NULL != op)
837 { 840 {
838 if (NULL != op->at_cb) 841 if (NULL != op->at_cb)
839 op->at_cb (op->cls, NULL, NULL); 842 op->at_cb (op->cls, NULL, NULL, NULL);
840 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); 843 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
841 free_op (op); 844 free_op (op);
842 } 845 }
@@ -846,17 +849,20 @@ handle_attestation_result (void *cls, const struct
846 { 849 {
847 struct GNUNET_RECLAIM_Attestation *att; 850 struct GNUNET_RECLAIM_Attestation *att;
848 att = GNUNET_RECLAIM_attestation_deserialize ((char *) &msg[1], att_len); 851 att = GNUNET_RECLAIM_attestation_deserialize ((char *) &msg[1], att_len);
852 char *read_ptr = ((char *) &msg[1]) + att_len;
853 attrs = GNUNET_RECLAIM_attribute_list_deserialize (read_ptr, attrs_len);
849 if (NULL != it) 854 if (NULL != it)
850 { 855 {
851 if (NULL != it->proc) 856 if (NULL != it->proc)
852 it->proc (it->proc_cls, &msg->identity, att); 857 it->proc (it->proc_cls, &msg->identity, att, attrs);
853 } 858 }
854 else if (NULL != op) 859 else if (NULL != op)
855 { 860 {
856 if (NULL != op->at_cb) 861 if (NULL != op->at_cb)
857 op->at_cb (op->cls, &msg->identity, att); 862 op->at_cb (op->cls, &msg->identity, att, attrs);
858 } 863 }
859 GNUNET_free (att); 864 GNUNET_free (att);
865 GNUNET_RECLAIM_attribute_list_destroy (attrs);
860 return; 866 return;
861 } 867 }
862 GNUNET_assert (0); 868 GNUNET_assert (0);