diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-10-12 14:47:51 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:01 +0100 |
commit | edd1533118eccaa14eaa157d6ca8d29b8d691404 (patch) | |
tree | eab044e3119338fb6b42f6644b729a247b4a15f7 /src | |
parent | f3c86065146ad989b6fdf2532147ebfc1a833935 (diff) | |
download | gnunet-edd1533118eccaa14eaa157d6ca8d29b8d691404.tar.gz gnunet-edd1533118eccaa14eaa157d6ca8d29b8d691404.zip |
Fixed direct Namestore Access
Diffstat (limited to 'src')
-rw-r--r-- | src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c | 9 | ||||
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 265 |
2 files changed, 266 insertions, 8 deletions
diff --git a/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c b/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c index 212425a6f..ade2a27bb 100644 --- a/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c +++ b/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c | |||
@@ -160,15 +160,14 @@ static struct | |||
160 | { NULL, UINT32_MAX } }; | 160 | { NULL, UINT32_MAX } }; |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * Mapping of attribute type numbers to human-readable | 163 | * Mapping of attestation type numbers to human-readable |
164 | * attribute type names. | 164 | * attestation type names. |
165 | */ | 165 | */ |
166 | static struct | 166 | static struct |
167 | { | 167 | { |
168 | const char *name; | 168 | const char *name; |
169 | uint32_t number; | 169 | uint32_t number; |
170 | } gnuid_attest_name_map[] = { { "STRING", | 170 | } gnuid_attest_name_map[] = { { "JWT", GNUNET_RECLAIM_ATTESTATION_TYPE_JWT }, |
171 | GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING }, | ||
172 | { NULL, UINT32_MAX } }; | 171 | { NULL, UINT32_MAX } }; |
173 | 172 | ||
174 | /** | 173 | /** |
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index c719f95fd..b42394906 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -242,6 +242,143 @@ struct RequestHandle | |||
242 | }; | 242 | }; |
243 | 243 | ||
244 | /** | 244 | /** |
245 | * Handle for attribute store request | ||
246 | */ | ||
247 | struct AttributeStoreHandle | ||
248 | { | ||
249 | /** | ||
250 | * DLL | ||
251 | */ | ||
252 | struct AttributeStoreHandle *next; | ||
253 | |||
254 | /** | ||
255 | * DLL | ||
256 | */ | ||
257 | struct AttributeStoreHandle *prev; | ||
258 | |||
259 | /** | ||
260 | * Client connection | ||
261 | */ | ||
262 | struct IdpClient *client; | ||
263 | |||
264 | /** | ||
265 | * Identity | ||
266 | */ | ||
267 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | ||
268 | |||
269 | /** | ||
270 | * Identity pubkey | ||
271 | */ | ||
272 | struct GNUNET_CRYPTO_EcdsaPublicKey identity_pkey; | ||
273 | |||
274 | /** | ||
275 | * QueueEntry | ||
276 | */ | ||
277 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; | ||
278 | |||
279 | /** | ||
280 | * The attribute to store | ||
281 | */ | ||
282 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; | ||
283 | |||
284 | /** | ||
285 | * The attestation to store | ||
286 | */ | ||
287 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; | ||
288 | |||
289 | /** | ||
290 | * The attribute expiration interval | ||
291 | */ | ||
292 | struct GNUNET_TIME_Relative exp; | ||
293 | |||
294 | /** | ||
295 | * request id | ||
296 | */ | ||
297 | uint32_t r_id; | ||
298 | }; | ||
299 | |||
300 | /** | ||
301 | * Handle to the service. | ||
302 | */ | ||
303 | struct GNUNET_RECLAIM_Handle | ||
304 | { | ||
305 | /** | ||
306 | * Configuration to use. | ||
307 | */ | ||
308 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
309 | |||
310 | /** | ||
311 | * Socket (if available). | ||
312 | */ | ||
313 | struct GNUNET_CLIENT_Connection *client; | ||
314 | |||
315 | /** | ||
316 | * Closure for 'cb'. | ||
317 | */ | ||
318 | void *cb_cls; | ||
319 | |||
320 | /** | ||
321 | * Head of active operations. | ||
322 | */ | ||
323 | struct GNUNET_RECLAIM_Operation *op_head; | ||
324 | |||
325 | /** | ||
326 | * Tail of active operations. | ||
327 | */ | ||
328 | struct GNUNET_RECLAIM_Operation *op_tail; | ||
329 | |||
330 | /** | ||
331 | * Head of active iterations | ||
332 | */ | ||
333 | struct GNUNET_RECLAIM_AttributeIterator *it_head; | ||
334 | |||
335 | /** | ||
336 | * Tail of active iterations | ||
337 | */ | ||
338 | struct GNUNET_RECLAIM_AttributeIterator *it_tail; | ||
339 | |||
340 | /** | ||
341 | * Head of active iterations | ||
342 | */ | ||
343 | struct GNUNET_RECLAIM_TicketIterator *ticket_it_head; | ||
344 | |||
345 | /** | ||
346 | * Tail of active iterations | ||
347 | */ | ||
348 | struct GNUNET_RECLAIM_TicketIterator *ticket_it_tail; | ||
349 | |||
350 | /** | ||
351 | * Currently pending transmission request, or NULL for none. | ||
352 | */ | ||
353 | struct GNUNET_CLIENT_TransmitHandle *th; | ||
354 | |||
355 | /** | ||
356 | * Task doing exponential back-off trying to reconnect. | ||
357 | */ | ||
358 | struct GNUNET_SCHEDULER_Task *reconnect_task; | ||
359 | |||
360 | /** | ||
361 | * Time for next connect retry. | ||
362 | */ | ||
363 | struct GNUNET_TIME_Relative reconnect_backoff; | ||
364 | |||
365 | /** | ||
366 | * Connection to service (if available). | ||
367 | */ | ||
368 | struct GNUNET_MQ_Handle *mq; | ||
369 | |||
370 | /** | ||
371 | * Request Id generator. Incremented by one for each request. | ||
372 | */ | ||
373 | uint32_t r_id_gen; | ||
374 | |||
375 | /** | ||
376 | * Are we polling for incoming messages right now? | ||
377 | */ | ||
378 | int in_receive; | ||
379 | }; | ||
380 | |||
381 | /** | ||
245 | * Cleanup lookup handle | 382 | * Cleanup lookup handle |
246 | * @param handle Handle to clean up | 383 | * @param handle Handle to clean up |
247 | */ | 384 | */ |
@@ -442,9 +579,131 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
442 | const char *url, | 579 | const char *url, |
443 | void *cls) | 580 | void *cls) |
444 | { | 581 | { |
445 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding Attestations not supported\n"); | 582 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; |
446 | GNUNET_SCHEDULER_add_now (&do_error, cls); | 583 | const char *identity; |
447 | return; | 584 | struct RequestHandle *handle = cls; |
585 | struct EgoEntry *ego_entry; | ||
586 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attribute; | ||
587 | struct GNUNET_TIME_Relative exp; | ||
588 | char term_data[handle->rest_handle->data_size + 1]; | ||
589 | json_t *data_json; | ||
590 | json_error_t err; | ||
591 | struct GNUNET_JSON_Specification attrspec[] = | ||
592 | { GNUNET_RECLAIM_JSON_spec_claim_attest (&attribute), | ||
593 | GNUNET_JSON_spec_end () }; | ||
594 | |||
595 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
596 | "Adding an attestation for %s.\n", | ||
597 | handle->url); | ||
598 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) >= strlen ( | ||
599 | handle->url)) | ||
600 | { | ||
601 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | ||
602 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
603 | return; | ||
604 | } | ||
605 | identity = handle->url + strlen ( | ||
606 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + 1; | ||
607 | |||
608 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
609 | ego_entry = ego_entry->next) | ||
610 | if (0 == strcmp (identity, ego_entry->identifier)) | ||
611 | break; | ||
612 | |||
613 | if (NULL == ego_entry) | ||
614 | { | ||
615 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity); | ||
616 | return; | ||
617 | } | ||
618 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | ||
619 | |||
620 | if (0 >= handle->rest_handle->data_size) | ||
621 | { | ||
622 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
623 | return; | ||
624 | } | ||
625 | |||
626 | term_data[handle->rest_handle->data_size] = '\0'; | ||
627 | GNUNET_memcpy (term_data, | ||
628 | handle->rest_handle->data, | ||
629 | handle->rest_handle->data_size); | ||
630 | data_json = json_loads (term_data, JSON_DECODE_ANY, &err); | ||
631 | GNUNET_assert (GNUNET_OK == | ||
632 | GNUNET_JSON_parse (data_json, attrspec, NULL, NULL)); | ||
633 | json_decref (data_json); | ||
634 | if (NULL == attribute) | ||
635 | { | ||
636 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
637 | "Unable to parse attestation from %s\n", | ||
638 | term_data); | ||
639 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
640 | return; | ||
641 | } | ||
642 | /** | ||
643 | * New ID for attribute | ||
644 | */ | ||
645 | if (0 == attribute->id) | ||
646 | attribute->id = | ||
647 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | ||
648 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
649 | exp = GNUNET_TIME_UNIT_HOURS; | ||
650 | /*New */ | ||
651 | struct GNUNET_RECLAIM_Handle *h = handle->idp; | ||
652 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey = identity_priv; | ||
653 | /*struct GNUNET_RECLAIM_ATTESTATION_Claim *attr = attribute;*/ | ||
654 | struct GNUNET_TIME_Relative *exp_interval = &exp; | ||
655 | /*GNUNET_RECLAIM_ContinuationWithStatus cont = &finished_cont;*/ | ||
656 | void *cont_cls = handle; | ||
657 | |||
658 | struct AttributeStoreHandle *ash; | ||
659 | struct GNUNET_GNSRECORD_Data rd[1]; | ||
660 | char *buf; | ||
661 | char *label; | ||
662 | size_t buf_size; | ||
663 | struct IdpClient *idp = cont_cls; | ||
664 | struct GNUNET_NAMESTORE_Handle *nsh; | ||
665 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
666 | if (NULL == nsh) | ||
667 | { | ||
668 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
669 | "error connecting to namestore"); | ||
670 | } | ||
671 | ash = GNUNET_new (struct AttributeStoreHandle); | ||
672 | ash->identity = *pkey; | ||
673 | ash->r_id = h->r_id_gen++; | ||
674 | ash->exp.rel_value_us = exp_interval->rel_value_us; | ||
675 | ash->attest = attribute; | ||
676 | ash->client = idp; | ||
677 | /*GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Type:%u\n", type); | ||
678 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ID:%s\n", id_str); | ||
679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Size:%u\n", data_size); | ||
680 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data:%s\n", data);*/ | ||
681 | buf_size = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (ash->attest); | ||
682 | buf = GNUNET_malloc (buf_size); | ||
683 | // Give the ash a new id if unset | ||
684 | if (0 == ash->attest->id) | ||
685 | ash->attest->id | ||
686 | = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | ||
687 | GNUNET_RECLAIM_ATTESTATION_serialize (ash->attest, buf); | ||
688 | label = GNUNET_STRINGS_data_to_string_alloc (&ash->attest->id, | ||
689 | sizeof(uint64_t)); | ||
690 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); | ||
691 | |||
692 | rd[0].data_size = buf_size; | ||
693 | rd[0].data = buf; | ||
694 | rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR; | ||
695 | rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
696 | rd[0].expiration_time = ash->exp.rel_value_us; | ||
697 | ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | ||
698 | &ash->identity, | ||
699 | label, | ||
700 | 1, | ||
701 | rd, | ||
702 | &finished_cont, | ||
703 | ash); | ||
704 | GNUNET_free (buf); | ||
705 | GNUNET_free (label); | ||
706 | GNUNET_JSON_parse_free (attrspec); | ||
448 | } | 707 | } |
449 | /*Placeholder*/ | 708 | /*Placeholder*/ |
450 | static void | 709 | static void |