add attestation API
[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_attribute_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 attr The attribute
142  */
143 typedef void (*GNUNET_RECLAIM_AttestationResult) (
144   void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
145   const struct GNUNET_RECLAIM_Attestation *attestation);
146
147
148 /**
149  * Connect to the re:claimID service.
150  *
151  * @param cfg Configuration to contact the re:claimID service.
152  * @return handle to communicate with the service
153  */
154 struct GNUNET_RECLAIM_Handle *
155 GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
156
157
158 /**
159  * Store an attribute.  If the attribute is already present,
160  * it is replaced with the new attribute.
161  *
162  * @param h handle to the reclaim service
163  * @param pkey Private key of the identity to add an attribute to
164  * @param attr The attribute
165  * @param exp_interval The relative expiration interval for the attribute
166  * @param cont Continuation to call when done
167  * @param cont_cls Closure for @a cont
168  * @return handle Used to to abort the request
169  */
170 struct GNUNET_RECLAIM_Operation *
171 GNUNET_RECLAIM_attribute_store (
172   struct GNUNET_RECLAIM_Handle *h,
173   const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
174   const struct GNUNET_RECLAIM_Attribute *attr,
175   const struct GNUNET_TIME_Relative *exp_interval,
176   GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
177
178
179 /**
180    * Store an attestation.  If the attestation is already present,
181    * it is replaced with the new attestation.
182    *
183    * @param h handle to the re:claimID service
184    * @param pkey private key of the identity
185    * @param attr the attestation value
186    * @param exp_interval the relative expiration interval for the attestation
187    * @param cont continuation to call when done
188    * @param cont_cls closure for @a cont
189    * @return handle to abort the request
190    */
191 struct GNUNET_RECLAIM_Operation *
192 GNUNET_RECLAIM_attestation_store (
193   struct GNUNET_RECLAIM_Handle *h,
194   const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
195   const struct GNUNET_RECLAIM_Attestation *attestation,
196   const struct GNUNET_TIME_Relative *exp_interval,
197   GNUNET_RECLAIM_ContinuationWithStatus cont,
198   void *cont_cls);
199
200
201 /**
202  * Delete an attribute. Tickets used to share this attribute are updated
203  * accordingly.
204  *
205  * @param h handle to the re:claimID service
206  * @param pkey Private key of the identity to add an attribute to
207  * @param attr The attribute
208  * @param cont Continuation to call when done
209  * @param cont_cls Closure for @a cont
210  * @return handle Used to to abort the request
211  */
212 struct GNUNET_RECLAIM_Operation *
213 GNUNET_RECLAIM_attribute_delete (
214   struct GNUNET_RECLAIM_Handle *h,
215   const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
216   const struct GNUNET_RECLAIM_Attribute *attr,
217   GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
218
219 /**
220  * Delete an attestation. Tickets used to share this attestation are updated
221  * accordingly.
222  *
223  * @param h handle to the re:claimID service
224  * @param pkey Private key of the identity to add an attribute to
225  * @param attr The attestation
226  * @param cont Continuation to call when done
227  * @param cont_cls Closure for @a cont
228  * @return handle Used to to abort the request
229  */
230 struct GNUNET_RECLAIM_Operation *
231 GNUNET_RECLAIM_attestation_delete (
232   struct GNUNET_RECLAIM_Handle *h,
233   const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
234   const struct GNUNET_RECLAIM_Attestation *attr,
235   GNUNET_RECLAIM_ContinuationWithStatus cont,
236   void *cont_cls);
237
238 /**
239  * List all attributes for a local identity.
240  * This MUST lock the `struct GNUNET_RECLAIM_Handle`
241  * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
242  * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
243  * immediately, and then again after
244  * #GNUNET_RECLAIM_get_attributes_next() is invoked.
245  *
246  * On error (disconnect), @a error_cb will be invoked.
247  * On normal completion, @a finish_cb proc will be
248  * invoked.
249  *
250  * @param h Handle to the re:claimID service
251  * @param identity Identity to iterate over
252  * @param error_cb Function to call on error (i.e. disconnect),
253  *        the handle is afterwards invalid
254  * @param error_cb_cls Closure for @a error_cb
255  * @param proc Function to call on each attribute
256  * @param proc_cls Closure for @a proc
257  * @param finish_cb Function to call on completion
258  *        the handle is afterwards invalid
259  * @param finish_cb_cls Closure for @a finish_cb
260  * @return an iterator Handle to use for iteration
261  */
262 struct GNUNET_RECLAIM_AttributeIterator *
263 GNUNET_RECLAIM_get_attributes_start (
264   struct GNUNET_RECLAIM_Handle *h,
265   const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
266   GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
267   GNUNET_RECLAIM_AttributeResult proc, void *proc_cls,
268   GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
269
270
271 /**
272  * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start
273  * for the next record.
274  *
275  * @param it The iterator
276  */
277 void
278 GNUNET_RECLAIM_get_attributes_next (
279   struct GNUNET_RECLAIM_AttributeIterator *it);
280
281
282 /**
283  * Stops iteration and releases the handle for further calls. Must
284  * be called on any iteration that has not yet completed prior to calling
285  * #GNUNET_RECLAIM_disconnect.
286  *
287  * @param it the iterator
288  */
289 void
290 GNUNET_RECLAIM_get_attributes_stop (
291   struct GNUNET_RECLAIM_AttributeIterator *it);
292
293
294 /**
295  * List all attestations for a local identity.
296  * This MUST lock the `struct GNUNET_RECLAIM_Handle`
297  * for any other calls than #GNUNET_RECLAIM_get_attestations_next() and
298  * #GNUNET_RECLAIM_get_attestations_stop. @a proc will be called once
299  * immediately, and then again after
300  * #GNUNET_RECLAIM_get_attestations_next() is invoked.
301  *
302  * On error (disconnect), @a error_cb will be invoked.
303  * On normal completion, @a finish_cb proc will be
304  * invoked.
305  *
306  * @param h Handle to the re:claimID service
307  * @param identity Identity to iterate over
308  * @param error_cb Function to call on error (i.e. disconnect),
309  *        the handle is afterwards invalid
310  * @param error_cb_cls Closure for @a error_cb
311  * @param proc Function to call on each attestation
312  * @param proc_cls Closure for @a proc
313  * @param finish_cb Function to call on completion
314  *        the handle is afterwards invalid
315  * @param finish_cb_cls Closure for @a finish_cb
316  * @return an iterator Handle to use for iteration
317  */
318 struct GNUNET_RECLAIM_AttestationIterator *
319 GNUNET_RECLAIM_get_attestations_start (
320   struct GNUNET_RECLAIM_Handle *h,
321   const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
322   GNUNET_SCHEDULER_TaskCallback error_cb,
323   void *error_cb_cls,
324   GNUNET_RECLAIM_AttestationResult proc,
325   void *proc_cls,
326   GNUNET_SCHEDULER_TaskCallback finish_cb,
327   void *finish_cb_cls);
328
329
330 /**
331  * Calls the record processor specified in #GNUNET_RECLAIM_get_attestation_start
332  * for the next record.
333  *
334  * @param it the iterator
335  */
336 void
337 GNUNET_RECLAIM_get_attestations_next (struct GNUNET_RECLAIM_AttestationIterator *ait);
338
339
340 /**
341  * Stops iteration and releases the handle for further calls. Must
342  * be called on any iteration that has not yet completed prior to calling
343  * #GNUNET_RECLAIM_disconnect.
344  *
345  * @param it the iterator
346  */
347 void
348 GNUNET_RECLAIM_get_attestations_stop (struct GNUNET_RECLAIM_AttestationIterator *ait);
349
350
351 /**
352  * Issues a ticket to a relying party. The identity may use
353  * GNUNET_RECLAIM_ticket_consume to consume the ticket
354  * and retrieve the attributes specified in the attribute list.
355  *
356  * @param h the identity provider to use
357  * @param iss the issuing identity (= the user)
358  * @param rp the subject of the ticket (= the relying party)
359  * @param attrs the attributes that the relying party is given access to
360  * @param cb the callback
361  * @param cb_cls the callback closure
362  * @return handle to abort the operation
363  */
364 struct GNUNET_RECLAIM_Operation *
365 GNUNET_RECLAIM_ticket_issue (
366   struct GNUNET_RECLAIM_Handle *h,
367   const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
368   const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
369   const struct GNUNET_RECLAIM_AttributeList *attrs,
370   GNUNET_RECLAIM_TicketCallback cb, void *cb_cls);
371
372
373 /**
374  * Revoked an issued ticket. The relying party will be unable to retrieve
375  * attributes. Other issued tickets remain unaffected.
376  * This includes tickets issued to other relying parties as well as to
377  * other tickets issued to the audience specified in this ticket.
378  *
379  * @param h the identity provider to use
380  * @param identity the issuing identity
381  * @param ticket the ticket to revoke
382  * @param cb the callback
383  * @param cb_cls the callback closure
384  * @return handle to abort the operation
385  */
386 struct GNUNET_RECLAIM_Operation *
387 GNUNET_RECLAIM_ticket_revoke (
388   struct GNUNET_RECLAIM_Handle *h,
389   const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
390   const struct GNUNET_RECLAIM_Ticket *ticket,
391   GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls);
392
393
394 /**
395  * Consumes an issued ticket. The ticket is used to retrieve identity
396  * information from the issuer
397  *
398  * @param h the identity provider to use
399  * @param identity the identity that is the subject of the issued ticket (the
400  * relying party)
401  * @param ticket the issued ticket to consume
402  * @param cb the callback to call
403  * @param cb_cls the callback closure
404  * @return handle to abort the operation
405  */
406 struct GNUNET_RECLAIM_Operation *
407 GNUNET_RECLAIM_ticket_consume (
408   struct GNUNET_RECLAIM_Handle *h,
409   const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
410   const struct GNUNET_RECLAIM_Ticket *ticket,
411   GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls);
412
413
414 /**
415  * Lists all tickets that have been issued to remote
416  * identites (relying parties)
417  *
418  * @param h the identity provider to use
419  * @param identity the issuing identity
420  * @param error_cb function to call on error (i.e. disconnect),
421  *        the handle is afterwards invalid
422  * @param error_cb_cls closure for @a error_cb
423  * @param proc function to call on each ticket; it
424  *        will be called repeatedly with a value (if available)
425  * @param proc_cls closure for @a proc
426  * @param finish_cb function to call on completion
427  *        the handle is afterwards invalid
428  * @param finish_cb_cls closure for @a finish_cb
429  * @return an iterator handle to use for iteration
430  */
431 struct GNUNET_RECLAIM_TicketIterator *
432 GNUNET_RECLAIM_ticket_iteration_start (
433   struct GNUNET_RECLAIM_Handle *h,
434   const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
435   GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
436   GNUNET_RECLAIM_TicketCallback proc, void *proc_cls,
437   GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
438
439
440 /**
441  * Calls the ticket processor specified in
442  * #GNUNET_RECLAIM_ticket_iteration_start for the next record.
443  *
444  * @param it the iterator
445  */
446 void
447 GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it);
448
449
450 /**
451  * Stops iteration and releases the handle for further calls.  Must
452  * be called on any iteration that has not yet completed prior to calling
453  * #GNUNET_RECLAIM_disconnect.
454  *
455  * @param it the iterator
456  */
457 void
458 GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it);
459
460
461 /**
462  * Disconnect from identity provider service.
463  *
464  * @param h identity provider service to disconnect
465  */
466 void
467 GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h);
468
469
470 /**
471  * Cancel an identity provider operation.  Note that the operation MAY still
472  * be executed; this merely cancels the continuation; if the request
473  * was already transmitted, the service may still choose to complete
474  * the operation.
475  *
476  * @param op operation to cancel
477  */
478 void
479 GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op);
480
481
482 #if 0 /* keep Emacsens' auto-indent happy */
483 {
484 #endif
485 #ifdef __cplusplus
486 }
487 #endif
488
489
490 /* ifndef GNUNET_RECLAIM_SERVICE_H */
491 #endif
492
493 /** @} */ /* end of group reclaim */
494
495 /* end of gnunet_reclaim_service.h */