diff options
Diffstat (limited to 'src/reclaim/plugin_reclaim_credential_jwt.c')
-rw-r--r-- | src/reclaim/plugin_reclaim_credential_jwt.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/reclaim/plugin_reclaim_credential_jwt.c b/src/reclaim/plugin_reclaim_credential_jwt.c index aac0a6ea5..e5dc90363 100644 --- a/src/reclaim/plugin_reclaim_credential_jwt.c +++ b/src/reclaim/plugin_reclaim_credential_jwt.c | |||
@@ -158,11 +158,10 @@ 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; |
165 | json_error_t *json_err = NULL; | 164 | json_error_t json_err; |
166 | 165 | ||
167 | attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); | 166 | attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); |
168 | 167 | ||
@@ -173,7 +172,7 @@ jwt_parse_attributes (void *cls, | |||
173 | (void **) &decoded_jwt); | 172 | (void **) &decoded_jwt); |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decoded JWT: %s\n", decoded_jwt); | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decoded JWT: %s\n", decoded_jwt); |
175 | GNUNET_assert (NULL != decoded_jwt); | 174 | GNUNET_assert (NULL != decoded_jwt); |
176 | json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err); | 175 | json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, &json_err); |
177 | GNUNET_free (decoded_jwt); | 176 | GNUNET_free (decoded_jwt); |
178 | const char *key; | 177 | const char *key; |
179 | const char *addr_key; | 178 | const char *addr_key; |
@@ -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 | ||
@@ -291,14 +294,14 @@ jwt_get_issuer (void *cls, | |||
291 | json_t *issuer_json; | 294 | json_t *issuer_json; |
292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n"); | 295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n"); |
293 | json_t *json_val; | 296 | json_t *json_val; |
294 | json_error_t *json_err = NULL; | 297 | json_error_t json_err; |
295 | 298 | ||
296 | jwt_string = GNUNET_strndup (data, data_size); | 299 | jwt_string = GNUNET_strndup (data, data_size); |
297 | jwt_body = strtok (jwt_string, delim); | 300 | jwt_body = strtok (jwt_string, delim); |
298 | jwt_body = strtok (NULL, delim); | 301 | jwt_body = strtok (NULL, delim); |
299 | GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body), | 302 | GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body), |
300 | (void **) &decoded_jwt); | 303 | (void **) &decoded_jwt); |
301 | json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err); | 304 | json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, &json_err); |
302 | GNUNET_free (decoded_jwt); | 305 | GNUNET_free (decoded_jwt); |
303 | GNUNET_free (jwt_string); | 306 | GNUNET_free (jwt_string); |
304 | if (NULL == json_val) | 307 | if (NULL == json_val) |
@@ -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, |
@@ -368,14 +371,14 @@ jwt_get_expiration (void *cls, | |||
368 | json_t *exp_json; | 371 | json_t *exp_json; |
369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n"); | 372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n"); |
370 | json_t *json_val; | 373 | json_t *json_val; |
371 | json_error_t *json_err = NULL; | 374 | json_error_t json_err; |
372 | 375 | ||
373 | jwt_string = GNUNET_strndup (data, data_size); | 376 | jwt_string = GNUNET_strndup (data, data_size); |
374 | jwt_body = strtok (jwt_string, delim); | 377 | jwt_body = strtok (jwt_string, delim); |
375 | jwt_body = strtok (NULL, delim); | 378 | jwt_body = strtok (NULL, delim); |
376 | GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body), | 379 | GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body), |
377 | (void **) &decoded_jwt); | 380 | (void **) &decoded_jwt); |
378 | json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err); | 381 | json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, &json_err); |
379 | GNUNET_free (decoded_jwt); | 382 | GNUNET_free (decoded_jwt); |
380 | GNUNET_free (jwt_string); | 383 | GNUNET_free (jwt_string); |
381 | if (NULL == json_val) | 384 | if (NULL == json_val) |
@@ -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, |