Merge branch 'identity_abe' into identity_oidc
[oweals/gnunet.git] / src / include / gnunet_identity_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2013 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 Christian Grothoff
23  *
24  * @file
25  * Identity service; implements identity management for GNUnet
26  *
27  * @defgroup identity  Identity service
28  * Identity management.
29  *
30  * Egos in GNUnet are ECDSA keys.  You assume an ego by using (signing
31  * with) a particular private key.  As GNUnet users are expected to
32  * have many egos, we need an identity service to allow users to
33  * manage their egos.  The identity service manages the egos (private
34  * keys) of the local user; it does NOT manage egos of other users
35  * (public keys).  For giving names to other users and manage their
36  * public keys securely, we use GNS.
37  *
38  * @see [Documentation](https://gnunet.org/identity-subsystem)
39  *
40  * @{
41  */
42 #ifndef GNUNET_IDENTITY_SERVICE_H
43 #define GNUNET_IDENTITY_SERVICE_H
44
45 #ifdef __cplusplus
46 extern "C"
47 {
48 #if 0                           /* keep Emacsens' auto-indent happy */
49 }
50 #endif
51 #endif
52
53 #include "gnunet_util_lib.h"
54
55
56 /**
57  * Version number of GNUnet Identity API.
58  */
59 #define GNUNET_IDENTITY_VERSION 0x00000000
60
61 /**
62  * Handle to access the identity service.
63  */
64 struct GNUNET_IDENTITY_Handle;
65
66 /**
67  * Handle for a ego.
68  */
69 struct GNUNET_IDENTITY_Ego;
70
71 /**
72  * Handle for an operation with the identity service.
73  */
74 struct GNUNET_IDENTITY_Operation;
75
76
77 /**
78  * Obtain the ECC key associated with a ego.
79  *
80  * @param ego the ego
81  * @return associated ECC key, valid as long as the ego is valid
82  */
83 const struct GNUNET_CRYPTO_EcdsaPrivateKey *
84 GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego);
85
86
87 /**
88  * Obtain the ego representing 'anonymous' users.
89  *
90  * @return handle for the anonymous user, must not be freed
91  */
92 const struct GNUNET_IDENTITY_Ego *
93 GNUNET_IDENTITY_ego_get_anonymous (void);
94
95
96 /**
97  * Get the identifier (public key) of an ego.
98  *
99  * @param ego identity handle with the private key
100  * @param pk set to ego's public key
101  */
102 void
103 GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego,
104                                     struct GNUNET_CRYPTO_EcdsaPublicKey *pk);
105
106
107 /**
108  * Method called to inform about the egos of this peer.
109  *
110  * When used with #GNUNET_IDENTITY_connect, this function is
111  * initially called for all egos and then again whenever a
112  * ego's name changes or if it is deleted.  At the end of
113  * the initial pass over all egos, the function is once called
114  * with 'NULL' for @a ego. That does NOT mean that the callback won't
115  * be invoked in the future or that there was an error.
116  *
117  * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get,
118  * this function is only called ONCE, and 'NULL' being passed in
119  * @a ego does indicate an error (i.e. name is taken or no default
120  * value is known).  If @a ego is non-NULL and if '*ctx'
121  * is set in those callbacks, the value WILL be passed to a subsequent
122  * call to the identity callback of #GNUNET_IDENTITY_connect (if
123  * that one was not NULL).
124  *
125  * When an identity is renamed, this function is called with the
126  * (known) @a ego but the NEW @a name.
127  *
128  * When an identity is deleted, this function is called with the
129  * (known) ego and "NULL" for the @a name.  In this case,
130  * the @a ego is henceforth invalid (and the @a ctx should also be
131  * cleaned up).
132  *
133  * @param cls closure
134  * @param ego ego handle
135  * @param ctx context for application to store data for this ego
136  *                 (during the lifetime of this process, initially NULL)
137  * @param name name assigned by the user for this ego,
138  *                   NULL if the user just deleted the ego and it
139  *                   must thus no longer be used
140  */
141 typedef void
142 (*GNUNET_IDENTITY_Callback)(void *cls,
143                             struct GNUNET_IDENTITY_Ego *ego,
144                             void **ctx,
145                             const char *name);
146
147
148 /**
149  * Connect to the identity service.
150  *
151  * @param cfg Configuration to contact the identity service.
152  * @param cb function to call on all identity events, can be NULL
153  * @param cb_cls closure for @a cb
154  * @return handle to communicate with identity service
155  */
156 struct GNUNET_IDENTITY_Handle *
157 GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
158                          GNUNET_IDENTITY_Callback cb,
159                          void *cb_cls);
160
161
162 /**
163  * Obtain the ego that is currently preferred/default for a service.
164  *
165  * @param id identity service to query
166  * @param service_name for which service is an identity wanted
167  * @param cb function to call with the result (will only be called once)
168  * @param cb_cls closure for @a cb
169  * @return handle to abort the operation
170  */
171 struct GNUNET_IDENTITY_Operation *
172 GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *id,
173                      const char *service_name,
174                      GNUNET_IDENTITY_Callback cb,
175                      void *cb_cls);
176
177
178 /**
179  * Function called once the requested operation has
180  * been completed.
181  *
182  * @param cls closure
183  * @param emsg NULL on success, otherwise an error message
184  */
185 typedef void
186 (*GNUNET_IDENTITY_Continuation)(void *cls,
187                                 const char *emsg);
188
189
190 /**
191  * Set the preferred/default ego for a service.
192  *
193  * @param id identity service to inform
194  * @param service_name for which service is an identity set
195  * @param ego new default identity to be set for this service
196  * @param cont function to call once the operation finished
197  * @param cont_cls closure for @a cont
198  * @return handle to abort the operation
199  */
200 struct GNUNET_IDENTITY_Operation *
201 GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *id,
202                      const char *service_name,
203                      struct GNUNET_IDENTITY_Ego *ego,
204                      GNUNET_IDENTITY_Continuation cont,
205                      void *cont_cls);
206
207
208 /**
209  * Disconnect from identity service.
210  *
211  * @param h identity service to disconnect
212  */
213 void
214 GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h);
215
216
217 /**
218  * Create a new ego with the given name.
219  *
220  * @param id identity service to use
221  * @param name desired name
222  * @param cont function to call with the result (will only be called once)
223  * @param cont_cls closure for @a cont
224  * @return handle to abort the operation
225  */
226 struct GNUNET_IDENTITY_Operation *
227 GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
228                         const char *name,
229                         GNUNET_IDENTITY_Continuation cont,
230                         void *cont_cls);
231
232
233 /**
234  * Renames an existing ego.
235  *
236  * @param id identity service to use
237  * @param old_name old name
238  * @param new_name desired new name
239  * @param cb function to call with the result (will only be called once)
240  * @param cb_cls closure for @a cb
241  * @return handle to abort the operation
242  */
243 struct GNUNET_IDENTITY_Operation *
244 GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *id,
245                         const char *old_name,
246                         const char *new_name,
247                         GNUNET_IDENTITY_Continuation cb,
248                         void *cb_cls);
249
250
251 /**
252  * Delete an existing ego.
253  *
254  * @param id identity service to use
255  * @param name name of the identity to delete
256  * @param cb function to call with the result (will only be called once)
257  * @param cb_cls closure for @a cb
258  * @return handle to abort the operation
259  */
260 struct GNUNET_IDENTITY_Operation *
261 GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id,
262                         const char *name,
263                         GNUNET_IDENTITY_Continuation cb,
264                         void *cb_cls);
265
266
267 /**
268  * Cancel an identity operation.  Note that the operation MAY still
269  * be executed; this merely cancels the continuation; if the request
270  * was already transmitted, the service may still choose to complete
271  * the operation.
272  *
273  * @param op operation to cancel
274  */
275 void
276 GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op);
277
278
279 /* ************* convenience API to lookup an ego ***************** */
280
281 /**
282  * Function called with the result.
283  *
284  * @param cls closure
285  * @param ego NULL on error / ego not found
286  */
287 typedef void
288 (*GNUNET_IDENTITY_EgoCallback)(void *cls,
289                                const struct GNUNET_IDENTITY_Ego *ego);
290
291 /**
292  * Handle for ego lookup.
293  */
294 struct GNUNET_IDENTITY_EgoLookup;
295
296
297 /**
298  * Lookup an ego by name.
299  *
300  * @param cfg configuration to use
301  * @param name name to look up
302  * @param cb callback to invoke with the result
303  * @param cb_cls closure for @a cb
304  * @return NULL on error
305  */
306 struct GNUNET_IDENTITY_EgoLookup *
307 GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
308                             const char *name,
309                             GNUNET_IDENTITY_EgoCallback cb,
310                             void *cb_cls);
311
312
313 /**
314  * Abort ego lookup attempt.
315  *
316  * @param el handle for lookup to abort
317  */
318 void
319 GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el);
320
321
322 #if 0                           /* keep Emacsens' auto-indent happy */
323 {
324 #endif
325 #ifdef __cplusplus
326 }
327 #endif
328
329 /* ifndef GNUNET_IDENTITY_SERVICE_H */
330 #endif
331
332 /** @} */ /* end of group identity */
333
334 /* end of gnunet_identity_service.h */