diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/reclaim/json_reclaim.c | 16 | ||||
-rw-r--r-- | src/reclaim/plugin_reclaim_credential_jwt.c | 20 | ||||
-rw-r--r-- | src/reclaim/plugin_reclaim_credential_pabc.c | 23 |
3 files changed, 43 insertions, 16 deletions
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index 4eeb22bee..b1ca7a4a5 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c | |||
@@ -290,10 +290,11 @@ parse_credential (void *cls, json_t *root, struct GNUNET_JSON_Specification *spe | |||
290 | { | 290 | { |
291 | struct GNUNET_RECLAIM_Credential *cred; | 291 | struct GNUNET_RECLAIM_Credential *cred; |
292 | const char *name_str = NULL; | 292 | const char *name_str = NULL; |
293 | const char *val_str = NULL; | ||
294 | const char *type_str = NULL; | 293 | const char *type_str = NULL; |
295 | const char *id_str = NULL; | 294 | const char *id_str = NULL; |
296 | char *data; | 295 | json_t *val_json; |
296 | char *data = NULL; | ||
297 | char *val_str = NULL; | ||
297 | int unpack_state; | 298 | int unpack_state; |
298 | uint32_t type; | 299 | uint32_t type; |
299 | size_t data_size; | 300 | size_t data_size; |
@@ -308,7 +309,7 @@ parse_credential (void *cls, json_t *root, struct GNUNET_JSON_Specification *spe | |||
308 | } | 309 | } |
309 | // interpret single attribute | 310 | // interpret single attribute |
310 | unpack_state = json_unpack (root, | 311 | unpack_state = json_unpack (root, |
311 | "{s:s, s?s, s:s, s:s!}", | 312 | "{s:s, s?s, s:s, s:o!}", |
312 | "name", | 313 | "name", |
313 | &name_str, | 314 | &name_str, |
314 | "id", | 315 | "id", |
@@ -316,14 +317,19 @@ parse_credential (void *cls, json_t *root, struct GNUNET_JSON_Specification *spe | |||
316 | "type", | 317 | "type", |
317 | &type_str, | 318 | &type_str, |
318 | "value", | 319 | "value", |
319 | &val_str); | 320 | &val_json); |
320 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || | 321 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_json) || |
321 | (NULL == type_str)) | 322 | (NULL == type_str)) |
322 | { | 323 | { |
323 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 324 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
324 | "Error json object has a wrong format!\n"); | 325 | "Error json object has a wrong format!\n"); |
325 | return GNUNET_SYSERR; | 326 | return GNUNET_SYSERR; |
326 | } | 327 | } |
328 | if (json_is_string (val_json)) { | ||
329 | val_str = GNUNET_strdup (json_string_value (val_json)); | ||
330 | } else { | ||
331 | val_str = json_dumps (val_json, JSON_COMPACT); | ||
332 | } | ||
327 | type = GNUNET_RECLAIM_credential_typename_to_number (type_str); | 333 | type = GNUNET_RECLAIM_credential_typename_to_number (type_str); |
328 | if (GNUNET_SYSERR == | 334 | if (GNUNET_SYSERR == |
329 | (GNUNET_RECLAIM_credential_string_to_value (type, | 335 | (GNUNET_RECLAIM_credential_string_to_value (type, |
diff --git a/src/reclaim/plugin_reclaim_credential_jwt.c b/src/reclaim/plugin_reclaim_credential_jwt.c index 425ac3450..e5dc90363 100644 --- a/src/reclaim/plugin_reclaim_credential_jwt.c +++ b/src/reclaim/plugin_reclaim_credential_jwt.c | |||
@@ -158,7 +158,6 @@ jwt_parse_attributes (void *cls, | |||
158 | struct GNUNET_RECLAIM_AttributeList *attrs; | 158 | struct GNUNET_RECLAIM_AttributeList *attrs; |
159 | char delim[] = "."; | 159 | char delim[] = "."; |
160 | char *val_str = NULL; | 160 | char *val_str = NULL; |
161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n"); | ||
162 | char *decoded_jwt; | 161 | char *decoded_jwt; |
163 | char *tmp; | 162 | char *tmp; |
164 | json_t *json_val; | 163 | json_t *json_val; |
@@ -252,6 +251,8 @@ struct GNUNET_RECLAIM_AttributeList * | |||
252 | jwt_parse_attributes_c (void *cls, | 251 | jwt_parse_attributes_c (void *cls, |
253 | const struct GNUNET_RECLAIM_Credential *cred) | 252 | const struct GNUNET_RECLAIM_Credential *cred) |
254 | { | 253 | { |
254 | if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT) | ||
255 | return NULL; | ||
255 | return jwt_parse_attributes (cls, cred->data, cred->data_size); | 256 | return jwt_parse_attributes (cls, cred->data, cred->data_size); |
256 | } | 257 | } |
257 | 258 | ||
@@ -267,6 +268,8 @@ struct GNUNET_RECLAIM_AttributeList * | |||
267 | jwt_parse_attributes_p (void *cls, | 268 | jwt_parse_attributes_p (void *cls, |
268 | const struct GNUNET_RECLAIM_Presentation *cred) | 269 | const struct GNUNET_RECLAIM_Presentation *cred) |
269 | { | 270 | { |
271 | if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT) | ||
272 | return NULL; | ||
270 | return jwt_parse_attributes (cls, cred->data, cred->data_size); | 273 | return jwt_parse_attributes (cls, cred->data, cred->data_size); |
271 | } | 274 | } |
272 | 275 | ||
@@ -355,7 +358,7 @@ jwt_get_issuer_p (void *cls, | |||
355 | * @param cred the jwt credential | 358 | * @param cred the jwt credential |
356 | * @return a string, containing the isser | 359 | * @return a string, containing the isser |
357 | */ | 360 | */ |
358 | int | 361 | enum GNUNET_GenericReturnValue |
359 | jwt_get_expiration (void *cls, | 362 | jwt_get_expiration (void *cls, |
360 | const char *data, | 363 | const char *data, |
361 | size_t data_size, | 364 | size_t data_size, |
@@ -396,13 +399,15 @@ jwt_get_expiration (void *cls, | |||
396 | * | 399 | * |
397 | * @param cls the plugin | 400 | * @param cls the plugin |
398 | * @param cred the jwt credential | 401 | * @param cred the jwt credential |
399 | * @return a string, containing the isser | 402 | * @return the expirati |
400 | */ | 403 | */ |
401 | int | 404 | enum GNUNET_GenericReturnValue |
402 | jwt_get_expiration_c (void *cls, | 405 | jwt_get_expiration_c (void *cls, |
403 | const struct GNUNET_RECLAIM_Credential *cred, | 406 | const struct GNUNET_RECLAIM_Credential *cred, |
404 | struct GNUNET_TIME_Absolute *exp) | 407 | struct GNUNET_TIME_Absolute *exp) |
405 | { | 408 | { |
409 | if (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT != cred->type) | ||
410 | return GNUNET_NO; | ||
406 | return jwt_get_expiration (cls, cred->data, cred->data_size, exp); | 411 | return jwt_get_expiration (cls, cred->data, cred->data_size, exp); |
407 | } | 412 | } |
408 | 413 | ||
@@ -414,22 +419,23 @@ jwt_get_expiration_c (void *cls, | |||
414 | * @param cred the jwt credential | 419 | * @param cred the jwt credential |
415 | * @return a string, containing the isser | 420 | * @return a string, containing the isser |
416 | */ | 421 | */ |
417 | int | 422 | enum GNUNET_GenericReturnValue |
418 | jwt_get_expiration_p (void *cls, | 423 | jwt_get_expiration_p (void *cls, |
419 | const struct GNUNET_RECLAIM_Presentation *cred, | 424 | const struct GNUNET_RECLAIM_Presentation *cred, |
420 | struct GNUNET_TIME_Absolute *exp) | 425 | struct GNUNET_TIME_Absolute *exp) |
421 | { | 426 | { |
427 | if (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT != cred->type) | ||
428 | return GNUNET_NO; | ||
422 | return jwt_get_expiration (cls, cred->data, cred->data_size, exp); | 429 | return jwt_get_expiration (cls, cred->data, cred->data_size, exp); |
423 | } | 430 | } |
424 | 431 | ||
425 | 432 | ||
426 | int | 433 | enum GNUNET_GenericReturnValue |
427 | jwt_create_presentation (void *cls, | 434 | jwt_create_presentation (void *cls, |
428 | const struct GNUNET_RECLAIM_Credential *cred, | 435 | const struct GNUNET_RECLAIM_Credential *cred, |
429 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 436 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
430 | struct GNUNET_RECLAIM_Presentation **pres) | 437 | struct GNUNET_RECLAIM_Presentation **pres) |
431 | { | 438 | { |
432 | // FIXME sanity checks?? | ||
433 | if (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT != cred->type) | 439 | if (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT != cred->type) |
434 | return GNUNET_NO; | 440 | return GNUNET_NO; |
435 | *pres = GNUNET_RECLAIM_presentation_new (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT, | 441 | *pres = GNUNET_RECLAIM_presentation_new (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT, |
diff --git a/src/reclaim/plugin_reclaim_credential_pabc.c b/src/reclaim/plugin_reclaim_credential_pabc.c index 87406e60b..84b1f92f5 100644 --- a/src/reclaim/plugin_reclaim_credential_pabc.c +++ b/src/reclaim/plugin_reclaim_credential_pabc.c | |||
@@ -151,6 +151,9 @@ inspect_attrs (char const *const key, | |||
151 | { | 151 | { |
152 | struct GNUNET_RECLAIM_AttributeList *attrs = ctx; | 152 | struct GNUNET_RECLAIM_AttributeList *attrs = ctx; |
153 | 153 | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
155 | "Found attribue in PABC credential: `%s': `%s'\n", | ||
156 | key, value); | ||
154 | GNUNET_RECLAIM_attribute_list_add (attrs, | 157 | GNUNET_RECLAIM_attribute_list_add (attrs, |
155 | key, | 158 | key, |
156 | NULL, | 159 | NULL, |
@@ -193,15 +196,19 @@ pabc_parse_attributes (void *cls, | |||
193 | (! json_is_object (json_attrs))) | 196 | (! json_is_object (json_attrs))) |
194 | { | 197 | { |
195 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 198 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
196 | "%s is not a valid pabc credentials (attributes not an object)\n", | 199 | "%s is not a valid pab credentials (attributes not an object)\n", |
197 | data); | 200 | data); |
198 | json_decref (json_root); | 201 | json_decref (json_root); |
199 | return NULL; | 202 | return NULL; |
200 | } | 203 | } |
201 | 204 | ||
205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
206 | "Collecting PABC attributes...\n"); | ||
202 | attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); | 207 | attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); |
203 | char *attr_str = json_dumps (json_attrs, JSON_DECODE_ANY); | 208 | char *attr_str = json_dumps (json_attrs, JSON_DECODE_ANY); |
204 | pabc_cred_inspect_credential (attr_str, &inspect_attrs, attrs); | 209 | GNUNET_assert (PABC_OK == |
210 | pabc_cred_inspect_credential (attr_str, | ||
211 | &inspect_attrs, attrs)); | ||
205 | json_decref (json_root); | 212 | json_decref (json_root); |
206 | return attrs; | 213 | return attrs; |
207 | } | 214 | } |
@@ -218,6 +225,8 @@ struct GNUNET_RECLAIM_AttributeList * | |||
218 | pabc_parse_attributes_c (void *cls, | 225 | pabc_parse_attributes_c (void *cls, |
219 | const struct GNUNET_RECLAIM_Credential *cred) | 226 | const struct GNUNET_RECLAIM_Credential *cred) |
220 | { | 227 | { |
228 | if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC) | ||
229 | return NULL; | ||
221 | return pabc_parse_attributes (cls, cred->data, cred->data_size); | 230 | return pabc_parse_attributes (cls, cred->data, cred->data_size); |
222 | } | 231 | } |
223 | 232 | ||
@@ -233,6 +242,8 @@ struct GNUNET_RECLAIM_AttributeList * | |||
233 | pabc_parse_attributes_p (void *cls, | 242 | pabc_parse_attributes_p (void *cls, |
234 | const struct GNUNET_RECLAIM_Presentation *cred) | 243 | const struct GNUNET_RECLAIM_Presentation *cred) |
235 | { | 244 | { |
245 | if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC) | ||
246 | return NULL; | ||
236 | return pabc_parse_attributes (cls, cred->data, cred->data_size); | 247 | return pabc_parse_attributes (cls, cred->data, cred->data_size); |
237 | } | 248 | } |
238 | 249 | ||
@@ -413,11 +424,13 @@ pabc_get_expiration (void *cls, | |||
413 | * @param cred the pabc credential | 424 | * @param cred the pabc credential |
414 | * @return a string, containing the isser | 425 | * @return a string, containing the isser |
415 | */ | 426 | */ |
416 | int | 427 | enum GNUNET_GenericReturnValue |
417 | pabc_get_expiration_c (void *cls, | 428 | pabc_get_expiration_c (void *cls, |
418 | const struct GNUNET_RECLAIM_Credential *cred, | 429 | const struct GNUNET_RECLAIM_Credential *cred, |
419 | struct GNUNET_TIME_Absolute *exp) | 430 | struct GNUNET_TIME_Absolute *exp) |
420 | { | 431 | { |
432 | if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC) | ||
433 | return GNUNET_NO; | ||
421 | return pabc_get_expiration (cls, cred->data, cred->data_size, exp); | 434 | return pabc_get_expiration (cls, cred->data, cred->data_size, exp); |
422 | } | 435 | } |
423 | 436 | ||
@@ -429,11 +442,13 @@ pabc_get_expiration_c (void *cls, | |||
429 | * @param cred the pabc credential | 442 | * @param cred the pabc credential |
430 | * @return a string, containing the isser | 443 | * @return a string, containing the isser |
431 | */ | 444 | */ |
432 | int | 445 | enum GNUNET_GenericReturnValue |
433 | pabc_get_expiration_p (void *cls, | 446 | pabc_get_expiration_p (void *cls, |
434 | const struct GNUNET_RECLAIM_Presentation *cred, | 447 | const struct GNUNET_RECLAIM_Presentation *cred, |
435 | struct GNUNET_TIME_Absolute *exp) | 448 | struct GNUNET_TIME_Absolute *exp) |
436 | { | 449 | { |
450 | if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC) | ||
451 | return GNUNET_NO; | ||
437 | return pabc_get_expiration (cls, cred->data, cred->data_size, exp); | 452 | return pabc_get_expiration (cls, cred->data, cred->data_size, exp); |
438 | } | 453 | } |
439 | 454 | ||