diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2021-04-20 19:03:41 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2021-04-20 19:03:41 +0200 |
commit | 22d8a6445a1807e9a9e032d85c0503ed08e70bf7 (patch) | |
tree | e9f9d6020e1f294c7fcbb31340d425f1158bf04e /src/reclaim/plugin_reclaim_credential_pabc.c | |
parent | 5faab5da8337e5060002cba8cf5c4c1d8bc89a1e (diff) | |
download | gnunet-22d8a6445a1807e9a9e032d85c0503ed08e70bf7.tar.gz gnunet-22d8a6445a1807e9a9e032d85c0503ed08e70bf7.zip |
- towards pabc fixing
Diffstat (limited to 'src/reclaim/plugin_reclaim_credential_pabc.c')
-rw-r--r-- | src/reclaim/plugin_reclaim_credential_pabc.c | 169 |
1 files changed, 67 insertions, 102 deletions
diff --git a/src/reclaim/plugin_reclaim_credential_pabc.c b/src/reclaim/plugin_reclaim_credential_pabc.c index 148cfec13..e17520528 100644 --- a/src/reclaim/plugin_reclaim_credential_pabc.c +++ b/src/reclaim/plugin_reclaim_credential_pabc.c | |||
@@ -144,6 +144,22 @@ pabc_number_to_typename (void *cls, uint32_t type) | |||
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | static void | ||
148 | inspect_attrs (char const *const key, | ||
149 | char const *const value, | ||
150 | void *ctx) | ||
151 | { | ||
152 | struct GNUNET_RECLAIM_AttributeList *attrs = ctx; | ||
153 | |||
154 | GNUNET_RECLAIM_attribute_list_add (attrs, | ||
155 | key, | ||
156 | NULL, | ||
157 | GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, | ||
158 | value, | ||
159 | strlen (value)); | ||
160 | } | ||
161 | |||
162 | |||
147 | /** | 163 | /** |
148 | * Parse a pabc and return the respective claim value as Attribute | 164 | * Parse a pabc and return the respective claim value as Attribute |
149 | * | 165 | * |
@@ -156,14 +172,9 @@ pabc_parse_attributes (void *cls, | |||
156 | const char *data, | 172 | const char *data, |
157 | size_t data_size) | 173 | size_t data_size) |
158 | { | 174 | { |
159 | const char *key; | ||
160 | struct GNUNET_RECLAIM_AttributeList *attrs; | 175 | struct GNUNET_RECLAIM_AttributeList *attrs; |
161 | char *val_str = NULL; | ||
162 | char *tmp; | ||
163 | json_t *value; | ||
164 | json_t *attr; | ||
165 | json_t *json_attrs; | ||
166 | json_t *json_root; | 176 | json_t *json_root; |
177 | json_t *json_attrs; | ||
167 | json_error_t *json_err = NULL; | 178 | json_error_t *json_err = NULL; |
168 | 179 | ||
169 | json_root = json_loads (data, JSON_DECODE_ANY, json_err); | 180 | json_root = json_loads (data, JSON_DECODE_ANY, json_err); |
@@ -177,55 +188,20 @@ pabc_parse_attributes (void *cls, | |||
177 | json_decref (json_root); | 188 | json_decref (json_root); |
178 | return NULL; | 189 | return NULL; |
179 | } | 190 | } |
180 | json_attrs = json_object_get (json_root, "attributes"); | 191 | json_attrs = json_object_get (json_root, PABC_JSON_PLAIN_ATTRS_KEY); |
181 | if ((NULL == json_attrs) || | 192 | if ((NULL == json_attrs) || |
182 | (! json_is_array (json_attrs))) | 193 | (! json_is_object (json_attrs))) |
183 | { | 194 | { |
184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 195 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
185 | "%s is not a valid pabc credentials (attributes not an array)\n", | 196 | "%s is not a valid pabc credentials (attributes not an object)\n", |
186 | data); | 197 | data); |
187 | json_decref (json_root); | 198 | json_decref (json_root); |
188 | return NULL; | 199 | return NULL; |
189 | } | 200 | } |
190 | 201 | ||
191 | attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); | 202 | attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); |
192 | for (int i = 0; i < json_array_size (json_attrs); i++) | 203 | char *attr_str = json_dumps (json_attrs, JSON_DECODE_ANY); |
193 | { | 204 | pabc_cred_inspect_credential (attr_str, &inspect_attrs, attrs); |
194 | attr = json_array_get (json_attrs, i); | ||
195 | if (! json_is_object (attr)) | ||
196 | { | ||
197 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
198 | "Found json entry is not an object!\n"); | ||
199 | GNUNET_RECLAIM_attribute_list_destroy (attrs); | ||
200 | json_decref (json_root); | ||
201 | return NULL; | ||
202 | } | ||
203 | /** | ||
204 | * This *should* only contain a single pair. | ||
205 | */ | ||
206 | json_object_foreach (attr, key, value) | ||
207 | { | ||
208 | if ((0 == strcmp ("issuer", key)) || | ||
209 | (0 == strcmp ("expiration", key)) || | ||
210 | (0 == strcmp ("subject", key))) | ||
211 | continue; | ||
212 | val_str = json_dumps (value, JSON_ENCODE_ANY); | ||
213 | tmp = val_str; | ||
214 | // Remove leading " from jasson conversion | ||
215 | if (tmp[0] == '"') | ||
216 | tmp++; | ||
217 | // Remove trailing " from jansson conversion | ||
218 | if (tmp[strlen (tmp) - 1] == '"') | ||
219 | tmp[strlen (tmp) - 1] = '\0'; | ||
220 | GNUNET_RECLAIM_attribute_list_add (attrs, | ||
221 | key, | ||
222 | NULL, | ||
223 | GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, | ||
224 | tmp, | ||
225 | strlen (tmp)); | ||
226 | GNUNET_free (val_str); | ||
227 | } | ||
228 | } | ||
229 | json_decref (json_root); | 205 | json_decref (json_root); |
230 | return attrs; | 206 | return attrs; |
231 | } | 207 | } |
@@ -260,6 +236,23 @@ pabc_parse_attributes_p (void *cls, | |||
260 | return pabc_parse_attributes (cls, cred->data, cred->data_size); | 236 | return pabc_parse_attributes (cls, cred->data, cred->data_size); |
261 | } | 237 | } |
262 | 238 | ||
239 | struct Finder | ||
240 | { | ||
241 | const char* target; | ||
242 | char *result; | ||
243 | }; | ||
244 | |||
245 | static void | ||
246 | find_attr (char const *const key, | ||
247 | char const *const value, | ||
248 | void *ctx) | ||
249 | { | ||
250 | struct Finder *fdr = ctx; | ||
251 | if (0 == strcmp (key, fdr->target)) | ||
252 | fdr->result = GNUNET_strdup (value); | ||
253 | } | ||
254 | |||
255 | |||
263 | 256 | ||
264 | /** | 257 | /** |
265 | * Parse a pabc and return an attribute value. | 258 | * Parse a pabc and return an attribute value. |
@@ -267,7 +260,7 @@ pabc_parse_attributes_p (void *cls, | |||
267 | * @param cls the plugin | 260 | * @param cls the plugin |
268 | * @param data the pabc credential data | 261 | * @param data the pabc credential data |
269 | * @param data_size the pabc credential size | 262 | * @param data_size the pabc credential size |
270 | * @param key the attribute key to look for. | 263 | * @param skey the attribute key to look for. |
271 | * @return a string, containing the isser | 264 | * @return a string, containing the isser |
272 | */ | 265 | */ |
273 | char * | 266 | char * |
@@ -276,13 +269,8 @@ pabc_get_attribute (void *cls, | |||
276 | size_t data_size, | 269 | size_t data_size, |
277 | const char *skey) | 270 | const char *skey) |
278 | { | 271 | { |
279 | const char *key; | ||
280 | char *val_str = NULL; | ||
281 | char *tmp; | ||
282 | json_t *json_root; | 272 | json_t *json_root; |
283 | json_t *json_attrs; | 273 | json_t *json_attrs; |
284 | json_t *value; | ||
285 | json_t *attr; | ||
286 | json_error_t *json_err = NULL; | 274 | json_error_t *json_err = NULL; |
287 | 275 | ||
288 | json_root = json_loads (data, JSON_DECODE_ANY, json_err); | 276 | json_root = json_loads (data, JSON_DECODE_ANY, json_err); |
@@ -290,50 +278,29 @@ pabc_get_attribute (void *cls, | |||
290 | (! json_is_object (json_root))) | 278 | (! json_is_object (json_root))) |
291 | { | 279 | { |
292 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
293 | "%s is not a valid pabc credentials (not an object)\n", | 281 | "%s is not a valid pabc credential (not an object)\n", |
294 | data); | 282 | data); |
295 | if (NULL != json_root) | 283 | if (NULL != json_root) |
296 | json_decref (json_root); | 284 | json_decref (json_root); |
297 | return NULL; | 285 | return NULL; |
298 | } | 286 | } |
299 | json_attrs = json_object_get (json_root, "attributes"); | 287 | json_attrs = json_object_get (json_root, PABC_JSON_PLAIN_ATTRS_KEY); |
300 | if ((NULL == json_attrs) || | 288 | if ((NULL == json_attrs) || |
301 | (! json_is_array (json_attrs))) | 289 | (! json_is_object (json_attrs))) |
302 | { | 290 | { |
303 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 291 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
304 | "%s is not a valid pabc credentials (attributes not an array)\n", | 292 | "%s is not a valid pabc credential (attributes not an object)\n", |
305 | data); | 293 | data); |
306 | json_decref (json_root); | 294 | json_decref (json_root); |
307 | return NULL; | 295 | return NULL; |
308 | } | 296 | } |
309 | 297 | char *attr_str = json_dumps (json_attrs, JSON_DECODE_ANY); | |
310 | for (int i = 0; i < json_array_size (json_attrs); i++) | ||
311 | { | ||
312 | attr = json_array_get (json_attrs, i); | ||
313 | if (! json_is_object (attr)) | ||
314 | continue; | ||
315 | /** | ||
316 | * This *should* only contain a single pair. | ||
317 | */ | ||
318 | json_object_foreach (attr, key, value) | ||
319 | { | ||
320 | if (0 != strcmp (skey, key)) | ||
321 | continue; | ||
322 | val_str = json_dumps (value, JSON_ENCODE_ANY); | ||
323 | tmp = val_str; | ||
324 | // Remove leading " from jasson conversion | ||
325 | if (tmp[0] == '"') | ||
326 | tmp++; | ||
327 | // Remove trailing " from jansson conversion | ||
328 | if (tmp[strlen (tmp) - 1] == '"') | ||
329 | tmp[strlen (tmp) - 1] = '\0'; | ||
330 | GNUNET_free (val_str); | ||
331 | json_decref (json_root); | ||
332 | return tmp; | ||
333 | } | ||
334 | } | ||
335 | json_decref (json_root); | 298 | json_decref (json_root); |
336 | return NULL; | 299 | struct Finder fdr; |
300 | memset (&fdr, 0, sizeof (fdr)); | ||
301 | fdr.target = skey; | ||
302 | pabc_cred_inspect_credential (attr_str, &find_attr, &fdr); | ||
303 | return fdr.result; | ||
337 | } | 304 | } |
338 | 305 | ||
339 | 306 | ||
@@ -403,9 +370,8 @@ pabc_get_expiration (void *cls, | |||
403 | json_t *json_root; | 370 | json_t *json_root; |
404 | json_t *json_attrs; | 371 | json_t *json_attrs; |
405 | json_t *value; | 372 | json_t *value; |
406 | json_t *attr; | 373 | json_t *exp_j; |
407 | json_error_t *json_err = NULL; | 374 | json_error_t *json_err = NULL; |
408 | const char*key; | ||
409 | 375 | ||
410 | json_root = json_loads (data, JSON_DECODE_ANY, json_err); | 376 | json_root = json_loads (data, JSON_DECODE_ANY, json_err); |
411 | if ((NULL == json_root) || | 377 | if ((NULL == json_root) || |
@@ -418,24 +384,23 @@ pabc_get_expiration (void *cls, | |||
418 | json_decref (json_root); | 384 | json_decref (json_root); |
419 | return GNUNET_SYSERR; | 385 | return GNUNET_SYSERR; |
420 | } | 386 | } |
421 | for (int i = 0; i < json_array_size (json_attrs); i++) | 387 | json_attrs = json_object_get (json_root, PABC_JSON_PLAIN_ATTRS_KEY); |
388 | if ((NULL == json_attrs) || | ||
389 | (! json_is_object (json_attrs))) | ||
422 | { | 390 | { |
423 | attr = json_array_get (json_attrs, i); | 391 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
424 | if (! json_is_object (attr)) | 392 | "%s is not a valid pabc credential (attributes not an object)\n", |
425 | continue; | 393 | data); |
426 | /** | 394 | json_decref (json_root); |
427 | * This *should* only contain a single pair. | 395 | return GNUNET_SYSERR; |
428 | */ | 396 | } |
429 | json_object_foreach (attr, key, value) | 397 | exp_j = json_object_get (json_attrs, "expiration"); |
430 | { | 398 | if ((NULL != exp_j) && |
431 | if (0 != strcmp ("expiration", key)) | 399 | json_is_integer (exp_j)) |
432 | continue; | 400 | { |
433 | if (! json_is_integer (value)) | 401 | exp->abs_value_us = json_integer_value (value) * 1000 * 1000; |
434 | continue; | 402 | json_decref (json_root); |
435 | exp->abs_value_us = json_integer_value (value) * 1000 * 1000; | 403 | return GNUNET_OK; |
436 | json_decref (json_root); | ||
437 | return GNUNET_OK; | ||
438 | } | ||
439 | } | 404 | } |
440 | json_decref (json_root); | 405 | json_decref (json_root); |
441 | return GNUNET_SYSERR; | 406 | return GNUNET_SYSERR; |