-add serializer
[oweals/gnunet.git] / src / include / gnunet_credential_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012-2014 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  * @author Adnan Husain
24  *
25  * @file
26  * API to the Credential service
27  *
28  * @defgroup credential  Credential service
29  * Credentials
30  *
31  * @{
32  */
33 #ifndef GNUNET_CREDENTIAL_SERVICE_H
34 #define GNUNET_CREDENTIAL_SERVICE_H
35
36 #include "gnunet_util_lib.h"
37 #include "gnunet_gns_service.h"
38 #include "gnunet_identity_service.h"
39
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #if 0                           /* keep Emacsens' auto-indent happy */
44 }
45 #endif
46 #endif
47
48
49 /**
50  * Connection to the Credential service.
51  */
52 struct GNUNET_CREDENTIAL_Handle;
53
54 /**
55  * Handle to control a lookup operation.
56  */
57 struct GNUNET_CREDENTIAL_Request;
58
59 /*
60 * Enum used for checking whether the issuer has the authority to issue credentials or is just a subject
61 */
62 enum GNUNET_CREDENTIAL_CredentialFlags {
63
64   //Subject had credentials before, but have been revoked now
65   GNUNET_CREDENTIAL_FLAG_REVOKED=0,
66
67   //Subject flag indicates that the subject is a holder of this credential and may present it as such
68   GNUNET_CREDENTIAL_FLAG_SUBJECT=1,
69
70   //Issuer flag is used to signify that the subject is allowed to issue this credential and delegate issuance
71   GNUNET_CREDENTIAL_FLAG_ISSUER=2
72
73 };
74
75 GNUNET_NETWORK_STRUCT_BEGIN
76 /**
77  * The credential record 
78  */
79 struct GNUNET_CREDENTIAL_CredentialRecordData {
80   
81   /**
82    * The signature for this credential by the issuer
83    */
84   struct GNUNET_CRYPTO_EcdsaSignature signature;
85   
86   /**
87    * Signature meta
88    */
89   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
90
91   /**
92    * Public key of the issuer
93    */
94   struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
95   
96   /**
97    * Public key of the subject this credential was issued to
98    */
99   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
100   
101   /**
102    * Expiration time of this credential
103    */
104   uint64_t expiration GNUNET_PACKED;
105   
106     /**
107    * Followed by the attribute string
108    */
109 };
110
111
112 /**
113  * The attribute delegation record
114 */
115 struct GNUNET_CREDENTIAL_AttributeRecordData {
116   
117   /**
118    * Public key of the subject this attribute was delegated to
119    */
120   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
121   
122   /**
123    * Followed by the attribute that was delegated to as string
124    * May be empty
125    */
126 };
127
128 /**
129  * A delegation
130 */
131 struct GNUNET_CREDENTIAL_Delegation {
132   
133   /**
134    * The issuer of the delegation
135    */
136   struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
137
138   /**
139    * Public key of the subject this attribute was delegated to
140    */
141   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
142
143   /**
144    * Length of the attribute
145    */
146   uint32_t issuer_attribute_len;
147
148   /**
149    * The attribute
150    */
151   const char *issuer_attribute;
152
153   /**
154    * Length of the attribute
155    */
156   uint32_t subject_attribute_len;
157
158   /**
159    * The attribute
160    */
161   const char *subject_attribute;
162 };
163
164
165 /**
166  * A credential
167 */
168 struct GNUNET_CREDENTIAL_Credential {
169   
170   /**
171    * The issuer of the credential
172    */
173   struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
174
175   /**
176    * Public key of the subject this credential was issued to
177    */
178   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
179
180   /**
181    * Length of the attribute
182    */
183   uint32_t issuer_attribute_len;
184
185   /**
186    * The attribute
187    */
188   const char *issuer_attribute;
189   
190 };
191
192
193 GNUNET_NETWORK_STRUCT_END
194
195
196
197 /**
198  * Initialize the connection with the Credential service.
199  *
200  * @param cfg configuration to use
201  * @return handle to the Credential service, or NULL on error
202  */
203 struct GNUNET_CREDENTIAL_Handle *
204 GNUNET_CREDENTIAL_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
205
206
207 /**
208  * Shutdown connection with the Credentail service.
209  *
210  * @param handle connection to shut down
211  */
212 void
213 GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle);
214
215
216 /**
217  * Iterator called on obtained result for an attribute verification.
218  *
219  * @param cls closure
220  * @param issuer the issuer of the attribute NULL if verification failed
221  * @param result the result of the verification
222  * @param rd the records in reply
223  */
224 typedef void (*GNUNET_CREDENTIAL_VerifyResultProcessor) (void *cls,
225                                                          unsigned int d_count,
226                                                          struct GNUNET_CREDENTIAL_Delegation *delegation_chain,
227                                                          struct GNUNET_CREDENTIAL_Credential *credential);
228
229 /**
230  * Iterator called on obtained result for an attribute delegation.
231  *
232  * @param cls closure
233  * @param success GNUNET_YES if successful
234  * @param result the record data that can be handed to the subject
235  */
236 typedef void (*GNUNET_CREDENTIAL_DelegateResultProcessor) (void *cls,
237                                                   uint32_t success);
238
239 /**
240  * Iterator called on obtained result for an attribute delegation removal.
241  *
242  * @param cls closure
243  * @param success GNUNET_YES if successful
244  * @param result the record data that can be handed to the subject
245  */
246 typedef void (*GNUNET_CREDENTIAL_RemoveDelegateResultProcessor) (void *cls,
247                                                   uint32_t success);
248
249
250
251
252 /**
253  * Performs attribute verification.
254  * Checks if there is a delegation chain from
255  * attribute ``issuer_attribute'' issued by the issuer
256  * with public key ``issuer_key'' maps to the attribute
257  * ``subject_attribute'' claimed by the subject with key
258  * ``subject_key''
259  *
260  * @param handle handle to the Credential service
261  * @param issuer_key the issuer public key
262  * @param issuer_attribute the issuer attribute
263  * @param subject_key the subject public key
264  * @param subject_attribute the attribute claimed by the subject
265  * @param proc function to call on result
266  * @param proc_cls closure for processor
267  * @return handle to the queued request
268  */
269 struct GNUNET_CREDENTIAL_Request*
270 GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
271                           const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
272                           const char *issuer_attribute,
273                           const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
274                           const char *subject_attribute,
275                           GNUNET_CREDENTIAL_VerifyResultProcessor proc,
276                           void *proc_cls);
277
278 /**
279  * Delegate an attribute
280  *
281  * @param handle handle to the Credential service
282  * @param issuer the ego that should be used to delegate the attribute
283  * @param attribute the name of the attribute to delegate
284  * @param subject the subject of the delegation
285  * @param delegated_attribute the name of the attribute that is delegated to
286  * @return handle to the queued request
287  */
288 struct GNUNET_CREDENTIAL_Request *
289 GNUNET_CREDENTIAL_add_delegation (struct GNUNET_CREDENTIAL_Handle *handle,
290                                   struct GNUNET_IDENTITY_Ego *issuer,
291                                   const char *attribute,
292                                   struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
293                                   const char *delegated_attribute,
294                                   GNUNET_CREDENTIAL_DelegateResultProcessor proc,
295                                   void *proc_cls);
296
297 /**
298  * Remove a delegation
299  *
300  * @param handle handle to the Credential service
301  * @param issuer the ego that was used to delegate the attribute
302  * @param attribute the name of the attribute that is delegated
303  * @return handle to the queued request
304  */
305 struct GNUNET_CREDENTIAL_Request *
306 GNUNET_CREDENTIAL_remove_delegation (struct GNUNET_CREDENTIAL_Handle *handle,
307                                   struct GNUNET_IDENTITY_Ego *issuer,
308                                   const char *attribute,
309                                   GNUNET_CREDENTIAL_RemoveDelegateResultProcessor proc,
310                                   void *proc_cls);
311
312
313
314 /**
315  * Issue an attribute to a subject
316  *
317  * @param handle handle to the Credential service
318  * @param issuer the ego that should be used to issue the attribute
319  * @param subject the subject of the attribute
320  * @param attribute the name of the attribute
321  * @param expiration the TTL of the credential
322  * @return handle to the queued request
323  */
324 struct GNUNET_CREDENTIAL_CredentialRecordData *
325 GNUNET_CREDENTIAL_issue (struct GNUNET_CREDENTIAL_Handle *handle,
326                          const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
327                          struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
328                          const char *attribute,
329                          struct GNUNET_TIME_Absolute *expiration);
330
331
332 /**
333  * Remove a credential
334  *
335  * @param handle handle to the Credential service
336  * @param issuer the identity that issued the credential
337  * @param subject the subject of the credential
338  * @param credential the name of the credential
339  * @return handle to the queued request
340  */
341 /**
342   struct GNUNET_CREDENTIAL_IssueRequest *
343   GNUNET_CREDENTIAL_remove (struct GNUNET_CREDENTIAL_Handle *handle,
344   struct GNUNET_IDENTITY_Ego *issuer,
345   struct GNUNET_IDENTITY_Ego *subject,
346   const char *credential,
347   GNUNET_CREDENTIAL_IssueResultProcessor proc,
348   void *proc_cls);
349   */
350
351
352 /**
353  * Cancel pending lookup request
354  *
355  * @param lr the lookup request to cancel
356  */
357 void
358 GNUNET_CREDENTIAL_verify_cancel (struct GNUNET_CREDENTIAL_Request *vr);
359
360
361 #if 0                           /* keep Emacsens' auto-indent happy */
362 {
363 #endif
364 #ifdef __cplusplus
365 }
366 #endif
367
368 #endif
369
370 /** @} */  /* end of group */