aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/plugin_reclaim_credential_pabc.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2021-02-22 18:20:24 +0100
committerMartin Schanzenbach <mschanzenbach@posteo.de>2021-04-20 10:50:36 +0200
commit40458566131dfc85381d8966bb465f455830400b (patch)
treec0fcfeca03bcfa34f9900ba82a6f7326ee89afa4 /src/reclaim/plugin_reclaim_credential_pabc.c
parent8562992bff092c27d6f589667c74659831da364c (diff)
downloadgnunet-40458566131dfc85381d8966bb465f455830400b.tar.gz
gnunet-40458566131dfc85381d8966bb465f455830400b.zip
-add pabc helpers
Diffstat (limited to 'src/reclaim/plugin_reclaim_credential_pabc.c')
-rw-r--r--src/reclaim/plugin_reclaim_credential_pabc.c140
1 files changed, 87 insertions, 53 deletions
diff --git a/src/reclaim/plugin_reclaim_credential_pabc.c b/src/reclaim/plugin_reclaim_credential_pabc.c
index 6bc94b404..dae23ab1a 100644
--- a/src/reclaim/plugin_reclaim_credential_pabc.c
+++ b/src/reclaim/plugin_reclaim_credential_pabc.c
@@ -31,6 +31,7 @@
31#include <inttypes.h> 31#include <inttypes.h>
32#include <jansson.h> 32#include <jansson.h>
33#include <libpabc/libpabc.h> 33#include <libpabc/libpabc.h>
34#include "pabc_helper.h"
34 35
35/** 36/**
36 * Convert the 'value' of an credential to a string. 37 * Convert the 'value' of an credential to a string.
@@ -43,9 +44,9 @@
43 */ 44 */
44static char * 45static char *
45pabc_value_to_string (void *cls, 46pabc_value_to_string (void *cls,
46 uint32_t type, 47 uint32_t type,
47 const void *data, 48 const void *data,
48 size_t data_size) 49 size_t data_size)
49{ 50{
50 switch (type) 51 switch (type)
51 { 52 {
@@ -71,10 +72,10 @@ pabc_value_to_string (void *cls,
71 */ 72 */
72static int 73static int
73pabc_string_to_value (void *cls, 74pabc_string_to_value (void *cls,
74 uint32_t type, 75 uint32_t type,
75 const char *s, 76 const char *s,
76 void **data, 77 void **data,
77 size_t *data_size) 78 size_t *data_size)
78{ 79{
79 if (NULL == s) 80 if (NULL == s)
80 return GNUNET_SYSERR; 81 return GNUNET_SYSERR;
@@ -100,7 +101,7 @@ static struct
100 const char *name; 101 const char *name;
101 uint32_t number; 102 uint32_t number;
102} pabc_cred_name_map[] = { { "PABC", GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC }, 103} pabc_cred_name_map[] = { { "PABC", GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC },
103 { NULL, UINT32_MAX } }; 104 { NULL, UINT32_MAX } };
104 105
105/** 106/**
106 * Convert a type name to the corresponding number. 107 * Convert a type name to the corresponding number.
@@ -136,8 +137,8 @@ pabc_number_to_typename (void *cls, uint32_t type)
136 137
137 i = 0; 138 i = 0;
138 while ((NULL != pabc_cred_name_map[i].name) && (type != 139 while ((NULL != pabc_cred_name_map[i].name) && (type !=
139 pabc_cred_name_map[i]. 140 pabc_cred_name_map[i].
140 number)) 141 number))
141 i++; 142 i++;
142 return pabc_cred_name_map[i].name; 143 return pabc_cred_name_map[i].name;
143} 144}
@@ -152,8 +153,8 @@ pabc_number_to_typename (void *cls, uint32_t type)
152 */ 153 */
153struct GNUNET_RECLAIM_AttributeList * 154struct GNUNET_RECLAIM_AttributeList *
154pabc_parse_attributes (void *cls, 155pabc_parse_attributes (void *cls,
155 const char *data, 156 const char *data,
156 size_t data_size) 157 size_t data_size)
157{ 158{
158 const char *key; 159 const char *key;
159 struct GNUNET_RECLAIM_AttributeList *attrs; 160 struct GNUNET_RECLAIM_AttributeList *attrs;
@@ -167,7 +168,7 @@ pabc_parse_attributes (void *cls,
167 168
168 json_root = json_loads (data, JSON_DECODE_ANY, json_err); 169 json_root = json_loads (data, JSON_DECODE_ANY, json_err);
169 if ((NULL == json_root) || 170 if ((NULL == json_root) ||
170 (!json_is_object (json_root))) 171 (! json_is_object (json_root)))
171 { 172 {
172 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
173 "%s is not a valid pabc credentials (not an object)\n", 174 "%s is not a valid pabc credentials (not an object)\n",
@@ -178,7 +179,7 @@ pabc_parse_attributes (void *cls,
178 } 179 }
179 json_attrs = json_object_get (json_root, "attributes"); 180 json_attrs = json_object_get (json_root, "attributes");
180 if ((NULL == json_attrs) || 181 if ((NULL == json_attrs) ||
181 (!json_is_array (json_attrs))) 182 (! json_is_array (json_attrs)))
182 { 183 {
183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
184 "%s is not a valid pabc credentials (attributes not an array)\n", 185 "%s is not a valid pabc credentials (attributes not an array)\n",
@@ -191,7 +192,7 @@ pabc_parse_attributes (void *cls,
191 for (int i = 0; i < json_array_size (json_attrs); i++) 192 for (int i = 0; i < json_array_size (json_attrs); i++)
192 { 193 {
193 attr = json_array_get (json_attrs, i); 194 attr = json_array_get (json_attrs, i);
194 if (!json_is_object(attr)) 195 if (! json_is_object (attr))
195 { 196 {
196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 "Found json entry is not an object!\n"); 198 "Found json entry is not an object!\n");
@@ -210,12 +211,12 @@ pabc_parse_attributes (void *cls,
210 continue; 211 continue;
211 val_str = json_dumps (value, JSON_ENCODE_ANY); 212 val_str = json_dumps (value, JSON_ENCODE_ANY);
212 tmp = val_str; 213 tmp = val_str;
213 //Remove leading " from jasson conversion 214 // Remove leading " from jasson conversion
214 if (tmp[0] == '"') 215 if (tmp[0] == '"')
215 tmp++; 216 tmp++;
216 //Remove trailing " from jansson conversion 217 // Remove trailing " from jansson conversion
217 if (tmp[strlen(tmp)-1] == '"') 218 if (tmp[strlen (tmp) - 1] == '"')
218 tmp[strlen(tmp)-1] = '\0'; 219 tmp[strlen (tmp) - 1] = '\0';
219 GNUNET_RECLAIM_attribute_list_add (attrs, 220 GNUNET_RECLAIM_attribute_list_add (attrs,
220 key, 221 key,
221 NULL, 222 NULL,
@@ -239,7 +240,7 @@ pabc_parse_attributes (void *cls,
239 */ 240 */
240struct GNUNET_RECLAIM_AttributeList * 241struct GNUNET_RECLAIM_AttributeList *
241pabc_parse_attributes_c (void *cls, 242pabc_parse_attributes_c (void *cls,
242 const struct GNUNET_RECLAIM_Credential *cred) 243 const struct GNUNET_RECLAIM_Credential *cred)
243{ 244{
244 return pabc_parse_attributes (cls, cred->data, cred->data_size); 245 return pabc_parse_attributes (cls, cred->data, cred->data_size);
245} 246}
@@ -254,23 +255,26 @@ pabc_parse_attributes_c (void *cls,
254 */ 255 */
255struct GNUNET_RECLAIM_AttributeList * 256struct GNUNET_RECLAIM_AttributeList *
256pabc_parse_attributes_p (void *cls, 257pabc_parse_attributes_p (void *cls,
257 const struct GNUNET_RECLAIM_Presentation *cred) 258 const struct GNUNET_RECLAIM_Presentation *cred)
258{ 259{
259 return pabc_parse_attributes (cls, cred->data, cred->data_size); 260 return pabc_parse_attributes (cls, cred->data, cred->data_size);
260} 261}
261 262
262 263
263/** 264/**
264 * Parse a pabc and return the issuer 265 * Parse a pabc and return an attribute value.
265 * 266 *
266 * @param cls the plugin 267 * @param cls the plugin
267 * @param cred the pabc credential 268 * @param data the pabc credential data
269 * @param data_size the pabc credential size
270 * @param key the attribute key to look for.
268 * @return a string, containing the isser 271 * @return a string, containing the isser
269 */ 272 */
270char * 273char *
271pabc_get_issuer (void *cls, 274pabc_get_attribute (void *cls,
272 const char *data, 275 const char *data,
273 size_t data_size) 276 size_t data_size,
277 const char *skey)
274{ 278{
275 const char *key; 279 const char *key;
276 char *val_str = NULL; 280 char *val_str = NULL;
@@ -283,7 +287,7 @@ pabc_get_issuer (void *cls,
283 287
284 json_root = json_loads (data, JSON_DECODE_ANY, json_err); 288 json_root = json_loads (data, JSON_DECODE_ANY, json_err);
285 if ((NULL == json_root) || 289 if ((NULL == json_root) ||
286 (!json_is_object (json_root))) 290 (! json_is_object (json_root)))
287 { 291 {
288 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 292 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
289 "%s is not a valid pabc credentials (not an object)\n", 293 "%s is not a valid pabc credentials (not an object)\n",
@@ -294,7 +298,7 @@ pabc_get_issuer (void *cls,
294 } 298 }
295 json_attrs = json_object_get (json_root, "attributes"); 299 json_attrs = json_object_get (json_root, "attributes");
296 if ((NULL == json_attrs) || 300 if ((NULL == json_attrs) ||
297 (!json_is_array (json_attrs))) 301 (! json_is_array (json_attrs)))
298 { 302 {
299 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 303 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
300 "%s is not a valid pabc credentials (attributes not an array)\n", 304 "%s is not a valid pabc credentials (attributes not an array)\n",
@@ -306,23 +310,23 @@ pabc_get_issuer (void *cls,
306 for (int i = 0; i < json_array_size (json_attrs); i++) 310 for (int i = 0; i < json_array_size (json_attrs); i++)
307 { 311 {
308 attr = json_array_get (json_attrs, i); 312 attr = json_array_get (json_attrs, i);
309 if (!json_is_object(attr)) 313 if (! json_is_object (attr))
310 continue; 314 continue;
311 /** 315 /**
312 * This *should* only contain a single pair. 316 * This *should* only contain a single pair.
313 */ 317 */
314 json_object_foreach (attr, key, value) 318 json_object_foreach (attr, key, value)
315 { 319 {
316 if (0 != strcmp ("issuer", key)) 320 if (0 != strcmp (skey, key))
317 continue; 321 continue;
318 val_str = json_dumps (value, JSON_ENCODE_ANY); 322 val_str = json_dumps (value, JSON_ENCODE_ANY);
319 tmp = val_str; 323 tmp = val_str;
320 //Remove leading " from jasson conversion 324 // Remove leading " from jasson conversion
321 if (tmp[0] == '"') 325 if (tmp[0] == '"')
322 tmp++; 326 tmp++;
323 //Remove trailing " from jansson conversion 327 // Remove trailing " from jansson conversion
324 if (tmp[strlen(tmp)-1] == '"') 328 if (tmp[strlen (tmp) - 1] == '"')
325 tmp[strlen(tmp)-1] = '\0'; 329 tmp[strlen (tmp) - 1] = '\0';
326 GNUNET_free (val_str); 330 GNUNET_free (val_str);
327 json_decref (json_root); 331 json_decref (json_root);
328 return tmp; 332 return tmp;
@@ -340,9 +344,25 @@ pabc_get_issuer (void *cls,
340 * @param cred the pabc credential 344 * @param cred the pabc credential
341 * @return a string, containing the isser 345 * @return a string, containing the isser
342 */ 346 */
347char*
348pabc_get_issuer (void *cls,
349 const char *data,
350 size_t data_size)
351{
352 return pabc_get_attribute (cls, data, data_size, "issuer");
353}
354
355
356/**
357 * Parse a pabc and return the issuer
358 *
359 * @param cls the plugin
360 * @param cred the pabc credential
361 * @return a string, containing the isser
362 */
343char * 363char *
344pabc_get_issuer_c (void *cls, 364pabc_get_issuer_c (void *cls,
345 const struct GNUNET_RECLAIM_Credential *cred) 365 const struct GNUNET_RECLAIM_Credential *cred)
346{ 366{
347 if (GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC != cred->type) 367 if (GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC != cred->type)
348 return NULL; 368 return NULL;
@@ -359,7 +379,7 @@ pabc_get_issuer_c (void *cls,
359 */ 379 */
360char * 380char *
361pabc_get_issuer_p (void *cls, 381pabc_get_issuer_p (void *cls,
362 const struct GNUNET_RECLAIM_Presentation *cred) 382 const struct GNUNET_RECLAIM_Presentation *cred)
363{ 383{
364 if (GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC != cred->type) 384 if (GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC != cred->type)
365 return NULL; 385 return NULL;
@@ -376,20 +396,20 @@ pabc_get_issuer_p (void *cls,
376 */ 396 */
377int 397int
378pabc_get_expiration (void *cls, 398pabc_get_expiration (void *cls,
379 const char *data, 399 const char *data,
380 size_t data_size, 400 size_t data_size,
381 struct GNUNET_TIME_Absolute *exp) 401 struct GNUNET_TIME_Absolute *exp)
382{ 402{
383 json_t *json_root; 403 json_t *json_root;
384 json_t *json_attrs; 404 json_t *json_attrs;
385 json_t *value; 405 json_t *value;
386 json_t *attr; 406 json_t *attr;
387 json_error_t *json_err = NULL; 407 json_error_t *json_err = NULL;
388 const char* key; 408 const char*key;
389 409
390 json_root = json_loads (data, JSON_DECODE_ANY, json_err); 410 json_root = json_loads (data, JSON_DECODE_ANY, json_err);
391 if ((NULL == json_root) || 411 if ((NULL == json_root) ||
392 (!json_is_object (json_root))) 412 (! json_is_object (json_root)))
393 { 413 {
394 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
395 "%s is not a valid pabc credentials (not an object)\n", 415 "%s is not a valid pabc credentials (not an object)\n",
@@ -401,7 +421,7 @@ pabc_get_expiration (void *cls,
401 for (int i = 0; i < json_array_size (json_attrs); i++) 421 for (int i = 0; i < json_array_size (json_attrs); i++)
402 { 422 {
403 attr = json_array_get (json_attrs, i); 423 attr = json_array_get (json_attrs, i);
404 if (!json_is_object(attr)) 424 if (! json_is_object (attr))
405 continue; 425 continue;
406 /** 426 /**
407 * This *should* only contain a single pair. 427 * This *should* only contain a single pair.
@@ -410,7 +430,7 @@ pabc_get_expiration (void *cls,
410 { 430 {
411 if (0 != strcmp ("expiration", key)) 431 if (0 != strcmp ("expiration", key))
412 continue; 432 continue;
413 if (!json_is_integer (value)) 433 if (! json_is_integer (value))
414 continue; 434 continue;
415 exp->abs_value_us = json_integer_value (value) * 1000 * 1000; 435 exp->abs_value_us = json_integer_value (value) * 1000 * 1000;
416 json_decref (json_root); 436 json_decref (json_root);
@@ -431,8 +451,8 @@ pabc_get_expiration (void *cls,
431 */ 451 */
432int 452int
433pabc_get_expiration_c (void *cls, 453pabc_get_expiration_c (void *cls,
434 const struct GNUNET_RECLAIM_Credential *cred, 454 const struct GNUNET_RECLAIM_Credential *cred,
435 struct GNUNET_TIME_Absolute *exp) 455 struct GNUNET_TIME_Absolute *exp)
436{ 456{
437 return pabc_get_expiration (cls, cred->data, cred->data_size, exp); 457 return pabc_get_expiration (cls, cred->data, cred->data_size, exp);
438} 458}
@@ -447,8 +467,8 @@ pabc_get_expiration_c (void *cls,
447 */ 467 */
448int 468int
449pabc_get_expiration_p (void *cls, 469pabc_get_expiration_p (void *cls,
450 const struct GNUNET_RECLAIM_Presentation *cred, 470 const struct GNUNET_RECLAIM_Presentation *cred,
451 struct GNUNET_TIME_Absolute *exp) 471 struct GNUNET_TIME_Absolute *exp)
452{ 472{
453 return pabc_get_expiration (cls, cred->data, cred->data_size, exp); 473 return pabc_get_expiration (cls, cred->data, cred->data_size, exp);
454} 474}
@@ -456,9 +476,9 @@ pabc_get_expiration_p (void *cls,
456 476
457int 477int
458pabc_create_presentation (void *cls, 478pabc_create_presentation (void *cls,
459 const struct GNUNET_RECLAIM_Credential *credential, 479 const struct GNUNET_RECLAIM_Credential *credential,
460 const struct GNUNET_RECLAIM_AttributeList *attrs, 480 const struct GNUNET_RECLAIM_AttributeList *attrs,
461 struct GNUNET_RECLAIM_Presentation **pres) 481 struct GNUNET_RECLAIM_Presentation **pres)
462{ 482{
463 struct pabc_context *ctx = NULL; 483 struct pabc_context *ctx = NULL;
464 struct pabc_user_context *usr_ctx = NULL; 484 struct pabc_user_context *usr_ctx = NULL;
@@ -466,6 +486,8 @@ pabc_create_presentation (void *cls,
466 struct pabc_credential *cred = NULL; 486 struct pabc_credential *cred = NULL;
467 struct pabc_blinded_proof *proof = NULL; 487 struct pabc_blinded_proof *proof = NULL;
468 struct GNUNET_RECLAIM_AttributeListEntry *ale; 488 struct GNUNET_RECLAIM_AttributeListEntry *ale;
489 char *issuer;
490 char *subject;
469 enum pabc_status status; 491 enum pabc_status status;
470 492
471 if (GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC != credential->type) 493 if (GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC != credential->type)
@@ -478,16 +500,28 @@ pabc_create_presentation (void *cls,
478 * Ideal would be an API that allows us to load pp by 500 * Ideal would be an API that allows us to load pp by
479 * issuer name. 501 * issuer name.
480 */ 502 */
481 //status = load_public_parameters (ctx, "issuerXY", &pp); 503 issuer = pabc_get_issuer_c (cls, credential);
504 if (NULL == issuer)
505 {
506 pabc_free_ctx (&ctx);
507 return GNUNET_SYSERR;
508 }
509 status = PABC_load_public_parameters (ctx, issuer, &pp);
482 if (status != PABC_OK) 510 if (status != PABC_OK)
483 { 511 {
484 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 512 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
485 "Failed to read public parameters.\n"); 513 "Failed to read public parameters.\n");
486 pabc_free_ctx (&ctx); 514 pabc_free_ctx (&ctx);
515 GNUNET_free (issuer);
487 return GNUNET_SYSERR; 516 return GNUNET_SYSERR;
488 } 517 }
489 //FIXME needs API 518 subject = pabc_get_attribute (cls,
490 //status = read_usr_ctx (usr_name, pp_name, ctx, pp, &usr_ctx); 519 credential->data,
520 credential->data_size,
521 "subject");
522 status = PABC_read_usr_ctx (subject, issuer, ctx, pp, &usr_ctx);
523 GNUNET_free (issuer);
524 GNUNET_free (subject);
491 if (PABC_OK != status) 525 if (PABC_OK != status)
492 { 526 {
493 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 527 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,