diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-10-23 21:50:46 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:03 +0100 |
commit | bb286cb253251e8210ed686dbde3dc8ecee16420 (patch) | |
tree | 4e7f625480adb0397df002f6e26bb6a3755ff3cc /src/reclaim | |
parent | c136a16600cd4f72d7def1af7b4aa7592310c898 (diff) | |
download | gnunet-bb286cb253251e8210ed686dbde3dc8ecee16420.tar.gz gnunet-bb286cb253251e8210ed686dbde3dc8ecee16420.zip |
Preparation for Reference Type
Diffstat (limited to 'src/reclaim')
-rw-r--r-- | src/reclaim/json_reclaim.c | 104 | ||||
-rw-r--r-- | src/reclaim/json_reclaim.h | 9 | ||||
-rw-r--r-- | src/reclaim/plugin_gnsrecord_reclaim.c | 3 | ||||
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 94 | ||||
-rw-r--r-- | src/reclaim/reclaim_api.c | 47 |
5 files changed, 256 insertions, 1 deletions
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index a0016bac8..552ca0e69 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c | |||
@@ -374,3 +374,107 @@ GNUNET_RECLAIM_JSON_spec_claim_attest (struct | |||
374 | *attr = NULL; | 374 | *attr = NULL; |
375 | return ret; | 375 | return ret; |
376 | } | 376 | } |
377 | |||
378 | /** | ||
379 | * Parse given JSON object to an attestation claim | ||
380 | * | ||
381 | * @param cls closure, NULL | ||
382 | * @param root the json object representing data | ||
383 | * @param spec where to write the data | ||
384 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | ||
385 | */ | ||
386 | static int | ||
387 | parse_attest_ref (void *cls, json_t *root, struct | ||
388 | GNUNET_JSON_Specification *spec) | ||
389 | { | ||
390 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr; | ||
391 | const char *name_str = NULL; | ||
392 | const char *ref_val_str = NULL; | ||
393 | const char *ref_id_str = NULL; | ||
394 | const char *id_str = NULL; | ||
395 | int unpack_state; | ||
396 | |||
397 | GNUNET_assert (NULL != root); | ||
398 | |||
399 | if (! json_is_object (root)) | ||
400 | { | ||
401 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
402 | "Error json is not array nor object!\n"); | ||
403 | return GNUNET_SYSERR; | ||
404 | } | ||
405 | // interpret single reference | ||
406 | unpack_state = json_unpack (root, | ||
407 | "{s:s, s?s, s:s, s:s!}", | ||
408 | "name", | ||
409 | &name_str, | ||
410 | "id", | ||
411 | &id_str, | ||
412 | "ref_id", | ||
413 | &ref_id_str, | ||
414 | "ref_value", | ||
415 | &ref_val_str); | ||
416 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == ref_val_str) || | ||
417 | (NULL == ref_id_str)) | ||
418 | { | ||
419 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
420 | "Error json object has a wrong format!\n"); | ||
421 | return GNUNET_SYSERR; | ||
422 | } | ||
423 | |||
424 | attr = GNUNET_RECLAIM_ATTESTATION_reference_new (name_str, ref_val_str); | ||
425 | |||
426 | attr->id = 0; | ||
427 | |||
428 | if ((NULL == ref_id_str) || (0 == strlen (ref_id_str))) | ||
429 | attr->id_attest = 0; | ||
430 | else | ||
431 | GNUNET_STRINGS_string_to_data (ref_id_str, | ||
432 | strlen (ref_id_str), | ||
433 | &attr->id_attest, | ||
434 | sizeof(uint64_t)); | ||
435 | |||
436 | *(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **) spec->ptr = attr; | ||
437 | return GNUNET_OK; | ||
438 | } | ||
439 | |||
440 | /** | ||
441 | * Cleanup data left from parsing RSA public key. | ||
442 | * | ||
443 | * @param cls closure, NULL | ||
444 | * @param[out] spec where to free the data | ||
445 | */ | ||
446 | static void | ||
447 | clean_attest_ref (void *cls, struct GNUNET_JSON_Specification *spec) | ||
448 | { | ||
449 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **attr; | ||
450 | |||
451 | attr = (struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **) spec->ptr; | ||
452 | if (NULL != *attr) | ||
453 | { | ||
454 | GNUNET_free (*attr); | ||
455 | *attr = NULL; | ||
456 | } | ||
457 | } | ||
458 | |||
459 | /** | ||
460 | * JSON Specification for Reclaim attestation references. | ||
461 | * | ||
462 | * @param ticket struct of GNUNET_RECLAIM_ATTESTATION_REFERENCE to fill | ||
463 | * @return JSON Specification | ||
464 | */ | ||
465 | struct GNUNET_JSON_Specification | ||
466 | GNUNET_RECLAIM_JSON_spec_claim_attest_ref (struct | ||
467 | GNUNET_RECLAIM_ATTESTATION_REFERENCE | ||
468 | **attr) | ||
469 | { | ||
470 | struct GNUNET_JSON_Specification ret = { .parser = &parse_attest_ref, | ||
471 | .cleaner = &clean_attest_ref, | ||
472 | .cls = NULL, | ||
473 | .field = NULL, | ||
474 | .ptr = attr, | ||
475 | .ptr_size = 0, | ||
476 | .size_ptr = NULL }; | ||
477 | |||
478 | *attr = NULL; | ||
479 | return ret; | ||
480 | } \ No newline at end of file | ||
diff --git a/src/reclaim/json_reclaim.h b/src/reclaim/json_reclaim.h index 4280cce48..9e6479e5e 100644 --- a/src/reclaim/json_reclaim.h +++ b/src/reclaim/json_reclaim.h | |||
@@ -56,3 +56,12 @@ GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket); | |||
56 | struct GNUNET_JSON_Specification | 56 | struct GNUNET_JSON_Specification |
57 | GNUNET_RECLAIM_JSON_spec_claim_attest (struct | 57 | GNUNET_RECLAIM_JSON_spec_claim_attest (struct |
58 | GNUNET_RECLAIM_ATTESTATION_Claim **attr); | 58 | GNUNET_RECLAIM_ATTESTATION_Claim **attr); |
59 | |||
60 | /** | ||
61 | * JSON Specification for Reclaim attestation references. | ||
62 | * | ||
63 | * @param ticket struct of GNUNET_RECLAIM_ATTESTATION_REFERENCE to fill | ||
64 | * @return JSON Specification | ||
65 | */ | ||
66 | struct GNUNET_JSON_Specification | ||
67 | GNUNET_RECLAIM_JSON_spec_claim_attest_ref(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **attr); | ||
diff --git a/src/reclaim/plugin_gnsrecord_reclaim.c b/src/reclaim/plugin_gnsrecord_reclaim.c index 58345edc4..e00b246c2 100644 --- a/src/reclaim/plugin_gnsrecord_reclaim.c +++ b/src/reclaim/plugin_gnsrecord_reclaim.c | |||
@@ -55,6 +55,7 @@ value_to_string (void *cls, uint32_t type, const void *data, size_t data_size) | |||
55 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: | 55 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: |
56 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: | 56 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: |
57 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR: | 57 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR: |
58 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_REF: | ||
58 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); | 59 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); |
59 | 60 | ||
60 | default: | 61 | default: |
@@ -95,6 +96,7 @@ string_to_value (void *cls, uint32_t type, const char *s, void **data, | |||
95 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: | 96 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: |
96 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: | 97 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: |
97 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR: | 98 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR: |
99 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_REF: | ||
98 | return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); | 100 | return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); |
99 | 101 | ||
100 | default: | 102 | default: |
@@ -119,6 +121,7 @@ static struct | |||
119 | { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT }, | 121 | { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT }, |
120 | { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT }, | 122 | { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT }, |
121 | { "RECLAIM_TICKET", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET }, | 123 | { "RECLAIM_TICKET", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET }, |
124 | { "RECLAIM_ATTEST_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_REF }, | ||
122 | { NULL, UINT32_MAX } | 125 | { NULL, UINT32_MAX } |
123 | }; | 126 | }; |
124 | 127 | ||
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 5908a38dd..b52cf9650 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -455,13 +455,105 @@ ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
455 | 455 | ||
456 | 456 | ||
457 | static void | 457 | static void |
458 | add_attestation_ref_cont (struct GNUNET_REST_RequestHandle *con_handle, | ||
459 | const char *url, | ||
460 | void *cls) | ||
461 | { | ||
462 | struct RequestHandle *handle = cls; | ||
463 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | ||
464 | const char *identity; | ||
465 | struct EgoEntry *ego_entry; | ||
466 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attribute; | ||
467 | struct GNUNET_TIME_Relative exp; | ||
468 | char term_data[handle->rest_handle->data_size + 1]; | ||
469 | json_t *data_json; | ||
470 | json_error_t err; | ||
471 | struct GNUNET_JSON_Specification attrspec[] = | ||
472 | { GNUNET_RECLAIM_JSON_spec_claim_attest_ref (&attribute), | ||
473 | GNUNET_JSON_spec_end () }; | ||
474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
475 | "Adding an attestation reference for %s.\n", | ||
476 | handle->url); | ||
477 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + strlen ( | ||
478 | "reference/") + 1 >= strlen ( | ||
479 | handle->url)) | ||
480 | { | ||
481 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | ||
482 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
483 | return; | ||
484 | } | ||
485 | identity = handle->url + strlen ( | ||
486 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + strlen ("reference/") + 1; | ||
487 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
488 | ego_entry = ego_entry->next) | ||
489 | if (0 == strcmp (identity, ego_entry->identifier)) | ||
490 | break; | ||
491 | if (NULL == ego_entry) | ||
492 | { | ||
493 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity); | ||
494 | return; | ||
495 | } | ||
496 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | ||
497 | if (0 >= handle->rest_handle->data_size) | ||
498 | { | ||
499 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
500 | return; | ||
501 | } | ||
502 | |||
503 | term_data[handle->rest_handle->data_size] = '\0'; | ||
504 | GNUNET_memcpy (term_data, | ||
505 | handle->rest_handle->data, | ||
506 | handle->rest_handle->data_size); | ||
507 | data_json = json_loads (term_data, JSON_DECODE_ANY, &err); | ||
508 | GNUNET_assert (GNUNET_OK == | ||
509 | GNUNET_JSON_parse (data_json, attrspec, NULL, NULL)); | ||
510 | json_decref (data_json); | ||
511 | if (NULL == attribute) | ||
512 | { | ||
513 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
514 | "Unable to parse attestation reference from %s\n", | ||
515 | term_data); | ||
516 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
517 | return; | ||
518 | } | ||
519 | /** | ||
520 | * New ID for attribute | ||
521 | */ | ||
522 | if (0 == attribute->id) | ||
523 | attribute->id = attribute->id_attest; | ||
524 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
525 | exp = GNUNET_TIME_UNIT_HOURS; | ||
526 | handle->idp_op = GNUNET_RECLAIM_attestation_reference_store (handle->idp, | ||
527 | identity_priv, | ||
528 | attribute, | ||
529 | &exp, | ||
530 | &finished_cont, | ||
531 | handle); | ||
532 | GNUNET_JSON_parse_free (attrspec); | ||
533 | } | ||
534 | |||
535 | |||
536 | static void | ||
458 | add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | 537 | add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, |
459 | const char *url, | 538 | const char *url, |
460 | void *cls) | 539 | void *cls) |
461 | { | 540 | { |
541 | struct RequestHandle *handle = cls; | ||
542 | /* Check for substring "reference" */ | ||
543 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) < strlen ( | ||
544 | handle->url)) | ||
545 | { | ||
546 | if ( strncmp ("reference/", (handle->url + strlen ( | ||
547 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) | ||
548 | + 1), strlen ( | ||
549 | "reference/")) == 0) | ||
550 | { | ||
551 | add_attestation_ref_cont (con_handle,url,cls); | ||
552 | return; | ||
553 | } | ||
554 | } | ||
462 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 555 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; |
463 | const char *identity; | 556 | const char *identity; |
464 | struct RequestHandle *handle = cls; | ||
465 | struct EgoEntry *ego_entry; | 557 | struct EgoEntry *ego_entry; |
466 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attribute; | 558 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attribute; |
467 | struct GNUNET_TIME_Relative exp; | 559 | struct GNUNET_TIME_Relative exp; |
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c index 860a0f0ab..a6ff0237d 100644 --- a/src/reclaim/reclaim_api.c +++ b/src/reclaim/reclaim_api.c | |||
@@ -1118,6 +1118,53 @@ GNUNET_RECLAIM_attestation_delete ( | |||
1118 | } | 1118 | } |
1119 | 1119 | ||
1120 | /** | 1120 | /** |
1121 | * Store an attestation reference. If the reference is already present, | ||
1122 | * it is replaced with the new reference. | ||
1123 | * | ||
1124 | * @param h handle to the re:claimID service | ||
1125 | * @param pkey private key of the identity | ||
1126 | * @param attr the reference value | ||
1127 | * @param exp_interval the relative expiration interval for the reference | ||
1128 | * @param cont continuation to call when done | ||
1129 | * @param cont_cls closure for @a cont | ||
1130 | * @return handle to abort the request | ||
1131 | */ | ||
1132 | struct GNUNET_RECLAIM_Operation * | ||
1133 | GNUNET_RECLAIM_attestation_reference_store ( | ||
1134 | struct GNUNET_RECLAIM_Handle *h, | ||
1135 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | ||
1136 | const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr, | ||
1137 | const struct GNUNET_TIME_Relative *exp_interval, | ||
1138 | GNUNET_RECLAIM_ContinuationWithStatus cont, | ||
1139 | void *cont_cls) | ||
1140 | { | ||
1141 | struct GNUNET_RECLAIM_Operation *op; | ||
1142 | struct AttributeStoreMessage *sam; | ||
1143 | size_t attr_len; | ||
1144 | op = GNUNET_new (struct GNUNET_RECLAIM_Operation); | ||
1145 | op->h = h; | ||
1146 | op->as_cb = cont; | ||
1147 | op->cls = cont_cls; | ||
1148 | op->r_id = h->r_id_gen++; | ||
1149 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | ||
1150 | attr_len = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (attr); | ||
1151 | op->env = GNUNET_MQ_msg_extra (sam, | ||
1152 | attr_len, | ||
1153 | GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_STORE); | ||
1154 | sam->identity = *pkey; | ||
1155 | sam->id = htonl (op->r_id); | ||
1156 | sam->exp = GNUNET_htonll (exp_interval->rel_value_us); | ||
1157 | |||
1158 | GNUNET_RECLAIM_ATTESTATION_REF_serialize (attr, (char *) &sam[1]); | ||
1159 | |||
1160 | sam->attr_len = htons (attr_len); | ||
1161 | if (NULL != h->mq) | ||
1162 | GNUNET_MQ_send_copy (h->mq, op->env); | ||
1163 | return op; | ||
1164 | } | ||
1165 | |||
1166 | |||
1167 | /** | ||
1121 | * List all attributes for a local identity. | 1168 | * List all attributes for a local identity. |
1122 | * This MUST lock the `struct GNUNET_RECLAIM_Handle` | 1169 | * This MUST lock the `struct GNUNET_RECLAIM_Handle` |
1123 | * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and | 1170 | * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and |