implement handle_validation_response logic
[oweals/gnunet.git] / src / include / gnunet_reclaim_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2016 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
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      Affero General Public License for more details.
14
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21 /**
22  * @author Martin Schanzenbach
23  *
24  * @file
25  * Identity provider service; implements identity provider for GNUnet
26  *
27  * @defgroup reclaim  Identity Provider service
28  * @{
29  */
30 #ifndef GNUNET_RECLAIM_SERVICE_H
31 #define GNUNET_RECLAIM_SERVICE_H
32
33 #ifdef __cplusplus
34 extern "C" {
35 #if 0 /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 #include "gnunet_reclaim_attribute_lib.h"
41 #include "gnunet_util_lib.h"
42
43 /**
44  * Version number of the re:claimID API.
45  */
46 #define GNUNET_RECLAIM_VERSION 0x00000000
47
48 /**
49  * Opaque handle to access the service.
50  */
51 struct GNUNET_RECLAIM_Handle;
52
53
54 /**
55  * Opaque handle for an operation at the re:claimID service.
56  */
57 struct GNUNET_RECLAIM_Operation;
58
59
60 /**
61  * The an authorization ticket. This ticket is meant to be transferred
62  * out of band the a relying party.
63  * The contents of a ticket must be protected and should be treated as a
64  * SHARED SECRET between user and relying party.
65  */
66 struct GNUNET_RECLAIM_Ticket
67 {
68   /**
69    * The ticket issuer (= the user)
70    */
71   struct GNUNET_CRYPTO_EcdsaPublicKey identity;
72
73   /**
74    * The ticket audience (= relying party)
75    */
76   struct GNUNET_CRYPTO_EcdsaPublicKey audience;
77
78   /**
79    * The ticket random (NBO)
80    */
81   uint64_t rnd;
82 };
83
84
85 /**
86  * Method called when a token has been issued.
87  * On success returns a ticket that can be given to the relying party to retrive
88  * the token
89  *
90  * @param cls closure
91  * @param ticket the ticket
92  */
93 typedef void (*GNUNET_RECLAIM_TicketCallback) (
94     void *cls, const struct GNUNET_RECLAIM_Ticket *ticket);
95
96
97 /**
98  * Continuation called to notify client about result of the
99  * operation.
100  *
101  * @param cls The callback closure
102  * @param success #GNUNET_SYSERR on failure
103  * @param emsg NULL on success, otherwise an error message
104  */
105 typedef void (*GNUNET_RECLAIM_ContinuationWithStatus) (void *cls,
106                                                        int32_t success,
107                                                        const char *emsg);
108
109
110 /**
111  * Callback used to notify the client of attribute results.
112  *
113  * @param cls The callback closure
114  * @param identity The identity authoritative over the attributes
115  * @param attr The attribute
116  */
117 typedef void (*GNUNET_RECLAIM_AttributeResult) (
118     void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
119     const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr);
120
121
122 /**
123  * Connect to the re:claimID service.
124  *
125  * @param cfg Configuration to contact the re:claimID service.
126  * @return handle to communicate with the service
127  */
128 struct GNUNET_RECLAIM_Handle *
129 GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
130
131
132 /**
133  * Store an attribute.  If the attribute is already present,
134  * it is replaced with the new attribute.
135  *
136  * @param h handle to the re:claimID service
137  * @param pkey Private key of the identity to add an attribute to
138  * @param attr The attribute
139  * @param exp_interval The relative expiration interval for the attribute
140  * @param cont Continuation to call when done
141  * @param cont_cls Closure for @a cont
142  * @return handle Used to to abort the request
143  */
144 struct GNUNET_RECLAIM_Operation *
145 GNUNET_RECLAIM_attribute_store (
146     struct GNUNET_RECLAIM_Handle *h,
147     const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
148     const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
149     const struct GNUNET_TIME_Relative *exp_interval,
150     GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
151
152
153 /**
154  * List all attributes for a local identity.
155  * This MUST lock the `struct GNUNET_RECLAIM_Handle`
156  * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
157  * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
158  * immediately, and then again after
159  * #GNUNET_RECLAIM_get_attributes_next() is invoked.
160  *
161  * On error (disconnect), @a error_cb will be invoked.
162  * On normal completion, @a finish_cb proc will be
163  * invoked.
164  *
165  * @param h Handle to the re:claimID service
166  * @param identity Identity to iterate over
167  * @param error_cb Function to call on error (i.e. disconnect),
168  *        the handle is afterwards invalid
169  * @param error_cb_cls Closure for @a error_cb
170  * @param proc Function to call on each attribute
171  * @param proc_cls Closure for @a proc
172  * @param finish_cb Function to call on completion
173  *        the handle is afterwards invalid
174  * @param finish_cb_cls Closure for @a finish_cb
175  * @return an iterator Handle to use for iteration
176  */
177 struct GNUNET_RECLAIM_AttributeIterator *
178 GNUNET_RECLAIM_get_attributes_start (
179     struct GNUNET_RECLAIM_Handle *h,
180     const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
181     GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
182     GNUNET_RECLAIM_AttributeResult proc, void *proc_cls,
183     GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
184
185
186 /**
187  * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start
188  * for the next record.
189  *
190  * @param it The iterator
191  */
192 void
193 GNUNET_RECLAIM_get_attributes_next (
194     struct GNUNET_RECLAIM_AttributeIterator *it);
195
196
197 /**
198  * Stops iteration and releases the handle for further calls. Must
199  * be called on any iteration that has not yet completed prior to calling
200  * #GNUNET_RECLAIM_disconnect.
201  *
202  * @param it the iterator
203  */
204 void
205 GNUNET_RECLAIM_get_attributes_stop (
206     struct GNUNET_RECLAIM_AttributeIterator *it);
207
208
209 /**
210  * Issues a ticket to a relying party. The identity may use
211  * GNUNET_RECLAIM_ticket_consume to consume the ticket
212  * and retrieve the attributes specified in the attribute list.
213  *
214  * @param h the identity provider to use
215  * @param iss the issuing identity (= the user)
216  * @param rp the subject of the ticket (= the relying party)
217  * @param attrs the attributes that the relying party is given access to
218  * @param cb the callback
219  * @param cb_cls the callback closure
220  * @return handle to abort the operation
221  */
222 struct GNUNET_RECLAIM_Operation *
223 GNUNET_RECLAIM_ticket_issue (
224     struct GNUNET_RECLAIM_Handle *h,
225     const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
226     const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
227     const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
228     GNUNET_RECLAIM_TicketCallback cb, void *cb_cls);
229
230 /**
231  * Revoked an issued ticket. The relying party will be unable to retrieve
232  * attributes. Other issued tickets remain unaffected.
233  * This includes tickets issued to other relying parties as well as to
234  * other tickets issued to the audience specified in this ticket.
235  *
236  * @param h the identity provider to use
237  * @param identity the issuing identity
238  * @param ticket the ticket to revoke
239  * @param cb the callback
240  * @param cb_cls the callback closure
241  * @return handle to abort the operation
242  */
243 struct GNUNET_RECLAIM_Operation *
244 GNUNET_RECLAIM_ticket_revoke (
245     struct GNUNET_RECLAIM_Handle *h,
246     const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
247     const struct GNUNET_RECLAIM_Ticket *ticket,
248     GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls);
249
250
251 /**
252  * Consumes an issued ticket. The ticket is used to retrieve identity
253  * information from the issuer
254  *
255  * @param h the identity provider to use
256  * @param identity the identity that is the subject of the issued ticket (the
257  * relying party)
258  * @param ticket the issued ticket to consume
259  * @param cb the callback to call
260  * @param cb_cls the callback closure
261  * @return handle to abort the operation
262  */
263 struct GNUNET_RECLAIM_Operation *
264 GNUNET_RECLAIM_ticket_consume (
265     struct GNUNET_RECLAIM_Handle *h,
266     const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
267     const struct GNUNET_RECLAIM_Ticket *ticket,
268     GNUNET_RECLAIM_AttributeResult cb, void *cb_cls);
269
270 /**
271  * Lists all tickets that have been issued to remote
272  * identites (relying parties)
273  *
274  * @param h the identity provider to use
275  * @param identity the issuing identity
276  * @param error_cb function to call on error (i.e. disconnect),
277  *        the handle is afterwards invalid
278  * @param error_cb_cls closure for @a error_cb
279  * @param proc function to call on each ticket; it
280  *        will be called repeatedly with a value (if available)
281  * @param proc_cls closure for @a proc
282  * @param finish_cb function to call on completion
283  *        the handle is afterwards invalid
284  * @param finish_cb_cls closure for @a finish_cb
285  * @return an iterator handle to use for iteration
286  */
287 struct GNUNET_RECLAIM_TicketIterator *
288 GNUNET_RECLAIM_ticket_iteration_start (
289     struct GNUNET_RECLAIM_Handle *h,
290     const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
291     GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
292     GNUNET_RECLAIM_TicketCallback proc, void *proc_cls,
293     GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
294
295
296 /**
297  * Calls the ticket processor specified in
298  * #GNUNET_RECLAIM_ticket_iteration_start for the next record.
299  *
300  * @param it the iterator
301  */
302 void
303 GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it);
304
305 /**
306  * Stops iteration and releases the handle for further calls.  Must
307  * be called on any iteration that has not yet completed prior to calling
308  * #GNUNET_RECLAIM_disconnect.
309  *
310  * @param it the iterator
311  */
312 void
313 GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it);
314
315 /**
316  * Disconnect from identity provider service.
317  *
318  * @param h identity provider service to disconnect
319  */
320 void
321 GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h);
322
323
324 /**
325  * Cancel an identity provider operation.  Note that the operation MAY still
326  * be executed; this merely cancels the continuation; if the request
327  * was already transmitted, the service may still choose to complete
328  * the operation.
329  *
330  * @param op operation to cancel
331  */
332 void
333 GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op);
334
335 #if 0 /* keep Emacsens' auto-indent happy */
336 {
337 #endif
338 #ifdef __cplusplus
339 }
340 #endif
341
342
343 /* ifndef GNUNET_RECLAIM_SERVICE_H */
344 #endif
345
346 /** @} */ /* end of group identity */
347
348 /* end of gnunet_reclaim_service.h */