diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-10-13 16:31:17 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:02 +0100 |
commit | 2c65283b0bd97a8719f4c71aee8cc091a491129a (patch) | |
tree | 61f1644f36c111342edbd1d19dfd3212b659da04 /src/reclaim/plugin_rest_reclaim.c | |
parent | d5178cdc05a0d91293d9ee2cef45ab9a1c515bac (diff) | |
download | gnunet-2c65283b0bd97a8719f4c71aee8cc091a491129a.tar.gz gnunet-2c65283b0bd97a8719f4c71aee8cc091a491129a.zip |
Add Attestations via Reclaim Service
Diffstat (limited to 'src/reclaim/plugin_rest_reclaim.c')
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 342 |
1 files changed, 11 insertions, 331 deletions
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index bb08e6385..9290925b8 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -242,210 +242,6 @@ 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 for attribute deletion request | ||
302 | */ | ||
303 | struct AttributeDeleteHandle | ||
304 | { | ||
305 | /** | ||
306 | * DLL | ||
307 | */ | ||
308 | struct AttributeDeleteHandle *next; | ||
309 | |||
310 | /** | ||
311 | * DLL | ||
312 | */ | ||
313 | struct AttributeDeleteHandle *prev; | ||
314 | |||
315 | /** | ||
316 | * Client connection | ||
317 | */ | ||
318 | struct IdpClient *client; | ||
319 | |||
320 | /** | ||
321 | * Identity | ||
322 | */ | ||
323 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | ||
324 | |||
325 | |||
326 | /** | ||
327 | * QueueEntry | ||
328 | */ | ||
329 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; | ||
330 | |||
331 | /** | ||
332 | * Iterator | ||
333 | */ | ||
334 | struct GNUNET_NAMESTORE_ZoneIterator *ns_it; | ||
335 | |||
336 | /** | ||
337 | * The attribute to delete | ||
338 | */ | ||
339 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; | ||
340 | |||
341 | /** | ||
342 | * The attestation to store | ||
343 | */ | ||
344 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; | ||
345 | |||
346 | /** | ||
347 | * Tickets to update | ||
348 | */ | ||
349 | struct TicketRecordsEntry *tickets_to_update_head; | ||
350 | |||
351 | /** | ||
352 | * Tickets to update | ||
353 | */ | ||
354 | struct TicketRecordsEntry *tickets_to_update_tail; | ||
355 | |||
356 | /** | ||
357 | * Attribute label | ||
358 | */ | ||
359 | char *label; | ||
360 | |||
361 | /** | ||
362 | * request id | ||
363 | */ | ||
364 | uint32_t r_id; | ||
365 | }; | ||
366 | |||
367 | /** | ||
368 | * Handle to the service. | ||
369 | */ | ||
370 | struct GNUNET_RECLAIM_Handle | ||
371 | { | ||
372 | /** | ||
373 | * Configuration to use. | ||
374 | */ | ||
375 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
376 | |||
377 | /** | ||
378 | * Socket (if available). | ||
379 | */ | ||
380 | struct GNUNET_CLIENT_Connection *client; | ||
381 | |||
382 | /** | ||
383 | * Closure for 'cb'. | ||
384 | */ | ||
385 | void *cb_cls; | ||
386 | |||
387 | /** | ||
388 | * Head of active operations. | ||
389 | */ | ||
390 | struct GNUNET_RECLAIM_Operation *op_head; | ||
391 | |||
392 | /** | ||
393 | * Tail of active operations. | ||
394 | */ | ||
395 | struct GNUNET_RECLAIM_Operation *op_tail; | ||
396 | |||
397 | /** | ||
398 | * Head of active iterations | ||
399 | */ | ||
400 | struct GNUNET_RECLAIM_AttributeIterator *it_head; | ||
401 | |||
402 | /** | ||
403 | * Tail of active iterations | ||
404 | */ | ||
405 | struct GNUNET_RECLAIM_AttributeIterator *it_tail; | ||
406 | |||
407 | /** | ||
408 | * Head of active iterations | ||
409 | */ | ||
410 | struct GNUNET_RECLAIM_TicketIterator *ticket_it_head; | ||
411 | |||
412 | /** | ||
413 | * Tail of active iterations | ||
414 | */ | ||
415 | struct GNUNET_RECLAIM_TicketIterator *ticket_it_tail; | ||
416 | |||
417 | /** | ||
418 | * Currently pending transmission request, or NULL for none. | ||
419 | */ | ||
420 | struct GNUNET_CLIENT_TransmitHandle *th; | ||
421 | |||
422 | /** | ||
423 | * Task doing exponential back-off trying to reconnect. | ||
424 | */ | ||
425 | struct GNUNET_SCHEDULER_Task *reconnect_task; | ||
426 | |||
427 | /** | ||
428 | * Time for next connect retry. | ||
429 | */ | ||
430 | struct GNUNET_TIME_Relative reconnect_backoff; | ||
431 | |||
432 | /** | ||
433 | * Connection to service (if available). | ||
434 | */ | ||
435 | struct GNUNET_MQ_Handle *mq; | ||
436 | |||
437 | /** | ||
438 | * Request Id generator. Incremented by one for each request. | ||
439 | */ | ||
440 | uint32_t r_id_gen; | ||
441 | |||
442 | /** | ||
443 | * Are we polling for incoming messages right now? | ||
444 | */ | ||
445 | int in_receive; | ||
446 | }; | ||
447 | |||
448 | /** | ||
449 | * Cleanup lookup handle | 245 | * Cleanup lookup handle |
450 | * @param handle Handle to clean up | 246 | * @param handle Handle to clean up |
451 | */ | 247 | */ |
@@ -656,6 +452,8 @@ ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
656 | GNUNET_free (tmp); | 452 | GNUNET_free (tmp); |
657 | GNUNET_RECLAIM_ticket_iteration_next (handle->ticket_it); | 453 | GNUNET_RECLAIM_ticket_iteration_next (handle->ticket_it); |
658 | } | 454 | } |
455 | |||
456 | |||
659 | static void | 457 | static void |
660 | add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | 458 | add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, |
661 | const char *url, | 459 | const char *url, |
@@ -729,58 +527,12 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
729 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | 527 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); |
730 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 528 | handle->idp = GNUNET_RECLAIM_connect (cfg); |
731 | exp = GNUNET_TIME_UNIT_HOURS; | 529 | exp = GNUNET_TIME_UNIT_HOURS; |
732 | /*New */ | 530 | handle->idp_op = GNUNET_RECLAIM_attestation_store (handle->idp, |
733 | struct GNUNET_RECLAIM_Handle *h = handle->idp; | 531 | identity_priv, |
734 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey = identity_priv; | 532 | attribute, |
735 | /*struct GNUNET_RECLAIM_ATTESTATION_Claim *attr = attribute;*/ | 533 | &exp, |
736 | struct GNUNET_TIME_Relative *exp_interval = &exp; | 534 | &finished_cont, |
737 | /*GNUNET_RECLAIM_ContinuationWithStatus cont = &finished_cont;*/ | 535 | handle); |
738 | void *cont_cls = handle; | ||
739 | |||
740 | struct AttributeStoreHandle *ash; | ||
741 | struct GNUNET_GNSRECORD_Data rd[1]; | ||
742 | char *buf; | ||
743 | char *label; | ||
744 | size_t buf_size; | ||
745 | struct IdpClient *idp = cont_cls; | ||
746 | struct GNUNET_NAMESTORE_Handle *nsh; | ||
747 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
748 | if (NULL == nsh) | ||
749 | { | ||
750 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
751 | "error connecting to namestore"); | ||
752 | } | ||
753 | ash = GNUNET_new (struct AttributeStoreHandle); | ||
754 | ash->identity = *pkey; | ||
755 | ash->r_id = h->r_id_gen++; | ||
756 | ash->exp.rel_value_us = exp_interval->rel_value_us; | ||
757 | ash->attest = attribute; | ||
758 | ash->client = idp; | ||
759 | buf_size = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (ash->attest); | ||
760 | buf = GNUNET_malloc (buf_size); | ||
761 | // Give the ash a new id if unset | ||
762 | if (0 == ash->attest->id) | ||
763 | ash->attest->id | ||
764 | = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | ||
765 | GNUNET_RECLAIM_ATTESTATION_serialize (ash->attest, buf); | ||
766 | label = GNUNET_STRINGS_data_to_string_alloc (&ash->attest->id, | ||
767 | sizeof(uint64_t)); | ||
768 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); | ||
769 | |||
770 | rd[0].data_size = buf_size; | ||
771 | rd[0].data = buf; | ||
772 | rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR; | ||
773 | rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
774 | rd[0].expiration_time = ash->exp.rel_value_us; | ||
775 | ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | ||
776 | &ash->identity, | ||
777 | label, | ||
778 | 1, | ||
779 | rd, | ||
780 | &finished_cont, | ||
781 | ash); | ||
782 | GNUNET_free (buf); | ||
783 | GNUNET_free (label); | ||
784 | GNUNET_JSON_parse_free (attrspec); | 536 | GNUNET_JSON_parse_free (attrspec); |
785 | } | 537 | } |
786 | /*Placeholder*/ | 538 | /*Placeholder*/ |
@@ -800,81 +552,9 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
800 | const char *url, | 552 | const char *url, |
801 | void *cls) | 553 | void *cls) |
802 | { | 554 | { |
803 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 555 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting Attestations not supported\n"); |
804 | struct RequestHandle *handle = cls; | 556 | GNUNET_SCHEDULER_add_now (&do_error, cls); |
805 | struct GNUNET_RECLAIM_ATTESTATION_Claim attr; | 557 | return; |
806 | struct EgoEntry *ego_entry; | ||
807 | char *identity_id_str; | ||
808 | char *identity; | ||
809 | char *id; | ||
810 | |||
811 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attestation.\n"); | ||
812 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) >= strlen ( | ||
813 | handle->url)) | ||
814 | { | ||
815 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | ||
816 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
817 | return; | ||
818 | } | ||
819 | identity_id_str = | ||
820 | strdup (handle->url + strlen ( | ||
821 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + 1); | ||
822 | identity = strtok (identity_id_str, "/"); | ||
823 | id = strtok (NULL, "/"); | ||
824 | if ((NULL == identity) || (NULL == id)) | ||
825 | { | ||
826 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n"); | ||
827 | GNUNET_free (identity_id_str); | ||
828 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
829 | return; | ||
830 | } | ||
831 | |||
832 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
833 | ego_entry = ego_entry->next) | ||
834 | if (0 == strcmp (identity, ego_entry->identifier)) | ||
835 | break; | ||
836 | handle->resp_object = json_array (); | ||
837 | if (NULL == ego_entry) | ||
838 | { | ||
839 | // Done | ||
840 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); | ||
841 | GNUNET_free (identity_id_str); | ||
842 | GNUNET_SCHEDULER_add_now (&return_response, handle); | ||
843 | return; | ||
844 | } | ||
845 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | ||
846 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
847 | memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_ATTESTATION_Claim)); | ||
848 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(uint64_t)); | ||
849 | attr.name = ""; | ||
850 | |||
851 | struct GNUNET_RECLAIM_Handle *h = handle->idp; | ||
852 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey = priv_key; | ||
853 | |||
854 | struct AttributeDeleteHandle *adh; | ||
855 | struct IdpClient *idp = handle; | ||
856 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_DELETE message\n"); | ||
857 | struct GNUNET_NAMESTORE_Handle *nsh; | ||
858 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
859 | adh = GNUNET_new (struct AttributeDeleteHandle); | ||
860 | adh->attest = &attr; | ||
861 | adh->r_id = h->r_id_gen++; | ||
862 | adh->identity = *pkey; | ||
863 | adh->label = GNUNET_STRINGS_data_to_string_alloc (&adh->attest->id, | ||
864 | sizeof(uint64_t)); | ||
865 | /*GNUNET_SERVICE_client_continue (idp->client);*/ | ||
866 | adh->client = idp; | ||
867 | /*GNUNET_CONTAINER_DLL_insert (idp->delete_op_head, idp->delete_op_tail, adh);*/ | ||
868 | adh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | ||
869 | &adh->identity, | ||
870 | adh->label, | ||
871 | 0, | ||
872 | NULL, | ||
873 | &delete_finished_cb, | ||
874 | adh); | ||
875 | |||
876 | |||
877 | GNUNET_free (identity_id_str); | ||
878 | } | 558 | } |
879 | 559 | ||
880 | /** | 560 | /** |