error handling
[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  * reclaim service; implements identity and personal data sharing
26  * for GNUnet
27  *
28  * @defgroup reclaim service
29  * @{
30  */
31 #ifndef GNUNET_RECLAIM_SERVICE_H
32 #define GNUNET_RECLAIM_SERVICE_H
33
34 #ifdef __cplusplus
35 extern "C" {
36 #if 0 /* keep Emacsens' auto-indent happy */
37 }
38 #endif
39 #endif
40
41 #include "gnunet_reclaim_lib.h"
42 #include "gnunet_util_lib.h"
43
44 /**
45  * Version number of the re:claimID API.
46  */
47 #define GNUNET_RECLAIM_VERSION 0x00000001
48
49 /**
50  * Opaque handle to access the service.
51  */
52 struct GNUNET_RECLAIM_Handle;
53
54
55 /**
56  * Opaque handle for an operation at the re:claimID service.
57  */
58 struct GNUNET_RECLAIM_Operation;
59
60
61 /**
62  * The authorization ticket. This ticket is meant to be transferred
63  * out of band to a relying party.
64  * The contents of a ticket must be protected and should be treated as a
65  * shared secret between user and relying party.
66  */
67 struct GNUNET_RECLAIM_Ticket
68 {
69   /**
70    * The ticket issuer (= the user)
71    */
72   struct GNUNET_CRYPTO_EcdsaPublicKey identity;
73
74   /**
75    * The ticket audience (= relying party)
76    */
77   struct GNUNET_CRYPTO_EcdsaPublicKey audience;
78
79   /**
80    * The ticket random identifier
81    */
82   struct GNUNET_RECLAIM_Identifier rnd;
83 };
84
85
86 /**
87  * Method called when a token has been issued.
88  * On success returns a ticket that can be given to a relying party
89  * in order for it retrive identity attributes
90  *
91  * @param cls closure
92  * @param ticket the ticket
93  */
94 typedef void (*GNUNET_RECLAIM_TicketCallback) (
95   void *cls, const struct GNUNET_RECLAIM_Ticket *ticket);
96
97
98 /**
99  * Continuation called to notify client about result of the
100  * operation.
101  *
102  * @param cls The callback closure
103  * @param success #GNUNET_SYSERR on failure
104  * @param emsg NULL on success, otherwise an error message
105  */
106 typedef void (*GNUNET_RECLAIM_ContinuationWithStatus) (void *cls,
107                                                        int32_t success,
108                                                        const char *emsg);
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  * @param attestation The attestation for the attribute (may be NULL)
117  */
118 typedef void (*GNUNET_RECLAIM_AttributeResult) (
119   void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
120   const struct GNUNET_RECLAIM_Attribute *attr);
121
122 /**
123  * Callback used to notify the client of attribute results.
124  *
125  * @param cls The callback closure
126  * @param identity The identity authoritative over the attributes
127  * @param attr The attribute
128  * @param attestation The attestation for the attribute (may be NULL)
129  */
130 typedef void (*GNUNET_RECLAIM_AttributeTicketResult) (
131   void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
132   const struct GNUNET_RECLAIM_Attribute *attr,
133   const struct GNUNET_RECLAIM_Attestation *attestation);
134
135
136 /**
137  * Callback used to notify the client of attestation results.
138  *
139  * @param cls The callback closure
140  * @param identity The identity authoritative over the attributes
141  * @param attestation The attestation
142  * @param attributes the parsed attributes
143  */
144 typedef void (*GNUNET_RECLAIM_AttestationResult) (
145   void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
146   const struct GNUNET_RECLAIM_Attestation *attestation);
147
148
149 /**
150  * Connect to the re:claimID service.
151  *
152  * @param cfg Configuration to contact the re:claimID service.
153  * @return handle to communicate with the service
154  */
155 struct GNUNET_RECLAIM_Handle *
156 GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
157
158
159 /**
160  * Store an attribute.  If the attribute is already present,
161  * it is replaced with the new attribute.
162  *
163  * @param h handle to the reclaim service
164  * @param pkey Private key of the identity to add an attribute to
165  * @param attr The attribute
166  * @param exp_interval The relative expiration interval for the attribute
167  * @param cont Continuation to call when done
168  * @param cont_cls Closure for @a cont
169  * @return handle Used to to abort the request
170  */
171 struct GNUNET_RECLAIM_Operation *
172 GNUNET_RECLAIM_attribute_store (
173   struct GNUNET_RECLAIM_Handle *h,
174   const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
175   const struct GNUNET_RECLAIM_Attribute *attr,
176   const struct GNUNET_TIME_Relative *exp_interval,
177   GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
178
179
180 /**
181    * Store an attestation.  If the attestation is already present,
182    * it is replaced with the new attestation.
183    *
184    * @param h handle to the re:claimID service
185    * @param pkey private key of the identity
186    * @param attr the attestation value
187    * @param exp_interval the relative expiration interval for the attestation
188    * @param cont continuation to call when done
189    * @param cont_cls closure for @a cont
190    * @return handle to abort the request
191    */
192 struct GNUNET_RECLAIM_Operation *
193 GNUNET_RECLAIM_attestation_store (
194   struct GNUNET_RECLAIM_Handle *h,
195   const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
196   const struct GNUNET_RECLAIM_Attestation *attestation,
197   const struct GNUNET_TIME_Relative *exp_interval,
198   GNUNET_RECLAIM_ContinuationWithStatus cont,
199   void *cont_cls);
200
201
202 /**
203  * Delete an attribute. Tickets used to share this attribute are updated
204  * accordingly.
205  *
206  * @param h handle to the re:claimID service
207  * @param pkey Private key of the identity to add an attribute to
208  * @param attr The attribute
209  * @param cont Continuation to call when done
210  * @param cont_cls Closure for @a cont
211  * @return handle Used to to abort the request
212  */
213 struct GNUNET_RECLAIM_Operation *
214 GNUNET_RECLAIM_attribute_delete (
215   struct GNUNET_RECLAIM_Handle *h,
216   const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
217   const struct GNUNET_RECLAIM_Attribute *attr,
218   GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
219
220 /**
221  * Delete an attestation. Tickets used to share this attestation are updated
222  * accordingly.
223  *
224  * @param h handle to the re:claimID service
225  * @param pkey Private key of the identity to add an attribute to
226  * @param attr The attestation
227  * @param cont Continuation to call when done
228  * @param cont_cls Closure for @a cont
229  * @return handle Used to to abort the request
230  */
231 struct GNUNET_RECLAIM_Operation *
232 GNUNET_RECLAIM_attestation_delete (
233   struct GNUNET_RECLAIM_Handle *h,
234   const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
235   const struct GNUNET_RECLAIM_Attestation *attr,
236   GNUNET_RECLAIM_ContinuationWithStatus cont,
237   void *cont_cls);
238
239 /**
240  * List all attributes for a local identity.
241  * This MUST lock the `struct GNUNET_RECLAIM_Handle`
242  * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
243  * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
244  * immediately, and then again after
245  * #GNUNET_RECLAIM_get_attributes_next() is invoked.
246  *
247  * On error (disconnect), @a error_cb will be invoked.
248  * On normal completion, @a finish_cb proc will be
249  * invoked.
250  *
251  * @param h Handle to the re:claimID service
252  * @param identity Identity to iterate over
253  * @param error_cb Function to call on error (i.e. disconnect),
254  *        the handle is afterwards invalid
255  * @param error_cb_cls Closure for @a error_cb
256  * @param proc Function to call on each attribute
257  * @param proc_cls Closure for @a proc
258  * @param finish_cb Function to call on completion
259  *        the handle is afterwards invalid
260  * @param finish_cb_cls Closure for @a finish_cb
261  * @return an iterator Handle to use for iteration
262  */
263 struct GNUNET_RECLAIM_AttributeIterator *
264 GNUNET_RECLAIM_get_attributes_start (
265   struct GNUNET_RECLAIM_Handle *h,
266   const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
267   GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
268   GNUNET_RECLAIM_AttributeResult proc, void *proc_cls,
269   GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
270
271
272 /**
273  * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start
274  * for the next record.
275  *
276  * @param it The iterator
277  */
278 void
279 GNUNET_RECLAIM_get_attributes_next (
280   struct GNUNET_RECLAIM_AttributeIterator *it);
281
282
283 /**
284  * Stops iteration and releases the handle for further calls. Must
285  * be called on any iteration that has not yet completed prior to calling
286  * #GNUNET_RECLAIM_disconnect.
287  *
288  * @param it the iterator
289  */
290 void
291 GNUNET_RECLAIM_get_attributes_stop (
292   struct GNUNET_RECLAIM_AttributeIterator *it);
293
294
295 /**
296  * List all attestations for a local identity.
297  * This MUST lock the `struct GNUNET_RECLAIM_Handle`
298  * for any other calls than #GNUNET_RECLAIM_get_attestations_next() and
299  * #GNUNET_RECLAIM_get_attestations_stop. @a proc will be called once
300  * immediately, and then again after
301  * #GNUNET_RECLAIM_get_attestations_next() is invoked.
302  *
303  * On error (disconnect), @a error_cb will be invoked.
304  * On normal completion, @a finish_cb proc will be
305  * invoked.
306  *
307  * @param h Handle to the re:claimID service
308  * @param identity Identity to iterate over
309  * @param error_cb Function to call on error (i.e. disconnect),
310  *        the handle is afterwards invalid
311  * @param error_cb_cls Closure for @a error_cb
312  * @param proc Function to call on each attestation
313  * @param proc_cls Closure for @a proc
314  * @param finish_cb Function to call on completion
315  *        the handle is afterwards invalid
316  * @param finish_cb_cls Closure for @a finish_cb
317  * @return an iterator Handle to use for iteration
318  */
319 struct GNUNET_RECLAIM_AttestationIterator *
320 GNUNET_RECLAIM_get_attestations_start (
321   struct GNUNET_RECLAIM_Handle *h,
322   const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
323   GNUNET_SCHEDULER_TaskCallback error_cb,
324   void *error_cb_cls,
325   GNUNET_RECLAIM_AttestationResult proc,
326   void *proc_cls,
327   GNUNET_SCHEDULER_TaskCallback finish_cb,
328   void *finish_cb_cls);
329
330
331 /**
332  * Calls the record processor specified in #GNUNET_RECLAIM_get_attestation_start
333  * for the next record.
334  *
335  * @param it the iterator
336  */
337 void
338 GNUNET_RECLAIM_get_attestations_next (struct GNUNET_RECLAIM_AttestationIterator *ait);
339
340
341 /**
342  * Stops iteration and releases the handle for further calls. Must
343  * be called on any iteration that has not yet completed prior to calling
344  * #GNUNET_RECLAIM_disconnect.
345  *
346  * @param it the iterator
347  */
348 void
349 GNUNET_RECLAIM_get_attestations_stop (struct GNUNET_RECLAIM_AttestationIterator *ait);
350
351
352 /**
353  * Issues a ticket to a relying party. The identity may use
354  * GNUNET_RECLAIM_ticket_consume to consume the ticket
355  * and retrieve the attributes specified in the attribute list.
356  *
357  * @param h the identity provider to use
358  * @param iss the issuing identity (= the user)
359  * @param rp the subject of the ticket (= the relying party)
360  * @param attrs the attributes that the relying party is given access to
361  * @param cb the callback
362  * @param cb_cls the callback closure
363  * @return handle to abort the operation
364  */
365 struct GNUNET_RECLAIM_Operation *
366 GNUNET_RECLAIM_ticket_issue (
367   struct GNUNET_RECLAIM_Handle *h,
368   const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
369   const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
370   const struct GNUNET_RECLAIM_AttributeList *attrs,
371   GNUNET_RECLAIM_TicketCallback cb, void *cb_cls);
372
373
374 /**
375  * Revoked an issued ticket. The relying party will be unable to retrieve
376  * attributes. Other issued tickets remain unaffected.
377  * This includes tickets issued to other relying parties as well as to
378  * other tickets issued to the audience specified in this ticket.
379  *
380  * @param h the identity provider to use
381  * @param identity the issuing identity
382  * @param ticket the ticket to revoke
383  * @param cb the callback
384  * @param cb_cls the callback closure
385  * @return handle to abort the operation
386  */
387 struct GNUNET_RECLAIM_Operation *
388 GNUNET_RECLAIM_ticket_revoke (
389   struct GNUNET_RECLAIM_Handle *h,
390   const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
391   const struct GNUNET_RECLAIM_Ticket *ticket,
392   GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls);
393
394
395 /**
396  * Consumes an issued ticket. The ticket is used to retrieve identity
397  * information from the issuer
398  *
399  * @param h the identity provider to use
400  * @param identity the identity that is the subject of the issued ticket (the
401  * relying party)
402  * @param ticket the issued ticket to consume
403  * @param cb the callback to call
404  * @param cb_cls the callback closure
405  * @return handle to abort the operation
406  */
407 struct GNUNET_RECLAIM_Operation *
408 GNUNET_RECLAIM_ticket_consume (
409   struct GNUNET_RECLAIM_Handle *h,
410   const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
411   const struct GNUNET_RECLAIM_Ticket *ticket,
412   GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls);
413
414
415 /**
416  * Lists all tickets that have been issued to remote
417  * identites (relying parties)
418  *
419  * @param h the identity provider to use
420  * @param identity the issuing identity
421  * @param error_cb function to call on error (i.e. disconnect),
422  *        the handle is afterwards invalid
423  * @param error_cb_cls closure for @a error_cb
424  * @param proc function to call on each ticket; it
425  *        will be called repeatedly with a value (if available)
426  * @param proc_cls closure for @a proc
427  * @param finish_cb function to call on completion
428  *        the handle is afterwards invalid
429  * @param finish_cb_cls closure for @a finish_cb
430  * @return an iterator handle to use for iteration
431  */
432 struct GNUNET_RECLAIM_TicketIterator *
433 GNUNET_RECLAIM_ticket_iteration_start (
434   struct GNUNET_RECLAIM_Handle *h,
435   const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
436   GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
437   GNUNET_RECLAIM_TicketCallback proc, void *proc_cls,
438   GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
439
440
441 /**
442  * Calls the ticket processor specified in
443  * #GNUNET_RECLAIM_ticket_iteration_start for the next record.
444  *
445  * @param it the iterator
446  */
447 void
448 GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it);
449
450
451 /**
452  * Stops iteration and releases the handle for further calls.  Must
453  * be called on any iteration that has not yet completed prior to calling
454  * #GNUNET_RECLAIM_disconnect.
455  *
456  * @param it the iterator
457  */
458 void
459 GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it);
460
461
462 /**
463  * Disconnect from identity provider service.
464  *
465  * @param h identity provider service to disconnect
466  */
467 void
468 GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h);
469
470
471 /**
472  * Cancel an identity provider operation.  Note that the operation MAY still
473  * be executed; this merely cancels the continuation; if the request
474  * was already transmitted, the service may still choose to complete
475  * the operation.
476  *
477  * @param op operation to cancel
478  */
479 void
480 GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op);
481
482
483 #if 0 /* keep Emacsens' auto-indent happy */
484 {
485 #endif
486 #ifdef __cplusplus
487 }
488 #endif
489
490
491 /* ifndef GNUNET_RECLAIM_SERVICE_H */
492 #endif
493
494 /** @} */ /* end of group reclaim */
495
496 /* end of gnunet_reclaim_service.h */