diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-13 11:33:41 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-14 10:01:24 +0200 |
commit | 41d086c02574e08a820612faf2cfb6e68049b316 (patch) | |
tree | 2f80bb52d05d3824451fa02b64b19467324cbdfe | |
parent | 0a6ac045814213ff33e9317a40daf7250528249a (diff) | |
download | gnunet-41d086c02574e08a820612faf2cfb6e68049b316.tar.gz gnunet-41d086c02574e08a820612faf2cfb6e68049b316.zip |
RECLAIM: less unneccessary crypto; syntax and build fixes
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/include/gnunet_gnsrecord_lib.h | 168 | ||||
-rw-r--r-- | src/reclaim/gnunet-reclaim.c | 411 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 12 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim_tickets.c | 205 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim_tickets.h | 77 | ||||
-rw-r--r-- | src/reclaim/plugin_gnsrecord_reclaim.c | 118 |
8 files changed, 336 insertions, 658 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in index 000d9939e..5c6a91963 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in | |||
@@ -283,6 +283,7 @@ src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c | |||
283 | src/reclaim-attribute/reclaim_attribute.c | 283 | src/reclaim-attribute/reclaim_attribute.c |
284 | src/reclaim/gnunet-reclaim.c | 284 | src/reclaim/gnunet-reclaim.c |
285 | src/reclaim/gnunet-service-reclaim.c | 285 | src/reclaim/gnunet-service-reclaim.c |
286 | src/reclaim/gnunet-service-reclaim_tickets.c | ||
286 | src/reclaim/json_reclaim.c | 287 | src/reclaim/json_reclaim.c |
287 | src/reclaim/oidc_helper.c | 288 | src/reclaim/oidc_helper.c |
288 | src/reclaim/plugin_gnsrecord_reclaim.c | 289 | src/reclaim/plugin_gnsrecord_reclaim.c |
diff --git a/src/Makefile.am b/src/Makefile.am index b16792e15..6eaafdeee 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -17,7 +17,7 @@ if HAVE_EXPERIMENTAL | |||
17 | reclaim | 17 | reclaim |
18 | if HAVE_ABE | 18 | if HAVE_ABE |
19 | EXP_DIR += \ | 19 | EXP_DIR += \ |
20 | abe \ | 20 | abe |
21 | endif | 21 | endif |
22 | if HAVE_JSON | 22 | if HAVE_JSON |
23 | EXP_DIR += \ | 23 | EXP_DIR += \ |
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h index 27228c0bc..8b3a6b720 100644 --- a/src/include/gnunet_gnsrecord_lib.h +++ b/src/include/gnunet_gnsrecord_lib.h | |||
@@ -35,9 +35,8 @@ | |||
35 | #define GNUNET_GNSRECORD_LIB_H | 35 | #define GNUNET_GNSRECORD_LIB_H |
36 | 36 | ||
37 | #ifdef __cplusplus | 37 | #ifdef __cplusplus |
38 | extern "C" | 38 | extern "C" { |
39 | { | 39 | #if 0 /* keep Emacsens' auto-indent happy */ |
40 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
41 | } | 40 | } |
42 | #endif | 41 | #endif |
43 | #endif | 42 | #endif |
@@ -125,7 +124,7 @@ extern "C" | |||
125 | /** | 124 | /** |
126 | * Record type for reclaim records | 125 | * Record type for reclaim records |
127 | */ | 126 | */ |
128 | #define GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ 65550 | 127 | #define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF 65550 |
129 | 128 | ||
130 | /** | 129 | /** |
131 | * Record type for RECLAIM master | 130 | * Record type for RECLAIM master |
@@ -145,8 +144,7 @@ extern "C" | |||
145 | /** | 144 | /** |
146 | * Flags that can be set for a record. | 145 | * Flags that can be set for a record. |
147 | */ | 146 | */ |
148 | enum GNUNET_GNSRECORD_Flags | 147 | enum GNUNET_GNSRECORD_Flags { |
149 | { | ||
150 | 148 | ||
151 | /** | 149 | /** |
152 | * No special options. | 150 | * No special options. |
@@ -177,17 +175,17 @@ enum GNUNET_GNSRECORD_Flags | |||
177 | */ | 175 | */ |
178 | GNUNET_GNSRECORD_RF_SHADOW_RECORD = 16 | 176 | GNUNET_GNSRECORD_RF_SHADOW_RECORD = 16 |
179 | 177 | ||
180 | /** | 178 | /** |
181 | * When comparing flags for record equality for removal, | 179 | * When comparing flags for record equality for removal, |
182 | * which flags should must match (in addition to the type, | 180 | * which flags should must match (in addition to the type, |
183 | * name, expiration value and data of the record)? All flags | 181 | * name, expiration value and data of the record)? All flags |
184 | * that are not listed here will be ignored for this purpose. | 182 | * that are not listed here will be ignored for this purpose. |
185 | * (for example, we don't expect that users will remember to | 183 | * (for example, we don't expect that users will remember to |
186 | * pass the '--private' option when removing a record from | 184 | * pass the '--private' option when removing a record from |
187 | * the namestore, hence we don't require this particular option | 185 | * the namestore, hence we don't require this particular option |
188 | * to match upon removal). See also | 186 | * to match upon removal). See also |
189 | * #GNUNET_GNSRECORD_records_cmp. | 187 | * #GNUNET_GNSRECORD_records_cmp. |
190 | */ | 188 | */ |
191 | #define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION) | 189 | #define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION) |
192 | }; | 190 | }; |
193 | 191 | ||
@@ -195,8 +193,7 @@ enum GNUNET_GNSRECORD_Flags | |||
195 | /** | 193 | /** |
196 | * A GNS record. | 194 | * A GNS record. |
197 | */ | 195 | */ |
198 | struct GNUNET_GNSRECORD_Data | 196 | struct GNUNET_GNSRECORD_Data { |
199 | { | ||
200 | 197 | ||
201 | /** | 198 | /** |
202 | * Binary value stored in the DNS record. Note: "data" must never | 199 | * Binary value stored in the DNS record. Note: "data" must never |
@@ -234,8 +231,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
234 | /** | 231 | /** |
235 | * Data stored in a PLACE record. | 232 | * Data stored in a PLACE record. |
236 | */ | 233 | */ |
237 | struct GNUNET_GNSRECORD_PlaceData | 234 | struct GNUNET_GNSRECORD_PlaceData { |
238 | { | ||
239 | /** | 235 | /** |
240 | * Public key of the place. | 236 | * Public key of the place. |
241 | */ | 237 | */ |
@@ -258,8 +254,7 @@ struct GNUNET_GNSRECORD_PlaceData | |||
258 | /** | 254 | /** |
259 | * Information we have in an encrypted block with record data (i.e. in the DHT). | 255 | * Information we have in an encrypted block with record data (i.e. in the DHT). |
260 | */ | 256 | */ |
261 | struct GNUNET_GNSRECORD_Block | 257 | struct GNUNET_GNSRECORD_Block { |
262 | { | ||
263 | 258 | ||
264 | /** | 259 | /** |
265 | * Signature of the block. | 260 | * Signature of the block. |
@@ -296,8 +291,7 @@ struct GNUNET_GNSRECORD_Block | |||
296 | * records do not require a separate network request, thus making TLSA | 291 | * records do not require a separate network request, thus making TLSA |
297 | * records inseparable from the "main" A/AAAA/VPN/etc. records. | 292 | * records inseparable from the "main" A/AAAA/VPN/etc. records. |
298 | */ | 293 | */ |
299 | struct GNUNET_GNSRECORD_BoxRecord | 294 | struct GNUNET_GNSRECORD_BoxRecord { |
300 | { | ||
301 | 295 | ||
302 | /** | 296 | /** |
303 | * Protocol of the boxed record (6 = TCP, 17 = UDP, etc.). | 297 | * Protocol of the boxed record (6 = TCP, 17 = UDP, etc.). |
@@ -316,7 +310,6 @@ struct GNUNET_GNSRECORD_BoxRecord | |||
316 | uint32_t record_type GNUNET_PACKED; | 310 | uint32_t record_type GNUNET_PACKED; |
317 | 311 | ||
318 | /* followed by the 'original' record */ | 312 | /* followed by the 'original' record */ |
319 | |||
320 | }; | 313 | }; |
321 | 314 | ||
322 | /** | 315 | /** |
@@ -326,8 +319,7 @@ struct GNUNET_GNSRECORD_BoxRecord | |||
326 | * the namespace the record belongs to. | 319 | * the namespace the record belongs to. |
327 | * It is exclusively found under the label ``+''. | 320 | * It is exclusively found under the label ``+''. |
328 | */ | 321 | */ |
329 | struct GNUNET_GNSRECORD_ReverseRecord | 322 | struct GNUNET_GNSRECORD_ReverseRecord { |
330 | { | ||
331 | /** | 323 | /** |
332 | * The public key of the namespace the is delegating to our namespace | 324 | * The public key of the namespace the is delegating to our namespace |
333 | */ | 325 | */ |
@@ -351,11 +343,8 @@ GNUNET_NETWORK_STRUCT_END | |||
351 | * @param rd_count number of entries in @a rd array | 343 | * @param rd_count number of entries in @a rd array |
352 | * @param rd array of records with data to store | 344 | * @param rd array of records with data to store |
353 | */ | 345 | */ |
354 | typedef void | 346 | typedef void (*GNUNET_GNSRECORD_RecordCallback) ( |
355 | (*GNUNET_GNSRECORD_RecordCallback) (void *cls, | 347 | void *cls, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); |
356 | unsigned int rd_count, | ||
357 | const struct GNUNET_GNSRECORD_Data *rd); | ||
358 | |||
359 | 348 | ||
360 | 349 | ||
361 | /* ***************** API related to GNSRECORD plugins ************** */ | 350 | /* ***************** API related to GNSRECORD plugins ************** */ |
@@ -369,10 +358,8 @@ typedef void | |||
369 | * @param data_size number of bytes in @a data | 358 | * @param data_size number of bytes in @a data |
370 | * @return NULL on error, otherwise human-readable representation of the value | 359 | * @return NULL on error, otherwise human-readable representation of the value |
371 | */ | 360 | */ |
372 | char * | 361 | char *GNUNET_GNSRECORD_value_to_string (uint32_t type, const void *data, |
373 | GNUNET_GNSRECORD_value_to_string (uint32_t type, | 362 | size_t data_size); |
374 | const void *data, | ||
375 | size_t data_size); | ||
376 | 363 | ||
377 | 364 | ||
378 | /** | 365 | /** |
@@ -385,11 +372,8 @@ GNUNET_GNSRECORD_value_to_string (uint32_t type, | |||
385 | * @param data_size set to number of bytes in @a data | 372 | * @param data_size set to number of bytes in @a data |
386 | * @return #GNUNET_OK on success | 373 | * @return #GNUNET_OK on success |
387 | */ | 374 | */ |
388 | int | 375 | int GNUNET_GNSRECORD_string_to_value (uint32_t type, const char *s, void **data, |
389 | GNUNET_GNSRECORD_string_to_value (uint32_t type, | 376 | size_t *data_size); |
390 | const char *s, | ||
391 | void **data, | ||
392 | size_t *data_size); | ||
393 | 377 | ||
394 | 378 | ||
395 | /** | 379 | /** |
@@ -398,8 +382,7 @@ GNUNET_GNSRECORD_string_to_value (uint32_t type, | |||
398 | * @param dns_typename name to convert | 382 | * @param dns_typename name to convert |
399 | * @return corresponding number, UINT32_MAX on error | 383 | * @return corresponding number, UINT32_MAX on error |
400 | */ | 384 | */ |
401 | uint32_t | 385 | uint32_t GNUNET_GNSRECORD_typename_to_number (const char *dns_typename); |
402 | GNUNET_GNSRECORD_typename_to_number (const char *dns_typename); | ||
403 | 386 | ||
404 | 387 | ||
405 | /** | 388 | /** |
@@ -408,8 +391,7 @@ GNUNET_GNSRECORD_typename_to_number (const char *dns_typename); | |||
408 | * @param type number of a type to convert | 391 | * @param type number of a type to convert |
409 | * @return corresponding typestring, NULL on error | 392 | * @return corresponding typestring, NULL on error |
410 | */ | 393 | */ |
411 | const char * | 394 | const char *GNUNET_GNSRECORD_number_to_typename (uint32_t type); |
412 | GNUNET_GNSRECORD_number_to_typename (uint32_t type); | ||
413 | 395 | ||
414 | 396 | ||
415 | /* convenience APIs for serializing / deserializing GNS records */ | 397 | /* convenience APIs for serializing / deserializing GNS records */ |
@@ -424,7 +406,7 @@ GNUNET_GNSRECORD_number_to_typename (uint32_t type); | |||
424 | */ | 406 | */ |
425 | ssize_t | 407 | ssize_t |
426 | GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, | 408 | GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, |
427 | const struct GNUNET_GNSRECORD_Data *rd); | 409 | const struct GNUNET_GNSRECORD_Data *rd); |
428 | 410 | ||
429 | 411 | ||
430 | /** | 412 | /** |
@@ -438,9 +420,8 @@ GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, | |||
438 | */ | 420 | */ |
439 | ssize_t | 421 | ssize_t |
440 | GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, | 422 | GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, |
441 | const struct GNUNET_GNSRECORD_Data *rd, | 423 | const struct GNUNET_GNSRECORD_Data *rd, |
442 | size_t dest_size, | 424 | size_t dest_size, char *dest); |
443 | char *dest); | ||
444 | 425 | ||
445 | 426 | ||
446 | /** | 427 | /** |
@@ -452,17 +433,14 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, | |||
452 | * @param dest where to put the data | 433 | * @param dest where to put the data |
453 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 434 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
454 | */ | 435 | */ |
455 | int | 436 | int GNUNET_GNSRECORD_records_deserialize (size_t len, const char *src, |
456 | GNUNET_GNSRECORD_records_deserialize (size_t len, | 437 | unsigned int rd_count, |
457 | const char *src, | 438 | struct GNUNET_GNSRECORD_Data *dest); |
458 | unsigned int rd_count, | ||
459 | struct GNUNET_GNSRECORD_Data *dest); | ||
460 | 439 | ||
461 | 440 | ||
462 | /* ******* general APIs relating to blocks, records and labels ******** */ | 441 | /* ******* general APIs relating to blocks, records and labels ******** */ |
463 | 442 | ||
464 | 443 | ||
465 | |||
466 | /** | 444 | /** |
467 | * Test if a given record is expired. | 445 | * Test if a given record is expired. |
468 | * | 446 | * |
@@ -470,8 +448,7 @@ GNUNET_GNSRECORD_records_deserialize (size_t len, | |||
470 | * @return #GNUNET_YES if the record is expired, | 448 | * @return #GNUNET_YES if the record is expired, |
471 | * #GNUNET_NO if not | 449 | * #GNUNET_NO if not |
472 | */ | 450 | */ |
473 | int | 451 | int GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd); |
474 | GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd); | ||
475 | 452 | ||
476 | 453 | ||
477 | /** | 454 | /** |
@@ -479,8 +456,7 @@ GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd); | |||
479 | * @param src source string | 456 | * @param src source string |
480 | * @return converted result | 457 | * @return converted result |
481 | */ | 458 | */ |
482 | char * | 459 | char *GNUNET_GNSRECORD_string_to_lowercase (const char *src); |
483 | GNUNET_GNSRECORD_string_to_lowercase (const char *src); | ||
484 | 460 | ||
485 | 461 | ||
486 | /** | 462 | /** |
@@ -489,10 +465,10 @@ GNUNET_GNSRECORD_string_to_lowercase (const char *src); | |||
489 | * NOT reentrant! | 465 | * NOT reentrant! |
490 | * | 466 | * |
491 | * @param z public key of a zone | 467 | * @param z public key of a zone |
492 | * @return string form; will be overwritten by next call to #GNUNET_GNSRECORD_z2s. | 468 | * @return string form; will be overwritten by next call to |
469 | * #GNUNET_GNSRECORD_z2s. | ||
493 | */ | 470 | */ |
494 | const char * | 471 | const char *GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z); |
495 | GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z); | ||
496 | 472 | ||
497 | 473 | ||
498 | /** | 474 | /** |
@@ -518,9 +494,8 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); | |||
518 | * @param pkey set to a public key on the eliptic curve | 494 | * @param pkey set to a public key on the eliptic curve |
519 | * @return #GNUNET_SYSERR if @a zkey has the wrong syntax | 495 | * @return #GNUNET_SYSERR if @a zkey has the wrong syntax |
520 | */ | 496 | */ |
521 | int | 497 | int GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, |
522 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | 498 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); |
523 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); | ||
524 | 499 | ||
525 | 500 | ||
526 | /** | 501 | /** |
@@ -530,10 +505,9 @@ GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | |||
530 | * @param label label of the record | 505 | * @param label label of the record |
531 | * @param query hash to use for the query | 506 | * @param query hash to use for the query |
532 | */ | 507 | */ |
533 | void | 508 | void GNUNET_GNSRECORD_query_from_private_key ( |
534 | GNUNET_GNSRECORD_query_from_private_key (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 509 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, |
535 | const char *label, | 510 | struct GNUNET_HashCode *query); |
536 | struct GNUNET_HashCode *query); | ||
537 | 511 | ||
538 | 512 | ||
539 | /** | 513 | /** |
@@ -543,10 +517,9 @@ GNUNET_GNSRECORD_query_from_private_key (const struct GNUNET_CRYPTO_EcdsaPrivate | |||
543 | * @param label label of the record | 517 | * @param label label of the record |
544 | * @param query hash to use for the query | 518 | * @param query hash to use for the query |
545 | */ | 519 | */ |
546 | void | 520 | void GNUNET_GNSRECORD_query_from_public_key ( |
547 | GNUNET_GNSRECORD_query_from_public_key (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, | 521 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label, |
548 | const char *label, | 522 | struct GNUNET_HashCode *query); |
549 | struct GNUNET_HashCode *query); | ||
550 | 523 | ||
551 | 524 | ||
552 | /** | 525 | /** |
@@ -558,12 +531,10 @@ GNUNET_GNSRECORD_query_from_public_key (const struct GNUNET_CRYPTO_EcdsaPublicKe | |||
558 | * @param rd record data | 531 | * @param rd record data |
559 | * @param rd_count number of records in @a rd | 532 | * @param rd_count number of records in @a rd |
560 | */ | 533 | */ |
561 | struct GNUNET_GNSRECORD_Block * | 534 | struct GNUNET_GNSRECORD_Block *GNUNET_GNSRECORD_block_create ( |
562 | GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 535 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, |
563 | struct GNUNET_TIME_Absolute expire, | 536 | struct GNUNET_TIME_Absolute expire, const char *label, |
564 | const char *label, | 537 | const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count); |
565 | const struct GNUNET_GNSRECORD_Data *rd, | ||
566 | unsigned int rd_count); | ||
567 | 538 | ||
568 | 539 | ||
569 | /** | 540 | /** |
@@ -577,12 +548,10 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
577 | * @param rd record data | 548 | * @param rd record data |
578 | * @param rd_count number of records in @a rd | 549 | * @param rd_count number of records in @a rd |
579 | */ | 550 | */ |
580 | struct GNUNET_GNSRECORD_Block * | 551 | struct GNUNET_GNSRECORD_Block *GNUNET_GNSRECORD_block_create2 ( |
581 | GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 552 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, |
582 | struct GNUNET_TIME_Absolute expire, | 553 | struct GNUNET_TIME_Absolute expire, const char *label, |
583 | const char *label, | 554 | const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count); |
584 | const struct GNUNET_GNSRECORD_Data *rd, | ||
585 | unsigned int rd_count); | ||
586 | 555 | ||
587 | 556 | ||
588 | /** | 557 | /** |
@@ -592,8 +561,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
592 | * @param block block to verify | 561 | * @param block block to verify |
593 | * @return #GNUNET_OK if the signature is valid | 562 | * @return #GNUNET_OK if the signature is valid |
594 | */ | 563 | */ |
595 | int | 564 | int GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); |
596 | GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); | ||
597 | 565 | ||
598 | 566 | ||
599 | /** | 567 | /** |
@@ -607,12 +575,10 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); | |||
607 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was | 575 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was |
608 | * not well-formed | 576 | * not well-formed |
609 | */ | 577 | */ |
610 | int | 578 | int GNUNET_GNSRECORD_block_decrypt ( |
611 | GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | 579 | const struct GNUNET_GNSRECORD_Block *block, |
612 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, | 580 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, const char *label, |
613 | const char *label, | 581 | GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); |
614 | GNUNET_GNSRECORD_RecordCallback proc, | ||
615 | void *proc_cls); | ||
616 | 582 | ||
617 | 583 | ||
618 | /** | 584 | /** |
@@ -622,9 +588,8 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | |||
622 | * @param b another record | 588 | * @param b another record |
623 | * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not. | 589 | * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not. |
624 | */ | 590 | */ |
625 | int | 591 | int GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, |
626 | GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, | 592 | const struct GNUNET_GNSRECORD_Data *b); |
627 | const struct GNUNET_GNSRECORD_Data *b); | ||
628 | 593 | ||
629 | 594 | ||
630 | /** | 595 | /** |
@@ -636,12 +601,11 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, | |||
636 | * @param rd array of records | 601 | * @param rd array of records |
637 | * @return absolute expiration time | 602 | * @return absolute expiration time |
638 | */ | 603 | */ |
639 | struct GNUNET_TIME_Absolute | 604 | struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time ( |
640 | GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, | 605 | unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); |
641 | const struct GNUNET_GNSRECORD_Data *rd); | ||
642 | 606 | ||
643 | 607 | ||
644 | #if 0 /* keep Emacsens' auto-indent happy */ | 608 | #if 0 /* keep Emacsens' auto-indent happy */ |
645 | { | 609 | { |
646 | #endif | 610 | #endif |
647 | #ifdef __cplusplus | 611 | #ifdef __cplusplus |
@@ -650,4 +614,4 @@ GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, | |||
650 | 614 | ||
651 | #endif | 615 | #endif |
652 | 616 | ||
653 | /** @} */ /* end of group */ | 617 | /** @} */ /* end of group */ |
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index c36955a04..790813eec 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.c | |||
@@ -23,14 +23,15 @@ | |||
23 | * @brief Identity Provider utility | 23 | * @brief Identity Provider utility |
24 | * | 24 | * |
25 | */ | 25 | */ |
26 | |||
27 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include <inttypes.h> | ||
28 | |||
28 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | |||
31 | #include "gnunet_identity_service.h" | ||
29 | #include "gnunet_namestore_service.h" | 32 | #include "gnunet_namestore_service.h" |
30 | #include "gnunet_reclaim_service.h" | 33 | #include "gnunet_reclaim_service.h" |
31 | #include "gnunet_identity_service.h" | ||
32 | #include "gnunet_signatures.h" | 34 | #include "gnunet_signatures.h" |
33 | |||
34 | /** | 35 | /** |
35 | * return value | 36 | * return value |
36 | */ | 37 | */ |
@@ -44,37 +45,37 @@ static int list; | |||
44 | /** | 45 | /** |
45 | * Relying party | 46 | * Relying party |
46 | */ | 47 | */ |
47 | static char* rp; | 48 | static char *rp; |
48 | 49 | ||
49 | /** | 50 | /** |
50 | * The attribute | 51 | * The attribute |
51 | */ | 52 | */ |
52 | static char* attr_name; | 53 | static char *attr_name; |
53 | 54 | ||
54 | /** | 55 | /** |
55 | * Attribute value | 56 | * Attribute value |
56 | */ | 57 | */ |
57 | static char* attr_value; | 58 | static char *attr_value; |
58 | 59 | ||
59 | /** | 60 | /** |
60 | * Attributes to issue | 61 | * Attributes to issue |
61 | */ | 62 | */ |
62 | static char* issue_attrs; | 63 | static char *issue_attrs; |
63 | 64 | ||
64 | /** | 65 | /** |
65 | * Ticket to consume | 66 | * Ticket to consume |
66 | */ | 67 | */ |
67 | static char* consume_ticket; | 68 | static char *consume_ticket; |
68 | 69 | ||
69 | /** | 70 | /** |
70 | * Attribute type | 71 | * Attribute type |
71 | */ | 72 | */ |
72 | static char* type_str; | 73 | static char *type_str; |
73 | 74 | ||
74 | /** | 75 | /** |
75 | * Ticket to revoke | 76 | * Ticket to revoke |
76 | */ | 77 | */ |
77 | static char* revoke_ticket; | 78 | static char *revoke_ticket; |
78 | 79 | ||
79 | /** | 80 | /** |
80 | * Ticket listing | 81 | * Ticket listing |
@@ -84,7 +85,7 @@ static int list_tickets; | |||
84 | /** | 85 | /** |
85 | * Ego name | 86 | * Ego name |
86 | */ | 87 | */ |
87 | static char* ego_name; | 88 | static char *ego_name; |
88 | 89 | ||
89 | /** | 90 | /** |
90 | * Identity handle | 91 | * Identity handle |
@@ -156,8 +157,7 @@ static struct GNUNET_SCHEDULER_Task *cleanup_task; | |||
156 | */ | 157 | */ |
157 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; | 158 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; |
158 | 159 | ||
159 | static void | 160 | static void do_cleanup (void *cls) |
160 | do_cleanup(void *cls) | ||
161 | { | 161 | { |
162 | cleanup_task = NULL; | 162 | cleanup_task = NULL; |
163 | if (NULL != timeout) | 163 | if (NULL != timeout) |
@@ -178,196 +178,146 @@ do_cleanup(void *cls) | |||
178 | GNUNET_free (attr_list); | 178 | GNUNET_free (attr_list); |
179 | } | 179 | } |
180 | 180 | ||
181 | static void | 181 | static void ticket_issue_cb (void *cls, |
182 | ticket_issue_cb (void* cls, | 182 | const struct GNUNET_RECLAIM_Ticket *ticket) |
183 | const struct GNUNET_RECLAIM_Ticket *ticket) | ||
184 | { | 183 | { |
185 | char* ticket_str; | 184 | char *ticket_str; |
186 | reclaim_op = NULL; | 185 | reclaim_op = NULL; |
187 | if (NULL != ticket) { | 186 | if (NULL != ticket) { |
188 | ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket, | 187 | ticket_str = GNUNET_STRINGS_data_to_string_alloc ( |
189 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 188 | ticket, sizeof (struct GNUNET_RECLAIM_Ticket)); |
190 | printf("%s\n", | 189 | printf ("%s\n", ticket_str); |
191 | ticket_str); | ||
192 | GNUNET_free (ticket_str); | 190 | GNUNET_free (ticket_str); |
193 | } | 191 | } |
194 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 192 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
195 | } | 193 | } |
196 | 194 | ||
197 | static void | 195 | static void store_attr_cont (void *cls, int32_t success, const char *emsg) |
198 | store_attr_cont (void *cls, | ||
199 | int32_t success, | ||
200 | const char*emsg) | ||
201 | { | 196 | { |
202 | reclaim_op = NULL; | 197 | reclaim_op = NULL; |
203 | if (GNUNET_SYSERR == success) { | 198 | if (GNUNET_SYSERR == success) { |
204 | fprintf (stderr, | 199 | fprintf (stderr, "%s\n", emsg); |
205 | "%s\n", emsg); | ||
206 | } | 200 | } |
207 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 201 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
208 | } | 202 | } |
209 | 203 | ||
210 | static void | 204 | static void process_attrs (void *cls, |
211 | process_attrs (void *cls, | 205 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
212 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 206 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
213 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | ||
214 | { | 207 | { |
215 | char *value_str; | 208 | char *value_str; |
216 | const char* attr_type; | 209 | const char *attr_type; |
217 | 210 | ||
218 | if (NULL == identity) | 211 | if (NULL == identity) { |
219 | { | ||
220 | reclaim_op = NULL; | 212 | reclaim_op = NULL; |
221 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 213 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
222 | return; | 214 | return; |
223 | } | 215 | } |
224 | if (NULL == attr) | 216 | if (NULL == attr) { |
225 | { | ||
226 | ret = 1; | 217 | ret = 1; |
227 | return; | 218 | return; |
228 | } | 219 | } |
229 | value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, | 220 | value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, attr->data, |
230 | attr->data, | ||
231 | attr->data_size); | 221 | attr->data_size); |
232 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); | 222 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); |
233 | fprintf (stdout, | 223 | fprintf (stdout, "%s: %s [%s,v%u,id=%" PRIu64 "]\n", attr->name, value_str, |
234 | "%s: %s [%s,v%u,id=%lu]\n", | 224 | attr_type, attr->version, attr->id); |
235 | attr->name, value_str, attr_type, attr->version, attr->id); | ||
236 | } | 225 | } |
237 | 226 | ||
238 | static void | 227 | static void ticket_iter_err (void *cls) |
239 | ticket_iter_err (void *cls) | ||
240 | { | 228 | { |
241 | ticket_iterator = NULL; | 229 | ticket_iterator = NULL; |
242 | fprintf (stderr, | 230 | fprintf (stderr, "Failed to iterate over tickets\n"); |
243 | "Failed to iterate over tickets\n"); | ||
244 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 231 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
245 | } | 232 | } |
246 | 233 | ||
247 | static void | 234 | static void ticket_iter_fin (void *cls) |
248 | ticket_iter_fin (void *cls) | ||
249 | { | 235 | { |
250 | ticket_iterator = NULL; | 236 | ticket_iterator = NULL; |
251 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 237 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
252 | } | 238 | } |
253 | 239 | ||
254 | static void | 240 | static void ticket_iter (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) |
255 | ticket_iter (void *cls, | ||
256 | const struct GNUNET_RECLAIM_Ticket *ticket) | ||
257 | { | 241 | { |
258 | fprintf (stdout, | 242 | fprintf (stdout, "Found ticket\n"); |
259 | "Found ticket\n"); | ||
260 | GNUNET_RECLAIM_ticket_iteration_next (ticket_iterator); | 243 | GNUNET_RECLAIM_ticket_iteration_next (ticket_iterator); |
261 | } | 244 | } |
262 | 245 | ||
263 | static void | 246 | static void iter_error (void *cls) |
264 | iter_error (void *cls) | ||
265 | { | 247 | { |
266 | attr_iterator = NULL; | 248 | attr_iterator = NULL; |
267 | fprintf (stderr, | 249 | fprintf (stderr, "Failed to iterate over attributes\n"); |
268 | "Failed to iterate over attributes\n"); | ||
269 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 250 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
270 | } | 251 | } |
271 | 252 | ||
272 | static void | 253 | static void timeout_task (void *cls) |
273 | timeout_task (void *cls) | ||
274 | { | 254 | { |
275 | timeout = NULL; | 255 | timeout = NULL; |
276 | ret = 1; | 256 | ret = 1; |
277 | fprintf (stderr, | 257 | fprintf (stderr, "Timeout\n"); |
278 | "Timeout\n"); | ||
279 | if (NULL == cleanup_task) | 258 | if (NULL == cleanup_task) |
280 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 259 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
281 | } | 260 | } |
282 | 261 | ||
283 | static void | 262 | static void process_rvk (void *cls, int success, const char *msg) |
284 | process_rvk (void *cls, int success, const char* msg) | ||
285 | { | 263 | { |
286 | reclaim_op = NULL; | 264 | reclaim_op = NULL; |
287 | if (GNUNET_OK != success) | 265 | if (GNUNET_OK != success) { |
288 | { | 266 | fprintf (stderr, "Revocation failed.\n"); |
289 | fprintf (stderr, | ||
290 | "Revocation failed.\n"); | ||
291 | ret = 1; | 267 | ret = 1; |
292 | } | 268 | } |
293 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 269 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
294 | } | 270 | } |
295 | 271 | ||
296 | static void | 272 | static void iter_finished (void *cls) |
297 | iter_finished (void *cls) | ||
298 | { | 273 | { |
299 | char *data; | 274 | char *data; |
300 | size_t data_size; | 275 | size_t data_size; |
301 | int type; | 276 | int type; |
302 | 277 | ||
303 | attr_iterator = NULL; | 278 | attr_iterator = NULL; |
304 | if (list) | 279 | if (list) { |
305 | { | ||
306 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 280 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
307 | return; | 281 | return; |
308 | } | 282 | } |
309 | 283 | ||
310 | if (issue_attrs) | 284 | if (issue_attrs) { |
311 | { | 285 | reclaim_op = GNUNET_RECLAIM_ticket_issue ( |
312 | reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle, | 286 | reclaim_handle, pkey, &rp_key, attr_list, &ticket_issue_cb, NULL); |
313 | pkey, | ||
314 | &rp_key, | ||
315 | attr_list, | ||
316 | &ticket_issue_cb, | ||
317 | NULL); | ||
318 | return; | 287 | return; |
319 | } | 288 | } |
320 | if (consume_ticket) | 289 | if (consume_ticket) { |
321 | { | 290 | reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle, pkey, &ticket, |
322 | reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle, | 291 | &process_attrs, NULL); |
323 | pkey, | 292 | timeout = GNUNET_SCHEDULER_add_delayed ( |
324 | &ticket, | 293 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), |
325 | &process_attrs, | 294 | &timeout_task, NULL); |
326 | NULL); | ||
327 | timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), | ||
328 | &timeout_task, | ||
329 | NULL); | ||
330 | return; | 295 | return; |
331 | } | 296 | } |
332 | if (revoke_ticket) | 297 | if (revoke_ticket) { |
333 | { | 298 | reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle, pkey, &ticket, |
334 | reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle, | 299 | &process_rvk, NULL); |
335 | pkey, | ||
336 | &ticket, | ||
337 | &process_rvk, | ||
338 | NULL); | ||
339 | return; | 300 | return; |
340 | } | 301 | } |
341 | if (attr_name) | 302 | if (attr_name) { |
342 | { | ||
343 | if (NULL == type_str) | 303 | if (NULL == type_str) |
344 | type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; | 304 | type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; |
345 | else | 305 | else |
346 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); | 306 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); |
347 | 307 | ||
348 | GNUNET_assert (GNUNET_SYSERR != GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, | 308 | GNUNET_assert (GNUNET_SYSERR != |
349 | attr_value, | 309 | GNUNET_RECLAIM_ATTRIBUTE_string_to_value ( |
350 | (void**)&data, | 310 | type, attr_value, (void **)&data, &data_size)); |
351 | &data_size)); | 311 | if (NULL != claim) { |
352 | if (NULL != claim) | ||
353 | { | ||
354 | claim->type = type; | 312 | claim->type = type; |
355 | claim->data = data; | 313 | claim->data = data; |
356 | claim->data_size = data_size; | 314 | claim->data_size = data_size; |
315 | } else { | ||
316 | claim = | ||
317 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size); | ||
357 | } | 318 | } |
358 | else | 319 | reclaim_op = GNUNET_RECLAIM_attribute_store ( |
359 | { | 320 | reclaim_handle, pkey, claim, &exp_interval, &store_attr_cont, NULL); |
360 | claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, | ||
361 | type, | ||
362 | data, | ||
363 | data_size); | ||
364 | } | ||
365 | reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle, | ||
366 | pkey, | ||
367 | claim, | ||
368 | &exp_interval, | ||
369 | &store_attr_cont, | ||
370 | NULL); | ||
371 | GNUNET_free (data); | 321 | GNUNET_free (data); |
372 | GNUNET_free (claim); | 322 | GNUNET_free (claim); |
373 | return; | 323 | return; |
@@ -375,28 +325,21 @@ iter_finished (void *cls) | |||
375 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 325 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
376 | } | 326 | } |
377 | 327 | ||
378 | static void | 328 | static void iter_cb (void *cls, |
379 | iter_cb (void *cls, | 329 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
380 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 330 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
381 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | ||
382 | { | 331 | { |
383 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 332 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
384 | char *attrs_tmp; | 333 | char *attrs_tmp; |
385 | char *attr_str; | 334 | char *attr_str; |
386 | const char *attr_type; | 335 | const char *attr_type; |
387 | 336 | ||
388 | if ((NULL != attr_name) && (NULL != claim)) | 337 | if ((NULL != attr_name) && (NULL != claim)) { |
389 | { | 338 | if (0 == strcasecmp (attr_name, attr->name)) { |
390 | if (0 == strcasecmp (attr_name, attr->name)) | 339 | claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, attr->type, |
391 | { | 340 | attr->data, attr->data_size); |
392 | claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, | ||
393 | attr->type, | ||
394 | attr->data, | ||
395 | attr->data_size); | ||
396 | } | 341 | } |
397 | } | 342 | } else if (issue_attrs) { |
398 | else if (issue_attrs) | ||
399 | { | ||
400 | attrs_tmp = GNUNET_strdup (issue_attrs); | 343 | attrs_tmp = GNUNET_strdup (issue_attrs); |
401 | attr_str = strtok (attrs_tmp, ","); | 344 | attr_str = strtok (attrs_tmp, ","); |
402 | while (NULL != attr_str) { | 345 | while (NULL != attr_str) { |
@@ -405,92 +348,62 @@ iter_cb (void *cls, | |||
405 | continue; | 348 | continue; |
406 | } | 349 | } |
407 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 350 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
408 | le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, | 351 | le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new ( |
409 | attr->type, | 352 | attr->name, attr->type, attr->data, attr->data_size); |
410 | attr->data, | ||
411 | attr->data_size); | ||
412 | le->claim->version = attr->version; | 353 | le->claim->version = attr->version; |
413 | le->claim->id = attr->id; | 354 | le->claim->id = attr->id; |
414 | GNUNET_CONTAINER_DLL_insert (attr_list->list_head, | 355 | GNUNET_CONTAINER_DLL_insert (attr_list->list_head, attr_list->list_tail, |
415 | attr_list->list_tail, | ||
416 | le); | 356 | le); |
417 | break; | 357 | break; |
418 | } | 358 | } |
419 | GNUNET_free (attrs_tmp); | 359 | GNUNET_free (attrs_tmp); |
420 | } | 360 | } else if (list) { |
421 | else if (list) | 361 | attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, attr->data, |
422 | { | ||
423 | attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, | ||
424 | attr->data, | ||
425 | attr->data_size); | 362 | attr->data_size); |
426 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); | 363 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); |
427 | fprintf (stdout, | 364 | fprintf (stdout, "%s: %s [%s,v%u,id=%" PRIu64 "]\n", attr->name, attr_str, |
428 | "%s: %s [%s,v%u,id=%lu]\n", | 365 | attr_type, attr->version, attr->id); |
429 | attr->name, attr_str, attr_type, attr->version, attr->id); | ||
430 | } | 366 | } |
431 | GNUNET_RECLAIM_get_attributes_next (attr_iterator); | 367 | GNUNET_RECLAIM_get_attributes_next (attr_iterator); |
432 | } | 368 | } |
433 | 369 | ||
434 | static void | 370 | static void start_process () |
435 | start_process () | ||
436 | { | 371 | { |
437 | if (NULL == pkey) | 372 | if (NULL == pkey) { |
438 | { | 373 | fprintf (stderr, "Ego %s not found\n", ego_name); |
439 | fprintf (stderr, | ||
440 | "Ego %s not found\n", ego_name); | ||
441 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 374 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
442 | return; | 375 | return; |
443 | } | 376 | } |
444 | 377 | ||
445 | if (list_tickets) | 378 | if (list_tickets) { |
446 | { | 379 | ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start ( |
447 | ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle, | 380 | reclaim_handle, pkey, &ticket_iter_err, NULL, &ticket_iter, NULL, |
448 | pkey, | 381 | &ticket_iter_fin, NULL); |
449 | &ticket_iter_err, | ||
450 | NULL, | ||
451 | &ticket_iter, | ||
452 | NULL, | ||
453 | &ticket_iter_fin, | ||
454 | NULL); | ||
455 | return; | 382 | return; |
456 | } | 383 | } |
457 | 384 | ||
458 | if (NULL != rp) | 385 | if (NULL != rp) |
459 | GNUNET_CRYPTO_ecdsa_public_key_from_string (rp, | 386 | GNUNET_CRYPTO_ecdsa_public_key_from_string (rp, strlen (rp), &rp_key); |
460 | strlen (rp), | ||
461 | &rp_key); | ||
462 | if (NULL != consume_ticket) | 387 | if (NULL != consume_ticket) |
463 | GNUNET_STRINGS_string_to_data (consume_ticket, | 388 | GNUNET_STRINGS_string_to_data (consume_ticket, strlen (consume_ticket), |
464 | strlen (consume_ticket), | ||
465 | &ticket, | 389 | &ticket, |
466 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 390 | sizeof (struct GNUNET_RECLAIM_Ticket)); |
467 | if (NULL != revoke_ticket) | 391 | if (NULL != revoke_ticket) |
468 | GNUNET_STRINGS_string_to_data (revoke_ticket, | 392 | GNUNET_STRINGS_string_to_data (revoke_ticket, strlen (revoke_ticket), |
469 | strlen (revoke_ticket), | ||
470 | &ticket, | 393 | &ticket, |
471 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 394 | sizeof (struct GNUNET_RECLAIM_Ticket)); |
472 | 395 | ||
473 | attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 396 | attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); |
474 | claim = NULL; | 397 | claim = NULL; |
475 | attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle, | 398 | attr_iterator = GNUNET_RECLAIM_get_attributes_start ( |
476 | pkey, | 399 | reclaim_handle, pkey, &iter_error, NULL, &iter_cb, NULL, &iter_finished, |
477 | &iter_error, | 400 | NULL); |
478 | NULL, | ||
479 | &iter_cb, | ||
480 | NULL, | ||
481 | &iter_finished, | ||
482 | NULL); | ||
483 | |||
484 | |||
485 | } | 401 | } |
486 | 402 | ||
487 | static int init = GNUNET_YES; | 403 | static int init = GNUNET_YES; |
488 | 404 | ||
489 | static void | 405 | static void ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, |
490 | ego_cb (void *cls, | 406 | const char *name) |
491 | struct GNUNET_IDENTITY_Ego *ego, | ||
492 | void **ctx, | ||
493 | const char *name) | ||
494 | { | 407 | { |
495 | if (NULL == name) { | 408 | if (NULL == name) { |
496 | if (GNUNET_YES == init) { | 409 | if (GNUNET_YES == init) { |
@@ -505,113 +418,75 @@ ego_cb (void *cls, | |||
505 | } | 418 | } |
506 | 419 | ||
507 | 420 | ||
508 | static void | 421 | static void run (void *cls, char *const *args, const char *cfgfile, |
509 | run (void *cls, | 422 | const struct GNUNET_CONFIGURATION_Handle *c) |
510 | char *const *args, | ||
511 | const char *cfgfile, | ||
512 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
513 | { | 423 | { |
514 | ret = 0; | 424 | ret = 0; |
515 | if (NULL == ego_name) | 425 | if (NULL == ego_name) { |
516 | { | ||
517 | ret = 1; | 426 | ret = 1; |
518 | fprintf (stderr, | 427 | fprintf (stderr, _ ("Ego is required\n")); |
519 | _("Ego is required\n")); | ||
520 | return; | 428 | return; |
521 | } | 429 | } |
522 | 430 | ||
523 | if ( (NULL == attr_value) && (NULL != attr_name) ) | 431 | if ((NULL == attr_value) && (NULL != attr_name)) { |
524 | { | ||
525 | ret = 1; | 432 | ret = 1; |
526 | fprintf (stderr, | 433 | fprintf (stderr, _ ("Attribute value missing!\n")); |
527 | _("Attribute value missing!\n")); | ||
528 | return; | 434 | return; |
529 | } | 435 | } |
530 | 436 | ||
531 | if ( (NULL == rp) && (NULL != issue_attrs) ) | 437 | if ((NULL == rp) && (NULL != issue_attrs)) { |
532 | { | ||
533 | ret = 1; | 438 | ret = 1; |
534 | fprintf (stderr, | 439 | fprintf (stderr, _ ("Requesting party key is required!\n")); |
535 | _("Requesting party key is required!\n")); | ||
536 | return; | 440 | return; |
537 | } | 441 | } |
538 | 442 | ||
539 | reclaim_handle = GNUNET_RECLAIM_connect (c); | 443 | reclaim_handle = GNUNET_RECLAIM_connect (c); |
540 | //Get Ego | 444 | // Get Ego |
541 | identity_handle = GNUNET_IDENTITY_connect (c, | 445 | identity_handle = GNUNET_IDENTITY_connect (c, &ego_cb, NULL); |
542 | &ego_cb, | ||
543 | NULL); | ||
544 | |||
545 | |||
546 | } | 446 | } |
547 | 447 | ||
548 | 448 | ||
549 | int | 449 | int main (int argc, char *const argv[]) |
550 | main(int argc, char *const argv[]) | ||
551 | { | 450 | { |
552 | exp_interval = GNUNET_TIME_UNIT_HOURS; | 451 | exp_interval = GNUNET_TIME_UNIT_HOURS; |
553 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 452 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
554 | 453 | ||
555 | GNUNET_GETOPT_option_string ('a', | 454 | GNUNET_GETOPT_option_string ('a', "add", "NAME", |
556 | "add", | 455 | gettext_noop ("Add an attribute NAME"), |
557 | "NAME", | 456 | &attr_name), |
558 | gettext_noop ("Add an attribute NAME"), | 457 | |
559 | &attr_name), | 458 | GNUNET_GETOPT_option_string ('V', "value", "VALUE", |
560 | 459 | gettext_noop ("The attribute VALUE"), | |
561 | GNUNET_GETOPT_option_string ('V', | 460 | &attr_value), |
562 | "value", | 461 | GNUNET_GETOPT_option_string ('e', "ego", "EGO", |
563 | "VALUE", | 462 | gettext_noop ("The EGO to use"), &ego_name), |
564 | gettext_noop ("The attribute VALUE"), | 463 | GNUNET_GETOPT_option_string ( |
565 | &attr_value), | 464 | 'r', "rp", "RP", gettext_noop ("Specify the relying party for issue"), |
566 | GNUNET_GETOPT_option_string ('e', | 465 | &rp), |
567 | "ego", | 466 | GNUNET_GETOPT_option_flag ( |
568 | "EGO", | 467 | 'D', "dump", gettext_noop ("List attributes for EGO"), &list), |
569 | gettext_noop ("The EGO to use"), | 468 | GNUNET_GETOPT_option_string ( |
570 | &ego_name), | 469 | 'i', "issue", "A1,A2,...", |
571 | GNUNET_GETOPT_option_string ('r', | 470 | gettext_noop ( |
572 | "rp", | 471 | "Issue a ticket for a set of attributes separated by comma"), |
573 | "RP", | 472 | &issue_attrs), |
574 | gettext_noop ("Specify the relying party for issue"), | 473 | GNUNET_GETOPT_option_string ('C', "consume", "TICKET", |
575 | &rp), | 474 | gettext_noop ("Consume a ticket"), |
576 | GNUNET_GETOPT_option_flag ('D', | 475 | &consume_ticket), |
577 | "dump", | 476 | GNUNET_GETOPT_option_string ('R', "revoke", "TICKET", |
578 | gettext_noop ("List attributes for EGO"), | 477 | gettext_noop ("Revoke a ticket"), |
579 | &list), | 478 | &revoke_ticket), |
580 | GNUNET_GETOPT_option_string ('i', | 479 | GNUNET_GETOPT_option_string ( |
581 | "issue", | 480 | 't', "type", "TYPE", gettext_noop ("Type of attribute"), &type_str), |
582 | "A1,A2,...", | 481 | GNUNET_GETOPT_option_flag ( |
583 | gettext_noop ("Issue a ticket for a set of attributes separated by comma"), | 482 | 'T', "tickets", gettext_noop ("List tickets of ego"), &list_tickets), |
584 | &issue_attrs), | 483 | GNUNET_GETOPT_option_relative_time ( |
585 | GNUNET_GETOPT_option_string ('C', | 484 | 'E', "expiration", "INTERVAL", |
586 | "consume", | 485 | gettext_noop ("Expiration interval of the attribute"), &exp_interval), |
587 | "TICKET", | 486 | |
588 | gettext_noop ("Consume a ticket"), | 487 | GNUNET_GETOPT_OPTION_END}; |
589 | &consume_ticket), | 488 | if (GNUNET_OK != |
590 | GNUNET_GETOPT_option_string ('R', | 489 | GNUNET_PROGRAM_run (argc, argv, "ct", "ct", options, &run, NULL)) |
591 | "revoke", | ||
592 | "TICKET", | ||
593 | gettext_noop ("Revoke a ticket"), | ||
594 | &revoke_ticket), | ||
595 | GNUNET_GETOPT_option_string ('t', | ||
596 | "type", | ||
597 | "TYPE", | ||
598 | gettext_noop ("Type of attribute"), | ||
599 | &type_str), | ||
600 | GNUNET_GETOPT_option_flag ('T', | ||
601 | "tickets", | ||
602 | gettext_noop ("List tickets of ego"), | ||
603 | &list_tickets), | ||
604 | GNUNET_GETOPT_option_relative_time ('E', | ||
605 | "expiration", | ||
606 | "INTERVAL", | ||
607 | gettext_noop ("Expiration interval of the attribute"), | ||
608 | &exp_interval), | ||
609 | |||
610 | GNUNET_GETOPT_OPTION_END | ||
611 | }; | ||
612 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct", | ||
613 | "ct", options, | ||
614 | &run, NULL)) | ||
615 | return 1; | 490 | return 1; |
616 | else | 491 | else |
617 | return ret; | 492 | return ret; |
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index 51d8554e2..fa3236af4 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -23,6 +23,10 @@ | |||
23 | * @brief reclaim Service | 23 | * @brief reclaim Service |
24 | * | 24 | * |
25 | */ | 25 | */ |
26 | #include "platform.h" | ||
27 | |||
28 | #include "gnunet_util_lib.h" | ||
29 | |||
26 | #include "gnunet-service-reclaim_tickets.h" | 30 | #include "gnunet-service-reclaim_tickets.h" |
27 | #include "gnunet_constants.h" | 31 | #include "gnunet_constants.h" |
28 | #include "gnunet_gnsrecord_lib.h" | 32 | #include "gnunet_gnsrecord_lib.h" |
@@ -32,8 +36,6 @@ | |||
32 | #include "gnunet_reclaim_attribute_lib.h" | 36 | #include "gnunet_reclaim_attribute_lib.h" |
33 | #include "gnunet_reclaim_plugin.h" | 37 | #include "gnunet_reclaim_plugin.h" |
34 | #include "gnunet_signatures.h" | 38 | #include "gnunet_signatures.h" |
35 | #include "gnunet_util_lib.h" | ||
36 | #include "platform.h" | ||
37 | #include "reclaim.h" | 39 | #include "reclaim.h" |
38 | 40 | ||
39 | /** | 41 | /** |
@@ -804,7 +806,7 @@ ticket_reissue_proc (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket, | |||
804 | code_record[0].data = authz_record_data; | 806 | code_record[0].data = authz_record_data; |
805 | code_record[0].data_size = authz_record_len; | 807 | code_record[0].data_size = authz_record_len; |
806 | code_record[0].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; | 808 | code_record[0].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; |
807 | code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ; | 809 | code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF; |
808 | code_record[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 810 | code_record[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
809 | 811 | ||
810 | label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); | 812 | label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); |
@@ -924,8 +926,8 @@ static void reenc_next_attribute (void *cls) | |||
924 | /* First check if attribute still exists */ | 926 | /* First check if attribute still exists */ |
925 | label = GNUNET_STRINGS_data_to_string_alloc (&rh->attrs->list_head->claim->id, | 927 | label = GNUNET_STRINGS_data_to_string_alloc (&rh->attrs->list_head->claim->id, |
926 | sizeof (uint64_t)); | 928 | sizeof (uint64_t)); |
927 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ID: %lu\n", | 929 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Name: %s\n", |
928 | rh->attrs->list_head->claim->id); | 930 | rh->attrs->list_head->claim->name); |
929 | rh->ns_qe = GNUNET_NAMESTORE_records_lookup ( | 931 | rh->ns_qe = GNUNET_NAMESTORE_records_lookup ( |
930 | nsh, &rh->identity, label, &check_attr_error, rh, &check_attr_cb, rh); | 932 | nsh, &rh->identity, label, &check_attr_error, rh, &check_attr_cb, rh); |
931 | GNUNET_free (label); | 933 | GNUNET_free (label); |
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c index 54e5659a4..16e831e22 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.c +++ b/src/reclaim/gnunet-service-reclaim_tickets.c | |||
@@ -236,28 +236,6 @@ static struct GNUNET_GNS_Handle *gns; | |||
236 | /* Handle to the statistics service */ | 236 | /* Handle to the statistics service */ |
237 | static struct GNUNET_STATISTICS_Handle *stats; | 237 | static struct GNUNET_STATISTICS_Handle *stats; |
238 | 238 | ||
239 | static int create_sym_key_from_ecdh ( | ||
240 | const struct GNUNET_HashCode *new_key_hash, | ||
241 | struct GNUNET_CRYPTO_SymmetricSessionKey *skey, | ||
242 | struct GNUNET_CRYPTO_SymmetricInitializationVector *iv) | ||
243 | { | ||
244 | struct GNUNET_CRYPTO_HashAsciiEncoded new_key_hash_str; | ||
245 | |||
246 | GNUNET_CRYPTO_hash_to_enc (new_key_hash, &new_key_hash_str); | ||
247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating symmetric rsa key from %s\n", | ||
248 | (char *)&new_key_hash_str); | ||
249 | static const char ctx_key[] = "gnuid-aes-ctx-key"; | ||
250 | GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), | ||
251 | new_key_hash, sizeof (struct GNUNET_HashCode), ctx_key, | ||
252 | strlen (ctx_key), NULL, 0); | ||
253 | static const char ctx_iv[] = "gnuid-aes-ctx-iv"; | ||
254 | GNUNET_CRYPTO_kdf ( | ||
255 | iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector), | ||
256 | new_key_hash, sizeof (struct GNUNET_HashCode), ctx_iv, strlen (ctx_iv), | ||
257 | NULL, 0); | ||
258 | return GNUNET_OK; | ||
259 | } | ||
260 | |||
261 | 239 | ||
262 | /** | 240 | /** |
263 | * Cleanup ticket consume handle | 241 | * Cleanup ticket consume handle |
@@ -351,67 +329,32 @@ static void lookup_authz_cb (void *cls, uint32_t rd_count, | |||
351 | const struct GNUNET_GNSRECORD_Data *rd) | 329 | const struct GNUNET_GNSRECORD_Data *rd) |
352 | { | 330 | { |
353 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; | 331 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; |
354 | struct GNUNET_HashCode new_key_hash; | ||
355 | struct GNUNET_CRYPTO_SymmetricSessionKey enc_key; | ||
356 | struct GNUNET_CRYPTO_SymmetricInitializationVector enc_iv; | ||
357 | struct GNUNET_CRYPTO_EcdhePublicKey *ecdh_key; | ||
358 | struct ParallelLookup *parallel_lookup; | 332 | struct ParallelLookup *parallel_lookup; |
359 | size_t size; | 333 | char *lbl; |
360 | char *buf; | ||
361 | char *attr_lbl; | ||
362 | char *lbls; | ||
363 | 334 | ||
364 | cth->lookup_request = NULL; | 335 | cth->lookup_request = NULL; |
365 | if (1 != rd_count) { | ||
366 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Number of keys %d != 1.", rd_count); | ||
367 | cth->cb (cth->cb_cls, NULL, NULL, GNUNET_SYSERR, "Number of keys %d != 1."); | ||
368 | cleanup_cth (cth); | ||
369 | return; | ||
370 | } | ||
371 | 336 | ||
372 | // Decrypt | ||
373 | ecdh_key = (struct GNUNET_CRYPTO_EcdhePublicKey *)rd->data; | ||
374 | |||
375 | buf = GNUNET_malloc (rd->data_size - | ||
376 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | ||
377 | |||
378 | // Calculate symmetric key from ecdh parameters | ||
379 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdsa_ecdh ( | ||
380 | &cth->identity, ecdh_key, &new_key_hash)); | ||
381 | create_sym_key_from_ecdh (&new_key_hash, &enc_key, &enc_iv); | ||
382 | size = GNUNET_CRYPTO_symmetric_decrypt ( | ||
383 | rd->data + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), | ||
384 | rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), &enc_key, | ||
385 | &enc_iv, buf); | ||
386 | |||
387 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
388 | "Decrypted bytes: %zd Expected bytes: %zd\n", size, | ||
389 | rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | ||
390 | GNUNET_STATISTICS_update ( | 337 | GNUNET_STATISTICS_update ( |
391 | stats, "reclaim_authz_lookup_time_total", | 338 | stats, "reclaim_authz_lookup_time_total", |
392 | GNUNET_TIME_absolute_get_duration (cth->lookup_start_time).rel_value_us, | 339 | GNUNET_TIME_absolute_get_duration (cth->lookup_start_time).rel_value_us, |
393 | GNUNET_YES); | 340 | GNUNET_YES); |
394 | GNUNET_STATISTICS_update (stats, "reclaim_authz_lookups_count", 1, | 341 | GNUNET_STATISTICS_update (stats, "reclaim_authz_lookups_count", 1, |
395 | GNUNET_YES); | 342 | GNUNET_YES); |
396 | lbls = GNUNET_strdup (buf); | ||
397 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Attributes found %s\n", lbls); | ||
398 | 343 | ||
399 | for (attr_lbl = strtok (lbls, ","); NULL != attr_lbl; | 344 | for (int i = 0; i < rd_count; i++) { |
400 | attr_lbl = strtok (NULL, ",")) { | 345 | lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size); |
401 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Looking up %s\n", attr_lbl); | 346 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Attribute ref found %s\n", lbl); |
402 | parallel_lookup = GNUNET_new (struct ParallelLookup); | 347 | parallel_lookup = GNUNET_new (struct ParallelLookup); |
403 | parallel_lookup->handle = cth; | 348 | parallel_lookup->handle = cth; |
404 | parallel_lookup->label = GNUNET_strdup (attr_lbl); | 349 | parallel_lookup->label = lbl; |
405 | parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get (); | 350 | parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get (); |
406 | parallel_lookup->lookup_request = GNUNET_GNS_lookup ( | 351 | parallel_lookup->lookup_request = GNUNET_GNS_lookup ( |
407 | gns, attr_lbl, &cth->ticket.identity, | 352 | gns, lbl, &cth->ticket.identity, GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, |
408 | GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, GNUNET_GNS_LO_DEFAULT, | 353 | GNUNET_GNS_LO_DEFAULT, &process_parallel_lookup_result, |
409 | &process_parallel_lookup_result, parallel_lookup); | 354 | parallel_lookup); |
410 | GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, | 355 | GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, |
411 | cth->parallel_lookups_tail, parallel_lookup); | 356 | cth->parallel_lookups_tail, parallel_lookup); |
412 | } | 357 | } |
413 | GNUNET_free (lbls); | ||
414 | GNUNET_free (buf); | ||
415 | cth->kill_task = GNUNET_SCHEDULER_add_delayed ( | 358 | cth->kill_task = GNUNET_SCHEDULER_add_delayed ( |
416 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3), | 359 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3), |
417 | &abort_parallel_lookups, cth); | 360 | &abort_parallel_lookups, cth); |
@@ -439,7 +382,7 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | |||
439 | label); | 382 | label); |
440 | cth->lookup_start_time = GNUNET_TIME_absolute_get (); | 383 | cth->lookup_start_time = GNUNET_TIME_absolute_get (); |
441 | cth->lookup_request = GNUNET_GNS_lookup ( | 384 | cth->lookup_request = GNUNET_GNS_lookup ( |
442 | gns, label, &cth->ticket.identity, GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ, | 385 | gns, label, &cth->ticket.identity, GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF, |
443 | GNUNET_GNS_LO_DEFAULT, &lookup_authz_cb, cth); | 386 | GNUNET_GNS_LO_DEFAULT, &lookup_authz_cb, cth); |
444 | GNUNET_free (label); | 387 | GNUNET_free (label); |
445 | return cth; | 388 | return cth; |
@@ -500,19 +443,11 @@ static void update_ticket_refs (void *cls) | |||
500 | struct TicketIssueHandle *handle = cls; | 443 | struct TicketIssueHandle *handle = cls; |
501 | struct GNUNET_GNSRECORD_Data refs_rd[handle->ticket_ref_num]; | 444 | struct GNUNET_GNSRECORD_Data refs_rd[handle->ticket_ref_num]; |
502 | struct TicketReference *tr; | 445 | struct TicketReference *tr; |
503 | char *buf; | ||
504 | size_t buf_size; | ||
505 | 446 | ||
506 | tr = handle->ticket_refs_head; | 447 | tr = handle->ticket_refs_head; |
507 | for (int i = 0; i < handle->ticket_ref_num; i++) { | 448 | for (int i = 0; i < handle->ticket_ref_num; i++) { |
508 | buf_size = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (tr->attrs); | 449 | refs_rd[i].data = &tr->ticket; |
509 | buf_size += sizeof (struct GNUNET_RECLAIM_Ticket); | 450 | refs_rd[i].data_size = sizeof (struct GNUNET_RECLAIM_Ticket); |
510 | buf = GNUNET_malloc (buf_size); | ||
511 | memcpy (buf, &tr->ticket, sizeof (struct GNUNET_RECLAIM_Ticket)); | ||
512 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( | ||
513 | tr->attrs, buf + sizeof (struct GNUNET_RECLAIM_Ticket)); | ||
514 | refs_rd[i].data = buf; | ||
515 | refs_rd[i].data_size = buf_size; | ||
516 | refs_rd[i].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; | 451 | refs_rd[i].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; |
517 | refs_rd[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF; | 452 | refs_rd[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF; |
518 | refs_rd[i].flags = | 453 | refs_rd[i].flags = |
@@ -523,8 +458,6 @@ static void update_ticket_refs (void *cls) | |||
523 | handle->ns_qe = GNUNET_NAMESTORE_records_store ( | 458 | handle->ns_qe = GNUNET_NAMESTORE_records_store ( |
524 | nsh, &handle->identity, GNUNET_GNS_EMPTY_LABEL_AT, handle->ticket_ref_num, | 459 | nsh, &handle->identity, GNUNET_GNS_EMPTY_LABEL_AT, handle->ticket_ref_num, |
525 | refs_rd, &store_ticket_refs_cont, handle); | 460 | refs_rd, &store_ticket_refs_cont, handle); |
526 | for (int i = 0; i < handle->ticket_ref_num; i++) | ||
527 | GNUNET_free ((char *)refs_rd[i].data); | ||
528 | } | 461 | } |
529 | 462 | ||
530 | 463 | ||
@@ -535,8 +468,7 @@ static void ticket_lookup_cb (void *cls, | |||
535 | { | 468 | { |
536 | struct TicketIssueHandle *handle = cls; | 469 | struct TicketIssueHandle *handle = cls; |
537 | struct TicketReference *tr; | 470 | struct TicketReference *tr; |
538 | const char *attr_data; | 471 | |
539 | size_t attr_data_len; | ||
540 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
541 | "Received tickets from local namestore.\n"); | 473 | "Received tickets from local namestore.\n"); |
542 | handle->ns_qe = NULL; | 474 | handle->ns_qe = NULL; |
@@ -551,10 +483,6 @@ static void ticket_lookup_cb (void *cls, | |||
551 | GNUNET_free (tr); | 483 | GNUNET_free (tr); |
552 | continue; | 484 | continue; |
553 | } | 485 | } |
554 | attr_data = rd[i].data + sizeof (struct GNUNET_RECLAIM_Ticket); | ||
555 | attr_data_len = rd[i].data_size - sizeof (struct GNUNET_RECLAIM_Ticket); | ||
556 | tr->attrs = | ||
557 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attr_data, attr_data_len); | ||
558 | GNUNET_CONTAINER_DLL_insert (handle->ticket_refs_head, | 486 | GNUNET_CONTAINER_DLL_insert (handle->ticket_refs_head, |
559 | handle->ticket_refs_tail, tr); | 487 | handle->ticket_refs_tail, tr); |
560 | handle->ticket_ref_num++; | 488 | handle->ticket_ref_num++; |
@@ -568,6 +496,10 @@ static void ticket_lookup_cb (void *cls, | |||
568 | GNUNET_SCHEDULER_add_now (&update_ticket_refs, handle); | 496 | GNUNET_SCHEDULER_add_now (&update_ticket_refs, handle); |
569 | } | 497 | } |
570 | 498 | ||
499 | |||
500 | /** | ||
501 | * TODO maybe we should cleanup the ATTRREFS here? | ||
502 | */ | ||
571 | static void ticket_lookup_error_cb (void *cls) | 503 | static void ticket_lookup_error_cb (void *cls) |
572 | { | 504 | { |
573 | struct TicketIssueHandle *handle = cls; | 505 | struct TicketIssueHandle *handle = cls; |
@@ -595,93 +527,36 @@ static void store_ticket_issue_cont (void *cls, int32_t success, | |||
595 | } | 527 | } |
596 | 528 | ||
597 | 529 | ||
598 | static int | 530 | static void issue_ticket (struct TicketIssueHandle *ih) |
599 | serialize_authz_record (const struct GNUNET_RECLAIM_Ticket *ticket, | ||
600 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | ||
601 | struct GNUNET_CRYPTO_EcdhePrivateKey **ecdh_privkey, | ||
602 | char **result) | ||
603 | { | 531 | { |
604 | struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey; | ||
605 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 532 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
606 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 533 | struct GNUNET_GNSRECORD_Data *attrs_record; |
607 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | ||
608 | struct GNUNET_HashCode new_key_hash; | ||
609 | ssize_t enc_size; | ||
610 | char *enc_keyinfo; | ||
611 | char *buf; | ||
612 | char *write_ptr; | ||
613 | char attrs_str_len; | ||
614 | char *label; | 534 | char *label; |
615 | 535 | size_t list_len = 0; | |
616 | GNUNET_assert (NULL != attrs->list_head); | 536 | int i; |
617 | attrs_str_len = 0; | 537 | |
618 | for (le = attrs->list_head; NULL != le; le = le->next) { | 538 | for (le = ih->attrs->list_head; NULL != le; le = le->next) |
619 | attrs_str_len += 15 + 1; // TODO propery calculate | 539 | list_len++; |
620 | } | 540 | |
621 | buf = GNUNET_malloc (attrs_str_len); | 541 | attrs_record = |
622 | write_ptr = buf; | 542 | GNUNET_malloc (list_len * sizeof (struct GNUNET_GNSRECORD_Data)); |
623 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing attributes\n"); | 543 | i = 0; |
624 | for (le = attrs->list_head; NULL != le; le = le->next) { | 544 | for (le = ih->attrs->list_head; NULL != le; le = le->next) { |
625 | label = | 545 | attrs_record[i].data = &le->claim->id; |
626 | GNUNET_STRINGS_data_to_string_alloc (&le->claim->id, sizeof (uint64_t)); | 546 | attrs_record[i].data_size = sizeof (le->claim->id); |
627 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding attribute to record: %s\n", | 547 | attrs_record[i].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; |
628 | label); | 548 | attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF; |
629 | 549 | attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | |
630 | GNUNET_memcpy (write_ptr, label, strlen (label)); | ||
631 | write_ptr[strlen (label)] = ','; | ||
632 | write_ptr += strlen (label) + 1; | ||
633 | GNUNET_free (label); | ||
634 | } | 550 | } |
635 | write_ptr--; | ||
636 | write_ptr[0] = '\0'; // replace last , with a 0-terminator | ||
637 | // ECDH keypair E = eG | ||
638 | *ecdh_privkey = GNUNET_CRYPTO_ecdhe_key_create (); | ||
639 | GNUNET_CRYPTO_ecdhe_key_get_public (*ecdh_privkey, &ecdh_pubkey); | ||
640 | enc_keyinfo = GNUNET_malloc (attrs_str_len); | ||
641 | // Derived key K = H(eB) | ||
642 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdh_ecdsa (*ecdh_privkey, | ||
643 | &ticket->audience, | ||
644 | &new_key_hash)); | ||
645 | create_sym_key_from_ecdh (&new_key_hash, &skey, &iv); | ||
646 | enc_size = GNUNET_CRYPTO_symmetric_encrypt (buf, attrs_str_len, &skey, &iv, | ||
647 | enc_keyinfo); | ||
648 | *result = | ||
649 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) + enc_size); | ||
650 | GNUNET_memcpy (*result, &ecdh_pubkey, | ||
651 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | ||
652 | GNUNET_memcpy (*result + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), | ||
653 | enc_keyinfo, enc_size); | ||
654 | GNUNET_free (enc_keyinfo); | ||
655 | GNUNET_free (buf); | ||
656 | return sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) + enc_size; | ||
657 | } | ||
658 | |||
659 | |||
660 | static void issue_ticket (struct TicketIssueHandle *ih) | ||
661 | { | ||
662 | struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; | ||
663 | struct GNUNET_GNSRECORD_Data code_record[1]; | ||
664 | char *authz_record_data; | ||
665 | size_t authz_record_len; | ||
666 | char *label; | ||
667 | |||
668 | // TODO rename function | ||
669 | authz_record_len = serialize_authz_record ( | ||
670 | &ih->ticket, ih->attrs, &ecdhe_privkey, &authz_record_data); | ||
671 | code_record[0].data = authz_record_data; | ||
672 | code_record[0].data_size = authz_record_len; | ||
673 | code_record[0].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; | ||
674 | code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ; | ||
675 | code_record[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
676 | 551 | ||
677 | label = | 552 | label = |
678 | GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd, sizeof (uint64_t)); | 553 | GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd, sizeof (uint64_t)); |
679 | // Publish record | 554 | // Publish record |
680 | ih->ns_qe = GNUNET_NAMESTORE_records_store ( | 555 | ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh, &ih->identity, label, |
681 | nsh, &ih->identity, label, 1, code_record, &store_ticket_issue_cont, ih); | 556 | list_len, attrs_record, |
682 | GNUNET_free (ecdhe_privkey); | 557 | &store_ticket_issue_cont, ih); |
558 | GNUNET_free (attrs_record); | ||
683 | GNUNET_free (label); | 559 | GNUNET_free (label); |
684 | GNUNET_free (authz_record_data); | ||
685 | } | 560 | } |
686 | 561 | ||
687 | 562 | ||
@@ -759,8 +634,6 @@ collect_tickets_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
759 | { | 634 | { |
760 | struct RECLAIM_TICKETS_Iterator *iter = cls; | 635 | struct RECLAIM_TICKETS_Iterator *iter = cls; |
761 | struct TicketReference *tr; | 636 | struct TicketReference *tr; |
762 | size_t attr_data_len; | ||
763 | const char *attr_data; | ||
764 | iter->ns_qe = NULL; | 637 | iter->ns_qe = NULL; |
765 | 638 | ||
766 | for (int i = 0; i < rd_count; i++) { | 639 | for (int i = 0; i < rd_count; i++) { |
@@ -774,10 +647,6 @@ collect_tickets_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
774 | GNUNET_free (tr); | 647 | GNUNET_free (tr); |
775 | continue; | 648 | continue; |
776 | } | 649 | } |
777 | attr_data = rd[i].data + sizeof (struct GNUNET_RECLAIM_Ticket); | ||
778 | attr_data_len = rd[i].data_size - sizeof (struct GNUNET_RECLAIM_Ticket); | ||
779 | tr->attrs = | ||
780 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attr_data, attr_data_len); | ||
781 | GNUNET_CONTAINER_DLL_insert (iter->tickets_head, iter->tickets_tail, tr); | 650 | GNUNET_CONTAINER_DLL_insert (iter->tickets_head, iter->tickets_tail, tr); |
782 | } | 651 | } |
783 | run_ticket_iteration_round (iter); | 652 | run_ticket_iteration_round (iter); |
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.h b/src/reclaim/gnunet-service-reclaim_tickets.h index 43bb902fd..ab0947865 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.h +++ b/src/reclaim/gnunet-service-reclaim_tickets.h | |||
@@ -29,16 +29,18 @@ | |||
29 | #define GNUNET_SERVICE_RECLAIM_TICKETS_H | 29 | #define GNUNET_SERVICE_RECLAIM_TICKETS_H |
30 | 30 | ||
31 | #include "platform.h" | 31 | #include "platform.h" |
32 | |||
32 | #include "gnunet_util_lib.h" | 33 | #include "gnunet_util_lib.h" |
34 | |||
33 | #include "gnunet_constants.h" | 35 | #include "gnunet_constants.h" |
34 | #include "gnunet_protocols.h" | ||
35 | #include "gnunet_gnsrecord_lib.h" | ||
36 | #include "gnunet_gns_service.h" | 36 | #include "gnunet_gns_service.h" |
37 | #include "gnunet_gnsrecord_lib.h" | ||
37 | #include "gnunet_namestore_service.h" | 38 | #include "gnunet_namestore_service.h" |
38 | #include "gnunet_statistics_service.h" | 39 | #include "gnunet_protocols.h" |
39 | #include "gnunet_reclaim_plugin.h" | ||
40 | #include "gnunet_reclaim_attribute_lib.h" | 40 | #include "gnunet_reclaim_attribute_lib.h" |
41 | #include "gnunet_reclaim_plugin.h" | ||
41 | #include "gnunet_signatures.h" | 42 | #include "gnunet_signatures.h" |
43 | #include "gnunet_statistics_service.h" | ||
42 | #include "reclaim.h" | 44 | #include "reclaim.h" |
43 | 45 | ||
44 | struct RECLAIM_TICKETS_Iterator; | 46 | struct RECLAIM_TICKETS_Iterator; |
@@ -50,9 +52,8 @@ struct RECLAIM_TICKETS_ConsumeHandle; | |||
50 | * @param cls closure | 52 | * @param cls closure |
51 | * @param ticket the ticket | 53 | * @param ticket the ticket |
52 | */ | 54 | */ |
53 | typedef void | 55 | typedef void (*RECLAIM_TICKETS_TicketIter) ( |
54 | (*RECLAIM_TICKETS_TicketIter) (void *cls, | 56 | void *cls, struct GNUNET_RECLAIM_Ticket *ticket); |
55 | struct GNUNET_RECLAIM_Ticket *ticket); | ||
56 | 57 | ||
57 | 58 | ||
58 | /** | 59 | /** |
@@ -60,57 +61,45 @@ typedef void | |||
60 | * | 61 | * |
61 | * @param cls closure | 62 | * @param cls closure |
62 | * @param ticket the ticket | 63 | * @param ticket the ticket |
63 | * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | 64 | * @param success #GNUNET_SYSERR on failure (including timeout/queue |
64 | * #GNUNET_OK on success | 65 | * drop/failure to validate) #GNUNET_OK on success |
65 | * @param emsg NULL on success, otherwise an error message | 66 | * @param emsg NULL on success, otherwise an error message |
66 | */ | 67 | */ |
67 | typedef void | 68 | typedef void (*RECLAIM_TICKETS_TicketResult) ( |
68 | (*RECLAIM_TICKETS_TicketResult) (void *cls, | 69 | void *cls, struct GNUNET_RECLAIM_Ticket *ticket, uint32_t success, |
69 | struct GNUNET_RECLAIM_Ticket *ticket, | 70 | const char *emsg); |
70 | uint32_t success, | ||
71 | const char *emsg); | ||
72 | 71 | ||
73 | 72 | ||
74 | typedef void | 73 | typedef void (*RECLAIM_TICKETS_ConsumeCallback) ( |
75 | (*RECLAIM_TICKETS_ConsumeCallback) (void *cls, | 74 | void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
76 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 75 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *l, uint32_t success, |
77 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *l, | 76 | const char *emsg); |
78 | uint32_t success, | ||
79 | const char *emsg); | ||
80 | 77 | ||
81 | struct RECLAIM_TICKETS_ConsumeHandle* | 78 | struct RECLAIM_TICKETS_ConsumeHandle * |
82 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | 79 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, |
83 | const struct GNUNET_RECLAIM_Ticket *ticket, | 80 | const struct GNUNET_RECLAIM_Ticket *ticket, |
84 | RECLAIM_TICKETS_ConsumeCallback cb, | 81 | RECLAIM_TICKETS_ConsumeCallback cb, void *cb_cls); |
85 | void* cb_cls); | ||
86 | 82 | ||
87 | void | 83 | void RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth); |
88 | RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth); | ||
89 | 84 | ||
90 | void | 85 | void RECLAIM_TICKETS_issue ( |
91 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 86 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
92 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 87 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
93 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | 88 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, |
94 | RECLAIM_TICKETS_TicketResult cb, | 89 | RECLAIM_TICKETS_TicketResult cb, void *cb_cls); |
95 | void* cb_cls); | ||
96 | 90 | ||
97 | void | 91 | void RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter); |
98 | RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter); | ||
99 | 92 | ||
100 | 93 | ||
101 | void | 94 | void RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter); |
102 | RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter); | ||
103 | 95 | ||
104 | 96 | ||
105 | struct RECLAIM_TICKETS_Iterator* | 97 | struct RECLAIM_TICKETS_Iterator *RECLAIM_TICKETS_iteration_start ( |
106 | RECLAIM_TICKETS_iteration_start (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 98 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
107 | RECLAIM_TICKETS_TicketIter cb, | 99 | RECLAIM_TICKETS_TicketIter cb, void *cb_cls); |
108 | void* cb_cls); | ||
109 | 100 | ||
110 | 101 | ||
111 | int | 102 | int RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c); |
112 | RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c); | ||
113 | 103 | ||
114 | void | 104 | void RECLAIM_TICKETS_deinit (void); |
115 | RECLAIM_TICKETS_deinit (void); | ||
116 | #endif | 105 | #endif |
diff --git a/src/reclaim/plugin_gnsrecord_reclaim.c b/src/reclaim/plugin_gnsrecord_reclaim.c index 2f075d8b9..612fec3bd 100644 --- a/src/reclaim/plugin_gnsrecord_reclaim.c +++ b/src/reclaim/plugin_gnsrecord_reclaim.c | |||
@@ -24,11 +24,12 @@ | |||
24 | * @author Martin Schanzenbach | 24 | * @author Martin Schanzenbach |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | |||
27 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | |||
28 | #include "gnunet_gnsrecord_lib.h" | 30 | #include "gnunet_gnsrecord_lib.h" |
29 | #include "gnunet_gnsrecord_plugin.h" | 31 | #include "gnunet_gnsrecord_plugin.h" |
30 | 32 | ||
31 | |||
32 | /** | 33 | /** |
33 | * Convert the 'value' of a record to a string. | 34 | * Convert the 'value' of a record to a string. |
34 | * | 35 | * |
@@ -38,25 +39,21 @@ | |||
38 | * @param data_size number of bytes in @a data | 39 | * @param data_size number of bytes in @a data |
39 | * @return NULL on error, otherwise human-readable representation of the value | 40 | * @return NULL on error, otherwise human-readable representation of the value |
40 | */ | 41 | */ |
41 | static char * | 42 | static char *value_to_string (void *cls, uint32_t type, const void *data, |
42 | value_to_string (void *cls, | 43 | size_t data_size) |
43 | uint32_t type, | ||
44 | const void *data, | ||
45 | size_t data_size) | ||
46 | { | 44 | { |
47 | switch (type) | 45 | switch (type) { |
48 | { | 46 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: |
49 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: | 47 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); |
50 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); | 48 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: |
51 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: | 49 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: |
52 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: | 50 | return GNUNET_strndup (data, data_size); |
53 | return GNUNET_strndup (data, data_size); | 51 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: |
54 | case GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ: | 52 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF: |
55 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF: | 53 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: |
56 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: | 54 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); |
57 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); | 55 | default: |
58 | default: | 56 | return NULL; |
59 | return NULL; | ||
60 | } | 57 | } |
61 | } | 58 | } |
62 | 59 | ||
@@ -72,36 +69,25 @@ value_to_string (void *cls, | |||
72 | * @param data_size set to number of bytes in @a data | 69 | * @param data_size set to number of bytes in @a data |
73 | * @return #GNUNET_OK on success | 70 | * @return #GNUNET_OK on success |
74 | */ | 71 | */ |
75 | static int | 72 | static int string_to_value (void *cls, uint32_t type, const char *s, |
76 | string_to_value (void *cls, | 73 | void **data, size_t *data_size) |
77 | uint32_t type, | ||
78 | const char *s, | ||
79 | void **data, | ||
80 | size_t *data_size) | ||
81 | { | 74 | { |
82 | if (NULL == s) | 75 | if (NULL == s) |
83 | return GNUNET_SYSERR; | 76 | return GNUNET_SYSERR; |
84 | switch (type) | 77 | switch (type) { |
85 | { | 78 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: |
86 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: | 79 | return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); |
87 | return GNUNET_STRINGS_string_to_data (s, | 80 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: |
88 | strlen (s), | 81 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: |
89 | *data, | 82 | *data = GNUNET_strdup (s); |
90 | *data_size); | 83 | *data_size = strlen (s); |
91 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: | 84 | return GNUNET_OK; |
92 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: | 85 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: |
93 | *data = GNUNET_strdup (s); | 86 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: |
94 | *data_size = strlen (s); | 87 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF: |
95 | return GNUNET_OK; | 88 | return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); |
96 | case GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ: | 89 | default: |
97 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: | 90 | return GNUNET_SYSERR; |
98 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF: | ||
99 | return GNUNET_STRINGS_string_to_data (s, | ||
100 | strlen (s), | ||
101 | *data, | ||
102 | *data_size); | ||
103 | default: | ||
104 | return GNUNET_SYSERR; | ||
105 | } | 91 | } |
106 | } | 92 | } |
107 | 93 | ||
@@ -114,14 +100,13 @@ static struct { | |||
114 | const char *name; | 100 | const char *name; |
115 | uint32_t number; | 101 | uint32_t number; |
116 | } name_map[] = { | 102 | } name_map[] = { |
117 | { "RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR }, | 103 | {"RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR}, |
118 | { "RECLAIM_AUTHZ", GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ }, | 104 | {"RECLAIM_ATTR_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF}, |
119 | { "RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER }, | 105 | {"RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER}, |
120 | { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT }, | 106 | {"RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT}, |
121 | { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT }, | 107 | {"RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT}, |
122 | { "RECLAIM_TICKETREF", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF }, | 108 | {"RECLAIM_TICKETREF", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF}, |
123 | { NULL, UINT32_MAX } | 109 | {NULL, UINT32_MAX}}; |
124 | }; | ||
125 | 110 | ||
126 | 111 | ||
127 | /** | 112 | /** |
@@ -131,15 +116,13 @@ static struct { | |||
131 | * @param dns_typename name to convert | 116 | * @param dns_typename name to convert |
132 | * @return corresponding number, UINT32_MAX on error | 117 | * @return corresponding number, UINT32_MAX on error |
133 | */ | 118 | */ |
134 | static uint32_t | 119 | static uint32_t typename_to_number (void *cls, const char *dns_typename) |
135 | typename_to_number (void *cls, | ||
136 | const char *dns_typename) | ||
137 | { | 120 | { |
138 | unsigned int i; | 121 | unsigned int i; |
139 | 122 | ||
140 | i=0; | 123 | i = 0; |
141 | while ( (NULL != name_map[i].name) && | 124 | while ((NULL != name_map[i].name) && |
142 | (0 != strcasecmp (dns_typename, name_map[i].name)) ) | 125 | (0 != strcasecmp (dns_typename, name_map[i].name))) |
143 | i++; | 126 | i++; |
144 | return name_map[i].number; | 127 | return name_map[i].number; |
145 | } | 128 | } |
@@ -152,15 +135,12 @@ typename_to_number (void *cls, | |||
152 | * @param type number of a type to convert | 135 | * @param type number of a type to convert |
153 | * @return corresponding typestring, NULL on error | 136 | * @return corresponding typestring, NULL on error |
154 | */ | 137 | */ |
155 | static const char * | 138 | static const char *number_to_typename (void *cls, uint32_t type) |
156 | number_to_typename (void *cls, | ||
157 | uint32_t type) | ||
158 | { | 139 | { |
159 | unsigned int i; | 140 | unsigned int i; |
160 | 141 | ||
161 | i=0; | 142 | i = 0; |
162 | while ( (NULL != name_map[i].name) && | 143 | while ((NULL != name_map[i].name) && (type != name_map[i].number)) |
163 | (type != name_map[i].number) ) | ||
164 | i++; | 144 | i++; |
165 | return name_map[i].name; | 145 | return name_map[i].name; |
166 | } | 146 | } |
@@ -172,8 +152,7 @@ number_to_typename (void *cls, | |||
172 | * @param cls NULL | 152 | * @param cls NULL |
173 | * @return the exported block API | 153 | * @return the exported block API |
174 | */ | 154 | */ |
175 | void * | 155 | void *libgnunet_plugin_gnsrecord_reclaim_init (void *cls) |
176 | libgnunet_plugin_gnsrecord_reclaim_init (void *cls) | ||
177 | { | 156 | { |
178 | struct GNUNET_GNSRECORD_PluginFunctions *api; | 157 | struct GNUNET_GNSRECORD_PluginFunctions *api; |
179 | 158 | ||
@@ -192,8 +171,7 @@ libgnunet_plugin_gnsrecord_reclaim_init (void *cls) | |||
192 | * @param cls the return value from #libgnunet_plugin_block_test_init | 171 | * @param cls the return value from #libgnunet_plugin_block_test_init |
193 | * @return NULL | 172 | * @return NULL |
194 | */ | 173 | */ |
195 | void * | 174 | void *libgnunet_plugin_gnsrecord_reclaim_done (void *cls) |
196 | libgnunet_plugin_gnsrecord_reclaim_done (void *cls) | ||
197 | { | 175 | { |
198 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; | 176 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; |
199 | 177 | ||