aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2021-04-21 09:06:26 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2021-04-21 09:06:26 +0200
commit8e4c4ea64be4bf099afb8ffd1fd24aae0b68003b (patch)
treed1c3fe812a3db059c270657f1007ee4541135085 /src/reclaim
parent985dcf84150151c8ad62549815da3a16e70ca4cd (diff)
downloadgnunet-8e4c4ea64be4bf099afb8ffd1fd24aae0b68003b.tar.gz
gnunet-8e4c4ea64be4bf099afb8ffd1fd24aae0b68003b.zip
-fix presentations
Diffstat (limited to 'src/reclaim')
-rw-r--r--src/reclaim/pabc_helper.c67
-rw-r--r--src/reclaim/plugin_reclaim_credential_pabc.c35
-rw-r--r--src/reclaim/reclaim_credential.c1
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)
31 GNUNET_DISK_OPEN_WRITE 31 GNUNET_DISK_OPEN_WRITE
32 | GNUNET_DISK_OPEN_TRUNCATE 32 | GNUNET_DISK_OPEN_TRUNCATE
33 | GNUNET_DISK_OPEN_CREATE, 33 | GNUNET_DISK_OPEN_CREATE,
34 GNUNET_DISK_PERM_USER_WRITE); 34 GNUNET_DISK_PERM_USER_WRITE
35 | GNUNET_DISK_PERM_USER_READ);
35 if (fh == NULL) 36 if (fh == NULL)
36 return GNUNET_SYSERR; 37 return GNUNET_SYSERR;
37 if (GNUNET_SYSERR == GNUNET_DISK_file_write (fh, 38 if (GNUNET_SYSERR == GNUNET_DISK_file_write (fh,
@@ -49,7 +50,8 @@ fail:
49static enum GNUNET_GenericReturnValue 50static enum GNUNET_GenericReturnValue
50init_pabc_dir () 51init_pabc_dir ()
51{ 52{
52 size_t filename_size = strlen (get_homedir ()) + 1 + strlen (".local") + 1; 53 size_t filename_size = strlen (get_homedir ()) + 1 + strlen (".local") + 1
54 + strlen ("pabc-reclaim") + 1;
53 snprintf (pabc_dir, filename_size, "%s/%s/%s", 55 snprintf (pabc_dir, filename_size, "%s/%s/%s",
54 get_homedir (), ".local", "pabc-reclaim"); 56 get_homedir (), ".local", "pabc-reclaim");
55 return GNUNET_DISK_directory_create (pabc_dir); 57 return GNUNET_DISK_directory_create (pabc_dir);
@@ -117,6 +119,8 @@ PABC_read_issuer_ppfile (const char *f, struct pabc_context *const ctx)
117 } 119 }
118 if (PABC_OK != pabc_decode_and_new_public_parameters (ctx, &pp, buffer)) 120 if (PABC_OK != pabc_decode_and_new_public_parameters (ctx, &pp, buffer))
119 { 121 {
122 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
123 "Failed to decode public parameters\n");
120 PABC_FREE_NULL (buffer); 124 PABC_FREE_NULL (buffer);
121 return NULL; 125 return NULL;
122 } 126 }
@@ -131,23 +135,28 @@ PABC_load_public_parameters (struct pabc_context *const ctx,
131 struct pabc_public_parameters **pp) 135 struct pabc_public_parameters **pp)
132{ 136{
133 char fname[PATH_MAX]; 137 char fname[PATH_MAX];
138 char *pp_filename;
134 const char *pdir = get_pabcdir (); 139 const char *pdir = get_pabcdir ();
135 140
136 if (ctx == NULL) 141 if (ctx == NULL)
137 return GNUNET_SYSERR; 142 return GNUNET_SYSERR;
138 if (pp_name == NULL) 143 if (pp_name == NULL)
139 return GNUNET_SYSERR; 144 return GNUNET_SYSERR;
140 if (pp == NULL)
141 return GNUNET_SYSERR;
142 145
146 GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename);
143 if (GNUNET_YES != GNUNET_DISK_directory_test (pdir, GNUNET_YES)) 147 if (GNUNET_YES != GNUNET_DISK_directory_test (pdir, GNUNET_YES))
144 { 148 {
149 GNUNET_free (pp_filename);
145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error reading %s\n", pdir); 150 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error reading %s\n", pdir);
146 return GNUNET_SYSERR; 151 return GNUNET_SYSERR;
147 } 152 }
148 snprintf (fname, PATH_MAX, "%s/%s%s", pdir, pp_name, PABC_PP_EXT); 153 snprintf (fname, PATH_MAX, "%s/%s%s", pdir, pp_filename, PABC_PP_EXT);
149 if (GNUNET_YES != GNUNET_DISK_file_test (fname)) 154 if (GNUNET_YES != GNUNET_DISK_file_test (fname))
155 {
156 GNUNET_free (pp_filename);
157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error testing %s\n", fname);
150 return GNUNET_SYSERR; 158 return GNUNET_SYSERR;
159 }
151 *pp = PABC_read_issuer_ppfile (fname, ctx); 160 *pp = PABC_read_issuer_ppfile (fname, ctx);
152 if (*pp) 161 if (*pp)
153 return GNUNET_OK; 162 return GNUNET_OK;
@@ -162,13 +171,17 @@ PABC_write_public_parameters (char const *const pp_name,
162{ 171{
163 char *json; 172 char *json;
164 char *filename; 173 char *filename;
174 char *pp_filename;
165 enum pabc_status status; 175 enum pabc_status status;
166 struct pabc_context *ctx = NULL; 176 struct pabc_context *ctx = NULL;
177
178 GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename);
167 PABC_ASSERT (pabc_new_ctx (&ctx)); 179 PABC_ASSERT (pabc_new_ctx (&ctx));
168 // store in json file 180 // store in json file
169 status = pabc_encode_public_parameters (ctx, pp, &json); 181 status = pabc_encode_public_parameters (ctx, pp, &json);
170 if (status != PABC_OK) 182 if (status != PABC_OK)
171 { 183 {
184 GNUNET_free (pp_filename);
172 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 185 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
173 "Failed to encode public parameters.\n"); 186 "Failed to encode public parameters.\n");
174 pabc_free_ctx (&ctx); 187 pabc_free_ctx (&ctx);
@@ -176,17 +189,20 @@ PABC_write_public_parameters (char const *const pp_name,
176 } 189 }
177 190
178 size_t filename_size = 191 size_t filename_size =
179 strlen (get_pabcdir ()) + 1 + strlen (pp_name) + strlen (PABC_PP_EXT) + 1; 192 strlen (get_pabcdir ()) + 1 + strlen (pp_filename) + strlen (PABC_PP_EXT)
193 + 1;
180 filename = GNUNET_malloc (filename_size); 194 filename = GNUNET_malloc (filename_size);
181 if (! filename) 195 if (! filename)
182 { 196 {
197 GNUNET_free (pp_filename);
183 PABC_FREE_NULL (json); 198 PABC_FREE_NULL (json);
184 pabc_free_ctx (&ctx); 199 pabc_free_ctx (&ctx);
185 return GNUNET_SYSERR; 200 return GNUNET_SYSERR;
186 } 201 }
187 snprintf (filename, filename_size, "%s/%s%s", get_pabcdir (), pp_name, 202 snprintf (filename, filename_size, "%s/%s%s", get_pabcdir (), pp_filename,
188 PABC_PP_EXT); 203 PABC_PP_EXT);
189 204
205 GNUNET_free (pp_filename);
190 if (GNUNET_OK != write_file (filename, json)) 206 if (GNUNET_OK != write_file (filename, json))
191 { 207 {
192 PABC_FREE_NULL (filename); 208 PABC_FREE_NULL (filename);
@@ -201,7 +217,6 @@ PABC_write_public_parameters (char const *const pp_name,
201} 217}
202 218
203 219
204
205enum GNUNET_GenericReturnValue 220enum GNUNET_GenericReturnValue
206PABC_write_usr_ctx (char const *const usr_name, 221PABC_write_usr_ctx (char const *const usr_name,
207 char const *const pp_name, 222 char const *const pp_name,
@@ -210,6 +225,11 @@ PABC_write_usr_ctx (char const *const usr_name,
210 struct pabc_user_context *const usr_ctx) 225 struct pabc_user_context *const usr_ctx)
211{ 226{
212 227
228 char *pp_filename;
229 char *json = NULL;
230 enum pabc_status status;
231 char *fname = NULL;
232
213 if (NULL == usr_name) 233 if (NULL == usr_name)
214 { 234 {
215 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer given.\n"); 235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer given.\n");
@@ -236,23 +256,24 @@ PABC_write_usr_ctx (char const *const usr_name,
236 return GNUNET_SYSERR; 256 return GNUNET_SYSERR;
237 } 257 }
238 258
239 char *json = NULL; 259 GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename);
240 enum pabc_status status;
241 status = pabc_encode_user_ctx (ctx, pp, usr_ctx, &json); 260 status = pabc_encode_user_ctx (ctx, pp, usr_ctx, &json);
242 if (PABC_OK != status) 261 if (PABC_OK != status)
243 { 262 {
263 GNUNET_free (pp_filename);
244 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to encode user context.\n"); 264 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to encode user context.\n");
245 return status; 265 return status;
246 } 266 }
247 267
248 char *fname = NULL;
249 size_t fname_size = strlen (get_pabcdir ()) + 1 + strlen (usr_name) + 1 268 size_t fname_size = strlen (get_pabcdir ()) + 1 + strlen (usr_name) + 1
250 + strlen (pp_name) + strlen (PABC_USR_EXT) + 1; 269 + strlen (pp_filename) + strlen (PABC_USR_EXT) + 1;
251 fname = GNUNET_malloc (fname_size); 270 fname = GNUNET_malloc (fname_size);
252 271
253 snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name, pp_name, 272 snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name,
273 pp_filename,
254 PABC_USR_EXT); 274 PABC_USR_EXT);
255 275
276 GNUNET_free (pp_filename);
256 if (GNUNET_OK == write_file (fname, json)) 277 if (GNUNET_OK == write_file (fname, json))
257 { 278 {
258 GNUNET_free (fname); 279 GNUNET_free (fname);
@@ -275,6 +296,12 @@ PABC_read_usr_ctx (char const *const usr_name,
275 struct pabc_public_parameters const *const pp, 296 struct pabc_public_parameters const *const pp,
276 struct pabc_user_context **usr_ctx) 297 struct pabc_user_context **usr_ctx)
277{ 298{
299 char *json = NULL;
300 char *pp_filename;
301 enum pabc_status status;
302
303 char *fname = NULL;
304
278 if (NULL == usr_name) 305 if (NULL == usr_name)
279 { 306 {
280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer given.\n"); 307 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer given.\n");
@@ -300,19 +327,19 @@ PABC_read_usr_ctx (char const *const usr_name,
300 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No user context given.\n"); 327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No user context given.\n");
301 return GNUNET_SYSERR; 328 return GNUNET_SYSERR;
302 } 329 }
330 GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename);
303 331
304 char *json = NULL;
305 enum pabc_status status;
306
307 char *fname = NULL;
308 size_t fname_size = strlen (get_pabcdir ()) + 1 + strlen (usr_name) + 1 332 size_t fname_size = strlen (get_pabcdir ()) + 1 + strlen (usr_name) + 1
309 + strlen (pp_name) + strlen (PABC_USR_EXT) + 1; 333 + strlen (pp_filename) + strlen (PABC_USR_EXT) + 1;
310 fname = GNUNET_malloc (fname_size); 334 fname = GNUNET_malloc (fname_size);
311 snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name, pp_name, 335 snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name,
336 pp_filename,
312 PABC_USR_EXT); 337 PABC_USR_EXT);
313 338 GNUNET_free (pp_filename);
314 if (GNUNET_OK != read_file (fname, &json)) 339 if (GNUNET_OK != read_file (fname, &json))
315 { 340 {
341 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
342 "Failed to read `%s'\n", fname);
316 PABC_FREE_NULL (fname); 343 PABC_FREE_NULL (fname);
317 return GNUNET_SYSERR; 344 return GNUNET_SYSERR;
318 } 345 }
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,
240 void *ctx) 240 void *ctx)
241{ 241{
242 struct Finder *fdr = ctx; 242 struct Finder *fdr = ctx;
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
244 "Found `%s', looking for `%s'\n",
245 key, fdr->target);
243 if (0 == strcmp (key, fdr->target)) 246 if (0 == strcmp (key, fdr->target))
244 fdr->result = GNUNET_strdup (value); 247 fdr->result = GNUNET_strdup (value);
245} 248}
@@ -260,37 +263,11 @@ pabc_get_attribute (void *cls,
260 size_t data_size, 263 size_t data_size,
261 const char *skey) 264 const char *skey)
262{ 265{
263 json_t *json_root;
264 json_t *json_attrs;
265 json_error_t *json_err = NULL;
266 266
267 json_root = json_loads (data, JSON_DECODE_ANY, json_err);
268 if ((NULL == json_root) ||
269 (! json_is_object (json_root)))
270 {
271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
272 "%s is not a valid pabc credential (not an object)\n",
273 data);
274 if (NULL != json_root)
275 json_decref (json_root);
276 return NULL;
277 }
278 json_attrs = json_object_get (json_root, PABC_JSON_PLAIN_ATTRS_KEY);
279 if ((NULL == json_attrs) ||
280 (! json_is_object (json_attrs)))
281 {
282 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
283 "%s is not a valid pabc credential (attributes not an object)\n",
284 data);
285 json_decref (json_root);
286 return NULL;
287 }
288 char *attr_str = json_dumps (json_attrs, JSON_DECODE_ANY);
289 json_decref (json_root);
290 struct Finder fdr; 267 struct Finder fdr;
291 memset (&fdr, 0, sizeof (fdr)); 268 memset (&fdr, 0, sizeof (fdr));
292 fdr.target = skey; 269 fdr.target = skey;
293 pabc_cred_inspect_credential (attr_str, &find_attr, &fdr); 270 pabc_cred_inspect_credential (data, &find_attr, &fdr);
294 return fdr.result; 271 return fdr.result;
295} 272}
296 273
@@ -463,9 +440,13 @@ pabc_create_presentation (void *cls,
463 issuer = pabc_get_issuer_c (cls, credential); 440 issuer = pabc_get_issuer_c (cls, credential);
464 if (NULL == issuer) 441 if (NULL == issuer)
465 { 442 {
443 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
444 "No issuer found in credential\n");
466 pabc_free_ctx (&ctx); 445 pabc_free_ctx (&ctx);
467 return GNUNET_SYSERR; 446 return GNUNET_SYSERR;
468 } 447 }
448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
449 "Got issuer for credential: %s\n", issuer);
469 status = PABC_load_public_parameters (ctx, issuer, &pp); 450 status = PABC_load_public_parameters (ctx, issuer, &pp);
470 if (status != PABC_OK) 451 if (status != PABC_OK)
471 { 452 {
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
1033/** 1033/**
1034 * Create a presentation from a credential and a lift of (selected) 1034 * Create a presentation from a credential and a lift of (selected)
1035 * attributes in the credential. 1035 * attributes in the credential.
1036 * FIXME not yet implemented
1037 * 1036 *
1038 * @param cred the credential to use 1037 * @param cred the credential to use
1039 * @param attrs the attributes to present from the credential 1038 * @param attrs the attributes to present from the credential