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)
504 for (le = attrs->list_head; NULL != le; le = le->next)
509 attribute_list_destroy (attrs);
513 GNUNET_CONTAINER_DLL_remove (h->op_head,
524 * Handle an incoming message of type
525 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT
528 * @param msg the message we received
529 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
532 check_attribute_result (void *cls,
533 const struct AttributeResultMessage *msg)
538 msg_len = ntohs (msg->header.size);
539 attr_len = ntohs (msg->attr_len);
540 if (msg_len != sizeof (struct AttributeResultMessage) + attr_len)
543 return GNUNET_SYSERR;
550 * Handle an incoming message of type
551 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT
554 * @param msg the message we received
557 handle_attribute_result (void *cls,
558 const struct AttributeResultMessage *msg)
560 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
561 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
562 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it;
563 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
565 uint32_t r_id = ntohl (msg->id);
567 attr_len = ntohs (msg->attr_len);
568 LOG (GNUNET_ERROR_TYPE_DEBUG,
569 "Processing attribute result.\n");
572 for (it = h->it_head; NULL != it; it = it->next)
573 if (it->r_id == r_id)
575 for (op = h->op_head; NULL != op; op = op->next)
576 if (op->r_id == r_id)
578 if ((NULL == it) && (NULL == op))
581 if ( (0 == (memcmp (&msg->identity,
583 sizeof (identity_dummy)))) )
585 if ((NULL == it) && (NULL == op))
593 if (NULL != it->finish_cb)
594 it->finish_cb (it->finish_cb_cls);
599 if (NULL != op->ar_cb)
603 GNUNET_CONTAINER_DLL_remove (h->op_head,
613 struct GNUNET_IDENTITY_PROVIDER_Attribute *attr;
614 attr = attribute_deserialize ((char*)&msg[1],
618 if (NULL != it->proc)
619 it->proc (it->proc_cls,
622 } else if (NULL != op)
624 if (NULL != op->ar_cb)
637 * Handle an incoming message of type
638 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT
641 * @param msg the message we received
642 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
645 check_ticket_result (void *cls,
646 const struct TicketResultMessage *msg)
650 msg_len = ntohs (msg->header.size);
651 if (msg_len < sizeof (struct TicketResultMessage))
654 return GNUNET_SYSERR;
662 * Handle an incoming message of type
663 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT
666 * @param msg the message we received
669 handle_ticket_result (void *cls,
670 const struct TicketResultMessage *msg)
672 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls;
673 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
674 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it;
675 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket;
676 uint32_t r_id = ntohl (msg->id);
679 for (op = handle->op_head; NULL != op; op = op->next)
680 if (op->r_id == r_id)
682 for (it = handle->ticket_it_head; NULL != it; it = it->next)
683 if (it->r_id == r_id)
685 if ((NULL == op) && (NULL == it))
687 msg_len = ntohs (msg->header.size);
690 GNUNET_CONTAINER_DLL_remove (handle->op_head,
693 if (msg_len == sizeof (struct TicketResultMessage))
695 if (NULL != op->tr_cb)
696 op->tr_cb (op->cls, NULL);
698 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1];
699 if (NULL != op->tr_cb)
700 op->tr_cb (op->cls, ticket);
704 } else if (NULL != it) {
705 GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head,
706 handle->ticket_it_tail,
708 if (msg_len == sizeof (struct TicketResultMessage))
710 if (NULL != it->tr_cb)
711 it->finish_cb (it->finish_cb_cls);
714 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1];
715 if (NULL != it->tr_cb)
716 it->tr_cb (it->cls, ticket);
725 * Handle an incoming message of type
726 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT
729 * @param msg the message we received
732 handle_revoke_ticket_result (void *cls,
733 const struct RevokeTicketResultMessage *msg)
735 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls;
736 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
737 uint32_t r_id = ntohl (msg->id);
740 LOG (GNUNET_ERROR_TYPE_DEBUG,
741 "Processing revocation result.\n");
744 for (op = h->op_head; NULL != op; op = op->next)
745 if (op->r_id == r_id)
749 success = ntohl (msg->success);
751 if (NULL != op->rvk_cb)
757 GNUNET_CONTAINER_DLL_remove (h->op_head,
769 * Try again to connect to the service.
771 * @param cls handle to the identity provider service.
774 reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
776 struct GNUNET_MQ_MessageHandler handlers[] = {
777 GNUNET_MQ_hd_fixed_size (attribute_store_response,
778 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE_RESPONSE,
779 struct AttributeStoreResultMessage,
781 GNUNET_MQ_hd_var_size (attribute_result,
782 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT,
783 struct AttributeResultMessage,
785 GNUNET_MQ_hd_var_size (ticket_result,
786 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT,
787 struct TicketResultMessage,
789 GNUNET_MQ_hd_var_size (consume_ticket_result,
790 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT,
791 struct ConsumeTicketResultMessage,
793 GNUNET_MQ_hd_fixed_size (revoke_ticket_result,
794 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT,
795 struct RevokeTicketResultMessage,
797 GNUNET_MQ_handler_end ()
799 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
801 GNUNET_assert (NULL == h->mq);
802 LOG (GNUNET_ERROR_TYPE_DEBUG,
803 "Connecting to identity provider service.\n");
805 h->mq = GNUNET_CLIENT_connect (h->cfg,
812 for (op = h->op_head; NULL != op; op = op->next)
813 GNUNET_MQ_send_copy (h->mq,
819 * Connect to the identity provider service.
821 * @param cfg the configuration to use
822 * @return handle to use
824 struct GNUNET_IDENTITY_PROVIDER_Handle *
825 GNUNET_IDENTITY_PROVIDER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
827 struct GNUNET_IDENTITY_PROVIDER_Handle *h;
829 h = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Handle);
842 * Cancel an operation. Note that the operation MAY still
843 * be executed; this merely cancels the continuation; if the request
844 * was already transmitted, the service may still choose to complete
847 * @param op operation to cancel
850 GNUNET_IDENTITY_PROVIDER_cancel (struct GNUNET_IDENTITY_PROVIDER_Operation *op)
852 struct GNUNET_IDENTITY_PROVIDER_Handle *h = op->h;
854 GNUNET_CONTAINER_DLL_remove (h->op_head,
857 GNUNET_MQ_discard (op->env);
863 * Disconnect from service
865 * @param h handle to destroy
868 GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
870 GNUNET_assert (NULL != h);
873 GNUNET_MQ_destroy (h->mq);
876 if (NULL != h->reconnect_task)
878 GNUNET_SCHEDULER_cancel (h->reconnect_task);
879 h->reconnect_task = NULL;
881 GNUNET_assert (NULL == h->op_head);
886 * Store an attribute. If the attribute is already present,
887 * it is replaced with the new attribute.
889 * @param h handle to the identity provider
890 * @param pkey private key of the identity
891 * @param name the attribute name
892 * @param value the attribute value
893 * @param cont continuation to call when done
894 * @param cont_cls closure for @a cont
895 * @return handle to abort the request
897 struct GNUNET_IDENTITY_PROVIDER_Operation *
898 GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
899 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
900 const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr,
901 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cont,
904 struct GNUNET_IDENTITY_PROVIDER_Operation *op;
905 struct AttributeStoreMessage *sam;
908 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation);
912 op->r_id = h->r_id_gen++;
913 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
916 attr_len = attribute_serialize_get_size (attr);
917 op->env = GNUNET_MQ_msg_extra (sam,
919 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE);
920 sam->identity = *pkey;
921 sam->id = htonl (op->r_id);
923 attribute_serialize (attr,
926 sam->attr_len = htons (attr_len);
928 GNUNET_MQ_send_copy (h->mq,
936 * Create a new attribute.
938 * @param name the attribute name
939 * @param type the attribute type
940 * @param data the attribute value
941 * @param data_size the attribute value size
942 * @return the new attribute
944 struct GNUNET_IDENTITY_PROVIDER_Attribute *
945 GNUNET_IDENTITY_PROVIDER_attribute_new (const char* attr_name,
950 return attribute_new (attr_name, attr_type, data, data_size);
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 attr 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_PROVIDER_AttributeList *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 = 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 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 id 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 id 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 id 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 */