From e78aaa7eb9f1f69c6c6f1efd53f4196820471ec9 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Tue, 20 Apr 2021 19:56:26 +0200 Subject: - fix --- src/reclaim/json_reclaim.c | 16 +++++++++++----- src/reclaim/plugin_reclaim_credential_jwt.c | 20 +++++++++++++------- src/reclaim/plugin_reclaim_credential_pabc.c | 23 +++++++++++++++++++---- 3 files changed, 43 insertions(+), 16 deletions(-) (limited to 'src') 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 { struct GNUNET_RECLAIM_Credential *cred; const char *name_str = NULL; - const char *val_str = NULL; const char *type_str = NULL; const char *id_str = NULL; - char *data; + json_t *val_json; + char *data = NULL; + char *val_str = NULL; int unpack_state; uint32_t type; size_t data_size; @@ -308,7 +309,7 @@ parse_credential (void *cls, json_t *root, struct GNUNET_JSON_Specification *spe } // interpret single attribute unpack_state = json_unpack (root, - "{s:s, s?s, s:s, s:s!}", + "{s:s, s?s, s:s, s:o!}", "name", &name_str, "id", @@ -316,14 +317,19 @@ parse_credential (void *cls, json_t *root, struct GNUNET_JSON_Specification *spe "type", &type_str, "value", - &val_str); - if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || + &val_json); + if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_json) || (NULL == type_str)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error json object has a wrong format!\n"); return GNUNET_SYSERR; } + if (json_is_string (val_json)) { + val_str = GNUNET_strdup (json_string_value (val_json)); + } else { + val_str = json_dumps (val_json, JSON_COMPACT); + } type = GNUNET_RECLAIM_credential_typename_to_number (type_str); if (GNUNET_SYSERR == (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, 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; @@ -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); } @@ -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, @@ -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, 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, { struct GNUNET_RECLAIM_AttributeList *attrs = ctx; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Found attribue in PABC credential: `%s': `%s'\n", + key, value); GNUNET_RECLAIM_attribute_list_add (attrs, key, NULL, @@ -193,15 +196,19 @@ pabc_parse_attributes (void *cls, (! json_is_object (json_attrs))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "%s is not a valid pabc credentials (attributes not an object)\n", + "%s is not a valid pab credentials (attributes not an object)\n", data); json_decref (json_root); return NULL; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Collecting PABC attributes...\n"); attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); char *attr_str = json_dumps (json_attrs, JSON_DECODE_ANY); - pabc_cred_inspect_credential (attr_str, &inspect_attrs, attrs); + GNUNET_assert (PABC_OK == + pabc_cred_inspect_credential (attr_str, + &inspect_attrs, attrs)); json_decref (json_root); return attrs; } @@ -218,6 +225,8 @@ struct GNUNET_RECLAIM_AttributeList * pabc_parse_attributes_c (void *cls, const struct GNUNET_RECLAIM_Credential *cred) { + if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC) + return NULL; return pabc_parse_attributes (cls, cred->data, cred->data_size); } @@ -233,6 +242,8 @@ struct GNUNET_RECLAIM_AttributeList * pabc_parse_attributes_p (void *cls, const struct GNUNET_RECLAIM_Presentation *cred) { + if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC) + return NULL; return pabc_parse_attributes (cls, cred->data, cred->data_size); } @@ -413,11 +424,13 @@ pabc_get_expiration (void *cls, * @param cred the pabc credential * @return a string, containing the isser */ -int +enum GNUNET_GenericReturnValue pabc_get_expiration_c (void *cls, const struct GNUNET_RECLAIM_Credential *cred, struct GNUNET_TIME_Absolute *exp) { + if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC) + return GNUNET_NO; return pabc_get_expiration (cls, cred->data, cred->data_size, exp); } @@ -429,11 +442,13 @@ pabc_get_expiration_c (void *cls, * @param cred the pabc credential * @return a string, containing the isser */ -int +enum GNUNET_GenericReturnValue pabc_get_expiration_p (void *cls, const struct GNUNET_RECLAIM_Presentation *cred, struct GNUNET_TIME_Absolute *exp) { + if (cred->type != GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC) + return GNUNET_NO; return pabc_get_expiration (cls, cred->data, cred->data_size, exp); } -- cgit v1.2.3