From 8e4c4ea64be4bf099afb8ffd1fd24aae0b68003b Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Wed, 21 Apr 2021 09:06:26 +0200 Subject: -fix presentations --- src/reclaim/pabc_helper.c | 67 +++++++++++++++++++--------- src/reclaim/plugin_reclaim_credential_pabc.c | 35 ++++----------- src/reclaim/reclaim_credential.c | 1 - 3 files changed, 55 insertions(+), 48 deletions(-) diff --git a/src/reclaim/pabc_helper.c b/src/reclaim/pabc_helper.c index c435ad5b3..1b1dbea0f 100644 --- a/src/reclaim/pabc_helper.c +++ b/src/reclaim/pabc_helper.c @@ -31,7 +31,8 @@ write_file (char const *const filename, const char *buffer) GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_WRITE); + GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_USER_READ); if (fh == NULL) return GNUNET_SYSERR; if (GNUNET_SYSERR == GNUNET_DISK_file_write (fh, @@ -49,7 +50,8 @@ fail: static enum GNUNET_GenericReturnValue init_pabc_dir () { - size_t filename_size = strlen (get_homedir ()) + 1 + strlen (".local") + 1; + size_t filename_size = strlen (get_homedir ()) + 1 + strlen (".local") + 1 + + strlen ("pabc-reclaim") + 1; snprintf (pabc_dir, filename_size, "%s/%s/%s", get_homedir (), ".local", "pabc-reclaim"); return GNUNET_DISK_directory_create (pabc_dir); @@ -117,6 +119,8 @@ PABC_read_issuer_ppfile (const char *f, struct pabc_context *const ctx) } if (PABC_OK != pabc_decode_and_new_public_parameters (ctx, &pp, buffer)) { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to decode public parameters\n"); PABC_FREE_NULL (buffer); return NULL; } @@ -131,23 +135,28 @@ PABC_load_public_parameters (struct pabc_context *const ctx, struct pabc_public_parameters **pp) { char fname[PATH_MAX]; + char *pp_filename; const char *pdir = get_pabcdir (); if (ctx == NULL) return GNUNET_SYSERR; if (pp_name == NULL) return GNUNET_SYSERR; - if (pp == NULL) - return GNUNET_SYSERR; + GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename); if (GNUNET_YES != GNUNET_DISK_directory_test (pdir, GNUNET_YES)) { + GNUNET_free (pp_filename); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error reading %s\n", pdir); return GNUNET_SYSERR; } - snprintf (fname, PATH_MAX, "%s/%s%s", pdir, pp_name, PABC_PP_EXT); + snprintf (fname, PATH_MAX, "%s/%s%s", pdir, pp_filename, PABC_PP_EXT); if (GNUNET_YES != GNUNET_DISK_file_test (fname)) + { + GNUNET_free (pp_filename); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error testing %s\n", fname); return GNUNET_SYSERR; + } *pp = PABC_read_issuer_ppfile (fname, ctx); if (*pp) return GNUNET_OK; @@ -162,13 +171,17 @@ PABC_write_public_parameters (char const *const pp_name, { char *json; char *filename; + char *pp_filename; enum pabc_status status; struct pabc_context *ctx = NULL; + + GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename); PABC_ASSERT (pabc_new_ctx (&ctx)); // store in json file status = pabc_encode_public_parameters (ctx, pp, &json); if (status != PABC_OK) { + GNUNET_free (pp_filename); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to encode public parameters.\n"); pabc_free_ctx (&ctx); @@ -176,17 +189,20 @@ PABC_write_public_parameters (char const *const pp_name, } size_t filename_size = - strlen (get_pabcdir ()) + 1 + strlen (pp_name) + strlen (PABC_PP_EXT) + 1; + strlen (get_pabcdir ()) + 1 + strlen (pp_filename) + strlen (PABC_PP_EXT) + + 1; filename = GNUNET_malloc (filename_size); if (! filename) { + GNUNET_free (pp_filename); PABC_FREE_NULL (json); pabc_free_ctx (&ctx); return GNUNET_SYSERR; } - snprintf (filename, filename_size, "%s/%s%s", get_pabcdir (), pp_name, + snprintf (filename, filename_size, "%s/%s%s", get_pabcdir (), pp_filename, PABC_PP_EXT); + GNUNET_free (pp_filename); if (GNUNET_OK != write_file (filename, json)) { PABC_FREE_NULL (filename); @@ -201,7 +217,6 @@ PABC_write_public_parameters (char const *const pp_name, } - enum GNUNET_GenericReturnValue PABC_write_usr_ctx (char const *const usr_name, char const *const pp_name, @@ -210,6 +225,11 @@ PABC_write_usr_ctx (char const *const usr_name, struct pabc_user_context *const usr_ctx) { + char *pp_filename; + char *json = NULL; + enum pabc_status status; + char *fname = NULL; + if (NULL == usr_name) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer given.\n"); @@ -236,23 +256,24 @@ PABC_write_usr_ctx (char const *const usr_name, return GNUNET_SYSERR; } - char *json = NULL; - enum pabc_status status; + GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename); status = pabc_encode_user_ctx (ctx, pp, usr_ctx, &json); if (PABC_OK != status) { + GNUNET_free (pp_filename); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to encode user context.\n"); return status; } - char *fname = NULL; size_t fname_size = strlen (get_pabcdir ()) + 1 + strlen (usr_name) + 1 - + strlen (pp_name) + strlen (PABC_USR_EXT) + 1; + + strlen (pp_filename) + strlen (PABC_USR_EXT) + 1; fname = GNUNET_malloc (fname_size); - snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name, pp_name, + snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name, + pp_filename, PABC_USR_EXT); + GNUNET_free (pp_filename); if (GNUNET_OK == write_file (fname, json)) { GNUNET_free (fname); @@ -275,6 +296,12 @@ PABC_read_usr_ctx (char const *const usr_name, struct pabc_public_parameters const *const pp, struct pabc_user_context **usr_ctx) { + char *json = NULL; + char *pp_filename; + enum pabc_status status; + + char *fname = NULL; + if (NULL == usr_name) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer given.\n"); @@ -300,19 +327,19 @@ PABC_read_usr_ctx (char const *const usr_name, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No user context given.\n"); return GNUNET_SYSERR; } + GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename); - char *json = NULL; - enum pabc_status status; - - char *fname = NULL; size_t fname_size = strlen (get_pabcdir ()) + 1 + strlen (usr_name) + 1 - + strlen (pp_name) + strlen (PABC_USR_EXT) + 1; + + strlen (pp_filename) + strlen (PABC_USR_EXT) + 1; fname = GNUNET_malloc (fname_size); - snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name, pp_name, + snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name, + pp_filename, PABC_USR_EXT); - + GNUNET_free (pp_filename); if (GNUNET_OK != read_file (fname, &json)) { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to read `%s'\n", fname); PABC_FREE_NULL (fname); return GNUNET_SYSERR; } diff --git a/src/reclaim/plugin_reclaim_credential_pabc.c b/src/reclaim/plugin_reclaim_credential_pabc.c index 4b19a3544..f17925248 100644 --- a/src/reclaim/plugin_reclaim_credential_pabc.c +++ b/src/reclaim/plugin_reclaim_credential_pabc.c @@ -240,6 +240,9 @@ find_attr (char const *const key, void *ctx) { struct Finder *fdr = ctx; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Found `%s', looking for `%s'\n", + key, fdr->target); if (0 == strcmp (key, fdr->target)) fdr->result = GNUNET_strdup (value); } @@ -260,37 +263,11 @@ pabc_get_attribute (void *cls, size_t data_size, const char *skey) { - json_t *json_root; - json_t *json_attrs; - json_error_t *json_err = NULL; - json_root = json_loads (data, JSON_DECODE_ANY, json_err); - if ((NULL == json_root) || - (! json_is_object (json_root))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "%s is not a valid pabc credential (not an object)\n", - data); - if (NULL != json_root) - json_decref (json_root); - return NULL; - } - json_attrs = json_object_get (json_root, PABC_JSON_PLAIN_ATTRS_KEY); - if ((NULL == json_attrs) || - (! json_is_object (json_attrs))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "%s is not a valid pabc credential (attributes not an object)\n", - data); - json_decref (json_root); - return NULL; - } - char *attr_str = json_dumps (json_attrs, JSON_DECODE_ANY); - json_decref (json_root); struct Finder fdr; memset (&fdr, 0, sizeof (fdr)); fdr.target = skey; - pabc_cred_inspect_credential (attr_str, &find_attr, &fdr); + pabc_cred_inspect_credential (data, &find_attr, &fdr); return fdr.result; } @@ -463,9 +440,13 @@ pabc_create_presentation (void *cls, issuer = pabc_get_issuer_c (cls, credential); if (NULL == issuer) { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "No issuer found in credential\n"); pabc_free_ctx (&ctx); return GNUNET_SYSERR; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got issuer for credential: %s\n", issuer); status = PABC_load_public_parameters (ctx, issuer, &pp); if (status != PABC_OK) { diff --git a/src/reclaim/reclaim_credential.c b/src/reclaim/reclaim_credential.c index c8c0d397c..da5cee988 100644 --- a/src/reclaim/reclaim_credential.c +++ b/src/reclaim/reclaim_credential.c @@ -1033,7 +1033,6 @@ GNUNET_RECLAIM_presentation_get_expiration (const struct /** * Create a presentation from a credential and a lift of (selected) * attributes in the credential. - * FIXME not yet implemented * * @param cred the credential to use * @param attrs the attributes to present from the credential -- cgit v1.2.3