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 "identity_provider.h"
33 #include "identity_attribute.h"
35 #define LOG(kind,...) GNUNET_log_from (kind, "identity-api",__VA_ARGS__)
40 * Handle for an operation with the service.
42 struct GNUNET_IDENTITY_PROVIDER_Operation
48 struct GNUNET_IDENTITY_PROVIDER_Handle *h;
51 * We keep operations in a DLL.
53 struct GNUNET_IDENTITY_PROVIDER_Operation *next;
56 * We keep operations in a DLL.
58 struct GNUNET_IDENTITY_PROVIDER_Operation *prev;
61 * Message to send to the service.
62 * Allocated at the end of this struct.
64 const struct GNUNET_MessageHeader *msg;
67 * Continuation to invoke after attribute store call
69 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus as_cb;
72 * Attribute result callback
74 GNUNET_IDENTITY_PROVIDER_AttributeResult ar_cb;
77 * Revocation result callback
79 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus rvk_cb;
82 * Ticket result callback
84 GNUNET_IDENTITY_PROVIDER_TicketCallback tr_cb;
87 * Envelope with the message for this queue entry.
89 struct GNUNET_MQ_Envelope *env;
97 * Closure for @e cont or @e cb.
104 * Handle for a ticket iterator operation
106 struct GNUNET_IDENTITY_PROVIDER_TicketIterator
112 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *next;
117 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *prev;
120 * Main handle to access the idp.
122 struct GNUNET_IDENTITY_PROVIDER_Handle *h;
125 * Function to call on completion.
127 GNUNET_SCHEDULER_TaskCallback finish_cb;
130 * Closure for @e error_cb.
135 * The continuation to call with the results
137 GNUNET_IDENTITY_PROVIDER_TicketCallback tr_cb;
140 * Closure for @e tr_cb.
145 * Function to call on errors.
147 GNUNET_SCHEDULER_TaskCallback error_cb;
150 * Closure for @e error_cb.
155 * Envelope of the message to send to the service, if not yet
158 struct GNUNET_MQ_Envelope *env;
161 * The operation id this zone iteration operation has
169 * Handle for a attribute iterator operation
171 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator
177 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *next;
182 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *prev;
185 * Main handle to access the idp.
187 struct GNUNET_IDENTITY_PROVIDER_Handle *h;
190 * Function to call on completion.
192 GNUNET_SCHEDULER_TaskCallback finish_cb;
195 * Closure for @e error_cb.
200 * The continuation to call with the results
202 GNUNET_IDENTITY_PROVIDER_AttributeResult proc;
205 * Closure for @e proc.
210 * Function to call on errors.
212 GNUNET_SCHEDULER_TaskCallback error_cb;
215 * Closure for @e error_cb.
220 * Envelope of the message to send to the service, if not yet
223 struct GNUNET_MQ_Envelope *env;
226 * Private key of the zone.
228 struct GNUNET_CRYPTO_EcdsaPrivateKey identity;
231 * The operation id this zone iteration operation has
239 * Handle for the service.
241 struct GNUNET_IDENTITY_PROVIDER_Handle
244 * Configuration to use.
246 const struct GNUNET_CONFIGURATION_Handle *cfg;
249 * Socket (if available).
251 struct GNUNET_CLIENT_Connection *client;
259 * Head of active operations.
261 struct GNUNET_IDENTITY_PROVIDER_Operation *op_head;
264 * Tail of active operations.
266 struct GNUNET_IDENTITY_PROVIDER_Operation *op_tail;
269 * Head of active iterations
271 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it_head;
274 * Tail of active iterations
276 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it_tail;
279 * Head of active iterations
281 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *ticket_it_head;
284 * Tail of active iterations
286 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *ticket_it_tail;
290 * Currently pending transmission request, or NULL for none.
292 struct GNUNET_CLIENT_TransmitHandle *th;
295 * Task doing exponential back-off trying to reconnect.
297 struct GNUNET_SCHEDULER_Task * reconnect_task;
300 * Time for next connect retry.
302 struct GNUNET_TIME_Relative reconnect_backoff;
305 * Connection to service (if available).
307 struct GNUNET_MQ_Handle *mq;
310 * Request Id generator. Incremented by one for each request.
315 * Are we polling for incoming messages right now?
323 * Try again to connect to the service.
325 * @param cls handle to the service.
328 reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *handle);
333 * @param cls the handle
336 reconnect_task (void *cls)
338 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls;
340 handle->reconnect_task = NULL;
346 * Disconnect from service and then reconnect.
348 * @param handle our handle
351 force_reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *handle)
353 GNUNET_MQ_destroy (handle->mq);
355 handle->reconnect_backoff
356 = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
357 handle->reconnect_task
358 = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
366 * @param it entry to free
369 free_it (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it)
371 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h;
373 GNUNET_CONTAINER_DLL_remove (h->it_head,
377 GNUNET_MQ_discard (it->env);
384 * Generic error handler, called with the appropriate error code and
385 * the same closure specified at the creation of the message queue.
386 * Not every message queue implementation supports an error handler.
388 * @param cls closure with the `struct GNUNET_GNS_Handle *`
389 * @param error error code
392 mq_error_handler (void *cls,
393 enum GNUNET_MQ_Error error)
395 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls;
396 force_reconnect (handle);
400 * Handle an incoming message of type
401 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
404 * @param msg the message we received
407 handle_attribute_store_response (void *cls,
408 const struct AttributeStoreResultMessage *msg)
410 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
411 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
412 uint32_t r_id = ntohl (msg->id);
416 for (op = h->op_head; NULL != op; op = op->next)
417 if (op->r_id == r_id)
422 res = ntohl (msg->op_result);
423 LOG (GNUNET_ERROR_TYPE_DEBUG,
424 "Received ATTRIBUTE_STORE_RESPONSE with result %d\n",
427 /* TODO: add actual error message to response... */
428 if (GNUNET_SYSERR == res)
429 emsg = _("failed to store record\n");
432 if (NULL != op->as_cb)
436 GNUNET_CONTAINER_DLL_remove (h->op_head,
445 * Handle an incoming message of type
446 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT
449 * @param msg the message we received
450 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
453 check_consume_ticket_result (void *cls,
454 const struct ConsumeTicketResultMessage *msg)
459 msg_len = ntohs (msg->header.size);
460 attrs_len = ntohs (msg->attrs_len);
461 if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len)
464 return GNUNET_SYSERR;
471 * Handle an incoming message of type
472 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT
475 * @param msg the message we received
478 handle_consume_ticket_result (void *cls,
479 const struct ConsumeTicketResultMessage *msg)
481 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
482 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
484 uint32_t r_id = ntohl (msg->id);
486 attrs_len = ntohs (msg->attrs_len);
487 LOG (GNUNET_ERROR_TYPE_DEBUG,
488 "Processing attribute result.\n");
491 for (op = h->op_head; NULL != op; op = op->next)
492 if (op->r_id == r_id)
498 struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs;
499 struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le;
500 attrs = attribute_list_deserialize ((char*)&msg[1],
502 if (NULL != op->ar_cb)
512 for (le = attrs->list_head; NULL != le; le = le->next)
516 attribute_list_destroy (attrs);
522 GNUNET_CONTAINER_DLL_remove (h->op_head,
533 * Handle an incoming message of type
534 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT
537 * @param msg the message we received
538 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
541 check_attribute_result (void *cls,
542 const struct AttributeResultMessage *msg)
547 msg_len = ntohs (msg->header.size);
548 attr_len = ntohs (msg->attr_len);
549 if (msg_len != sizeof (struct AttributeResultMessage) + attr_len)
552 return GNUNET_SYSERR;
559 * Handle an incoming message of type
560 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT
563 * @param msg the message we received
566 handle_attribute_result (void *cls,
567 const struct AttributeResultMessage *msg)
569 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
570 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
571 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it;
572 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
574 uint32_t r_id = ntohl (msg->id);
576 attr_len = ntohs (msg->attr_len);
577 LOG (GNUNET_ERROR_TYPE_DEBUG,
578 "Processing attribute result.\n");
581 for (it = h->it_head; NULL != it; it = it->next)
582 if (it->r_id == r_id)
584 for (op = h->op_head; NULL != op; op = op->next)
585 if (op->r_id == r_id)
587 if ((NULL == it) && (NULL == op))
590 if ( (0 == (memcmp (&msg->identity,
592 sizeof (identity_dummy)))) )
594 if ((NULL == it) && (NULL == op))
602 if (NULL != it->finish_cb)
603 it->finish_cb (it->finish_cb_cls);
608 if (NULL != op->ar_cb)
612 GNUNET_CONTAINER_DLL_remove (h->op_head,
622 struct GNUNET_IDENTITY_PROVIDER_Attribute *attr;
623 attr = attribute_deserialize ((char*)&msg[1],
627 if (NULL != it->proc)
628 it->proc (it->proc_cls,
631 } else if (NULL != op)
633 if (NULL != op->ar_cb)
646 * Handle an incoming message of type
647 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT
650 * @param msg the message we received
651 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
654 check_ticket_result (void *cls,
655 const struct TicketResultMessage *msg)
659 msg_len = ntohs (msg->header.size);
660 if (msg_len < sizeof (struct TicketResultMessage))
663 return GNUNET_SYSERR;
671 * Handle an incoming message of type
672 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT
675 * @param msg the message we received
678 handle_ticket_result (void *cls,
679 const struct TicketResultMessage *msg)
681 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls;
682 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
683 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it;
684 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket;
685 uint32_t r_id = ntohl (msg->id);
688 for (op = handle->op_head; NULL != op; op = op->next)
689 if (op->r_id == r_id)
691 for (it = handle->ticket_it_head; NULL != it; it = it->next)
692 if (it->r_id == r_id)
694 if ((NULL == op) && (NULL == it))
696 msg_len = ntohs (msg->header.size);
699 GNUNET_CONTAINER_DLL_remove (handle->op_head,
702 if (msg_len == sizeof (struct TicketResultMessage))
704 if (NULL != op->tr_cb)
705 op->tr_cb (op->cls, NULL);
707 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1];
708 if (NULL != op->tr_cb)
709 op->tr_cb (op->cls, ticket);
713 } else if (NULL != it) {
714 if (msg_len == sizeof (struct TicketResultMessage))
716 if (NULL != it->tr_cb)
717 GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head,
718 handle->ticket_it_tail,
720 it->finish_cb (it->finish_cb_cls);
723 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1];
724 if (NULL != it->tr_cb)
725 it->tr_cb (it->cls, ticket);
733 * Handle an incoming message of type
734 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT
737 * @param msg the message we received
740 handle_revoke_ticket_result (void *cls,
741 const struct RevokeTicketResultMessage *msg)
743 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
744 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
745 uint32_t r_id = ntohl (msg->id);
748 LOG (GNUNET_ERROR_TYPE_DEBUG,
749 "Processing revocation result.\n");
752 for (op = h->op_head; NULL != op; op = op->next)
753 if (op->r_id == r_id)
757 success = ntohl (msg->success);
759 if (NULL != op->rvk_cb)
765 GNUNET_CONTAINER_DLL_remove (h->op_head,
777 * Try again to connect to the service.
779 * @param cls handle to the identity provider service.
782 reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
784 struct GNUNET_MQ_MessageHandler handlers[] = {
785 GNUNET_MQ_hd_fixed_size (attribute_store_response,
786 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE_RESPONSE,
787 struct AttributeStoreResultMessage,
789 GNUNET_MQ_hd_var_size (attribute_result,
790 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT,
791 struct AttributeResultMessage,
793 GNUNET_MQ_hd_var_size (ticket_result,
794 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT,
795 struct TicketResultMessage,
797 GNUNET_MQ_hd_var_size (consume_ticket_result,
798 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT,
799 struct ConsumeTicketResultMessage,
801 GNUNET_MQ_hd_fixed_size (revoke_ticket_result,
802 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT,
803 struct RevokeTicketResultMessage,
805 GNUNET_MQ_handler_end ()
807 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
809 GNUNET_assert (NULL == h->mq);
810 LOG (GNUNET_ERROR_TYPE_DEBUG,
811 "Connecting to identity provider service.\n");
813 h->mq = GNUNET_CLIENT_connect (h->cfg,
820 for (op = h->op_head; NULL != op; op = op->next)
821 GNUNET_MQ_send_copy (h->mq,
827 * Connect to the identity provider service.
829 * @param cfg the configuration to use
830 * @return handle to use
832 struct GNUNET_IDENTITY_PROVIDER_Handle *
833 GNUNET_IDENTITY_PROVIDER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
835 struct GNUNET_IDENTITY_PROVIDER_Handle *h;
837 h = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Handle);
850 * Cancel an operation. Note that the operation MAY still
851 * be executed; this merely cancels the continuation; if the request
852 * was already transmitted, the service may still choose to complete
855 * @param op operation to cancel
858 GNUNET_IDENTITY_PROVIDER_cancel (struct GNUNET_IDENTITY_PROVIDER_Operation *op)
860 struct GNUNET_IDENTITY_PROVIDER_Handle *h = op->h;
862 GNUNET_CONTAINER_DLL_remove (h->op_head,
865 GNUNET_MQ_discard (op->env);
871 * Disconnect from service
873 * @param h handle to destroy
876 GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
878 GNUNET_assert (NULL != h);
881 GNUNET_MQ_destroy (h->mq);
884 if (NULL != h->reconnect_task)
886 GNUNET_SCHEDULER_cancel (h->reconnect_task);
887 h->reconnect_task = NULL;
889 GNUNET_assert (NULL == h->op_head);
894 * Store an attribute. If the attribute is already present,
895 * it is replaced with the new attribute.
897 * @param h handle to the identity provider
898 * @param pkey private key of the identity
899 * @param name the attribute name
900 * @param value the attribute value
901 * @param cont continuation to call when done
902 * @param cont_cls closure for @a cont
903 * @return handle to abort the request
905 struct GNUNET_IDENTITY_PROVIDER_Operation *
906 GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
907 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
908 const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr,
909 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cont,
912 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
913 struct AttributeStoreMessage *sam;
916 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation);
920 op->r_id = h->r_id_gen++;
921 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
924 attr_len = attribute_serialize_get_size (attr);
925 op->env = GNUNET_MQ_msg_extra (sam,
927 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE);
928 sam->identity = *pkey;
929 sam->id = htonl (op->r_id);
931 attribute_serialize (attr,
934 sam->attr_len = htons (attr_len);
936 GNUNET_MQ_send_copy (h->mq,
944 * Create a new attribute.
946 * @param name the attribute name
947 * @param type the attribute type
948 * @param data the attribute value
949 * @param data_size the attribute value size
950 * @return the new attribute
952 struct GNUNET_IDENTITY_PROVIDER_Attribute *
953 GNUNET_IDENTITY_PROVIDER_attribute_new (const char* attr_name,
958 return attribute_new (attr_name, attr_type, data, data_size);
962 * List all attributes for a local identity.
963 * This MUST lock the `struct GNUNET_IDENTITY_PROVIDER_Handle`
964 * for any other calls than #GNUNET_IDENTITY_PROVIDER_get_attributes_next() and
965 * #GNUNET_IDENTITY_PROVIDER_get_attributes_stop. @a proc will be called once
966 * immediately, and then again after
967 * #GNUNET_IDENTITY_PROVIDER_get_attributes_next() is invoked.
969 * On error (disconnect), @a error_cb will be invoked.
970 * On normal completion, @a finish_cb proc will be
973 * @param h handle to the idp
974 * @param identity identity to access
975 * @param error_cb function to call on error (i.e. disconnect),
976 * the handle is afterwards invalid
977 * @param error_cb_cls closure for @a error_cb
978 * @param proc function to call on each attribute; it
979 * will be called repeatedly with a value (if available)
980 * @param proc_cls closure for @a proc
981 * @param finish_cb function to call on completion
982 * the handle is afterwards invalid
983 * @param finish_cb_cls closure for @a finish_cb
984 * @return an iterator handle to use for iteration
986 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *
987 GNUNET_IDENTITY_PROVIDER_get_attributes_start (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
988 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
989 GNUNET_SCHEDULER_TaskCallback error_cb,
991 GNUNET_IDENTITY_PROVIDER_AttributeResult proc,
993 GNUNET_SCHEDULER_TaskCallback finish_cb,
996 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it;
997 struct GNUNET_MQ_Envelope *env;
998 struct AttributeIterationStartMessage *msg;
1001 rid = h->r_id_gen++;
1002 it = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator);
1004 it->error_cb = error_cb;
1005 it->error_cb_cls = error_cb_cls;
1006 it->finish_cb = finish_cb;
1007 it->finish_cb_cls = finish_cb_cls;
1009 it->proc_cls = proc_cls;
1011 it->identity = *identity;
1012 GNUNET_CONTAINER_DLL_insert_tail (h->it_head,
1015 env = GNUNET_MQ_msg (msg,
1016 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_START);
1017 msg->id = htonl (rid);
1018 msg->identity = *identity;
1022 GNUNET_MQ_send (h->mq,
1029 * Calls the record processor specified in #GNUNET_IDENTITY_PROVIDER_get_attributes_start
1030 * for the next record.
1032 * @param it the iterator
1035 GNUNET_IDENTITY_PROVIDER_get_attributes_next (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it)
1037 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h;
1038 struct AttributeIterationNextMessage *msg;
1039 struct GNUNET_MQ_Envelope *env;
1041 env = GNUNET_MQ_msg (msg,
1042 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_NEXT);
1043 msg->id = htonl (it->r_id);
1044 GNUNET_MQ_send (h->mq,
1050 * Stops iteration and releases the idp handle for further calls. Must
1051 * be called on any iteration that has not yet completed prior to calling
1052 * #GNUNET_IDENTITY_PROVIDER_disconnect.
1054 * @param it the iterator
1057 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it)
1059 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h;
1060 struct GNUNET_MQ_Envelope *env;
1061 struct AttributeIterationStopMessage *msg;
1065 env = GNUNET_MQ_msg (msg,
1066 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_STOP);
1067 msg->id = htonl (it->r_id);
1068 GNUNET_MQ_send (h->mq,
1076 * Issues a ticket to another identity. The identity may use
1077 * @GNUNET_IDENTITY_PROVIDER_authorization_ticket_consume to consume the ticket
1078 * and retrieve the attributes specified in the AttributeList.
1080 * @param h the identity provider to use
1081 * @param iss the issuing identity
1082 * @param rp the subject of the ticket (the relying party)
1083 * @param attr the attributes that the relying party is given access to
1084 * @param cb the callback
1085 * @param cb_cls the callback closure
1086 * @return handle to abort the operation
1088 struct GNUNET_IDENTITY_PROVIDER_Operation *
1089 GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
1090 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
1091 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
1092 const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs,
1093 GNUNET_IDENTITY_PROVIDER_TicketCallback cb,
1096 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
1097 struct IssueTicketMessage *tim;
1100 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation);
1104 op->r_id = h->r_id_gen++;
1105 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
1108 attr_len = attribute_list_serialize_get_size (attrs);
1109 op->env = GNUNET_MQ_msg_extra (tim,
1111 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_TICKET);
1112 tim->identity = *iss;
1114 tim->id = htonl (op->r_id);
1116 attribute_list_serialize (attrs,
1119 tim->attr_len = htons (attr_len);
1121 GNUNET_MQ_send_copy (h->mq,
1127 * Consumes an issued ticket. The ticket is persisted
1128 * and used to retrieve identity information from the issuer
1130 * @param id the identity provider to use
1131 * @param identity the identity that is the subject of the issued ticket (the relying party)
1132 * @param ticket the issued ticket to consume
1133 * @param cb the callback to call
1134 * @param cb_cls the callback closure
1135 * @return handle to abort the operation
1137 struct GNUNET_IDENTITY_PROVIDER_Operation *
1138 GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
1139 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1140 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
1141 GNUNET_IDENTITY_PROVIDER_AttributeResult cb,
1144 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
1145 struct ConsumeTicketMessage *ctm;
1147 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation);
1151 op->r_id = h->r_id_gen++;
1152 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
1155 op->env = GNUNET_MQ_msg_extra (ctm,
1156 sizeof (const struct GNUNET_IDENTITY_PROVIDER_Ticket),
1157 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET);
1158 ctm->identity = *identity;
1159 ctm->id = htonl (op->r_id);
1161 GNUNET_memcpy ((char*)&ctm[1],
1163 sizeof (const struct GNUNET_IDENTITY_PROVIDER_Ticket));
1166 GNUNET_MQ_send_copy (h->mq,
1174 * Lists all tickets that have been issued to remote
1175 * identites (relying parties)
1177 * @param h the identity provider to use
1178 * @param identity the issuing identity
1179 * @param error_cb function to call on error (i.e. disconnect),
1180 * the handle is afterwards invalid
1181 * @param error_cb_cls closure for @a error_cb
1182 * @param proc function to call on each ticket; it
1183 * will be called repeatedly with a value (if available)
1184 * @param proc_cls closure for @a proc
1185 * @param finish_cb function to call on completion
1186 * the handle is afterwards invalid
1187 * @param finish_cb_cls closure for @a finish_cb
1188 * @return an iterator handle to use for iteration
1190 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *
1191 GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
1192 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1193 GNUNET_SCHEDULER_TaskCallback error_cb,
1195 GNUNET_IDENTITY_PROVIDER_TicketCallback proc,
1197 GNUNET_SCHEDULER_TaskCallback finish_cb,
1198 void *finish_cb_cls)
1200 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it;
1201 struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub;
1202 struct GNUNET_MQ_Envelope *env;
1203 struct TicketIterationStartMessage *msg;
1206 GNUNET_CRYPTO_ecdsa_key_get_public (identity,
1208 rid = h->r_id_gen++;
1209 it = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_TicketIterator);
1211 it->error_cb = error_cb;
1212 it->error_cb_cls = error_cb_cls;
1213 it->finish_cb = finish_cb;
1214 it->finish_cb_cls = finish_cb_cls;
1218 GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head,
1221 env = GNUNET_MQ_msg (msg,
1222 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START);
1223 msg->id = htonl (rid);
1224 msg->identity = identity_pub;
1225 msg->is_audience = htonl (GNUNET_NO);
1229 GNUNET_MQ_send (h->mq,
1237 * Lists all tickets that have been issued to remote
1238 * identites (relying parties)
1240 * @param id the identity provider to use
1241 * @param identity the issuing identity
1242 * @param error_cb function to call on error (i.e. disconnect),
1243 * the handle is afterwards invalid
1244 * @param error_cb_cls closure for @a error_cb
1245 * @param proc function to call on each ticket; it
1246 * will be called repeatedly with a value (if available)
1247 * @param proc_cls closure for @a proc
1248 * @param finish_cb function to call on completion
1249 * the handle is afterwards invalid
1250 * @param finish_cb_cls closure for @a finish_cb
1251 * @return an iterator handle to use for iteration
1253 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *
1254 GNUNET_IDENTITY_PROVIDER_ticket_iteration_start_rp (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
1255 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
1256 GNUNET_SCHEDULER_TaskCallback error_cb,
1258 GNUNET_IDENTITY_PROVIDER_TicketCallback proc,
1260 GNUNET_SCHEDULER_TaskCallback finish_cb,
1261 void *finish_cb_cls)
1263 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it;
1264 struct GNUNET_MQ_Envelope *env;
1265 struct TicketIterationStartMessage *msg;
1268 rid = h->r_id_gen++;
1269 it = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_TicketIterator);
1271 it->error_cb = error_cb;
1272 it->error_cb_cls = error_cb_cls;
1273 it->finish_cb = finish_cb;
1274 it->finish_cb_cls = finish_cb_cls;
1278 GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head,
1281 env = GNUNET_MQ_msg (msg,
1282 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START);
1283 msg->id = htonl (rid);
1284 msg->identity = *identity;
1285 msg->is_audience = htonl (GNUNET_YES);
1289 GNUNET_MQ_send (h->mq,
1297 * Calls the record processor specified in #GNUNET_IDENTITY_PROVIDER_ticket_iteration_start
1298 * for the next record.
1300 * @param it the iterator
1303 GNUNET_IDENTITY_PROVIDER_ticket_iteration_next (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it)
1305 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h;
1306 struct TicketIterationNextMessage *msg;
1307 struct GNUNET_MQ_Envelope *env;
1309 env = GNUNET_MQ_msg (msg,
1310 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT);
1311 msg->id = htonl (it->r_id);
1312 GNUNET_MQ_send (h->mq,
1318 * Stops iteration and releases the idp handle for further calls. Must
1319 * be called on any iteration that has not yet completed prior to calling
1320 * #GNUNET_IDENTITY_PROVIDER_disconnect.
1322 * @param it the iterator
1325 GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it)
1327 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h;
1328 struct GNUNET_MQ_Envelope *env;
1329 struct TicketIterationStopMessage *msg;
1333 env = GNUNET_MQ_msg (msg,
1334 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP);
1335 msg->id = htonl (it->r_id);
1336 GNUNET_MQ_send (h->mq,
1343 * Revoked an issued ticket. The relying party will be unable to retrieve
1344 * updated attributes.
1346 * @param id the identity provider to use
1347 * @param identity the issuing identity
1348 * @param ticket the ticket to revoke
1349 * @param cb the callback
1350 * @param cb_cls the callback closure
1351 * @return handle to abort the operation
1353 struct GNUNET_IDENTITY_PROVIDER_Operation *
1354 GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
1355 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1356 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
1357 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cb,
1360 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
1361 struct GNUNET_MQ_Envelope *env;
1362 struct RevokeTicketMessage *msg;
1365 rid = h->r_id_gen++;
1366 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation);
1371 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
1374 env = GNUNET_MQ_msg_extra (msg,
1375 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket),
1376 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET);
1377 msg->id = htonl (rid);
1378 msg->identity = *identity;
1381 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
1385 GNUNET_MQ_send (h->mq,
1392 /* end of identity_provider_api.c */