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 | |
parent | c136a16600cd4f72d7def1af7b4aa7592310c898 (diff) | |
download | gnunet-bb286cb253251e8210ed686dbde3dc8ecee16420.tar.gz gnunet-bb286cb253251e8210ed686dbde3dc8ecee16420.zip |
Preparation for Reference Type
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_gnsrecord_lib.h | 5 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 2 | ||||
-rw-r--r-- | src/include/gnunet_reclaim_attribute_lib.h | 73 | ||||
-rw-r--r-- | src/include/gnunet_reclaim_service.h | 22 | ||||
-rw-r--r-- | src/reclaim-attribute/reclaim_attribute.c | 128 | ||||
-rw-r--r-- | src/reclaim-attribute/reclaim_attribute.h | 29 | ||||
-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 |
11 files changed, 514 insertions, 2 deletions
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h index 41e23e1ab..9e430c2aa 100644 --- a/src/include/gnunet_gnsrecord_lib.h +++ b/src/include/gnunet_gnsrecord_lib.h | |||
@@ -146,6 +146,11 @@ extern "C" { | |||
146 | #define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR 65554 | 146 | #define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR 65554 |
147 | 147 | ||
148 | /** | 148 | /** |
149 | * Record type for reclaim attestation references | ||
150 | */ | ||
151 | #define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_REF 65555 | ||
152 | |||
153 | /** | ||
149 | * Flags that can be set for a record. | 154 | * Flags that can be set for a record. |
150 | */ | 155 | */ |
151 | enum GNUNET_GNSRECORD_Flags | 156 | enum GNUNET_GNSRECORD_Flags |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index f1dc74462..f8d424359 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -2720,6 +2720,8 @@ extern "C" { | |||
2720 | 2720 | ||
2721 | #define GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT 979 | 2721 | #define GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT 979 |
2722 | 2722 | ||
2723 | #define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_STORE 980 | ||
2724 | |||
2723 | /************************************************** | 2725 | /************************************************** |
2724 | * | 2726 | * |
2725 | * ABD MESSAGE TYPES | 2727 | * ABD MESSAGE TYPES |
diff --git a/src/include/gnunet_reclaim_attribute_lib.h b/src/include/gnunet_reclaim_attribute_lib.h index 8476e77fc..cfdecae79 100644 --- a/src/include/gnunet_reclaim_attribute_lib.h +++ b/src/include/gnunet_reclaim_attribute_lib.h | |||
@@ -138,6 +138,34 @@ struct GNUNET_RECLAIM_ATTESTATION_Claim | |||
138 | }; | 138 | }; |
139 | 139 | ||
140 | /** | 140 | /** |
141 | * A reference to an Attestatiom. | ||
142 | */ | ||
143 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE | ||
144 | { | ||
145 | /** | ||
146 | * ID | ||
147 | */ | ||
148 | uint64_t id; | ||
149 | |||
150 | /** | ||
151 | * Referenced ID of Attestation | ||
152 | */ | ||
153 | uint64_t id_attest; | ||
154 | |||
155 | /** | ||
156 | * The name of the attribute/attestation reference value. Note "name" must never be individually | ||
157 | * free'd | ||
158 | */ | ||
159 | const char *name; | ||
160 | |||
161 | /** | ||
162 | * The name of the attribute/attestation reference value. Note "name" must never be individually | ||
163 | * free'd | ||
164 | */ | ||
165 | const char *reference_value; | ||
166 | }; | ||
167 | |||
168 | /** | ||
141 | * A list of GNUNET_RECLAIM_ATTRIBUTE_Claim structures. | 169 | * A list of GNUNET_RECLAIM_ATTRIBUTE_Claim structures. |
142 | */ | 170 | */ |
143 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList | 171 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList |
@@ -450,6 +478,51 @@ GNUNET_RECLAIM_ATTESTATION_number_to_typename (uint32_t type); | |||
450 | uint32_t | 478 | uint32_t |
451 | GNUNET_RECLAIM_ATTESTATION_typename_to_number (const char *typename); | 479 | GNUNET_RECLAIM_ATTESTATION_typename_to_number (const char *typename); |
452 | 480 | ||
481 | /** | ||
482 | * Create a new attestation reference. | ||
483 | * | ||
484 | * @param attr_name the referenced claim name | ||
485 | * @param ref_value the claim name in the attestation | ||
486 | * @return the new reference | ||
487 | */ | ||
488 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * | ||
489 | GNUNET_RECLAIM_ATTESTATION_reference_new (const char *attr_name, | ||
490 | const char *ref_value); | ||
491 | |||
492 | |||
493 | /** | ||
494 | * Get required size for serialization buffer | ||
495 | * | ||
496 | * @param attr the reference to serialize | ||
497 | * @return the required buffer size | ||
498 | */ | ||
499 | size_t | ||
500 | GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size ( | ||
501 | const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr); | ||
502 | |||
503 | /** | ||
504 | * Serialize a reference | ||
505 | * | ||
506 | * @param attr the reference to serialize | ||
507 | * @param result the serialized reference | ||
508 | * @return length of serialized data | ||
509 | */ | ||
510 | size_t | ||
511 | GNUNET_RECLAIM_ATTESTATION_REF_serialize ( | ||
512 | const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr, | ||
513 | char *result); | ||
514 | |||
515 | /** | ||
516 | * Deserialize a reference | ||
517 | * | ||
518 | * @param data the serialized reference | ||
519 | * @param data_size the length of the serialized data | ||
520 | * | ||
521 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller | ||
522 | */ | ||
523 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * | ||
524 | GNUNET_RECLAIM_ATTESTATION_REF_deserialize (const char *data, size_t data_size); | ||
525 | |||
453 | #if 0 /* keep Emacsens' auto-indent happy */ | 526 | #if 0 /* keep Emacsens' auto-indent happy */ |
454 | { | 527 | { |
455 | #endif | 528 | #endif |
diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h index e7384fd06..eb6c1bc9e 100644 --- a/src/include/gnunet_reclaim_service.h +++ b/src/include/gnunet_reclaim_service.h | |||
@@ -117,7 +117,7 @@ typedef void (*GNUNET_RECLAIM_ContinuationWithStatus) (void *cls, | |||
117 | */ | 117 | */ |
118 | typedef void (*GNUNET_RECLAIM_AttributeResult) ( | 118 | typedef void (*GNUNET_RECLAIM_AttributeResult) ( |
119 | void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 119 | void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
120 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | 120 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, |
121 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest); | 121 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest); |
122 | 122 | ||
123 | 123 | ||
@@ -242,6 +242,26 @@ GNUNET_RECLAIM_get_attributes_start ( | |||
242 | GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, | 242 | GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, |
243 | GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); | 243 | GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); |
244 | 244 | ||
245 | /** | ||
246 | * Store an attestation reference. If the reference is already present, | ||
247 | * it is replaced with the new reference. | ||
248 | * | ||
249 | * @param h handle to the re:claimID service | ||
250 | * @param pkey private key of the identity | ||
251 | * @param attr the reference value | ||
252 | * @param exp_interval the relative expiration interval for the reference | ||
253 | * @param cont continuation to call when done | ||
254 | * @param cont_cls closure for @a cont | ||
255 | * @return handle to abort the request | ||
256 | */ | ||
257 | struct GNUNET_RECLAIM_Operation * | ||
258 | GNUNET_RECLAIM_attestation_reference_store ( | ||
259 | struct GNUNET_RECLAIM_Handle *h, | ||
260 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | ||
261 | const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr, | ||
262 | const struct GNUNET_TIME_Relative *exp_interval, | ||
263 | GNUNET_RECLAIM_ContinuationWithStatus cont, | ||
264 | void *cont_cls); | ||
245 | 265 | ||
246 | /** | 266 | /** |
247 | * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start | 267 | * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start |
diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c index 9ac75dfba..0083ac53e 100644 --- a/src/reclaim-attribute/reclaim_attribute.c +++ b/src/reclaim-attribute/reclaim_attribute.c | |||
@@ -401,6 +401,41 @@ GNUNET_RECLAIM_ATTESTATION_claim_new (const char *attr_name, | |||
401 | } | 401 | } |
402 | 402 | ||
403 | /** | 403 | /** |
404 | * Create a new attestation reference. | ||
405 | * | ||
406 | * @param attr_name the referenced claim name | ||
407 | * @param ref_value the claim name in the attestation | ||
408 | * @return the new reference | ||
409 | */ | ||
410 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * | ||
411 | GNUNET_RECLAIM_ATTESTATION_reference_new (const char *attr_name, | ||
412 | const char *ref_value) | ||
413 | { | ||
414 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr; | ||
415 | char *write_ptr; | ||
416 | char *attr_name_tmp = GNUNET_strdup (attr_name); | ||
417 | char *ref_value_tmp = GNUNET_strdup (ref_value); | ||
418 | |||
419 | GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); | ||
420 | GNUNET_STRINGS_utf8_tolower (ref_value, ref_value_tmp); | ||
421 | |||
422 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE) | ||
423 | + strlen (attr_name_tmp) + strlen (ref_value_tmp) + 2); | ||
424 | |||
425 | write_ptr = (char *) &attr[1]; | ||
426 | GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1); | ||
427 | attr->name = write_ptr; | ||
428 | |||
429 | write_ptr = (char *) &attr[1]; | ||
430 | GNUNET_memcpy (write_ptr, ref_value_tmp, strlen (ref_value_tmp) + 1); | ||
431 | attr->reference_value = write_ptr; | ||
432 | |||
433 | GNUNET_free (attr_name_tmp); | ||
434 | GNUNET_free (ref_value_tmp); | ||
435 | return attr; | ||
436 | } | ||
437 | |||
438 | /** | ||
404 | * Add a new attribute to a claim list | 439 | * Add a new attribute to a claim list |
405 | * | 440 | * |
406 | * @param attr_name the name of the new attribute claim | 441 | * @param attr_name the name of the new attribute claim |
@@ -762,4 +797,97 @@ GNUNET_RECLAIM_ATTESTATION_deserialize (const char *data, size_t data_size) | |||
762 | return attr; | 797 | return attr; |
763 | } | 798 | } |
764 | 799 | ||
800 | /** | ||
801 | * Get required size for serialization buffer | ||
802 | * | ||
803 | * @param attr the reference to serialize | ||
804 | * @return the required buffer size | ||
805 | */ | ||
806 | size_t | ||
807 | GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size ( | ||
808 | const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr) | ||
809 | { | ||
810 | return sizeof(struct Attestation_Reference) + strlen (attr->name) + strlen ( | ||
811 | attr->reference_value); | ||
812 | } | ||
813 | |||
814 | |||
815 | /** | ||
816 | * Serialize a reference | ||
817 | * | ||
818 | * @param attr the reference to serialize | ||
819 | * @param result the serialized reference | ||
820 | * @return length of serialized data | ||
821 | */ | ||
822 | size_t | ||
823 | GNUNET_RECLAIM_ATTESTATION_REF_serialize ( | ||
824 | const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr, | ||
825 | char *result) | ||
826 | { | ||
827 | size_t name_len; | ||
828 | size_t refval_len; | ||
829 | struct Attestation_Reference *attr_ser; | ||
830 | char *write_ptr; | ||
831 | attr_ser = (struct Attestation_Reference *) result; | ||
832 | attr_ser->reference_id = GNUNET_htonll (attr->id); | ||
833 | attr_ser->attestation_id = GNUNET_htonll (attr->id_attest); | ||
834 | name_len = strlen (attr->name); | ||
835 | refval_len = strlen (attr->reference_value); | ||
836 | attr_ser->name_len = htons (name_len); | ||
837 | attr_ser->ref_value_len = htons (refval_len); | ||
838 | write_ptr = (char *) &attr_ser[1]; | ||
839 | GNUNET_memcpy (write_ptr, attr->name, name_len); | ||
840 | write_ptr += name_len; | ||
841 | GNUNET_memcpy (write_ptr, attr->reference_value, refval_len); | ||
842 | |||
843 | return sizeof(struct Attestation_Reference) + strlen (attr->name) + strlen ( | ||
844 | attr->reference_value); | ||
845 | } | ||
846 | |||
847 | |||
848 | /** | ||
849 | * Deserialize a reference | ||
850 | * | ||
851 | * @param data the serialized reference | ||
852 | * @param data_size the length of the serialized data | ||
853 | * | ||
854 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller | ||
855 | */ | ||
856 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * | ||
857 | GNUNET_RECLAIM_ATTESTATION_REF_deserialize (const char *data, size_t data_size) | ||
858 | { | ||
859 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr; | ||
860 | struct Attestation_Reference *attr_ser; | ||
861 | size_t name_len; | ||
862 | size_t refval_len; | ||
863 | char *write_ptr; | ||
864 | |||
865 | if (data_size < sizeof(struct Attestation_Reference)) | ||
866 | return NULL; | ||
867 | attr_ser = (struct Attestation_Reference *) data; | ||
868 | name_len = ntohs (attr_ser->name_len); | ||
869 | refval_len = ntohs (attr_ser->ref_value_len); | ||
870 | if (data_size < sizeof(struct Attestation_Reference) + refval_len + name_len) | ||
871 | { | ||
872 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
873 | "Buffer too small to deserialize\n"); | ||
874 | return NULL; | ||
875 | } | ||
876 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE) | ||
877 | + refval_len + name_len + 2); | ||
878 | |||
879 | attr->id = GNUNET_ntohll (attr_ser->reference_id); | ||
880 | attr->id_attest = GNUNET_ntohll (attr_ser->attestation_id); | ||
881 | |||
882 | write_ptr = (char *) &attr[1]; | ||
883 | GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); | ||
884 | write_ptr[name_len] = '\0'; | ||
885 | attr->name = write_ptr; | ||
886 | |||
887 | write_ptr += name_len + 1; | ||
888 | GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, refval_len); | ||
889 | write_ptr[refval_len] = '\0'; | ||
890 | attr->reference_value = write_ptr; | ||
891 | return attr; | ||
892 | } | ||
765 | /* end of reclaim_attribute.c */ | 893 | /* end of reclaim_attribute.c */ |
diff --git a/src/reclaim-attribute/reclaim_attribute.h b/src/reclaim-attribute/reclaim_attribute.h index 750afc479..80f1e5aac 100644 --- a/src/reclaim-attribute/reclaim_attribute.h +++ b/src/reclaim-attribute/reclaim_attribute.h | |||
@@ -94,4 +94,33 @@ struct Attestation | |||
94 | // followed by data_size Attestation value data | 94 | // followed by data_size Attestation value data |
95 | }; | 95 | }; |
96 | 96 | ||
97 | /** | ||
98 | * Serialized attestation reference | ||
99 | */ | ||
100 | struct Attestation_Reference | ||
101 | { | ||
102 | /** | ||
103 | * Reference ID | ||
104 | */ | ||
105 | uint64_t reference_id; | ||
106 | |||
107 | /** | ||
108 | * The ID of the referenced attestation | ||
109 | */ | ||
110 | uint64_t attestation_id; | ||
111 | |||
112 | /** | ||
113 | * Claim Name length | ||
114 | */ | ||
115 | uint32_t name_len; | ||
116 | |||
117 | /** | ||
118 | * Length of the referenced value | ||
119 | */ | ||
120 | uint32_t ref_value_len; | ||
121 | |||
122 | |||
123 | // followed by the name and referenced value | ||
124 | }; | ||
125 | |||
97 | #endif | 126 | #endif |
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 |