-add api impl for revocation
[oweals/gnunet.git] / src / include / gnunet_identity_provider_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
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
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.
19 */
20
21 /**
22  * @author Martin Schanzenbach
23  *
24  * @file
25  * Identity provider service; implements identity provider for GNUnet
26  *
27  * @defgroup identity-provider  Identity Provider service
28  * @{
29  */
30 #ifndef GNUNET_IDENTITY_PROVIDER_SERVICE_H
31 #define GNUNET_IDENTITY_PROVIDER_SERVICE_H
32
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #if 0                           /* keep Emacsens' auto-indent happy */
37 }
38 #endif
39 #endif
40
41 #include "gnunet_util_lib.h"
42
43
44 /**
45  * Version number of GNUnet Identity Provider API.
46  */
47 #define GNUNET_IDENTITY_PROVIDER_VERSION 0x00000000
48
49 /**
50  * Handle to access the identity service.
51  */
52 struct GNUNET_IDENTITY_PROVIDER_Handle;
53
54 /**
55  * Handle for a token.
56  */
57 struct GNUNET_IDENTITY_PROVIDER_Token;
58
59 /**
60  * The ticket
61  */
62 struct GNUNET_IDENTITY_PROVIDER_Ticket
63 {
64   /**
65    * The ticket issuer
66    */
67   struct GNUNET_CRYPTO_EcdsaPublicKey identity;
68
69   /**
70    * The ticket audience
71    */
72   struct GNUNET_CRYPTO_EcdsaPublicKey audience;
73
74   /**
75    * The ticket random (NBO)
76    */
77   uint64_t rnd;
78 };
79
80 /**
81  * Handle for an operation with the identity provider service.
82  */
83 struct GNUNET_IDENTITY_PROVIDER_Operation;
84
85 /**
86  * Flags that can be set for an attribute.
87  */
88 enum GNUNET_IDENTITY_PROVIDER_AttributeType
89 {
90
91   /**
92    * No value attribute.
93    */
94   GNUNET_IDENTITY_PROVIDER_AT_NULL = 0,
95
96   /**
97    * String attribute.
98    */
99   GNUNET_IDENTITY_PROVIDER_AT_STRING = 1,
100
101 };
102
103
104
105 /**
106  * An attribute.
107  */
108 struct GNUNET_IDENTITY_PROVIDER_Attribute
109 {
110
111   /**
112    * Type of Attribute.
113    */
114   uint32_t attribute_type;
115
116   /**
117    * Number of bytes in @e data.
118    */
119   size_t data_size;
120
121   /**
122    * The name of the attribute. Note "name" must never be individually
123    * free'd
124    */
125   const char* name;
126
127   /**
128    * Binary value stored as attribute value.  Note: "data" must never
129    * be individually 'malloc'ed, but instead always points into some
130    * existing data area.
131    */
132   const void *data;
133
134 };
135
136 struct GNUNET_IDENTITY_PROVIDER_AttributeList
137 {
138   /**
139    * List head
140    */
141   struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *list_head;
142
143   /**
144    * List tail
145    */
146   struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *list_tail;
147 };
148
149 struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry
150 {
151   /**
152    * DLL
153    */
154   struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *prev;
155
156   /**
157    * DLL
158    */
159   struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *next;
160
161   /**
162    * The attribute
163    */
164   struct GNUNET_IDENTITY_PROVIDER_Attribute *attribute;
165 };
166
167 /**
168  * Connect to the identity provider service.
169  *
170  * @param cfg Configuration to contact the identity provider service.
171  * @return handle to communicate with identity provider service
172  */
173 struct GNUNET_IDENTITY_PROVIDER_Handle *
174 GNUNET_IDENTITY_PROVIDER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
175
176 /**
177  * Continuation called to notify client about result of the
178  * operation.
179  *
180  * @param cls closure
181  * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
182  *                #GNUNET_NO if content was already there or not found
183  *                #GNUNET_YES (or other positive value) on success
184  * @param emsg NULL on success, otherwise an error message
185  */
186 typedef void
187 (*GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus) (void *cls,
188                                             int32_t success,
189                                             const char *emsg);
190
191
192 /**
193  * Store an attribute.  If the attribute is already present,
194  * it is replaced with the new attribute.
195  *
196  * @param h handle to the identity provider
197  * @param pkey private key of the identity
198  * @param attr the attribute
199  * @param cont continuation to call when done
200  * @param cont_cls closure for @a cont
201  * @return handle to abort the request
202  */
203 struct GNUNET_IDENTITY_PROVIDER_Operation *
204 GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
205                                           const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
206                                           const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr,
207                                           GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cont,
208                                           void *cont_cls);
209
210
211 /**
212  * Create a new attribute.
213  *
214  * @param name the attribute name
215  * @param type the attribute type
216  * @param data the attribute value
217  * @param data_size the attribute value size
218  * @return the new attribute
219  */
220 struct GNUNET_IDENTITY_PROVIDER_Attribute *
221 GNUNET_IDENTITY_PROVIDER_attribute_new (const char* attr_name,
222                                         uint32_t attr_type,
223                                         const void* data,
224                                         size_t data_size);
225
226 /**
227  * Process an attribute that was stored in the idp.
228  *
229  * @param cls closure
230  * @param attr the attribute
231  */
232 typedef void
233 (*GNUNET_IDENTITY_PROVIDER_AttributeResult) (void *cls,
234                                    const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
235                                    const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr);
236
237
238
239 /**
240  * List all attributes for a local identity. 
241  * This MUST lock the `struct GNUNET_IDENTITY_PROVIDER_Handle`
242  * for any other calls than #GNUNET_IDENTITY_PROVIDER_get_attributes_next() and
243  * #GNUNET_IDENTITY_PROVIDER_get_attributes_stop. @a proc will be called once
244  * immediately, and then again after
245  * #GNUNET_IDENTITY_PROVIDER_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 idp
252  * @param identity identity to access
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; it
257  *        will be called repeatedly with a value (if available)
258  * @param proc_cls closure for @a proc
259  * @param finish_cb function to call on completion
260  *        the handle is afterwards invalid
261  * @param finish_cb_cls closure for @a finish_cb
262  * @return an iterator handle to use for iteration
263  */
264 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *
265 GNUNET_IDENTITY_PROVIDER_get_attributes_start (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
266                                                const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
267                                                GNUNET_SCHEDULER_TaskCallback error_cb,
268                                                void *error_cb_cls,
269                                                GNUNET_IDENTITY_PROVIDER_AttributeResult proc,
270                                                void *proc_cls,
271                                                GNUNET_SCHEDULER_TaskCallback finish_cb,
272                                                void *finish_cb_cls);
273
274
275 /**
276  * Calls the record processor specified in #GNUNET_IDENTITY_PROVIDER_get_attributes_start
277  * for the next record.
278  *
279  * @param it the iterator
280  */
281 void
282 GNUNET_IDENTITY_PROVIDER_get_attributes_next (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it);
283
284
285 /**
286  * Stops iteration and releases the idp handle for further calls.  Must
287  * be called on any iteration that has not yet completed prior to calling
288  * #GNUNET_IDENTITY_PROVIDER_disconnect.
289  *
290  * @param it the iterator
291  */
292 void
293 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it);
294
295
296 /**
297  * Method called when a token has been issued.
298  * On success returns a ticket that can be given to the audience to retrive the
299  * token
300  *
301  * @param cls closure
302  * @param ticket the ticket
303  */
304 typedef void
305 (*GNUNET_IDENTITY_PROVIDER_TicketCallback)(void *cls,
306                             const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket);
307
308 /**
309  * Issues a ticket to another identity. The identity may use
310  * @GNUNET_IDENTITY_PROVIDER_authorization_ticket_consume to consume the ticket
311  * and retrieve the attributes specified in the AttributeList.
312  *
313  * @param id the identity provider to use
314  * @param iss the issuing identity
315  * @param rp the subject of the ticket (the relying party)
316  * @param attr the attributes that the relying party is given access to
317  * @param cb the callback
318  * @param cb_cls the callback closure
319  * @return handle to abort the operation
320  */
321 struct GNUNET_IDENTITY_PROVIDER_Operation *
322 GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *id,
323                                        const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
324                                        const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
325                                        const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs,
326                                        GNUNET_IDENTITY_PROVIDER_TicketCallback cb,
327                                        void *cb_cls);
328
329 /**
330  * Revoked an issued ticket. The relying party will be unable to retrieve
331  * updated attributes.
332  *
333  * @param id the identity provider to use
334  * @param identity the issuing identity
335  * @param ticket the ticket to revoke
336  * @param cb the callback
337  * @param cb_cls the callback closure
338  * @return handle to abort the operation
339  */
340 struct GNUNET_IDENTITY_PROVIDER_Operation *
341 GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *id,
342                                         const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
343                                         const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
344                                         GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cb,
345                                         void *cb_cls);
346
347
348
349 /**
350  * Consumes an issued ticket. The ticket is persisted
351  * and used to retrieve identity information from the issuer
352  *
353  * @param id the identity provider to use
354  * @param identity the identity that is the subject of the issued ticket (the audience)
355  * @param ticket the issued ticket to consume
356  * @param cb the callback to call
357  * @param cb_cls the callback closure
358  * @return handle to abort the operation
359  */
360 struct GNUNET_IDENTITY_PROVIDER_Operation *
361 GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle *id,
362                                          const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
363                                          const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
364                                          GNUNET_IDENTITY_PROVIDER_AttributeResult cb,
365                                          void *cb_cls);
366
367 /**
368  * Lists all tickets that have been issued to remote
369  * identites (relying parties)
370  *
371  * @param h the identity provider to use
372  * @param identity the issuing identity
373  * @param error_cb function to call on error (i.e. disconnect),
374  *        the handle is afterwards invalid
375  * @param error_cb_cls closure for @a error_cb
376  * @param proc function to call on each ticket; it
377  *        will be called repeatedly with a value (if available)
378  * @param proc_cls closure for @a proc
379  * @param finish_cb function to call on completion
380  *        the handle is afterwards invalid
381  * @param finish_cb_cls closure for @a finish_cb
382  * @return an iterator handle to use for iteration
383  */
384 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *
385 GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
386                                                  const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
387                                                  GNUNET_SCHEDULER_TaskCallback error_cb,
388                                                  void *error_cb_cls,
389                                                  GNUNET_IDENTITY_PROVIDER_TicketCallback proc,
390                                                  void *proc_cls,
391                                                  GNUNET_SCHEDULER_TaskCallback finish_cb,
392                                                  void *finish_cb_cls);
393
394 /**
395  * Lists all tickets that have been issued to remote
396  * identites (relying parties)
397  *
398  * @param id the identity provider to use
399  * @param identity the issuing identity
400  * @param error_cb function to call on error (i.e. disconnect),
401  *        the handle is afterwards invalid
402  * @param error_cb_cls closure for @a error_cb
403  * @param proc function to call on each ticket; it
404  *        will be called repeatedly with a value (if available)
405  * @param proc_cls closure for @a proc
406  * @param finish_cb function to call on completion
407  *        the handle is afterwards invalid
408  * @param finish_cb_cls closure for @a finish_cb
409  * @return an iterator handle to use for iteration
410  */
411 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *
412 GNUNET_IDENTITY_PROVIDER_ticket_iteration_start_rp (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
413                                                     const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
414                                                     GNUNET_SCHEDULER_TaskCallback error_cb,
415                                                     void *error_cb_cls,
416                                                     GNUNET_IDENTITY_PROVIDER_TicketCallback proc,
417                                                     void *proc_cls,
418                                                     GNUNET_SCHEDULER_TaskCallback finish_cb,
419                                                     void *finish_cb_cls);
420
421 /**
422  * Calls the record processor specified in #GNUNET_IDENTITY_PROVIDER_ticket_iteration_start
423  * for the next record.
424  *
425  * @param it the iterator
426  */
427 void
428 GNUNET_IDENTITY_PROVIDER_ticket_iteration_next (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it);
429
430 /**
431  * Stops iteration and releases the idp handle for further calls.  Must
432  * be called on any iteration that has not yet completed prior to calling
433  * #GNUNET_IDENTITY_PROVIDER_disconnect.
434  *
435  * @param it the iterator
436  */
437 void
438 GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it);
439
440 /**
441  * Disconnect from identity provider service.
442  *
443  * @param h identity provider service to disconnect
444  */
445 void
446 GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h);
447
448
449 /**
450  * Cancel an identity provider operation.  Note that the operation MAY still
451  * be executed; this merely cancels the continuation; if the request
452  * was already transmitted, the service may still choose to complete
453  * the operation.
454  *
455  * @param op operation to cancel
456  */
457 void
458 GNUNET_IDENTITY_PROVIDER_cancel (struct GNUNET_IDENTITY_PROVIDER_Operation *op);
459
460 #if 0                           /* keep Emacsens' auto-indent happy */
461 {
462 #endif
463 #ifdef __cplusplus
464 }
465 #endif
466
467
468 /* ifndef GNUNET_IDENTITY_PROVIDER_SERVICE_H */
469 #endif
470
471 /** @} */ /* end of group identity */
472
473 /* end of gnunet_identity_provider_service.h */