aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/plugin_reclaim_credential_pabc.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2021-02-22 14:19:18 +0100
committerMartin Schanzenbach <mschanzenbach@posteo.de>2021-04-20 10:50:34 +0200
commit2305c2f718507d3a1870606686493f32af824220 (patch)
treef2dff99c1f490145eacdee2a3caa2a6a1698e725 /src/reclaim/plugin_reclaim_credential_pabc.c
parentbc3ee32f932c63ffd012318d8c9847aff9efd5ef (diff)
downloadgnunet-2305c2f718507d3a1870606686493f32af824220.tar.gz
gnunet-2305c2f718507d3a1870606686493f32af824220.zip
-get pabc metadata from attributes
Diffstat (limited to 'src/reclaim/plugin_reclaim_credential_pabc.c')
-rw-r--r--src/reclaim/plugin_reclaim_credential_pabc.c85
1 files changed, 62 insertions, 23 deletions
diff --git a/src/reclaim/plugin_reclaim_credential_pabc.c b/src/reclaim/plugin_reclaim_credential_pabc.c
index 422d7c82b..6bc94b404 100644
--- a/src/reclaim/plugin_reclaim_credential_pabc.c
+++ b/src/reclaim/plugin_reclaim_credential_pabc.c
@@ -204,6 +204,10 @@ pabc_parse_attributes (void *cls,
204 */ 204 */
205 json_object_foreach (attr, key, value) 205 json_object_foreach (attr, key, value)
206 { 206 {
207 if ((0 == strcmp ("issuer", key)) ||
208 (0 == strcmp ("expiration", key)) ||
209 (0 == strcmp ("subject", key)))
210 continue;
207 val_str = json_dumps (value, JSON_ENCODE_ANY); 211 val_str = json_dumps (value, JSON_ENCODE_ANY);
208 tmp = val_str; 212 tmp = val_str;
209 //Remove leading " from jasson conversion 213 //Remove leading " from jasson conversion
@@ -268,10 +272,13 @@ pabc_get_issuer (void *cls,
268 const char *data, 272 const char *data,
269 size_t data_size) 273 size_t data_size)
270{ 274{
275 const char *key;
271 char *val_str = NULL; 276 char *val_str = NULL;
272 char *tmp; 277 char *tmp;
273 json_t *json_iss;
274 json_t *json_root; 278 json_t *json_root;
279 json_t *json_attrs;
280 json_t *value;
281 json_t *attr;
275 json_error_t *json_err = NULL; 282 json_error_t *json_err = NULL;
276 283
277 json_root = json_loads (data, JSON_DECODE_ANY, json_err); 284 json_root = json_loads (data, JSON_DECODE_ANY, json_err);
@@ -285,24 +292,44 @@ pabc_get_issuer (void *cls,
285 json_decref (json_root); 292 json_decref (json_root);
286 return NULL; 293 return NULL;
287 } 294 }
288 json_iss = json_object_get (json_root, "issuer"); 295 json_attrs = json_object_get (json_root, "attributes");
289 if (NULL == json_iss) 296 if ((NULL == json_attrs) ||
297 (!json_is_array (json_attrs)))
290 { 298 {
291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 299 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
292 "%s is not a valid pabc credential (issuer malformed or missing)\n", 300 "%s is not a valid pabc credentials (attributes not an array)\n",
293 data); 301 data);
294 json_decref (json_root); 302 json_decref (json_root);
295 return NULL; 303 return NULL;
296 } 304 }
297 val_str = json_dumps (json_iss, JSON_ENCODE_ANY); 305
298 tmp = val_str; 306 for (int i = 0; i < json_array_size (json_attrs); i++)
299 //Remove leading " from jasson conversion 307 {
300 if (tmp[0] == '"') 308 attr = json_array_get (json_attrs, i);
301 tmp++; 309 if (!json_is_object(attr))
302 //Remove trailing " from jansson conversion 310 continue;
303 if (tmp[strlen(tmp)-1] == '"') 311 /**
304 tmp[strlen(tmp)-1] = '\0'; 312 * This *should* only contain a single pair.
305 return tmp; 313 */
314 json_object_foreach (attr, key, value)
315 {
316 if (0 != strcmp ("issuer", key))
317 continue;
318 val_str = json_dumps (value, JSON_ENCODE_ANY);
319 tmp = val_str;
320 //Remove leading " from jasson conversion
321 if (tmp[0] == '"')
322 tmp++;
323 //Remove trailing " from jansson conversion
324 if (tmp[strlen(tmp)-1] == '"')
325 tmp[strlen(tmp)-1] = '\0';
326 GNUNET_free (val_str);
327 json_decref (json_root);
328 return tmp;
329 }
330 }
331 json_decref (json_root);
332 return NULL;
306} 333}
307 334
308 335
@@ -353,9 +380,12 @@ pabc_get_expiration (void *cls,
353 size_t data_size, 380 size_t data_size,
354 struct GNUNET_TIME_Absolute *exp) 381 struct GNUNET_TIME_Absolute *exp)
355{ 382{
356 json_t *json_exp;
357 json_t *json_root; 383 json_t *json_root;
384 json_t *json_attrs;
385 json_t *value;
386 json_t *attr;
358 json_error_t *json_err = NULL; 387 json_error_t *json_err = NULL;
388 const char* key;
359 389
360 json_root = json_loads (data, JSON_DECODE_ANY, json_err); 390 json_root = json_loads (data, JSON_DECODE_ANY, json_err);
361 if ((NULL == json_root) || 391 if ((NULL == json_root) ||
@@ -368,18 +398,27 @@ pabc_get_expiration (void *cls,
368 json_decref (json_root); 398 json_decref (json_root);
369 return GNUNET_SYSERR; 399 return GNUNET_SYSERR;
370 } 400 }
371 json_exp = json_object_get (json_root, "expiration"); 401 for (int i = 0; i < json_array_size (json_attrs); i++)
372 if ((NULL == json_exp) || (! json_is_integer (json_exp)))
373 { 402 {
374 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 403 attr = json_array_get (json_attrs, i);
375 "%s is not a valid pabc credential (expiration malformed or missing)\n", 404 if (!json_is_object(attr))
376 data); 405 continue;
377 json_decref (json_root); 406 /**
378 return GNUNET_SYSERR; 407 * This *should* only contain a single pair.
408 */
409 json_object_foreach (attr, key, value)
410 {
411 if (0 != strcmp ("expiration", key))
412 continue;
413 if (!json_is_integer (value))
414 continue;
415 exp->abs_value_us = json_integer_value (value) * 1000 * 1000;
416 json_decref (json_root);
417 return GNUNET_OK;
418 }
379 } 419 }
380 exp->abs_value_us = json_integer_value (json_exp) * 1000 * 1000;
381 json_decref (json_root); 420 json_decref (json_root);
382 return GNUNET_OK; 421 return GNUNET_SYSERR;
383} 422}
384 423
385 424