diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-02-04 23:34:10 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-02-09 20:38:10 +0100 |
commit | 5fb277e8d012d687f4d2d032571cd4b57946bbfb (patch) | |
tree | 2387ee8a40ef9d308e6d34ebd0f8af0dc90feb5f /src/reclaim-attribute | |
parent | 065ecd9a0f92ecafd6c552494a6310b92cc08597 (diff) | |
download | gnunet-5fb277e8d012d687f4d2d032571cd4b57946bbfb.tar.gz gnunet-5fb277e8d012d687f4d2d032571cd4b57946bbfb.zip |
towards better API
Diffstat (limited to 'src/reclaim-attribute')
-rw-r--r-- | src/reclaim-attribute/Makefile.am | 2 | ||||
-rw-r--r-- | src/reclaim-attribute/plugin_reclaim_attestation_jwt.c | 53 | ||||
-rw-r--r-- | src/reclaim-attribute/reclaim_attestation.c | 18 |
3 files changed, 72 insertions, 1 deletions
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 |
45 | libgnunet_plugin_reclaim_attestation_jwt_la_LIBADD = \ | 45 | libgnunet_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) |
48 | libgnunet_plugin_reclaim_attestation_jwt_la_LDFLAGS = \ | 50 | libgnunet_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 | */ | ||
153 | struct GNUNET_RECLAIM_AttributeList * | ||
154 | jwt_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 | |||
504 | struct GNUNET_RECLAIM_AttributeList* | ||
505 | GNUNET_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 | } | ||