summaryrefslogtreecommitdiff
path: root/src/reclaim/plugin_reclaim_credential_jwt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reclaim/plugin_reclaim_credential_jwt.c')
-rw-r--r--src/reclaim/plugin_reclaim_credential_jwt.c32
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,
struct GNUNET_RECLAIM_AttributeList *attrs;
char delim[] = ".";
char *val_str = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
char *decoded_jwt;
char *tmp;
json_t *json_val;
- json_error_t *json_err = NULL;
+ json_error_t json_err;
attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
@@ -173,7 +172,7 @@ jwt_parse_attributes (void *cls,
(void **) &decoded_jwt);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decoded JWT: %s\n", decoded_jwt);
GNUNET_assert (NULL != decoded_jwt);
- json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
+ json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, &json_err);
GNUNET_free (decoded_jwt);
const char *key;
const char *addr_key;
@@ -252,6 +251,8 @@ struct GNUNET_RECLAIM_AttributeList *
jwt_parse_attributes_c (void *cls,
const struct GNUNET_RECLAIM_Credential *cred)
{
+ if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT)
+ return NULL;
return jwt_parse_attributes (cls, cred->data, cred->data_size);
}
@@ -267,6 +268,8 @@ struct GNUNET_RECLAIM_AttributeList *
jwt_parse_attributes_p (void *cls,
const struct GNUNET_RECLAIM_Presentation *cred)
{
+ if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT)
+ return NULL;
return jwt_parse_attributes (cls, cred->data, cred->data_size);
}
@@ -291,14 +294,14 @@ jwt_get_issuer (void *cls,
json_t *issuer_json;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
json_t *json_val;
- json_error_t *json_err = NULL;
+ json_error_t json_err;
jwt_string = GNUNET_strndup (data, data_size);
jwt_body = strtok (jwt_string, delim);
jwt_body = strtok (NULL, delim);
GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body),
(void **) &decoded_jwt);
- json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
+ json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, &json_err);
GNUNET_free (decoded_jwt);
GNUNET_free (jwt_string);
if (NULL == json_val)
@@ -355,7 +358,7 @@ jwt_get_issuer_p (void *cls,
* @param cred the jwt credential
* @return a string, containing the isser
*/
-int
+enum GNUNET_GenericReturnValue
jwt_get_expiration (void *cls,
const char *data,
size_t data_size,
@@ -368,14 +371,14 @@ jwt_get_expiration (void *cls,
json_t *exp_json;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
json_t *json_val;
- json_error_t *json_err = NULL;
+ json_error_t json_err;
jwt_string = GNUNET_strndup (data, data_size);
jwt_body = strtok (jwt_string, delim);
jwt_body = strtok (NULL, delim);
GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body),
(void **) &decoded_jwt);
- json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
+ json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, &json_err);
GNUNET_free (decoded_jwt);
GNUNET_free (jwt_string);
if (NULL == json_val)
@@ -396,13 +399,15 @@ jwt_get_expiration (void *cls,
*
* @param cls the plugin
* @param cred the jwt credential
- * @return a string, containing the isser
+ * @return the expirati
*/
-int
+enum GNUNET_GenericReturnValue
jwt_get_expiration_c (void *cls,
const struct GNUNET_RECLAIM_Credential *cred,
struct GNUNET_TIME_Absolute *exp)
{
+ if (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT != cred->type)
+ return GNUNET_NO;
return jwt_get_expiration (cls, cred->data, cred->data_size, exp);
}
@@ -414,22 +419,23 @@ jwt_get_expiration_c (void *cls,
* @param cred the jwt credential
* @return a string, containing the isser
*/
-int
+enum GNUNET_GenericReturnValue
jwt_get_expiration_p (void *cls,
const struct GNUNET_RECLAIM_Presentation *cred,
struct GNUNET_TIME_Absolute *exp)
{
+ if (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT != cred->type)
+ return GNUNET_NO;
return jwt_get_expiration (cls, cred->data, cred->data_size, exp);
}
-int
+enum GNUNET_GenericReturnValue
jwt_create_presentation (void *cls,
const struct GNUNET_RECLAIM_Credential *cred,
const struct GNUNET_RECLAIM_AttributeList *attrs,
struct GNUNET_RECLAIM_Presentation **pres)
{
- // FIXME sanity checks??
if (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT != cred->type)
return GNUNET_NO;
*pres = GNUNET_RECLAIM_presentation_new (GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT,