2 This file is part of GNUnet.
3 Copyright (C) 2016 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public Liceidentity as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public Liceidentity for more details.
15 You should have received a copy of the GNU General Public Liceidentity
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file identity-provider/identity_provider_api.c
23 * @brief api to interact with the identity provider service
24 * @author Martin Schanzenbach
27 #include "gnunet_util_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_mq_lib.h"
31 #include "gnunet_identity_provider_service.h"
32 #include "gnunet_identity_attribute_lib.h"
33 #include "identity_provider.h"
35 #define LOG(kind,...) GNUNET_log_from (kind, "identity-api",__VA_ARGS__)
39 * Handle for an operation with the service.
41 struct GNUNET_IDENTITY_PROVIDER_Operation
47 struct GNUNET_IDENTITY_PROVIDER_Handle *h;
50 * We keep operations in a DLL.
52 struct GNUNET_IDENTITY_PROVIDER_Operation *next;
55 * We keep operations in a DLL.
57 struct GNUNET_IDENTITY_PROVIDER_Operation *prev;
60 * Message to send to the service.
61 * Allocated at the end of this struct.
63 const struct GNUNET_MessageHeader *msg;
66 * Continuation to invoke after attribute store call
68 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus as_cb;
71 * Attribute result callback
73 GNUNET_IDENTITY_PROVIDER_AttributeResult ar_cb;
76 * Revocation result callback
78 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus rvk_cb;
81 * Ticket result callback
83 GNUNET_IDENTITY_PROVIDER_TicketCallback tr_cb;
86 * Envelope with the message for this queue entry.
88 struct GNUNET_MQ_Envelope *env;
96 * Closure for @e cont or @e cb.
103 * Handle for a ticket iterator operation
105 struct GNUNET_IDENTITY_PROVIDER_TicketIterator
111 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *next;
116 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *prev;
119 * Main handle to access the idp.
121 struct GNUNET_IDENTITY_PROVIDER_Handle *h;
124 * Function to call on completion.
126 GNUNET_SCHEDULER_TaskCallback finish_cb;
129 * Closure for @e error_cb.
134 * The continuation to call with the results
136 GNUNET_IDENTITY_PROVIDER_TicketCallback tr_cb;
139 * Closure for @e tr_cb.
144 * Function to call on errors.
146 GNUNET_SCHEDULER_TaskCallback error_cb;
149 * Closure for @e error_cb.
154 * Envelope of the message to send to the service, if not yet
157 struct GNUNET_MQ_Envelope *env;
160 * The operation id this zone iteration operation has
168 * Handle for a attribute iterator operation
170 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator
176 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *next;
181 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *prev;
184 * Main handle to access the idp.
186 struct GNUNET_IDENTITY_PROVIDER_Handle *h;
189 * Function to call on completion.
191 GNUNET_SCHEDULER_TaskCallback finish_cb;
194 * Closure for @e error_cb.
199 * The continuation to call with the results
201 GNUNET_IDENTITY_PROVIDER_AttributeResult proc;
204 * Closure for @e proc.
209 * Function to call on errors.
211 GNUNET_SCHEDULER_TaskCallback error_cb;
214 * Closure for @e error_cb.
219 * Envelope of the message to send to the service, if not yet
222 struct GNUNET_MQ_Envelope *env;
225 * Private key of the zone.
227 struct GNUNET_CRYPTO_EcdsaPrivateKey identity;
230 * The operation id this zone iteration operation has
238 * Handle for the service.
240 struct GNUNET_IDENTITY_PROVIDER_Handle
243 * Configuration to use.
245 const struct GNUNET_CONFIGURATION_Handle *cfg;
248 * Socket (if available).
250 struct GNUNET_CLIENT_Connection *client;
258 * Head of active operations.
260 struct GNUNET_IDENTITY_PROVIDER_Operation *op_head;
263 * Tail of active operations.
265 struct GNUNET_IDENTITY_PROVIDER_Operation *op_tail;
268 * Head of active iterations
270 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it_head;
273 * Tail of active iterations
275 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it_tail;
278 * Head of active iterations
280 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *ticket_it_head;
283 * Tail of active iterations
285 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *ticket_it_tail;
289 * Currently pending transmission request, or NULL for none.
291 struct GNUNET_CLIENT_TransmitHandle *th;
294 * Task doing exponential back-off trying to reconnect.
296 struct GNUNET_SCHEDULER_Task * reconnect_task;
299 * Time for next connect retry.
301 struct GNUNET_TIME_Relative reconnect_backoff;
304 * Connection to service (if available).
306 struct GNUNET_MQ_Handle *mq;
309 * Request Id generator. Incremented by one for each request.
314 * Are we polling for incoming messages right now?
321 * Try again to connect to the service.
323 * @param h handle to the identity provider service.
326 reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h);
331 * @param cls the handle
334 reconnect_task (void *cls)
336 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls;
338 handle->reconnect_task = NULL;
344 * Disconnect from service and then reconnect.
346 * @param handle our service
349 force_reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *handle)
351 GNUNET_MQ_destroy (handle->mq);
353 handle->reconnect_backoff
354 = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
355 handle->reconnect_task
356 = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
364 * @param it entry to free
367 free_it (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it)
369 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h;
371 GNUNET_CONTAINER_DLL_remove (h->it_head,
375 GNUNET_MQ_discard (it->env);
380 free_op (struct GNUNET_IDENTITY_PROVIDER_Operation* op)
385 GNUNET_MQ_discard (op->env);
391 * Generic error handler, called with the appropriate error code and
392 * the same closure specified at the creation of the message queue.
393 * Not every message queue implementation supports an error handler.
395 * @param cls closure with the `struct GNUNET_GNS_Handle *`
396 * @param error error code
399 mq_error_handler (void *cls,
400 enum GNUNET_MQ_Error error)
402 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls;
403 force_reconnect (handle);
407 * Handle an incoming message of type
408 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
411 * @param msg the message we received
414 handle_attribute_store_response (void *cls,
415 const struct AttributeStoreResultMessage *msg)
417 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
418 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
419 uint32_t r_id = ntohl (msg->id);
423 for (op = h->op_head; NULL != op; op = op->next)
424 if (op->r_id == r_id)
429 res = ntohl (msg->op_result);
430 LOG (GNUNET_ERROR_TYPE_DEBUG,
431 "Received ATTRIBUTE_STORE_RESPONSE with result %d\n",
434 /* TODO: add actual error message to response... */
435 if (GNUNET_SYSERR == res)
436 emsg = _("failed to store record\n");
439 if (NULL != op->as_cb)
443 GNUNET_CONTAINER_DLL_remove (h->op_head,
452 * Handle an incoming message of type
453 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT
456 * @param msg the message we received
457 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
460 check_consume_ticket_result (void *cls,
461 const struct ConsumeTicketResultMessage *msg)
466 msg_len = ntohs (msg->header.size);
467 attrs_len = ntohs (msg->attrs_len);
468 if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len)
471 return GNUNET_SYSERR;
478 * Handle an incoming message of type
479 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT
482 * @param msg the message we received
485 handle_consume_ticket_result (void *cls,
486 const struct ConsumeTicketResultMessage *msg)
488 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
489 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
491 uint32_t r_id = ntohl (msg->id);
493 attrs_len = ntohs (msg->attrs_len);
494 LOG (GNUNET_ERROR_TYPE_DEBUG,
495 "Processing attribute result.\n");
498 for (op = h->op_head; NULL != op; op = op->next)
499 if (op->r_id == r_id)
505 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs;
506 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le;
507 attrs = GNUNET_IDENTITY_ATTRIBUTE_list_deserialize ((char*)&msg[1],
509 if (NULL != op->ar_cb)
519 for (le = attrs->list_head; NULL != le; le = le->next)
523 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (attrs);
531 GNUNET_CONTAINER_DLL_remove (h->op_head,
543 * Handle an incoming message of type
544 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT
547 * @param msg the message we received
548 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
551 check_attribute_result (void *cls,
552 const struct AttributeResultMessage *msg)
557 msg_len = ntohs (msg->header.size);
558 attr_len = ntohs (msg->attr_len);
559 if (msg_len != sizeof (struct AttributeResultMessage) + attr_len)
562 return GNUNET_SYSERR;
569 * Handle an incoming message of type
570 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT
573 * @param msg the message we received
576 handle_attribute_result (void *cls,
577 const struct AttributeResultMessage *msg)
579 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
580 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
581 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it;
582 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
584 uint32_t r_id = ntohl (msg->id);
586 attr_len = ntohs (msg->attr_len);
587 LOG (GNUNET_ERROR_TYPE_DEBUG,
588 "Processing attribute result.\n");
591 for (it = h->it_head; NULL != it; it = it->next)
592 if (it->r_id == r_id)
594 for (op = h->op_head; NULL != op; op = op->next)
595 if (op->r_id == r_id)
597 if ((NULL == it) && (NULL == op))
600 if ( (0 == (memcmp (&msg->identity,
602 sizeof (identity_dummy)))) )
604 if ((NULL == it) && (NULL == op))
612 if (NULL != it->finish_cb)
613 it->finish_cb (it->finish_cb_cls);
618 if (NULL != op->ar_cb)
622 GNUNET_CONTAINER_DLL_remove (h->op_head,
632 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr;
633 attr = GNUNET_IDENTITY_ATTRIBUTE_deserialize ((char*)&msg[1],
637 if (NULL != it->proc)
638 it->proc (it->proc_cls,
641 } else if (NULL != op)
643 if (NULL != op->ar_cb)
656 * Handle an incoming message of type
657 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT
660 * @param msg the message we received
661 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
664 check_ticket_result (void *cls,
665 const struct TicketResultMessage *msg)
669 msg_len = ntohs (msg->header.size);
670 if (msg_len < sizeof (struct TicketResultMessage))
673 return GNUNET_SYSERR;
681 * Handle an incoming message of type
682 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT
685 * @param msg the message we received
688 handle_ticket_result (void *cls,
689 const struct TicketResultMessage *msg)
691 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls;
692 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
693 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it;
694 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket;
695 uint32_t r_id = ntohl (msg->id);
698 for (op = handle->op_head; NULL != op; op = op->next)
699 if (op->r_id == r_id)
701 for (it = handle->ticket_it_head; NULL != it; it = it->next)
702 if (it->r_id == r_id)
704 if ((NULL == op) && (NULL == it))
706 msg_len = ntohs (msg->header.size);
709 GNUNET_CONTAINER_DLL_remove (handle->op_head,
712 if (msg_len == sizeof (struct TicketResultMessage))
714 if (NULL != op->tr_cb)
715 op->tr_cb (op->cls, NULL);
717 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1];
718 if (NULL != op->tr_cb)
719 op->tr_cb (op->cls, ticket);
723 } else if (NULL != it) {
724 if (msg_len == sizeof (struct TicketResultMessage))
726 if (NULL != it->tr_cb)
727 GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head,
728 handle->ticket_it_tail,
730 it->finish_cb (it->finish_cb_cls);
733 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1];
734 if (NULL != it->tr_cb)
735 it->tr_cb (it->cls, ticket);
744 * Handle an incoming message of type
745 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT
748 * @param msg the message we received
751 handle_revoke_ticket_result (void *cls,
752 const struct RevokeTicketResultMessage *msg)
754 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
755 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
756 uint32_t r_id = ntohl (msg->id);
759 LOG (GNUNET_ERROR_TYPE_DEBUG,
760 "Processing revocation result.\n");
763 for (op = h->op_head; NULL != op; op = op->next)
764 if (op->r_id == r_id)
768 success = ntohl (msg->success);
770 if (NULL != op->rvk_cb)
776 GNUNET_CONTAINER_DLL_remove (h->op_head,
788 * Try again to connect to the service.
790 * @param h handle to the identity provider service.
793 reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
795 struct GNUNET_MQ_MessageHandler handlers[] = {
796 GNUNET_MQ_hd_fixed_size (attribute_store_response,
797 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE_RESPONSE,
798 struct AttributeStoreResultMessage,
800 GNUNET_MQ_hd_var_size (attribute_result,
801 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT,
802 struct AttributeResultMessage,
804 GNUNET_MQ_hd_var_size (ticket_result,
805 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT,
806 struct TicketResultMessage,
808 GNUNET_MQ_hd_var_size (consume_ticket_result,
809 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT,
810 struct ConsumeTicketResultMessage,
812 GNUNET_MQ_hd_fixed_size (revoke_ticket_result,
813 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT,
814 struct RevokeTicketResultMessage,
816 GNUNET_MQ_handler_end ()
818 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
820 GNUNET_assert (NULL == h->mq);
821 LOG (GNUNET_ERROR_TYPE_DEBUG,
822 "Connecting to identity provider service.\n");
824 h->mq = GNUNET_CLIENT_connect (h->cfg,
831 for (op = h->op_head; NULL != op; op = op->next)
832 GNUNET_MQ_send_copy (h->mq,
838 * Connect to the identity provider service.
840 * @param cfg the configuration to use
841 * @return handle to use
843 struct GNUNET_IDENTITY_PROVIDER_Handle *
844 GNUNET_IDENTITY_PROVIDER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
846 struct GNUNET_IDENTITY_PROVIDER_Handle *h;
848 h = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Handle);
861 * Cancel an operation. Note that the operation MAY still
862 * be executed; this merely cancels the continuation; if the request
863 * was already transmitted, the service may still choose to complete
866 * @param op operation to cancel
869 GNUNET_IDENTITY_PROVIDER_cancel (struct GNUNET_IDENTITY_PROVIDER_Operation *op)
871 struct GNUNET_IDENTITY_PROVIDER_Handle *h = op->h;
873 GNUNET_CONTAINER_DLL_remove (h->op_head,
876 GNUNET_MQ_discard (op->env);
882 * Disconnect from service
884 * @param h handle to destroy
887 GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
889 GNUNET_assert (NULL != h);
892 GNUNET_MQ_destroy (h->mq);
895 if (NULL != h->reconnect_task)
897 GNUNET_SCHEDULER_cancel (h->reconnect_task);
898 h->reconnect_task = NULL;
900 GNUNET_assert (NULL == h->op_head);
905 * Store an attribute. If the attribute is already present,
906 * it is replaced with the new attribute.
908 * @param h handle to the identity provider
909 * @param pkey private key of the identity
910 * @param attr the attribute value
911 * @param cont continuation to call when done
912 * @param cont_cls closure for @a cont
913 * @return handle to abort the request
915 struct GNUNET_IDENTITY_PROVIDER_Operation *
916 GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
917 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
918 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr,
919 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cont,
922 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
923 struct AttributeStoreMessage *sam;
926 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation);
930 op->r_id = h->r_id_gen++;
931 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
934 attr_len = GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (attr);
935 op->env = GNUNET_MQ_msg_extra (sam,
937 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE);
938 sam->identity = *pkey;
939 sam->id = htonl (op->r_id);
941 GNUNET_IDENTITY_ATTRIBUTE_serialize (attr,
944 sam->attr_len = htons (attr_len);
946 GNUNET_MQ_send_copy (h->mq,
954 * List all attributes for a local identity.
955 * This MUST lock the `struct GNUNET_IDENTITY_PROVIDER_Handle`
956 * for any other calls than #GNUNET_IDENTITY_PROVIDER_get_attributes_next() and
957 * #GNUNET_IDENTITY_PROVIDER_get_attributes_stop. @a proc will be called once
958 * immediately, and then again after
959 * #GNUNET_IDENTITY_PROVIDER_get_attributes_next() is invoked.
961 * On error (disconnect), @a error_cb will be invoked.
962 * On normal completion, @a finish_cb proc will be
965 * @param h handle to the idp
966 * @param identity identity to access
967 * @param error_cb function to call on error (i.e. disconnect),
968 * the handle is afterwards invalid
969 * @param error_cb_cls closure for @a error_cb
970 * @param proc function to call on each attribute; it
971 * will be called repeatedly with a value (if available)
972 * @param proc_cls closure for @a proc
973 * @param finish_cb function to call on completion
974 * the handle is afterwards invalid
975 * @param finish_cb_cls closure for @a finish_cb
976 * @return an iterator handle to use for iteration
978 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *
979 GNUNET_IDENTITY_PROVIDER_get_attributes_start (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
980 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
981 GNUNET_SCHEDULER_TaskCallback error_cb,
983 GNUNET_IDENTITY_PROVIDER_AttributeResult proc,
985 GNUNET_SCHEDULER_TaskCallback finish_cb,
988 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it;
989 struct GNUNET_MQ_Envelope *env;
990 struct AttributeIterationStartMessage *msg;
994 it = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator);
996 it->error_cb = error_cb;
997 it->error_cb_cls = error_cb_cls;
998 it->finish_cb = finish_cb;
999 it->finish_cb_cls = finish_cb_cls;
1001 it->proc_cls = proc_cls;
1003 it->identity = *identity;
1004 GNUNET_CONTAINER_DLL_insert_tail (h->it_head,
1007 env = GNUNET_MQ_msg (msg,
1008 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_START);
1009 msg->id = htonl (rid);
1010 msg->identity = *identity;
1014 GNUNET_MQ_send (h->mq,
1021 * Calls the record processor specified in #GNUNET_IDENTITY_PROVIDER_get_attributes_start
1022 * for the next record.
1024 * @param it the iterator
1027 GNUNET_IDENTITY_PROVIDER_get_attributes_next (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it)
1029 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h;
1030 struct AttributeIterationNextMessage *msg;
1031 struct GNUNET_MQ_Envelope *env;
1033 env = GNUNET_MQ_msg (msg,
1034 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_NEXT);
1035 msg->id = htonl (it->r_id);
1036 GNUNET_MQ_send (h->mq,
1042 * Stops iteration and releases the idp handle for further calls. Must
1043 * be called on any iteration that has not yet completed prior to calling
1044 * #GNUNET_IDENTITY_PROVIDER_disconnect.
1046 * @param it the iterator
1049 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it)
1051 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h;
1052 struct GNUNET_MQ_Envelope *env;
1053 struct AttributeIterationStopMessage *msg;
1057 env = GNUNET_MQ_msg (msg,
1058 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_STOP);
1059 msg->id = htonl (it->r_id);
1060 GNUNET_MQ_send (h->mq,
1068 * Issues a ticket to another identity. The identity may use
1069 * @GNUNET_IDENTITY_PROVIDER_authorization_ticket_consume to consume the ticket
1070 * and retrieve the attributes specified in the AttributeList.
1072 * @param h the identity provider to use
1073 * @param iss the issuing identity
1074 * @param rp the subject of the ticket (the relying party)
1075 * @param attrs the attributes that the relying party is given access to
1076 * @param cb the callback
1077 * @param cb_cls the callback closure
1078 * @return handle to abort the operation
1080 struct GNUNET_IDENTITY_PROVIDER_Operation *
1081 GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
1082 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
1083 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
1084 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs,
1085 GNUNET_IDENTITY_PROVIDER_TicketCallback cb,
1088 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
1089 struct IssueTicketMessage *tim;
1092 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation);
1096 op->r_id = h->r_id_gen++;
1097 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
1100 attr_len = GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (attrs);
1101 op->env = GNUNET_MQ_msg_extra (tim,
1103 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_TICKET);
1104 tim->identity = *iss;
1106 tim->id = htonl (op->r_id);
1108 GNUNET_IDENTITY_ATTRIBUTE_list_serialize (attrs,
1111 tim->attr_len = htons (attr_len);
1113 GNUNET_MQ_send_copy (h->mq,
1119 * Consumes an issued ticket. The ticket is persisted
1120 * and used to retrieve identity information from the issuer
1122 * @param h the identity provider to use
1123 * @param identity the identity that is the subject of the issued ticket (the relying party)
1124 * @param ticket the issued ticket to consume
1125 * @param cb the callback to call
1126 * @param cb_cls the callback closure
1127 * @return handle to abort the operation
1129 struct GNUNET_IDENTITY_PROVIDER_Operation *
1130 GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
1131 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1132 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
1133 GNUNET_IDENTITY_PROVIDER_AttributeResult cb,
1136 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
1137 struct ConsumeTicketMessage *ctm;
1139 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation);
1143 op->r_id = h->r_id_gen++;
1144 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
1147 op->env = GNUNET_MQ_msg_extra (ctm,
1148 sizeof (const struct GNUNET_IDENTITY_PROVIDER_Ticket),
1149 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET);
1150 ctm->identity = *identity;
1151 ctm->id = htonl (op->r_id);
1153 GNUNET_memcpy ((char*)&ctm[1],
1155 sizeof (const struct GNUNET_IDENTITY_PROVIDER_Ticket));
1158 GNUNET_MQ_send_copy (h->mq,
1166 * Lists all tickets that have been issued to remote
1167 * identites (relying parties)
1169 * @param h the identity provider to use
1170 * @param identity the issuing identity
1171 * @param error_cb function to call on error (i.e. disconnect),
1172 * the handle is afterwards invalid
1173 * @param error_cb_cls closure for @a error_cb
1174 * @param proc function to call on each ticket; it
1175 * will be called repeatedly with a value (if available)
1176 * @param proc_cls closure for @a proc
1177 * @param finish_cb function to call on completion
1178 * the handle is afterwards invalid
1179 * @param finish_cb_cls closure for @a finish_cb
1180 * @return an iterator handle to use for iteration
1182 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *
1183 GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
1184 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1185 GNUNET_SCHEDULER_TaskCallback error_cb,
1187 GNUNET_IDENTITY_PROVIDER_TicketCallback proc,
1189 GNUNET_SCHEDULER_TaskCallback finish_cb,
1190 void *finish_cb_cls)
1192 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it;
1193 struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub;
1194 struct GNUNET_MQ_Envelope *env;
1195 struct TicketIterationStartMessage *msg;
1198 GNUNET_CRYPTO_ecdsa_key_get_public (identity,
1200 rid = h->r_id_gen++;
1201 it = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_TicketIterator);
1203 it->error_cb = error_cb;
1204 it->error_cb_cls = error_cb_cls;
1205 it->finish_cb = finish_cb;
1206 it->finish_cb_cls = finish_cb_cls;
1210 GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head,
1213 env = GNUNET_MQ_msg (msg,
1214 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START);
1215 msg->id = htonl (rid);
1216 msg->identity = identity_pub;
1217 msg->is_audience = htonl (GNUNET_NO);
1221 GNUNET_MQ_send (h->mq,
1229 * Lists all tickets that have been issued to remote
1230 * identites (relying parties)
1232 * @param h the identity provider to use
1233 * @param identity the issuing identity
1234 * @param error_cb function to call on error (i.e. disconnect),
1235 * the handle is afterwards invalid
1236 * @param error_cb_cls closure for @a error_cb
1237 * @param proc function to call on each ticket; it
1238 * will be called repeatedly with a value (if available)
1239 * @param proc_cls closure for @a proc
1240 * @param finish_cb function to call on completion
1241 * the handle is afterwards invalid
1242 * @param finish_cb_cls closure for @a finish_cb
1243 * @return an iterator handle to use for iteration
1245 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *
1246 GNUNET_IDENTITY_PROVIDER_ticket_iteration_start_rp (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
1247 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
1248 GNUNET_SCHEDULER_TaskCallback error_cb,
1250 GNUNET_IDENTITY_PROVIDER_TicketCallback proc,
1252 GNUNET_SCHEDULER_TaskCallback finish_cb,
1253 void *finish_cb_cls)
1255 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it;
1256 struct GNUNET_MQ_Envelope *env;
1257 struct TicketIterationStartMessage *msg;
1260 rid = h->r_id_gen++;
1261 it = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_TicketIterator);
1263 it->error_cb = error_cb;
1264 it->error_cb_cls = error_cb_cls;
1265 it->finish_cb = finish_cb;
1266 it->finish_cb_cls = finish_cb_cls;
1270 GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head,
1273 env = GNUNET_MQ_msg (msg,
1274 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START);
1275 msg->id = htonl (rid);
1276 msg->identity = *identity;
1277 msg->is_audience = htonl (GNUNET_YES);
1281 GNUNET_MQ_send (h->mq,
1289 * Calls the record processor specified in #GNUNET_IDENTITY_PROVIDER_ticket_iteration_start
1290 * for the next record.
1292 * @param it the iterator
1295 GNUNET_IDENTITY_PROVIDER_ticket_iteration_next (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it)
1297 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h;
1298 struct TicketIterationNextMessage *msg;
1299 struct GNUNET_MQ_Envelope *env;
1301 env = GNUNET_MQ_msg (msg,
1302 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT);
1303 msg->id = htonl (it->r_id);
1304 GNUNET_MQ_send (h->mq,
1310 * Stops iteration and releases the idp handle for further calls. Must
1311 * be called on any iteration that has not yet completed prior to calling
1312 * #GNUNET_IDENTITY_PROVIDER_disconnect.
1314 * @param it the iterator
1317 GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it)
1319 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h;
1320 struct GNUNET_MQ_Envelope *env;
1321 struct TicketIterationStopMessage *msg;
1325 env = GNUNET_MQ_msg (msg,
1326 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP);
1327 msg->id = htonl (it->r_id);
1328 GNUNET_MQ_send (h->mq,
1335 * Revoked an issued ticket. The relying party will be unable to retrieve
1336 * updated attributes.
1338 * @param h the identity provider to use
1339 * @param identity the issuing identity
1340 * @param ticket the ticket to revoke
1341 * @param cb the callback
1342 * @param cb_cls the callback closure
1343 * @return handle to abort the operation
1345 struct GNUNET_IDENTITY_PROVIDER_Operation *
1346 GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
1347 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1348 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
1349 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cb,
1352 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
1353 struct GNUNET_MQ_Envelope *env;
1354 struct RevokeTicketMessage *msg;
1357 rid = h->r_id_gen++;
1358 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation);
1363 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
1366 env = GNUNET_MQ_msg_extra (msg,
1367 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket),
1368 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET);
1369 msg->id = htonl (rid);
1370 msg->identity = *identity;
1373 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
1377 GNUNET_MQ_send (h->mq,
1384 /* end of identity_provider_api.c */